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

4.115
Last change on this file since a7c39d3 was a7c39d3, checked in by Joel Sherrill <joel.sherrill@…>, on 08/01/11 at 21:54:19

2011-08-01 Xiang Cui <medivhc@…>

  • imfs_fslink/Makefile.am, imfs_fssymlink/Makefile.am, mimfs_fslink/Makefile.am, mimfs_fssymlink/Makefile.am, mrfs_fslink/Makefile.am, mrfs_fssymlink/Makefile.am, mrfs_support/fs_config.h: Correcting from previous commit of incorrect tarball.
  • fserror/fserror.doc, fserror/test.c, fspatheval/patheval.doc, fspatheval/test.c, fspermission/fspermission.doc, fspermission/test.c, fsrdwr/fsrdwr.doc, fsrdwr/init.c, fstime/fstime.doc, fstime/test.c, imfs_fserror/.cvsignore, imfs_fserror/Makefile.am, imfs_fslink/.cvsignore, imfs_fspatheval/.cvsignore, imfs_fspatheval/Makefile.am, imfs_fspermission/.cvsignore, imfs_fspermission/Makefile.am, imfs_fsrdwr/.cvsignore, imfs_fsrdwr/Makefile.am, imfs_fssymlink/.cvsignore, imfs_fstime/.cvsignore, imfs_fstime/Makefile.am, imfs_support/fs_supprot.h, mdosfs_fserror/.cvsignore, mdosfs_fserror/Makefile.am, mdosfs_fspatheval/.cvsignore, mdosfs_fspatheval/Makefile.am, mdosfs_fsrdwr/.cvsignore, mdosfs_fsrdwr/Makefile.am, mdosfs_fstime/.cvsignore, mdosfs_fstime/Makefile.am, mimfs_fserror/.cvsignore, mimfs_fserror/Makefile.am, mimfs_fslink/.cvsignore, mimfs_fspatheval/.cvsignore, mimfs_fspatheval/Makefile.am, mimfs_fspermission/.cvsignore, mimfs_fspermission/Makefile.am, mimfs_fsrdwr/.cvsignore, mimfs_fsrdwr/Makefile.am, mimfs_fssymlink/.cvsignore, mimfs_fstime/.cvsignore, mimfs_fstime/Makefile.am, mrfs_fserror/.cvsignore, mrfs_fserror/Makefile.am, mrfs_fslink/.cvsignore, mrfs_fspatheval/.cvsignore, mrfs_fspatheval/Makefile.am, mrfs_fspermission/.cvsignore, mrfs_fspermission/Makefile.am, mrfs_fsrdwr/.cvsignore, mrfs_fsrdwr/Makefile.am, mrfs_fssymlink/.cvsignore, mrfs_fstime/.cvsignore, mrfs_fstime/Makefile.am: New files.
  • 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 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
24void 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
51void 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
80void 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}
147void 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
181void 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.