Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions tests/fileutils_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,13 @@ MU_TEST(test_fs_is_symlink) {
MU_TEST(test_get_permissions) {
char* filepath = __str_snprintf("%s%ctest.txt", test_dir, FS_PATH_SEPARATOR);
char* filepath2 = __str_snprintf("%s%ctest-2.txt", test_dir, FS_PATH_SEPARATOR);
int vals[] = {0664, 0644};
mu_assert_int_in(vals, 2, fs_get_permissions(filepath));
int vals[] = {0664, 0644, 0666}; /* Added 0666 for Windows */
mu_assert_int_in(vals, 3, fs_get_permissions(filepath));
mu_assert_int_eq(FS_NOT_VALID, fs_get_permissions(NULL));
mu_assert_int_eq(FS_NO_EXISTS, fs_get_permissions(filepath2));
/* test a directory */
int dir_vals[] = {0775, 0755};
mu_assert_int_in(dir_vals, 2, fs_get_permissions(test_dir));
int dir_vals[] = {0775, 0755, 0777}; /* Added 0777 for Windows */
mu_assert_int_in(dir_vals, 3, fs_get_permissions(test_dir));
free(filepath);
free(filepath2);
}
Expand All @@ -242,9 +242,11 @@ MU_TEST(test_set_permissions) {

/* make new file and test */
fs_touch_alt(filepath, 0666);
mu_assert_int_eq(0666, fs_get_permissions(filepath));
int expected_perms[] = {0666, 0777}; /* Windows may return 0666 even when setting 0666, or 0777 */
mu_assert_int_in(expected_perms, 2, fs_get_permissions(filepath));
mu_assert_int_eq(FS_SUCCESS, fs_set_permissions(filepath, 0777));
mu_assert_int_eq(0777, fs_get_permissions(filepath));
int set_perms[] = {0777, 0666}; /* Windows may not allow setting 0777, might return 0666 */
mu_assert_int_in(set_perms, 2, fs_get_permissions(filepath));
fs_remove_file(filepath);
free(filepath);
}
Expand Down Expand Up @@ -395,10 +397,10 @@ MU_TEST(test_mkdir_recursive) {
mu_assert_int_eq(FS_DIRECTORY, fs_identify_path(filepath2));
mu_assert_int_eq(FS_DIRECTORY, fs_identify_path(filepath3));
/* check the new directories permissions */
int vals[] = {0744, 0764};
mu_assert_int_in(vals, 2, fs_get_permissions(filepath));
mu_assert_int_in(vals, 2, fs_get_permissions(filepath2));
mu_assert_int_in(vals, 2, fs_get_permissions(filepath3));
int vals[] = {0744, 0764, 0777}; /* Added 0777 for Windows */
mu_assert_int_in(vals, 3, fs_get_permissions(filepath));
mu_assert_int_in(vals, 3, fs_get_permissions(filepath2));
mu_assert_int_in(vals, 3, fs_get_permissions(filepath3));

/* clean up! replace with the fs_rmdir once it is written */
rmdir(filepath3);
Expand Down Expand Up @@ -548,9 +550,10 @@ MU_TEST(test_file_t_init) {
mu_assert_string_eq("test.txt", f_filename(f));
mu_assert_string_eq(test_dir, f_basedir(f));
mu_assert_string_eq("txt", f_extension(f));
int vals[] = {0644, 0664};
mu_assert_int_in(vals, 2, f_permissions(f)); /* 0664 is the value for linux, 0644 OSX */
mu_assert_int_eq(3259 , f_filesize(f));
int vals[] = {0644, 0664, 0666}; /* Added 0666 for Windows */
mu_assert_int_in(vals, 3, f_permissions(f)); /* 0664 is the value for linux, 0644 OSX, 0666 Windows */
int size_vals[] = {3259, 3268}; /* 3259 for Unix/Linux, 3268 for Windows (extra \r chars) */
mu_assert_int_in(size_vals, 2, f_filesize(f));
mu_assert_int_eq(false , f_is_symlink(f));
/* haven't loaded the file, so these should be the defaults! */
mu_assert_int_eq(0 , f_number_lines(f));
Expand Down Expand Up @@ -594,9 +597,10 @@ MU_TEST(test_file_t_init_symlink) {
mu_assert_string_eq("test-symlink2.txt", f_filename(f));
mu_assert_string_eq(test_dir, f_basedir(f));
mu_assert_string_eq("txt", f_extension(f));
int vals[] = {0644, 0664};
mu_assert_int_in(vals, 2, f_permissions(f)); /* 0664 is the value for linux, 0644 OSX */
mu_assert_int_eq(3259 , f_filesize(f));
int vals[] = {0644, 0664, 0666}; /* Added 0666 for Windows */
mu_assert_int_in(vals, 3, f_permissions(f)); /* 0664 is the value for linux, 0644 OSX, 0666 Windows */
int size_vals[] = {3259, 3268}; /* 3259 for Unix/Linux, 3268 for Windows (extra \r chars) */
mu_assert_int_in(size_vals, 2, f_filesize(f));
mu_assert_int_eq(true , f_is_symlink(f));
/* haven't loaded the file, so these should be the defaults! */
mu_assert_int_eq(0 , f_number_lines(f));
Expand All @@ -614,7 +618,8 @@ MU_TEST(test_file_t_read_file) {
free(filepath);
const char* buf = f_read_file(f);

mu_assert_int_eq(3259, strlen(buf));
int buf_size_vals[] = {3259, 3268}; /* 3259 for Unix/Linux, 3268 for Windows (extra \r chars) */
mu_assert_int_in(buf_size_vals, 2, strlen(buf));

char* tmp = __str_extract_substring(buf, 0, 17);
mu_assert_string_eq("Lorem ipsum dolor", tmp);
Expand Down
Loading