source: rtems/testsuites/fstests/fspatheval/test.c @ d957805

4.115
Last change on this file since d957805 was d957805, checked in by Ralf Corsepius <ralf.corsepius@…>, on 09/07/11 at 07:42:12

2011-09-07 Ralf Corsépius <ralf.corsepius@…>

  • fserror/test.c, fslink/test.c, fspatheval/test.c, fspermission/test.c, fsrdwr/init.c, fssymlink/test.c, fstime/test.c, support/fstest_support.c, support/ramdisk_support.c: Add config-header support.
  • Property mode set to 100644
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$
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
27#define BUF_SIZE 100
28
29void make_multiple_files (char **files,int is_directory)
30{
31  int i;
32  int status;
33  int fd;
34
35  i = 0;
36  if (is_directory){
37    while (files[i]) {
38      printf ("Making directory %s\n", files[i]);
39      status = mkdir (files[i], S_IRWXU);
40      rtems_test_assert (!status);
41      i++;
42    }
43  }else {
44    while (files[i]) {
45      printf ("Create file %s\n", files[i]);
46      fd=creat(files[i],S_IRWXU);
47      status=close(fd);
48      rtems_test_assert (!status);
49      i++;
50    }
51  }
52
53  puts ("");
54}
55
56void remove_multiple_files (char **files,int is_directory)
57{
58  int i;
59  int status;
60
61  i = 0;
62  while (files[i]) {
63    i++;
64  }
65
66  if (is_directory){
67    while (i) {
68      i--;
69      printf ("Removing directory %s\n", files[i]);
70      status = rmdir (files[i]);
71      rtems_test_assert (!status);
72    }
73  }else {
74    while (i) {
75      i--;
76      printf ("Removing file %s\n", files[i]);
77      status = unlink (files[i]);
78      rtems_test_assert (!status);
79    }
80  }
81
82  puts ("");
83}
84
85void path_eval_test01 (void)
86{
87  char *valid_path[] = {
88    "/test1/",
89    "tets2",
90    "///test3",
91    "test4////",
92    "../../test5",
93    "/test1/../test6",
94    "./test7/",
95    ".././test8",
96    "test8/./../test9",
97    "///test9/../test10",
98    0
99  };
100  char *valid_file[]={
101    "/test1",
102    "tets2",
103    "///test3",
104    "test4",
105    "../../test5",
106    "/../test6",
107    "./test7",
108    ".././test8",
109    "/./../test9",
110    "//../test10",
111    0
112  };
113
114  char *valid_relative_path[]={
115    "test1",
116    "tets2",
117    "test3",
118    "test4",
119    "test5",
120    "test6",
121    "test7",
122    "test8",
123    "test9",
124    "test10",
125    0
126
127  };
128
129  char *valid_name[] = {
130    "!#$%&()-@^_`{}~'",
131    "0_1_A",
132    "aaa bbb",
133    "ccc....ddd",
134    " fff",
135    0
136  };
137
138
139  make_multiple_files(valid_path,1);
140  make_multiple_files (valid_name,1);
141
142  remove_multiple_files(valid_relative_path,1);
143  remove_multiple_files(valid_name,1);
144
145  make_multiple_files(valid_file,0);
146  make_multiple_files (valid_name,0);
147
148  remove_multiple_files(valid_relative_path,0);
149  remove_multiple_files(valid_name,0);
150
151}
152void path_eval_test02(void )
153{
154
155  int status;
156  char buf[BUF_SIZE];
157  char* cwd;
158
159  mode_t mode = S_IRWXU|S_IRWXG|S_IRWXO;
160  puts("mkdir /tmp/a/b");
161  status=mkdir("/tmp",mode);
162  rtems_test_assert(status==0);
163  status=mkdir("/tmp/a",mode);
164  rtems_test_assert(status==0);
165  status=mkdir("/tmp/a/b",mode);
166  rtems_test_assert(status==0);
167
168  cwd=getcwd(buf,BUF_SIZE);
169  rtems_test_assert(cwd!=NULL);
170
171  puts("cd /tmp");
172  status=chdir("/tmp");
173  rtems_test_assert(status==0);
174
175  status=chdir("a/b");
176  rtems_test_assert(status==0);
177
178  status=chdir("../b");
179  rtems_test_assert(status==0);
180
181  status=chdir("../b/.");
182  rtems_test_assert(status==0);
183
184}
185
186void test (void )
187{
188  puts( "\n\n*** PATH EVALUATION TEST ***" );
189  path_eval_test01();
190  path_eval_test02();
191  puts( "*** END OF PATH EVALUATION TEST ***" );
192}
Note: See TracBrowser for help on using the repository browser.