apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject cvs commit: apr/test Makefile.in test_apr.h testall.c testsockets.c
Date Sun, 24 Nov 2002 06:54:55 GMT
rbb         2002/11/23 22:54:55

  Modified:    test     Makefile.in test_apr.h testall.c testsockets.c
  Log:
  Migrate testsockets to the new test suite.
  
  Revision  Changes    Path
  1.112     +3 -6      apr/test/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/apr/test/Makefile.in,v
  retrieving revision 1.111
  retrieving revision 1.112
  diff -u -r1.111 -r1.112
  --- Makefile.in	24 Nov 2002 06:13:59 -0000	1.111
  +++ Makefile.in	24 Nov 2002 06:54:55 -0000	1.112
  @@ -26,7 +26,6 @@
   	testpoll@EXEEXT@ \
   	testhash@EXEEXT@ \
   	testuser@EXEEXT@ \
  -	testsockets@EXEEXT@ \
   	testdup@EXEEXT@ \
   	testatomic@EXEEXT@ \
   	testmutexscope@EXEEXT@ \
  @@ -129,9 +128,6 @@
   testhash@EXEEXT@: testhash.lo $(LOCAL_LIBS)
   	$(LINK) testhash.lo $(LOCAL_LIBS) $(ALL_LIBS)
   
  -testsockets@EXEEXT@: testsockets.lo $(LOCAL_LIBS)
  -	$(LINK) testsockets.lo $(LOCAL_LIBS) $(ALL_LIBS)
  -
   testuser@EXEEXT@: testuser.lo $(LOCAL_LIBS)
   	$(LINK) testuser.lo $(LOCAL_LIBS) $(ALL_LIBS)
   
  @@ -153,12 +149,13 @@
   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 \
  -         testdso.lo testoc.lo testdup.lo CuTest.lo mod_test.la \
  +         testdso.lo testoc.lo testdup.lo testsockets.lo CuTest.lo mod_test.la \
            libmod_test.la occhild@EXEEXT@ $(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     \
  -	testdso.lo testoc.lo testdup.lo CuTest.lo $(LOCAL_LIBS) $(ALL_LIBS)
  +	testdso.lo testoc.lo testdup.lo testsockets.lo CuTest.lo \
  +	$(LOCAL_LIBS) $(ALL_LIBS)
   
   
   # DO NOT REMOVE
  
  
  
  1.26      +1 -0      apr/test/test_apr.h
  
  Index: test_apr.h
  ===================================================================
  RCS file: /home/cvs/apr/test/test_apr.h,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- test_apr.h	24 Nov 2002 06:13:59 -0000	1.25
  +++ test_apr.h	24 Nov 2002 06:54:55 -0000	1.26
  @@ -83,6 +83,7 @@
   CuSuite *testdso(void);
   CuSuite *testoc(void);
   CuSuite *testdup(void);
  +CuSuite *testsockets(void);
   
   
   
  
  
  
  1.24      +1 -0      apr/test/testall.c
  
  Index: testall.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testall.c,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- testall.c	24 Nov 2002 06:13:59 -0000	1.23
  +++ testall.c	24 Nov 2002 06:54:55 -0000	1.24
  @@ -81,6 +81,7 @@
       {"testrand", testrand},
       {"testdso", testdso},
       {"testoc", testoc},
  +    {"testsockets", testsockets},
       {"LastTest", NULL}
   };
   
  
  
  
  1.7       +93 -65    apr/test/testsockets.c
  
  Index: testsockets.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testsockets.c,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- testsockets.c	20 Nov 2002 03:50:22 -0000	1.6
  +++ testsockets.c	24 Nov 2002 06:54:55 -0000	1.7
  @@ -52,10 +52,6 @@
    * <http://www.apache.org/>.
    */
   
  -#include <assert.h>
  -#include <stdio.h>
  -#include <stdlib.h>
  -#include <string.h>
   #include "apr_network_io.h"
   #include "apr_errno.h"
   #include "apr_general.h"
  @@ -64,93 +60,125 @@
   
   #if APR_HAVE_IPV6
   #define US "::1"
  +#define FAMILY APR_INET6
   #else
   #define US "127.0.0.1"
  +#define FAMILY APR_INET
   #endif
   
  -static void closeapr(void)
  +#define STRLEN 21
  +
  +static void tcp_socket(CuTest *tc)
   {
  -    apr_terminate();
  +    apr_status_t rv;
  +    apr_socket_t *sock = NULL;
  +
  +    rv = apr_socket_create(&sock, APR_INET, SOCK_STREAM, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    CuAssertPtrNotNull(tc, sock);
  +    apr_socket_close(sock);
   }
   
  -static void close_sock(apr_socket_t *sock)
  +static void udp_socket(CuTest *tc)
   {
  -    STD_TEST_NEQ("    Closing socket", apr_socket_close(sock))
  -}
  +    apr_status_t rv;
  +    apr_socket_t *sock = NULL;
   
  -#define STRLEN 21
  +    rv = apr_socket_create(&sock, APR_INET, SOCK_DGRAM, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    CuAssertPtrNotNull(tc, sock);
  +    apr_socket_close(sock);
  +}
   
  -int main(void)
  +static void tcp6_socket(CuTest *tc)
   {
  -    apr_pool_t *pool;
  -    apr_socket_t *sock = NULL, *sock2 = NULL;
  -    apr_sockaddr_t *from;
  -    apr_sockaddr_t *to;
  -    apr_size_t len = 30;
  -    char sendbuf[STRLEN] = "APR_INET, SOCK_DGRAM";
  -    char recvbuf[80];
  -    char *ip_addr;
  -    apr_port_t fromport;
   #if APR_HAVE_IPV6
  -    int family = APR_INET6;
  +    apr_status_t rv;
  +    apr_socket_t *sock = NULL;
  +
  +    rv = apr_socket_create(&sock, APR_INET6, SOCK_STREAM, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    CuAssertPtrNotNull(tc, sock);
  +    apr_socket_close(sock);
   #else
  -    int family = APR_INET;
  +    CuNotImpl(tc, "IPv6");
   #endif
  +}
   
  -    STD_TEST_NEQ("Initializing APR", apr_initialize())
  -
  -    atexit(closeapr);
  -    STD_TEST_NEQ("Creating 1st pool", apr_pool_create(&pool, NULL))
  -
  -    printf("Testing socket creation functions.\n");
  -
  -    STD_TEST_NEQ("    Creating a TCP socket",
  -                 apr_socket_create(&sock, APR_INET, SOCK_STREAM, pool))
  -    close_sock(sock);
  -
  -    STD_TEST_NEQ("    Creating UDP socket",
  -                 apr_socket_create(&sock, APR_INET, SOCK_DGRAM, pool))
  -    close_sock(sock);
  -
  +static void udp6_socket(CuTest *tc)
  +{
   #if APR_HAVE_IPV6
  -    STD_TEST_NEQ("    Creating an IPv6 TCP socket",
  -                 apr_socket_create(&sock, APR_INET6, SOCK_STREAM, pool))
  -    close_sock(sock);
  -
  -    STD_TEST_NEQ("    Creating an IPv6 UDP socket",
  -                 apr_socket_create(&sock, APR_INET6, SOCK_DGRAM, pool))
  -    close_sock(sock);
  +    apr_status_t rv;
  +    apr_socket_t *sock = NULL;
  +
  +    rv = apr_socket_create(&sock, APR_INET6, SOCK_DGRAM, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    CuAssertPtrNotNull(tc, sock);
  +    apr_socket_close(sock);
   #else
  -    printf("NO IPv6 support.\n");
  +    CuNotImpl(tc, "IPv6");
   #endif
  +}
   
  -    printf("Now trying sendto/recvfrom (simple tests only)\n");
  -
  -    STD_TEST_NEQ("    Creating socket #1 for test",
  -                 apr_socket_create(&sock, family, SOCK_DGRAM, pool))
  -    STD_TEST_NEQ("    Creating socket #2 for test",
  -                 apr_socket_create(&sock2, family, SOCK_DGRAM, pool))
  -
  -    apr_sockaddr_info_get(&to, US, APR_UNSPEC, 7772, 0, pool);
  -    apr_sockaddr_info_get(&from, US, APR_UNSPEC, 7771, 0, pool);
  +static void sendto_receivefrom(CuTest *tc)
  +{
  +    apr_status_t rv;
  +    apr_socket_t *sock = NULL;
  +    apr_socket_t *sock2 = NULL;
  +    char sendbuf[STRLEN] = "APR_INET, SOCK_DGRAM";
  +    char recvbuf[80];
  +    char *ip_addr;
  +    apr_port_t fromport;
  +    apr_sockaddr_t *from;
  +    apr_sockaddr_t *to;
  +    apr_size_t len = 30;
   
  -    STD_TEST_NEQ("    Binding socket #1", apr_socket_bind(sock, to))
  -    STD_TEST_NEQ("    Binding socket #2", apr_socket_bind(sock2, from))
  +    rv = apr_socket_create(&sock, FAMILY, SOCK_DGRAM, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    rv = apr_socket_create(&sock2, FAMILY, SOCK_DGRAM, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +
  +    rv = apr_sockaddr_info_get(&to, US, APR_UNSPEC, 7772, 0, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    rv = apr_sockaddr_info_get(&from, US, APR_UNSPEC, 7771, 0, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +
  +    rv = apr_socket_bind(sock, to);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    rv = apr_socket_bind(sock2, from);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
   
       len = STRLEN;
  +    rv = apr_socket_sendto(sock2, to, 0, sendbuf, &len);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    CuAssertIntEquals(tc, STRLEN, len);
   
  -    STD_TEST_NEQ("    Trying to sendto",
  -                 apr_socket_sendto(sock2, to, 0, sendbuf, &len))
       len = 80;
  -    STD_TEST_NEQ("    Trying to recvfrom",
  -                 apr_socket_recvfrom(from, sock, 0, recvbuf, &len))
  -    printf("\t\tGot back %d bytes [%s] from recvfrom\n", len, recvbuf);   
  +    rv = apr_socket_recvfrom(from, sock, 0, recvbuf, &len);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    CuAssertIntEquals(tc, STRLEN, len);
  +    CuAssertStrEquals(tc, "APR_INET, SOCK_DGRAM", recvbuf);
  +
       apr_sockaddr_ip_get(&ip_addr, from);
       apr_sockaddr_port_get(&fromport, from);
  -    printf("\t\tData came from %s:%u\n", ip_addr, fromport);
  +    CuAssertStrEquals(tc, US, ip_addr);
  +    CuAssertIntEquals(tc, 7771, fromport);
  +
  +    apr_socket_close(sock);
  +    apr_socket_close(sock2);
  +}
  +
  +CuSuite *testsockets(void)
  +{
  +    CuSuite *suite = CuSuiteNew("Socket Creation");
   
  -    close_sock(sock);
  -    close_sock(sock2);
  +    SUITE_ADD_TEST(suite, tcp_socket);
  +    SUITE_ADD_TEST(suite, udp_socket);
   
  -    return 1;
  +    SUITE_ADD_TEST(suite, tcp6_socket);
  +    SUITE_ADD_TEST(suite, udp6_socket);
  +
  +    SUITE_ADD_TEST(suite, sendto_receivefrom);
  +    return suite;
   }
  +
  
  
  

Mime
View raw message