apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dr...@apache.org
Subject cvs commit: apr/test testfile.c
Date Mon, 14 May 2001 19:55:41 GMT
dreid       01/05/14 12:55:39

  Modified:    test     testfile.c
  Log:
  The remainder of the changes to testfile.
  
  Revision  Changes    Path
  1.34      +74 -147   apr/test/testfile.c
  
  Index: testfile.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testfile.c,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- testfile.c	2001/05/14 15:12:28	1.33
  +++ testfile.c	2001/05/14 19:55:30	1.34
  @@ -85,8 +85,8 @@
       {0,                NULL}
   }; 
   
  -int test_filedel(apr_pool_t *);
  -int testdirs(apr_pool_t *);
  +void test_filedel(apr_pool_t *);
  +void testdirs(apr_pool_t *);
   static void test_read(apr_pool_t *);
   
   static void closeapr(void)
  @@ -97,6 +97,7 @@
   int main(void)
   {
       apr_pool_t *pool;
  +    apr_pool_t *pool2;
       apr_file_t *thefile = NULL;
       apr_finfo_t finfo;
       apr_socket_t *testsock = NULL;
  @@ -105,6 +106,7 @@
       apr_int32_t flag = APR_READ | APR_WRITE | APR_CREATE;
       apr_size_t nbytes = 0;
       apr_off_t zer = 0;
  +    char errmsg[120];
       char *buf;
       const char *str;
       char *filename = "test.fil";
  @@ -141,21 +143,11 @@
           MSG_AND_EXIT("Wrong filename\n")
       }
       
  -    printf("%-60s", "    Writing to file");
  -    
       nbytes = strlen("this is a test");
  -    status = apr_file_write(thefile, "this is a test", &nbytes);
  -    if (status != APR_SUCCESS) {
  -        printf("Failed\n");
  -        PRINT_ERROR(status);
  -    }
  -    if (nbytes != strlen("this is a test")) {
  -        printf("Failed\n");
  -        MSG_AND_EXIT("Failed to write correctly.");
  -    }
  -    else {
  -        printf("OK\n");
  -    }
  +    STD_TEST_NEQ("    Writing to the file", 
  +                 apr_file_write(thefile, "this is a test", &nbytes))
  +    TEST_NEQ("    Checking we wrote everything", nbytes,
  +             strlen("this is a test"), "OK", "Failed to write everything")
   
       zer = 0;
       STD_TEST_NEQ("    Moving to the start of file", 
  @@ -181,20 +173,15 @@
       buf = (char *)apr_palloc(pool, nbytes + 1);
       STD_TEST_NEQ("    Reading from the file",
                    apr_file_read(thefile, buf, &nbytes))
  -    if (nbytes != strlen("this is a test")) {
  -        MSG_AND_EXIT("We didn't read properly.\n");
  -    }
  -    
  +    TEST_NEQ("    Checking what we read", nbytes, strlen("this is a test"),
  +             "OK", "We didn't read properly.\n")
       STD_TEST_NEQ("    Adding user data to the file",
                    apr_file_data_set(thefile, "This is a test",
                                      "test", apr_pool_cleanup_null))
  -
       STD_TEST_NEQ("    Getting user data from the file",
                    apr_file_data_get((void **)&teststr, "test", thefile))
  -                 
  -    if (strcmp(teststr, "This is a test")) {
  -        MSG_AND_EXIT("Got the data, but it was wrong");
  -    }
  +    TEST_NEQ("    Checking the data we got", strcmp(teststr, "This is a test"), 0,
  +             "OK", "Got the data, but it was wrong")
   
       printf("%-60s", "    Getting fileinfo");
       status = apr_file_info_get(&finfo, APR_FINFO_NORM, thefile);
  @@ -261,37 +248,30 @@
       test_read(pool);
   
       apr_pool_destroy(pool);
  +
  +    printf("\nAll tests passed OK\n");
       return 1;
   }
   
  -int test_filedel(apr_pool_t *pool)
  +void test_filedel(apr_pool_t *pool)
   {
       apr_file_t *thefile = NULL;
       apr_int32_t flag = APR_READ | APR_WRITE | APR_CREATE;
  -    apr_status_t stat;
  -  
  -    stat = apr_file_open(&thefile, "testdel", flag, APR_UREAD | APR_UWRITE | APR_GREAD,
pool);
  -    if (stat != APR_SUCCESS) {
  -         return stat;
  -    }
  -
  -    if ((stat = apr_file_close(thefile))  != APR_SUCCESS) {
  -        return stat;
  -    }
  -
  -    if ((stat = apr_file_remove("testdel", pool))  != APR_SUCCESS) {
  -        return stat;
  -    }
  -
  -    stat = apr_file_open(&thefile, "testdel", APR_READ, APR_UREAD | APR_UWRITE | APR_GREAD,
pool);
  -    if (stat == APR_SUCCESS) {
  -        return stat;
  -    }
     
  -    return APR_SUCCESS;
  +    STD_TEST_NEQ("    Creating the file",
  +                 apr_file_open(&thefile, "testdel", flag, 
  +                               APR_UREAD | APR_UWRITE | APR_GREAD, pool))
  +    STD_TEST_NEQ("    Closing the file",
  +                 apr_file_close(thefile))
  +    STD_TEST_NEQ("    Removing the file", apr_file_remove("testdel", pool))
  +    TEST_EQ("    Checking it's gone",
  +            apr_file_open(&thefile, "testdel", APR_READ, 
  +                          APR_UREAD | APR_UWRITE | APR_GREAD, pool),
  +            APR_SUCCESS,
  +            "OK", "Failed")
   }
   
  -int testdirs(apr_pool_t *pool)
  +void testdirs(apr_pool_t *pool)
   {
       apr_dir_t *temp;  
       apr_file_t *file = NULL;
  @@ -299,44 +279,27 @@
       apr_finfo_t dirent;
   
       fprintf(stdout, "Testing Directory functions.\n");
  -
  -    fprintf(stdout, "\tMakeing Directory.......");
  -    if (apr_dir_make("testdir", APR_UREAD | APR_UWRITE | APR_UEXECUTE | APR_GREAD | APR_GWRITE
| APR_GEXECUTE | APR_WREAD | APR_WWRITE | APR_WEXECUTE, pool)  != APR_SUCCESS) {
  -        fprintf(stderr, "Could not create directory\n");
  -        return -1;
  -    }
  -    else {
  -        fprintf(stdout, "OK\n");
  -    }
   
  -    if (apr_file_open(&file, "testdir/testfile", APR_READ | APR_WRITE | APR_CREATE,
APR_UREAD | APR_UWRITE | APR_UEXECUTE, pool) != APR_SUCCESS) {;
  -        return -1;
  -    }
  +    STD_TEST_NEQ("    Making directory",
  +                 apr_dir_make("testdir", 
  +                               APR_UREAD | APR_UWRITE | APR_UEXECUTE |
  +                               APR_GREAD | APR_GWRITE | APR_GEXECUTE | 
  +                               APR_WREAD | APR_WWRITE | APR_WEXECUTE, pool))
  +
  +    STD_TEST_NEQ("    Creating a file in the new directory",
  +                 apr_file_open(&file, "testdir/testfile", 
  +                               APR_READ | APR_WRITE | APR_CREATE, 
  +                               APR_UREAD | APR_UWRITE | APR_UEXECUTE, pool))
   
       bytes = strlen("Another test!!!");
       apr_file_write(file, "Another test!!", &bytes); 
   	apr_file_close(file);
  -
  -    fprintf(stdout, "\tOpening Directory.......");
  -    if (apr_dir_open(&temp, "testdir", pool) != APR_SUCCESS) {
  -        fprintf(stderr, "Could not open directory\n");
  -        return -1;
  -    }
  -    else {
  -        fprintf(stdout, "OK\n");
  -    }
   
  -    fprintf(stdout, "\tReading Directory.......");
  -    if ((apr_dir_read(&dirent, APR_FINFO_DIRENT, temp))  != APR_SUCCESS) {
  -        fprintf(stderr, "Could not read directory\n");
  -        return -1;
  -    }
  -    else {
  -        fprintf(stdout, "OK\n");
  -    }
  -   
  -    fprintf(stdout, "\tGetting Information about the file.......\n");
  -    fprintf(stdout, "\t\tFile name.......");
  +    STD_TEST_NEQ("    Opening directory", apr_dir_open(&temp, "testdir", pool))
  +    STD_TEST_NEQ("    Reading directory", 
  +                 apr_dir_read(&dirent, APR_FINFO_DIRENT, temp))
  +       
  +    printf("    Getting Information about the file...\n");
       do {
           /* Because I want the file I created, I am skipping the "." and ".."
            * files that are here. 
  @@ -345,61 +308,22 @@
                                   | APR_FINFO_SIZE | APR_FINFO_MTIME, temp) 
                   != APR_SUCCESS) {
               fprintf(stderr, "Error reading directory testdir"); 
  -            return -1;
  +            exit(-1);
           }
       } while (dirent.name[0] == '.');
  -    if (strcmp(dirent.name, "testfile")) {
  -        fprintf(stderr, "Got wrong file name %s\n", dirent.name);
  -        return -1;
  -    }
  -    fprintf(stdout, "OK\n");
  -
  -    fprintf(stdout, "\t\tFile type.......");
  -    if (dirent.filetype != APR_REG) {
  -        fprintf(stderr, "Got wrong file type\n");
  -        return -1;
  -    }
  -    fprintf(stdout, "OK\n");
  -
  -    fprintf(stdout, "\t\tFile size.......");
  -    if (dirent.size != bytes) {
  -        fprintf(stderr, "Got wrong file size %" APR_OFF_T_FMT "\n", dirent.size);
  -        return -1;
  -    }
  -    fprintf(stdout, "OK\n");
  -     
  -    fprintf(stdout, "\tRewinding directory.......");
  -    apr_dir_rewind(temp); 
  -    fprintf(stdout, "OK\n");
  -    
  -    fprintf(stdout, "\tClosing Directory.......");
  -    if (apr_dir_close(temp)  != APR_SUCCESS) {
  -        fprintf(stderr, "Could not close directory\n");
  -        return -1;
  -    }
  -    else {
  -        fprintf(stdout, "OK\n");
  -    }
  -
  -    fprintf(stdout, "\tRemoving file from directory.......");
  -    if (apr_file_remove("testdir/testfile", pool)  != APR_SUCCESS) {
  -        fprintf(stderr, "Could not remove file\n");
  -        return -1;
  -    }
  -    else {
  -        fprintf(stdout, "OK\n");
  -    }
  -
  -    fprintf(stdout, "\tRemoving Directory.......");
  -    if (apr_dir_remove("testdir", pool)  != APR_SUCCESS) {
  -        fprintf(stderr, "Could not remove directory\n");
  -        return -1;
  -    }
  -    else {
  -        fprintf(stdout, "OK\n");
  -    }
  -    
  -    return 1; 
  +    TEST_NEQ("        File name",
  +             strcmp(dirent.name, "testfile"), 0,
  +             "OK", "Got wrong file name");
  +    TEST_NEQ("        File type", dirent.filetype, APR_REG,
  +             "OK", "Got wrong file type")
  +    TEST_NEQ("        File size", dirent.size, bytes,
  +             "OK", "Got wrong file size")
  +    printf("    Done checking file information\n");
  +    STD_TEST_NEQ("    Rewind directory", apr_dir_rewind(temp))
  +    STD_TEST_NEQ("    Closing directory", apr_dir_close(temp))
  +    STD_TEST_NEQ("    Removing file from directory",
  +                 apr_file_remove("testdir/testfile", pool))
  +    STD_TEST_NEQ("    Removing directory", apr_dir_remove("testdir", pool))
   }    
   
   #define TESTREAD_BLKSIZE 1024
  @@ -414,6 +338,7 @@
   
       /* Create a test file with known content.
        */
  +    
       rv = apr_file_open(&f, fname, APR_CREATE | APR_WRITE | APR_TRUNCATE, APR_UREAD
| APR_UWRITE, p);
       if (rv) {
           fprintf(stderr, "apr_file_open()->%d/%s\n",
  @@ -460,7 +385,7 @@
     return bytes[1];
   }
   
  -static void test_read_guts(apr_pool_t *p, const char *fname, apr_int32_t extra_flags)
  +static int test_read_guts(apr_pool_t *p, const char *fname, apr_int32_t extra_flags)
   {
       apr_file_t *f = NULL;
       apr_status_t rv;
  @@ -473,9 +398,9 @@
       read_one(f, 'a');
       read_one(f, 'b');
       if (extra_flags & APR_BUFFERED) {
  -        fprintf(stdout, 
  -                "\n\t\tskipping apr_file_ungetc() for APR_BUFFERED... "
  -                "doesn't work yet...\n\t\t\t\t ");
  +        printf("\n        skipping apr_file_ungetc() for APR_BUFFERED as it "
  +               "doesn't work yet\n");
  +        return (0);
       }
       else {
           rv = apr_file_ungetc('b', f);
  @@ -542,6 +467,7 @@
       assert(rv == APR_EOF);
       rv = apr_file_close(f);
       assert(!rv);
  +    return (1);
   }
   
   static void test_bigread(apr_pool_t *p, const char *fname, apr_int32_t extra_flags)
  @@ -582,23 +508,24 @@
       const char *fname = "testread.dat";
       apr_status_t rv;
   
  -    fprintf(stdout, "Testing file read functions.\n");
  +    printf("Testing file read functions.\n");
   
       create_testread(p, fname);
  -    fprintf(stdout, "\tBuffered file tests......");
  -    test_read_guts(p, fname, APR_BUFFERED);
  -    fprintf(stdout, "OK\n");
  -    fprintf(stdout, "\tUnbuffered file tests....");
  +    printf("%-60s", "    Buffered file tests");
  +    if (test_read_guts(p, fname, APR_BUFFERED))
  +        printf("OK\n");
  +    printf("%-60s", "    Unbuffered file tests");
       test_read_guts(p, fname, 0);
  -    fprintf(stdout, "OK\n");
  -    fprintf(stdout, "\tMore buffered file tests......");
  +    printf("OK\n");
  +    printf("%-60s", "    More buffered file tests");
       test_bigread(p, fname, APR_BUFFERED);
  -    fprintf(stdout, "OK\n");
  -    fprintf(stdout, "\tMore unbuffered file tests......");
  +    printf("OK\n");
  +    printf("%-60s", "    More unbuffered file tests");
       test_bigread(p, fname, 0);
  -    fprintf(stdout, "OK\n");
  +    printf("OK\n");
       rv = apr_file_remove(fname, p);
       assert(!rv);
  -    fprintf(stdout, "\tAll read tests...........OK\n");
  +    printf("%-60s", "    All read tests");
  +    printf("OK\n");
   }
   
  
  
  

Mime
View raw message