1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2011. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.com/license/LICENSE. |
---|
8 | * |
---|
9 | * $Id$ |
---|
10 | */ |
---|
11 | |
---|
12 | #ifdef HAVE_CONFIG_H |
---|
13 | #include "config.h" |
---|
14 | #endif |
---|
15 | |
---|
16 | #include <sys/stat.h> |
---|
17 | #include <fcntl.h> |
---|
18 | #include <errno.h> |
---|
19 | #include <stdio.h> |
---|
20 | #include <stdint.h> |
---|
21 | #include <stdlib.h> |
---|
22 | #include <string.h> |
---|
23 | #include <unistd.h> |
---|
24 | |
---|
25 | #include "fstest.h" |
---|
26 | #include "pmacros.h" |
---|
27 | |
---|
28 | #define BUF_SIZE 100 |
---|
29 | |
---|
30 | void make_multiple_files (char **files,int is_directory) |
---|
31 | { |
---|
32 | int i; |
---|
33 | int status; |
---|
34 | int fd; |
---|
35 | |
---|
36 | i = 0; |
---|
37 | if (is_directory){ |
---|
38 | while (files[i]) { |
---|
39 | printf ("Making directory %s\n", files[i]); |
---|
40 | status = mkdir (files[i], S_IRWXU); |
---|
41 | rtems_test_assert (!status); |
---|
42 | i++; |
---|
43 | } |
---|
44 | }else { |
---|
45 | while (files[i]) { |
---|
46 | printf ("Create file %s\n", files[i]); |
---|
47 | fd=creat(files[i],S_IRWXU); |
---|
48 | status=close(fd); |
---|
49 | rtems_test_assert (!status); |
---|
50 | i++; |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | puts (""); |
---|
55 | } |
---|
56 | |
---|
57 | void remove_multiple_files (char **files,int is_directory) |
---|
58 | { |
---|
59 | int i; |
---|
60 | int status; |
---|
61 | |
---|
62 | i = 0; |
---|
63 | while (files[i]) { |
---|
64 | i++; |
---|
65 | } |
---|
66 | |
---|
67 | if (is_directory){ |
---|
68 | while (i) { |
---|
69 | i--; |
---|
70 | printf ("Removing directory %s\n", files[i]); |
---|
71 | status = rmdir (files[i]); |
---|
72 | rtems_test_assert (!status); |
---|
73 | } |
---|
74 | }else { |
---|
75 | while (i) { |
---|
76 | i--; |
---|
77 | printf ("Removing file %s\n", files[i]); |
---|
78 | status = unlink (files[i]); |
---|
79 | rtems_test_assert (!status); |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | puts (""); |
---|
84 | } |
---|
85 | |
---|
86 | void path_eval_test01 (void) |
---|
87 | { |
---|
88 | char *valid_path[] = { |
---|
89 | "/test1/", |
---|
90 | "tets2", |
---|
91 | "///test3", |
---|
92 | "test4////", |
---|
93 | "../../test5", |
---|
94 | "/test1/../test6", |
---|
95 | "./test7/", |
---|
96 | ".././test8", |
---|
97 | "test8/./../test9", |
---|
98 | "///test9/../test10", |
---|
99 | 0 |
---|
100 | }; |
---|
101 | char *valid_file[]={ |
---|
102 | "/test1", |
---|
103 | "tets2", |
---|
104 | "///test3", |
---|
105 | "test4", |
---|
106 | "../../test5", |
---|
107 | "/../test6", |
---|
108 | "./test7", |
---|
109 | ".././test8", |
---|
110 | "/./../test9", |
---|
111 | "//../test10", |
---|
112 | 0 |
---|
113 | }; |
---|
114 | |
---|
115 | char *valid_relative_path[]={ |
---|
116 | "test1", |
---|
117 | "tets2", |
---|
118 | "test3", |
---|
119 | "test4", |
---|
120 | "test5", |
---|
121 | "test6", |
---|
122 | "test7", |
---|
123 | "test8", |
---|
124 | "test9", |
---|
125 | "test10", |
---|
126 | 0 |
---|
127 | |
---|
128 | }; |
---|
129 | |
---|
130 | char *valid_name[] = { |
---|
131 | "!#$%&()-@^_`{}~'", |
---|
132 | "0_1_A", |
---|
133 | "aaa bbb", |
---|
134 | "ccc....ddd", |
---|
135 | " fff", |
---|
136 | 0 |
---|
137 | }; |
---|
138 | |
---|
139 | |
---|
140 | make_multiple_files(valid_path,1); |
---|
141 | make_multiple_files (valid_name,1); |
---|
142 | |
---|
143 | remove_multiple_files(valid_relative_path,1); |
---|
144 | remove_multiple_files(valid_name,1); |
---|
145 | |
---|
146 | make_multiple_files(valid_file,0); |
---|
147 | make_multiple_files (valid_name,0); |
---|
148 | |
---|
149 | remove_multiple_files(valid_relative_path,0); |
---|
150 | remove_multiple_files(valid_name,0); |
---|
151 | |
---|
152 | } |
---|
153 | void path_eval_test02(void ) |
---|
154 | { |
---|
155 | |
---|
156 | int status; |
---|
157 | char buf[BUF_SIZE]; |
---|
158 | char* cwd; |
---|
159 | |
---|
160 | mode_t mode = S_IRWXU|S_IRWXG|S_IRWXO; |
---|
161 | puts("mkdir /tmp/a/b"); |
---|
162 | status=mkdir("/tmp",mode); |
---|
163 | rtems_test_assert(status==0); |
---|
164 | status=mkdir("/tmp/a",mode); |
---|
165 | rtems_test_assert(status==0); |
---|
166 | status=mkdir("/tmp/a/b",mode); |
---|
167 | rtems_test_assert(status==0); |
---|
168 | |
---|
169 | cwd=getcwd(buf,BUF_SIZE); |
---|
170 | rtems_test_assert(cwd!=NULL); |
---|
171 | |
---|
172 | puts("cd /tmp"); |
---|
173 | status=chdir("/tmp"); |
---|
174 | rtems_test_assert(status==0); |
---|
175 | |
---|
176 | status=chdir("a/b"); |
---|
177 | rtems_test_assert(status==0); |
---|
178 | |
---|
179 | status=chdir("../b"); |
---|
180 | rtems_test_assert(status==0); |
---|
181 | |
---|
182 | status=chdir("../b/."); |
---|
183 | rtems_test_assert(status==0); |
---|
184 | |
---|
185 | } |
---|
186 | |
---|
187 | void test (void ) |
---|
188 | { |
---|
189 | puts( "\n\n*** PATH EVALUATION TEST ***" ); |
---|
190 | path_eval_test01(); |
---|
191 | path_eval_test02(); |
---|
192 | puts( "*** END OF PATH EVALUATION TEST ***" ); |
---|
193 | } |
---|