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