Changeset 3352


Ignore:
Timestamp:
May 7, 2007, 4:53:18 AM (18 years ago)
Author:
bird
Message:

Some more tests.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/libc-0.6/src/libctests/libc/smoketests/rmdir-1.c

    r3351 r3352  
    3131#include <unistd.h>
    3232#include <errno.h>
     33#include <limits.h>
    3334#include <sys/stat.h>
     35#include <string.h>
    3436
    3537
    3638/* this testcase is a bit backwards... */
    37 int main()
     39int main(int argc, char **argv)
    3840{
    3941    struct stat s;
    4042    int rc = 0;
     43    char szBuf[PATH_MAX];
     44
    4145#define LINK_NAME                  "rmdir-1-broken-link"
    4246#define DOES_NOT_EXIST             "rmdir-1-does-not-exist"
    4347#define DIRECTORY_THAT_DOES_EXIST  "rmdir-1-directory-that-does-exist"
    4448
    45     /* cleanup previous runs. */
     49    /* cleanup previous runs and check preconditions. */
    4650    unlink(LINK_NAME);
    4751    rmdir(DIRECTORY_THAT_DOES_EXIST);
     
    4953    {
    5054        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]);
    5162        return 1;
    5263    }
     
    126137    rmdir(DIRECTORY_THAT_DOES_EXIST);
    127138    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
    129181    /* summary */
    130182    if (!rc)
  • trunk/libc/tests/libc/smoketests/rmdir-1.c

    r3351 r3352  
    3131#include <unistd.h>
    3232#include <errno.h>
     33#include <limits.h>
    3334#include <sys/stat.h>
     35#include <string.h>
    3436
    3537
    3638/* this testcase is a bit backwards... */
    37 int main()
     39int main(int argc, char **argv)
    3840{
    3941    struct stat s;
    4042    int rc = 0;
     43    char szBuf[PATH_MAX];
     44
    4145#define LINK_NAME                  "rmdir-1-broken-link"
    4246#define DOES_NOT_EXIST             "rmdir-1-does-not-exist"
    4347#define DIRECTORY_THAT_DOES_EXIST  "rmdir-1-directory-that-does-exist"
    4448
    45     /* cleanup previous runs. */
     49    /* cleanup previous runs and check preconditions. */
    4650    unlink(LINK_NAME);
    4751    rmdir(DIRECTORY_THAT_DOES_EXIST);
     
    4953    {
    5054        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]);
    5162        return 1;
    5263    }
     
    126137    rmdir(DIRECTORY_THAT_DOES_EXIST);
    127138    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
    129181    /* summary */
    130182    if (!rc)
Note: See TracChangeset for help on using the changeset viewer.