]>
git.saurik.com Git - apple/hfs.git/blob - tests/cases/test-readdir.c
7 #include "test-utils.h"
8 #include "disk-image.h"
13 static disk_image_t
*di
;
15 int run_readdir(__unused test_ctx_t
*ctx
)
17 di
= disk_image_get();
20 asprintf(&path
, "%s/readdir.data", di
->mount_point
);
22 systemx("/bin/rm", "-rf", path
, NULL
);
23 assert_no_err(mkdir(path
, 0777));
26 asprintf(&file
, "%s/file1", path
);
30 assert_with_errno((fd
= open(file
, O_CREAT
| O_TRUNC
| O_RDWR
, 0666)) >= 0);
31 assert_no_err(close(fd
));
33 file
[strlen(file
) - 1] = '2';
34 assert_with_errno((fd
= open(file
, O_CREAT
| O_TRUNC
| O_RDWR
, 0666)) >= 0);
35 assert_no_err(close(fd
));
39 assert_with_errno((dir
= opendir(path
)) != NULL
);
41 struct dirent entry
, *dp
;
42 assert_no_err(readdir_r(dir
, &entry
, &dp
));
43 assert(!strcmp(dp
->d_name
, "."));
44 assert_no_err(readdir_r(dir
, &entry
, &dp
));
45 assert(!strcmp(dp
->d_name
, ".."));
46 assert_no_err(readdir_r(dir
, &entry
, &dp
));
47 assert(!strcmp(dp
->d_name
, "file1"));
48 assert_no_err(readdir_r(dir
, &entry
, &dp
));
49 assert(!strcmp(dp
->d_name
, "file2"));
50 assert_no_err(readdir_r(dir
, &entry
, &dp
));
55 assert_with_errno((dir
= opendir(path
)) != NULL
);
57 assert_no_err(readdir_r(dir
, &entry
, &dp
));
58 assert(!strcmp(dp
->d_name
, "."));
59 assert_no_err(readdir_r(dir
, &entry
, &dp
));
60 assert(!strcmp(dp
->d_name
, ".."));
61 assert_no_err(readdir_r(dir
, &entry
, &dp
));
62 assert(!strcmp(dp
->d_name
, "file1"));
63 assert_no_err(readdir_r(dir
, &entry
, &dp
));
64 assert(!strcmp(dp
->d_name
, "file2"));
65 assert_no_err(readdir_r(dir
, &entry
, &dp
));
67 assert_no_err(readdir_r(dir
, &entry
, &dp
));
72 assert_no_err(readdir_r(dir
, &entry
, &dp
));
75 assert_no_err(closedir(dir
));
77 assert_with_errno((dir
= opendir(path
)) != NULL
);
79 assert_no_err(readdir_r(dir
, &entry
, &dp
));
80 assert(!strcmp(dp
->d_name
, "."));
81 assert_no_err(readdir_r(dir
, &entry
, &dp
));
82 assert(!strcmp(dp
->d_name
, ".."));
83 assert_no_err(readdir_r(dir
, &entry
, &dp
));
84 assert(!strcmp(dp
->d_name
, "file1"));
85 assert_no_err(readdir_r(dir
, &entry
, &dp
));
86 assert_no_err(readdir_r(dir
, &entry
, &dp
));
88 assert_no_err(readdir_r(dir
, &entry
, &dp
));
91 file
[strlen(file
) - 1] = '1';
94 assert_no_err(readdir_r(dir
, &entry
, &dp
));
97 assert_no_err(closedir(dir
));
99 assert_with_errno((dir
= opendir(path
)) != NULL
);
100 assert_with_errno((fd
= open(file
, O_CREAT
| O_TRUNC
| O_RDWR
, 0666)) >= 0);
101 assert_no_err(close(fd
));
105 assert_no_err(readdir_r(dir
, &entry
, &dp
));
108 assert_no_err(readdir_r(dir
, &entry
, &dp
));
112 assert_no_err(unlink(file
));
115 assert_no_err(closedir(dir
));