You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by rb...@apache.org on 2002/11/23 22:53:00 UTC

cvs commit: apr/test Makefile.in mod_test.c test_apr.h testall.c testdso.c

rbb         2002/11/23 13:53:00

  Modified:    test     Makefile.in mod_test.c test_apr.h testall.c
                        testdso.c
  Log:
  Migrate testdso to the new test suite.
  
  Revision  Changes    Path
  1.109     +2 -2      apr/test/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/apr/test/Makefile.in,v
  retrieving revision 1.108
  retrieving revision 1.109
  diff -u -r1.108 -r1.109
  --- Makefile.in	23 Nov 2002 21:38:30 -0000	1.108
  +++ Makefile.in	23 Nov 2002 21:53:00 -0000	1.109
  @@ -157,11 +157,11 @@
   testall: testall.lo testtime.lo teststr.lo testvsn.lo testipsub.lo \
            testmmap.lo testud.lo testtable.lo testsleep.lo testpools.lo \
            testfmt.lo testfile.lo testdir.lo testfileinfo.lo testrand.lo \
  -         CuTest.lo mod_test.la libmod_test.la $(LOCAL_LIBS)
  +         testdso.lo CuTest.lo mod_test.la libmod_test.la $(LOCAL_LIBS)
   	$(LINK) testall.lo testtime.lo teststr.lo testvsn.lo testipsub.lo \
   	testmmap.lo testud.lo testtable.lo testsleep.lo testpools.lo      \
   	testfmt.lo testfile.lo testdir.lo testfileinfo.lo testrand.lo     \
  -	CuTest.lo $(LOCAL_LIBS) $(ALL_LIBS)
  +	testdso.lo CuTest.lo $(LOCAL_LIBS) $(ALL_LIBS)
   
   
   # DO NOT REMOVE
  
  
  
  1.5       +5 -13     apr/test/mod_test.c
  
  Index: mod_test.c
  ===================================================================
  RCS file: /home/cvs/apr/test/mod_test.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- mod_test.c	3 Dec 2000 06:47:28 -0000	1.4
  +++ mod_test.c	23 Nov 2002 21:53:00 -0000	1.5
  @@ -1,21 +1,13 @@
   #include <stdio.h>
   
  -int goodbyes = 0;
  -
  -void print_hello(void);
  -int print_goodbye(int reps);
  -
  -void print_hello(void)
  +void print_hello(char str[256])
   {
  -    fprintf(stdout,"Hello - I'm a DSO!\n");
  +    apr_cpystrn(str, "Hello - I'm a DSO!\n", strlen("Hello - I'm a DSO!\n") + 1);
   }
   
  -int print_goodbye(int reps)
  +int count_reps(int reps)
   {
       int i = 0;
  -    for (i = 0;i < reps; i++) {
  -        fprintf (stdout, "Goodbye from the DSO! (%d of %d)\n", i+1, reps);
  -    }
  -    goodbyes = reps;
  -    return 0;
  +    for (i = 0;i < reps; i++);
  +    return i;
   }
  
  
  
  1.23      +1 -0      apr/test/test_apr.h
  
  Index: test_apr.h
  ===================================================================
  RCS file: /home/cvs/apr/test/test_apr.h,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- test_apr.h	23 Nov 2002 16:04:51 -0000	1.22
  +++ test_apr.h	23 Nov 2002 21:53:00 -0000	1.23
  @@ -80,6 +80,7 @@
   CuSuite *testdir(void);
   CuSuite *testfileinfo(void);
   CuSuite *testrand(void);
  +CuSuite *testdso(void);
   
   
   
  
  
  
  1.20      +1 -0      apr/test/testall.c
  
  Index: testall.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testall.c,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- testall.c	23 Nov 2002 21:47:03 -0000	1.19
  +++ testall.c	23 Nov 2002 21:53:00 -0000	1.20
  @@ -78,6 +78,7 @@
       {"testdir", testdir},
       {"testfileinfo", testfileinfo},
       {"testrand", testrand},
  +    {"testdso", testdso},
       {"LastTest", NULL}
   };
   
  
  
  
  1.22      +210 -96   apr/test/testdso.c
  
  Index: testdso.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testdso.c,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- testdso.c	24 Jun 2002 07:01:19 -0000	1.21
  +++ testdso.c	23 Nov 2002 21:53:00 -0000	1.22
  @@ -53,16 +53,11 @@
    */
   
   
  +#include "test_apr.h"
   #include "apr_general.h"
   #include "apr_pools.h"
   #include "apr_errno.h"
   #include "apr_dso.h"
  -#include <string.h>
  -#include <stdlib.h>
  -#include <stdio.h>
  -#if APR_HAVE_UNISTD_H
  -#include <unistd.h>
  -#endif
   
   #ifdef NETWARE
   # define LIB_NAME "mod_test.nlm"
  @@ -80,104 +75,223 @@
   # endif
   #endif
   
  -void test_shared_library(const char *libname, apr_pool_t *pool)
  +static char *filename;
  +static char *filename2;
  +
  +void test_load_module(CuTest *tc)
  +{
  +    apr_dso_handle_t *h = NULL;
  +    apr_status_t status;
  +    char errstr[256];
  +
  +    status = apr_dso_load(&h, filename, p);
  +    CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
  +    CuAssertPtrNotNull(tc, h);
  +
  +    apr_dso_unload(h);
  +}
  +
  +void test_dso_sym(CuTest *tc)
   {
       apr_dso_handle_t *h = NULL;
       apr_dso_handle_sym_t func1 = NULL;
  -    apr_dso_handle_sym_t func2 = NULL;
       apr_status_t status;
  -    void (*function)(void);
  -    void (*function1)(int);
  -    int *retval;
  -    char filename[256];   
  +    void (*function)(char str[256]);
  +    char teststr[256];
  +    char errstr[256];
  +
  +    status = apr_dso_load(&h, filename, p);
  +    CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
  +    CuAssertPtrNotNull(tc, h);
  +
  +    status = apr_dso_sym(&func1, h, "print_hello");
  +    CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
  +    CuAssertPtrNotNull(tc, func1);
   
  -    getcwd(filename, 256);
  -    strcat(filename, "/");
  -    strcat(filename, libname);
  +    function = (void *)func1;
  +    (*function)(teststr);
  +    CuAssertStrEquals(tc, "Hello - I'm a DSO!\n", teststr);
  +
  +    apr_dso_unload(h);
  +}
  +
  +void test_dso_sym_return_value(CuTest *tc)
  +{
  +    apr_dso_handle_t *h = NULL;
  +    apr_dso_handle_sym_t func1 = NULL;
  +    apr_status_t status;
  +    int (*function)(int);
  +    char teststr[256];
  +    char errstr[256];
  +
  +    status = apr_dso_load(&h, filename, p);
  +    CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
  +    CuAssertPtrNotNull(tc, h);
  +
  +    status = apr_dso_sym(&func1, h, "count_reps");
  +    CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
  +    CuAssertPtrNotNull(tc, func1);
   
  -    fprintf(stdout,"Trying to load DSO now.....................");
  -    fflush(stdout);
  -    if ((status = apr_dso_load(&h, filename, pool)) != APR_SUCCESS){
  -        char my_error[256];
  -        apr_strerror(status, my_error, sizeof(my_error));
  -        fprintf(stderr, "%s!\n", my_error);
  -        exit (-1);
  -    }
  -    fprintf(stdout,"OK\n");
  -
  -    fprintf(stdout,"Trying to get the DSO's attention..........");
  -    fflush(stdout);
  -    if ((status = apr_dso_sym(&func1, h, "print_hello")) != APR_SUCCESS) { 
  -        char my_error[256];
  -        apr_dso_error(h, my_error, sizeof(my_error));
  -        fprintf(stderr, "%s\n", my_error);
  -        exit (-1);
  -    }        
  -    fprintf(stdout,"OK\n");
  -    
       function = (void *)func1;
  -    (*function)();
  +    status = (*function)(5);
  +    CuAssertIntEquals(tc, 5, status);
  +
  +    apr_dso_unload(h);
  +}
  +
  +void test_unload_module(CuTest *tc)
  +{
  +    apr_dso_handle_t *h = NULL;
  +    apr_status_t status;
  +    char errstr[256];
  +    apr_dso_handle_sym_t func1 = NULL;
  +
  +    status = apr_dso_load(&h, filename, p);
  +    CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
  +    CuAssertPtrNotNull(tc, h);
  +
  +    status = apr_dso_unload(h);
  +    CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
  +
  +    status = apr_dso_sym(&func1, h, "print_hello");
  +    CuAssertIntEquals(tc, APR_EINIT, status);
  +}
  +
  +
  +void test_load_non_module(CuTest *tc)
  +{
  +#ifndef LIB_NAME2
  +    CuNotImpl(tc, "Can't load non-module library");
  +#else
  +    apr_dso_handle_t *h = NULL;
  +    apr_status_t status;
  +    char errstr[256];
  +
  +    status = apr_dso_load(&h, filename2, p);
  +    CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
  +    CuAssertPtrNotNull(tc, h);
   
  -    fprintf(stdout,"Saying farewell 5 times....................");
  -    fflush(stdout);
  -    if (apr_dso_sym(&func2, h, "print_goodbye") != APR_SUCCESS) {
  -        fprintf(stderr, "Failed!\n");
  -        exit (-1);
  -    }        
  -    fprintf(stdout,"OK\n");
  -
  -    function1 = (void *)(int)func2;
  -    (*function1)(5);
  -
  -    fprintf(stdout,"Checking how many times I said goodbye..");
  -    fflush(stdout);
  -    if (apr_dso_sym(&func1, h, "goodbyes") != APR_SUCCESS) {
  -        fprintf(stderr, "Failed!\n");
  -        exit (-1);
  -    }
  -    retval = (int *)func1;
  -    fprintf(stdout,"%d..", (*retval));
  -    fflush(stdout);
  -    if ((*retval) == 5){
  -        fprintf(stderr,"OK\n");
  -    } else {
  -        fprintf(stderr,"Failed!\n");
  -    }
  -       
  -    fprintf(stdout,"Trying to unload DSO now...................");
  -    if (apr_dso_unload(h) != APR_SUCCESS) {
  -        fprintf(stderr, "Failed!\n");
  -        exit (-1);
  -    }
  -    fprintf(stdout,"OK\n");
  -
  -    fprintf(stdout,"Checking it's been unloaded................");
  -    fflush(stdout);
  -    if (apr_dso_sym(&func1, h, "print_hello") == APR_SUCCESS) {
  -        fprintf(stderr, "Failed!\n");
  -        exit (-1);
  -    }        
  -    fprintf(stdout,"OK\n");
  -}
  -
  -int main (int argc, char ** argv)
  -{
  -    apr_pool_t *pool;
  -
  -    apr_initialize();
  -    atexit(apr_terminate);
  -        
  -    if (apr_pool_create(&pool, NULL) != APR_SUCCESS) {
  -        fprintf(stderr, "Couldn't allocate context.");
  -        exit(-1);
  -    }
  -
  -    fprintf(stdout,"=== Checking module library ===\n");
  -    test_shared_library(LIB_NAME, pool);
  -#ifdef LIB_NAME2
  -    fprintf(stdout,"=== Checking non-module library ===\n");
  -    test_shared_library(LIB_NAME2, pool);
  +    apr_dso_unload(h);
   #endif
  +}
   
  -    return 0;
  +void test_dso_sym_non_module(CuTest *tc)
  +{
  +#ifndef LIB_NAME2
  +    CuNotImpl(tc, "Can't load non-module library");
  +#else
  +    apr_dso_handle_t *h = NULL;
  +    apr_dso_handle_sym_t func1 = NULL;
  +    apr_status_t status;
  +    void (*function)(char str[256]);
  +    char teststr[256];
  +    char errstr[256];
  +
  +    status = apr_dso_load(&h, filename2, p);
  +    CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
  +    CuAssertPtrNotNull(tc, h);
  +
  +    status = apr_dso_sym(&func1, h, "print_hello");
  +    CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
  +    CuAssertPtrNotNull(tc, func1);
  +
  +    function = (void *)func1;
  +    (*function)(teststr);
  +    CuAssertStrEquals(tc, "Hello - I'm a DSO!\n", teststr);
  +
  +    apr_dso_unload(h);
  +#endif
  +}
  +
  +void test_dso_sym_return_value_non_mod(CuTest *tc)
  +{
  +#ifndef LIB_NAME2
  +    CuNotImpl(tc, "Can't load non-module library");
  +#else
  +    apr_dso_handle_t *h = NULL;
  +    apr_dso_handle_sym_t func1 = NULL;
  +    apr_status_t status;
  +    int (*function)(int);
  +    char teststr[256];
  +    char errstr[256];
  +
  +    status = apr_dso_load(&h, filename2, p);
  +    CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
  +    CuAssertPtrNotNull(tc, h);
  +
  +    status = apr_dso_sym(&func1, h, "count_reps");
  +    CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
  +    CuAssertPtrNotNull(tc, func1);
  +
  +    function = (void *)func1;
  +    status = (*function)(5);
  +    CuAssertIntEquals(tc, 5, status);
  +
  +    apr_dso_unload(h);
  +#endif
   }
  +
  +void test_unload_non_module(CuTest *tc)
  +{
  +#ifndef LIB_NAME2
  +    CuNotImpl(tc, "Can't load non-module library");
  +#else
  +    apr_dso_handle_t *h = NULL;
  +    apr_status_t status;
  +    char errstr[256];
  +    apr_dso_handle_sym_t func1 = NULL;
  +
  +    status = apr_dso_load(&h, filename2, p);
  +    CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
  +    CuAssertPtrNotNull(tc, h);
  +
  +    status = apr_dso_unload(h);
  +    CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status);
  +
  +    status = apr_dso_sym(&func1, h, "print_hello");
  +    CuAssertIntEquals(tc, APR_EINIT, status);
  +#endif
  +}
  +
  +static void test_load_notthere(CuTest *tc)
  +{
  +    apr_dso_handle_t *h = NULL;
  +    apr_dso_handle_sym_t func1 = NULL;
  +    apr_status_t status;
  +    char errstr[256];
  +
  +    status = apr_dso_load(&h, "No_File.so", p);
  +    CuAssertIntEquals(tc, APR_EDSOOPEN, status);
  +    CuAssertPtrNotNull(tc, h);
  +
  +    apr_dso_unload(h);
  +}    
  +
  +CuSuite *testdso(void)
  +{
  +    filename = apr_pcalloc(p, 256);
  +    getcwd(filename, 256);
  +    filename = apr_pstrcat(p, filename, "/", LIB_NAME, NULL);
  +
  +    filename2 = apr_pcalloc(p, 256);
  +    getcwd(filename2, 256);
  +    filename2 = apr_pstrcat(p, filename2, "/", LIB_NAME2, NULL);
  +
  +
  +    CuSuite *suite = CuSuiteNew("Test DSO");
  +
  +    SUITE_ADD_TEST(suite, test_load_module);
  +    SUITE_ADD_TEST(suite, test_dso_sym);
  +    SUITE_ADD_TEST(suite, test_dso_sym_return_value);
  +    SUITE_ADD_TEST(suite, test_unload_module);
  +
  +    SUITE_ADD_TEST(suite, test_load_non_module);
  +    SUITE_ADD_TEST(suite, test_dso_sym_non_module);
  +    SUITE_ADD_TEST(suite, test_dso_sym_return_value_non_mod);
  +    SUITE_ADD_TEST(suite, test_unload_non_module);
  +
  +    SUITE_ADD_TEST(suite, test_load_notthere);
  +
  +    return suite;
  +}
  +