VirtualBox

source: vbox/trunk/src/recompiler/tests/test_path.c@ 6359

Last change on this file since 6359 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
File size: 4.5 KB
Line 
1/* Test path override code */
2#define _GNU_SOURCE
3#include "../path.c"
4#include <stdarg.h>
5#include <sys/stat.h>
6#include <fcntl.h>
7
8/* Any log message kills the test. */
9void gemu_log(const char *fmt, ...)
10{
11 va_list ap;
12
13 fprintf(stderr, "FATAL: ");
14 va_start(ap, fmt);
15 vfprintf(stderr, fmt, ap);
16 va_end(ap);
17 exit(1);
18}
19
20#define NO_CHANGE(_path) \
21 do { \
22 if (strcmp(path(_path), _path) != 0) return __LINE__; \
23 } while(0)
24
25#define CHANGE_TO(_path, _newpath) \
26 do { \
27 if (strcmp(path(_path), _newpath) != 0) return __LINE__; \
28 } while(0)
29
30static void cleanup(void)
31{
32 unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE");
33 unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE2");
34 unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE3");
35 unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE4");
36 unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE5");
37 rmdir("/tmp/qemu-test_path/DIR1/DIR2");
38 rmdir("/tmp/qemu-test_path/DIR1/DIR3");
39 rmdir("/tmp/qemu-test_path/DIR1");
40 rmdir("/tmp/qemu-test_path");
41}
42
43static unsigned int do_test(void)
44{
45 if (mkdir("/tmp/qemu-test_path", 0700) != 0)
46 return __LINE__;
47
48 if (mkdir("/tmp/qemu-test_path/DIR1", 0700) != 0)
49 return __LINE__;
50
51 if (mkdir("/tmp/qemu-test_path/DIR1/DIR2", 0700) != 0)
52 return __LINE__;
53
54 if (mkdir("/tmp/qemu-test_path/DIR1/DIR3", 0700) != 0)
55 return __LINE__;
56
57 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE", 0600)) != 0)
58 return __LINE__;
59
60 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE2", 0600)) != 0)
61 return __LINE__;
62
63 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE3", 0600)) != 0)
64 return __LINE__;
65
66 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE4", 0600)) != 0)
67 return __LINE__;
68
69 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE5", 0600)) != 0)
70 return __LINE__;
71
72 init_paths("/tmp/qemu-test_path");
73
74 NO_CHANGE("/tmp");
75 NO_CHANGE("/tmp/");
76 NO_CHANGE("/tmp/qemu-test_path");
77 NO_CHANGE("/tmp/qemu-test_path/");
78 NO_CHANGE("/tmp/qemu-test_path/D");
79 NO_CHANGE("/tmp/qemu-test_path/DI");
80 NO_CHANGE("/tmp/qemu-test_path/DIR");
81 NO_CHANGE("/tmp/qemu-test_path/DIR1");
82 NO_CHANGE("/tmp/qemu-test_path/DIR1/");
83
84 NO_CHANGE("/D");
85 NO_CHANGE("/DI");
86 NO_CHANGE("/DIR");
87 NO_CHANGE("/DIR2");
88 NO_CHANGE("/DIR1.");
89
90 CHANGE_TO("/DIR1", "/tmp/qemu-test_path/DIR1");
91 CHANGE_TO("/DIR1/", "/tmp/qemu-test_path/DIR1");
92
93 NO_CHANGE("/DIR1/D");
94 NO_CHANGE("/DIR1/DI");
95 NO_CHANGE("/DIR1/DIR");
96 NO_CHANGE("/DIR1/DIR1");
97
98 CHANGE_TO("/DIR1/DIR2", "/tmp/qemu-test_path/DIR1/DIR2");
99 CHANGE_TO("/DIR1/DIR2/", "/tmp/qemu-test_path/DIR1/DIR2");
100
101 CHANGE_TO("/DIR1/DIR3", "/tmp/qemu-test_path/DIR1/DIR3");
102 CHANGE_TO("/DIR1/DIR3/", "/tmp/qemu-test_path/DIR1/DIR3");
103
104 NO_CHANGE("/DIR1/DIR2/F");
105 NO_CHANGE("/DIR1/DIR2/FI");
106 NO_CHANGE("/DIR1/DIR2/FIL");
107 NO_CHANGE("/DIR1/DIR2/FIL.");
108
109 CHANGE_TO("/DIR1/DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
110 CHANGE_TO("/DIR1/DIR2/FILE2", "/tmp/qemu-test_path/DIR1/DIR2/FILE2");
111 CHANGE_TO("/DIR1/DIR2/FILE3", "/tmp/qemu-test_path/DIR1/DIR2/FILE3");
112 CHANGE_TO("/DIR1/DIR2/FILE4", "/tmp/qemu-test_path/DIR1/DIR2/FILE4");
113 CHANGE_TO("/DIR1/DIR2/FILE5", "/tmp/qemu-test_path/DIR1/DIR2/FILE5");
114
115 NO_CHANGE("/DIR1/DIR2/FILE6");
116 NO_CHANGE("/DIR1/DIR2/FILE/X");
117
118 CHANGE_TO("/DIR1/../DIR1", "/tmp/qemu-test_path/DIR1");
119 CHANGE_TO("/DIR1/../DIR1/", "/tmp/qemu-test_path/DIR1");
120 CHANGE_TO("/../DIR1", "/tmp/qemu-test_path/DIR1");
121 CHANGE_TO("/../DIR1/", "/tmp/qemu-test_path/DIR1");
122 CHANGE_TO("/DIR1/DIR2/../DIR2", "/tmp/qemu-test_path/DIR1/DIR2");
123 CHANGE_TO("/DIR1/DIR2/../DIR2/../../DIR1/DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
124 CHANGE_TO("/DIR1/DIR2/../DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
125
126 NO_CHANGE("/DIR1/DIR2/../DIR1");
127 NO_CHANGE("/DIR1/DIR2/../FILE");
128
129 CHANGE_TO("/./DIR1/DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
130 CHANGE_TO("/././DIR1/DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
131 CHANGE_TO("/DIR1/./DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
132 CHANGE_TO("/DIR1/././DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
133 CHANGE_TO("/DIR1/DIR2/./FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
134 CHANGE_TO("/DIR1/DIR2/././FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
135 CHANGE_TO("/./DIR1/./DIR2/./FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
136
137 return 0;
138}
139
140int main(int argc, char *argv[])
141{
142 int ret;
143
144 ret = do_test();
145 cleanup();
146 if (ret) {
147 fprintf(stderr, "test_path: failed on line %i\n", ret);
148 return 1;
149 }
150 return 0;
151}
152
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette