rbb         99/02/25 11:48:58

  Modified:    apr/test testfile.c
  Log:
  Updated test program for apr_read and apr_write.
  
  Revision  Changes    Path
  1.3       +50 -4     apache-apr/apr/test/testfile.c
  
  Index: testfile.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/test/testfile.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- testfile.c        1999/02/25 17:34:33     1.2
  +++ testfile.c        1999/02/25 19:48:57     1.3
  @@ -63,10 +63,14 @@
   {
       apr_file_t *thefile = NULL;
       apr_status_t status = 0;
  -    apr_int32_t flag = APR_READ | APR_CREATE | APR_NONBLOCK;
  +    apr_int32_t flag = APR_READ | APR_WRITE | APR_CREATE | APR_NONBLOCK;
  +    apr_uint64_t rv = 0;
  +    apr_uint64_t nbytes = 0;
  +    char buf;
  +    char *filename = "test.fil";
   
       fprintf(stdout, "Opening file.......");
  -    thefile = apr_open("test.fil", flag, 444);
  +    thefile = apr_open(filename, flag, 444);
       if (thefile == NULL) {
           perror("Didn't open file");
           exit(-1);
  @@ -80,7 +84,7 @@
           fprintf(stderr, "Bad file des\n");
           exit(-1);
       }
  -    if (strcmp(thefile->fname, "rbb.fil") != 0) {
  +    if (strcmp(thefile->fname, filename) != 0) {
           fprintf(stderr, "wrong filename\n");
           exit(-1);
       }
  @@ -88,8 +92,50 @@
           fprintf(stdout, "OK\n");
       }
   
  +    fprintf(stdout, "Writing to file.......");
  +    
  +    nbytes = (apr_uint64_t)strlen("this is a test");
  +    rv = apr_write(thefile, "this is a test", nbytes);
  +    if (rv == -1) {
  +        perror("something's wrong");
  +        exit(-1);
  +    }
  +    if (rv != nbytes) {
  +        fprintf(stderr, "didn't write properly.\n");
  +        exit(-1);
  +    }
  +    else {
  +        fprintf(stdout, "OK\n");
  +    }
  +
  +    fprintf(stdout, "Moving to start of file.......");
  +
  +    if (lseek(thefile->filedes, SEEK_SET, 0) != 0) {
  +        perror("couldn't seek to beginning of file.");
  +        exit(-1);
  +    }
  +    else {
  +        fprintf(stdout, "OK\n");
  +    }
  +
  +    fprintf(stdout, "Reading from the file.......");
  +    nbytes = (apr_uint64_t)strlen("this is a test");
  +    rv = apr_read(thefile, &buf, nbytes);
  +    if (rv == -1) {
  +        perror("something's wrong");
  +        exit(-1);
  +    }
  +    nbytes = (apr_uint64_t)strlen("this is a test");
  +    if (rv != nbytes) {
  +        fprintf(stderr, "didn't read properly.\n");
  +        exit(-1);
  +    }
  +    else {
  +        fprintf(stdout, "OK\n");
  +    }
  +
       fprintf(stdout, "Closing File.......");
  -    status = apr_close(*thefile);
  +    status = apr_close(thefile);
       if (status == APR_FAILURE) {
           fprintf(stderr, "Couldn't close the file\n");
           exit(-1); 
  
  
  

Reply via email to