]> git.saurik.com Git - apple/hfs.git/blob - tests/cases/test-unicode-file-names.c
hfs-407.1.3.tar.gz
[apple/hfs.git] / tests / cases / test-unicode-file-names.c
1 #include <glob.h>
2 #include <sys/fcntl.h>
3 #include <sys/stat.h>
4 #include <unistd.h>
5 #include <spawn.h>
6
7 #include "hfs-tests.h"
8 #include "test-utils.h"
9 #include "disk-image.h"
10
11 TEST(unicode_file_names)
12
13 static disk_image_t *di;
14
15 int run_unicode_file_names(__unused test_ctx_t *ctx)
16 {
17 di = disk_image_get();
18 char *dir;
19
20 asprintf(&dir, "%s/unicode-file-names", di->mount_point);
21
22 pid_t pid;
23 assert_no_err(posix_spawn(&pid, "/bin/rm", NULL, NULL,
24 (char *[]){ "rm", "-rf", dir, NULL }, NULL));
25 int stat;
26 assert_with_errno(waitpid(pid, &stat, 0) == pid);
27
28 assert_no_err(mkdir(dir, 0777));
29
30 char *path;
31 asprintf(&path, "%s/file-\xcd\x80\xcd\x81\xcd\x82\xcd\x83\xcd\x84\xcd\x85\xcd\x86\xcd\x87\xcd\x88\xcd\x89\xcd\x90", dir);
32
33 int fd;
34 assert_with_errno((fd = open(path, O_RDWR | O_CREAT, 0666)) >= 0);
35
36 assert_no_err(close(fd));
37
38 /*
39 * Create a hard link (so that we can force the cache to
40 * be purged).
41 */
42 char *path2;
43 asprintf(&path2, "%s/hard-link", dir);
44 assert_no_err(link(path, path2));
45
46 glob_t gl;
47
48 assert_no_err(chdir(dir));
49
50 assert_no_err(glob("*", 0, NULL, &gl));
51
52 int i;
53 for (i = 0; i < gl.gl_matchc; ++i) {
54 if (!strncmp(gl.gl_pathv[i], "file", 4))
55 goto found;
56 }
57
58 assert_fail("could not find file!");
59
60 found:
61
62 // Paths should be different: gl_pathv should be normalised
63 assert(strcmp(gl.gl_pathv[i], path) != 0);
64
65 char *path3;
66 asprintf(&path3, "%s/%s", dir, gl.gl_pathv[i]);
67
68 assert((fd = open(path3, O_RDONLY)) >= 0);
69
70 assert_no_err(unlink(path3));
71 assert_no_err (close(fd));
72
73 free(dir);
74 free(path);
75 free(path2);
76 free(path3);
77
78 return 0;
79 }