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

4.115
Last change on this file since d6da1b1 was bc75887, checked in by Sebastian Huber <sebastian.huber@…>, on 03/16/14 at 15:15:33

tests/fstests: Use <rtems/test.h>

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