Changeset 3352
- Timestamp:
- May 7, 2007, 4:53:18 AM (18 years ago)
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/libc-0.6/src/libctests/libc/smoketests/rmdir-1.c
r3351 r3352 31 31 #include <unistd.h> 32 32 #include <errno.h> 33 #include <limits.h> 33 34 #include <sys/stat.h> 35 #include <string.h> 34 36 35 37 36 38 /* this testcase is a bit backwards... */ 37 int main( )39 int main(int argc, char **argv) 38 40 { 39 41 struct stat s; 40 42 int rc = 0; 43 char szBuf[PATH_MAX]; 44 41 45 #define LINK_NAME "rmdir-1-broken-link" 42 46 #define DOES_NOT_EXIST "rmdir-1-does-not-exist" 43 47 #define DIRECTORY_THAT_DOES_EXIST "rmdir-1-directory-that-does-exist" 44 48 45 /* cleanup previous runs . */49 /* cleanup previous runs and check preconditions. */ 46 50 unlink(LINK_NAME); 47 51 rmdir(DIRECTORY_THAT_DOES_EXIST); … … 49 53 { 50 54 printf("rmdir-1: FAILURE - '%s' exists!\n", DOES_NOT_EXIST); 55 return 1; 56 } 57 if ( stat(argv[0], &s) 58 || !S_ISREG(s.st_mode) 59 ) 60 { 61 printf("rmdir-1: FAILURE - '%s' deosn't exist or isn't a regular file! (argv[0])\n", argv[0]); 51 62 return 1; 52 63 } … … 126 137 rmdir(DIRECTORY_THAT_DOES_EXIST); 127 138 unlink(LINK_NAME); 128 139 140 /* 4th test */ 141 if (rmdir(DIRECTORY_THAT_DOES_EXIST "/" DIRECTORY_THAT_DOES_EXIST) != -1) 142 { 143 printf("rmdir-1: FAILURE - rmdir('%s') shall fail but it didn't.\n", DIRECTORY_THAT_DOES_EXIST "/" DIRECTORY_THAT_DOES_EXIST); 144 rc++; 145 } 146 else if (errno != ENOENT) 147 { 148 printf("rmdir-1: FAILURE - expected ENOENT but got errno=%d (%s) (4rd test)\n", errno, strerror(errno)); 149 rc++; 150 } 151 else 152 { 153 errno = 0; 154 if ( rmdir(DIRECTORY_THAT_DOES_EXIST "/" DIRECTORY_THAT_DOES_EXIST "/" DIRECTORY_THAT_DOES_EXIST) != -1 155 || errno != ENOENT) 156 { 157 printf("rmdir-1: FAILURE - rmdir('%s') succeeded or didn't fail with ENOENT. errno=%d (%s)\n", 158 DIRECTORY_THAT_DOES_EXIST "/" DIRECTORY_THAT_DOES_EXIST "/" DIRECTORY_THAT_DOES_EXIST, 159 errno, strerror(errno)); 160 rc++; 161 } 162 else 163 printf("rmdir-1: removal of non-existing directory inside a non-existing directory failed like it should.\n"); 164 } 165 166 /* 5th test */ 167 strcat(strcpy(szBuf, argv[0]), "/parent-is-a-file"); 168 if (rmdir(szBuf) != -1) 169 { 170 printf("rmdir-1: FAILURE - rmdir('%s') shall fail but it didn't.\n", szBuf); 171 rc++; 172 } 173 else if (errno != ENOTDIR) 174 { 175 printf("rmdir-1: FAILURE - expected ENOTDIR but got errno=%d (%s) (5th test)\n", errno, strerror(errno)); 176 rc++; 177 } 178 else 179 printf("rmdir-1: removal of directory with a file in the path failed like it should.\n"); 180 129 181 /* summary */ 130 182 if (!rc) -
trunk/libc/tests/libc/smoketests/rmdir-1.c
r3351 r3352 31 31 #include <unistd.h> 32 32 #include <errno.h> 33 #include <limits.h> 33 34 #include <sys/stat.h> 35 #include <string.h> 34 36 35 37 36 38 /* this testcase is a bit backwards... */ 37 int main( )39 int main(int argc, char **argv) 38 40 { 39 41 struct stat s; 40 42 int rc = 0; 43 char szBuf[PATH_MAX]; 44 41 45 #define LINK_NAME "rmdir-1-broken-link" 42 46 #define DOES_NOT_EXIST "rmdir-1-does-not-exist" 43 47 #define DIRECTORY_THAT_DOES_EXIST "rmdir-1-directory-that-does-exist" 44 48 45 /* cleanup previous runs . */49 /* cleanup previous runs and check preconditions. */ 46 50 unlink(LINK_NAME); 47 51 rmdir(DIRECTORY_THAT_DOES_EXIST); … … 49 53 { 50 54 printf("rmdir-1: FAILURE - '%s' exists!\n", DOES_NOT_EXIST); 55 return 1; 56 } 57 if ( stat(argv[0], &s) 58 || !S_ISREG(s.st_mode) 59 ) 60 { 61 printf("rmdir-1: FAILURE - '%s' deosn't exist or isn't a regular file! (argv[0])\n", argv[0]); 51 62 return 1; 52 63 } … … 126 137 rmdir(DIRECTORY_THAT_DOES_EXIST); 127 138 unlink(LINK_NAME); 128 139 140 /* 4th test */ 141 if (rmdir(DIRECTORY_THAT_DOES_EXIST "/" DIRECTORY_THAT_DOES_EXIST) != -1) 142 { 143 printf("rmdir-1: FAILURE - rmdir('%s') shall fail but it didn't.\n", DIRECTORY_THAT_DOES_EXIST "/" DIRECTORY_THAT_DOES_EXIST); 144 rc++; 145 } 146 else if (errno != ENOENT) 147 { 148 printf("rmdir-1: FAILURE - expected ENOENT but got errno=%d (%s) (4rd test)\n", errno, strerror(errno)); 149 rc++; 150 } 151 else 152 { 153 errno = 0; 154 if ( rmdir(DIRECTORY_THAT_DOES_EXIST "/" DIRECTORY_THAT_DOES_EXIST "/" DIRECTORY_THAT_DOES_EXIST) != -1 155 || errno != ENOENT) 156 { 157 printf("rmdir-1: FAILURE - rmdir('%s') succeeded or didn't fail with ENOENT. errno=%d (%s)\n", 158 DIRECTORY_THAT_DOES_EXIST "/" DIRECTORY_THAT_DOES_EXIST "/" DIRECTORY_THAT_DOES_EXIST, 159 errno, strerror(errno)); 160 rc++; 161 } 162 else 163 printf("rmdir-1: removal of non-existing directory inside a non-existing directory failed like it should.\n"); 164 } 165 166 /* 5th test */ 167 strcat(strcpy(szBuf, argv[0]), "/parent-is-a-file"); 168 if (rmdir(szBuf) != -1) 169 { 170 printf("rmdir-1: FAILURE - rmdir('%s') shall fail but it didn't.\n", szBuf); 171 rc++; 172 } 173 else if (errno != ENOTDIR) 174 { 175 printf("rmdir-1: FAILURE - expected ENOTDIR but got errno=%d (%s) (5th test)\n", errno, strerror(errno)); 176 rc++; 177 } 178 else 179 printf("rmdir-1: removal of directory with a file in the path failed like it should.\n"); 180 129 181 /* summary */ 130 182 if (!rc)
Note:
See TracChangeset
for help on using the changeset viewer.