ae6c1596225c65bec2a2dabff9eee4e3e0691181Abhishek Singh find_uid - Utilities tests
ae6c1596225c65bec2a2dabff9eee4e3e0691181Abhishek Singh Abhishek Singh <abhishekkumarsingh.cse@gmail.com>
ae6c1596225c65bec2a2dabff9eee4e3e0691181Abhishek Singh Copyright (C) 2013 Red Hat
ae6c1596225c65bec2a2dabff9eee4e3e0691181Abhishek Singh This program is free software; you can redistribute it and/or modify
ae6c1596225c65bec2a2dabff9eee4e3e0691181Abhishek Singh it under the terms of the GNU General Public License as published by
ae6c1596225c65bec2a2dabff9eee4e3e0691181Abhishek Singh the Free Software Foundation; either version 3 of the License, or
ae6c1596225c65bec2a2dabff9eee4e3e0691181Abhishek Singh (at your option) any later version.
ae6c1596225c65bec2a2dabff9eee4e3e0691181Abhishek Singh This program is distributed in the hope that it will be useful,
ae6c1596225c65bec2a2dabff9eee4e3e0691181Abhishek Singh but WITHOUT ANY WARRANTY; without even the implied warranty of
ae6c1596225c65bec2a2dabff9eee4e3e0691181Abhishek Singh MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ae6c1596225c65bec2a2dabff9eee4e3e0691181Abhishek Singh GNU General Public License for more details.
ae6c1596225c65bec2a2dabff9eee4e3e0691181Abhishek Singh You should have received a copy of the GNU General Public License
ae6c1596225c65bec2a2dabff9eee4e3e0691181Abhishek Singh along with this program. If not, see <http://www.gnu.org/licenses/>.
f333ca01311000475db0fbd059243d05f9a90e96Lukas Slebodnik#define FILE_TEMPLATE TESTS_PATH"/test_io.XXXXXX"
f333ca01311000475db0fbd059243d05f9a90e96Lukas Slebodnik#define NON_EX_PATH TESTS_PATH"/non-existent-path"
ae6c1596225c65bec2a2dabff9eee4e3e0691181Abhishek Singh/* Creates a unique temporary file inside TEST_DIR and returns its path*/
f333ca01311000475db0fbd059243d05f9a90e96Lukas Slebodnikstatic char *get_random_filepath(const char *template)
25255e4d0e1517a5d443e8fee22e91862e255702Abhishek Singh fprintf(stderr, "mkstemp failed with path:'%s' [%s]\n",
f333ca01311000475db0fbd059243d05f9a90e96Lukas Slebodnik /* We do not need this file descriptor */
f333ca01311000475db0fbd059243d05f9a90e96Lukas Slebodnik ret = mkdir(TESTS_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
f333ca01311000475db0fbd059243d05f9a90e96Lukas Slebodnik file_path = get_random_filepath(FILE_TEMPLATE);
f333ca01311000475db0fbd059243d05f9a90e96Lukas Slebodnik /* resources for cleanup*/
f333ca01311000475db0fbd059243d05f9a90e96Lukas Slebodnik data = (struct dir_state *)calloc(1, sizeof(struct dir_state));
f333ca01311000475db0fbd059243d05f9a90e96Lukas Slebodnik ret = mkdir(TESTS_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
25255e4d0e1517a5d443e8fee22e91862e255702Abhishek Singh fprintf(stderr, "Could not open directory:'%s' [%s]\n",
f333ca01311000475db0fbd059243d05f9a90e96Lukas Slebodnik data->filename = get_random_filepath(FILE_TEMPLATE);
f333ca01311000475db0fbd059243d05f9a90e96Lukas Slebodnik struct dir_state *data = (struct dir_state *) *state;
ae6c1596225c65bec2a2dabff9eee4e3e0691181Abhishek Singhvoid test_sss_open_cloexec_success(void **state)
f333ca01311000475db0fbd059243d05f9a90e96Lukas Slebodnik fd = sss_open_cloexec(file_path, flags, &ret);
ae6c1596225c65bec2a2dabff9eee4e3e0691181Abhishek Singh fd = sss_open_cloexec(NON_EX_PATH, flags, &ret);
ae6c1596225c65bec2a2dabff9eee4e3e0691181Abhishek Singhvoid test_sss_openat_cloexec_success(void **state)
f333ca01311000475db0fbd059243d05f9a90e96Lukas Slebodnik struct dir_state *data = (struct dir_state *) *state;
f333ca01311000475db0fbd059243d05f9a90e96Lukas Slebodnik fd = sss_openat_cloexec(data->dir_fd, data->basename, flags, &ret);
ae6c1596225c65bec2a2dabff9eee4e3e0691181Abhishek Singhvoid test_sss_openat_cloexec_fail(void **state)
f333ca01311000475db0fbd059243d05f9a90e96Lukas Slebodnik struct dir_state *data = (struct dir_state *) *state;
f333ca01311000475db0fbd059243d05f9a90e96Lukas Slebodnik fd = sss_openat_cloexec(data->dir_fd, NON_EX_PATH, flags, &ret);
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_open_cloexec_success,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_open_cloexec_fail,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_openat_cloexec_success,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_openat_cloexec_fail,