gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r18721 - libmwmodem/src/tests


From: gnunet
Subject: [GNUnet-SVN] r18721 - libmwmodem/src/tests
Date: Tue, 20 Dec 2011 16:41:11 +0100

Author: ruppa
Date: 2011-12-20 16:41:11 +0100 (Tue, 20 Dec 2011)
New Revision: 18721

Modified:
   libmwmodem/src/tests/libmwmodem_test_ipv4.c
   libmwmodem/src/tests/libmwmodem_test_ipv6.c
Log:


Modified: libmwmodem/src/tests/libmwmodem_test_ipv4.c
===================================================================
--- libmwmodem/src/tests/libmwmodem_test_ipv4.c 2011-12-20 14:43:53 UTC (rev 
18720)
+++ libmwmodem/src/tests/libmwmodem_test_ipv4.c 2011-12-20 15:41:11 UTC (rev 
18721)
@@ -18,6 +18,7 @@
 */
 
 #include <libmwmodem.h>
+#include <sys/socket.h>
 #include <string.h>
 #include <netinet/in.h>
 #include <stdio.h>
@@ -29,23 +30,23 @@
 //     if (package->header !=((uint32_t) "joh0"))
        if (package->header != package->header)
        {
-               printf("Error: failure of Test from MWMODEM_run in 
MWMODEM_InformationCallback at package->Header!");
+               printf("Error: failure of Test from MWMODEM_run in 
MWMODEM_InformationCallback at package->Header!\n");
 //             return;
        }
        if ((package->time.tv_nsec!=(1*MWMODEM_TACT_NANO_SEC)% (1000 * 1000 * 
1000))&&
                                
(package->time.tv_sec!=(1*MWMODEM_TACT_NANO_SEC)/ (1000 * 1000 * 1000)))
        {
-               printf("Error: failure of Test from MWMODEM_run in 
MWMODEM_InformationCallback at package->time!");
+               printf("Error: failure of Test from MWMODEM_run in 
MWMODEM_InformationCallback at package->time!\n");
                return;
        }
        if (package->symbolrate!=100)
        {
-               printf("Error: failure of Test from MWMODEM_run in 
MWMODEM_InformationCallback at package->symbolrate!");
+               printf("Error: failure of Test from MWMODEM_run in 
MWMODEM_InformationCallback at package->symbolrate!\n");
                return;
        }
        if (package->num_channels!=1)
        {
-               printf("Error: failure of Test from MWMODEM_run in 
MWMODEM_InformationCallback at package->num_channels!");
+               printf("Error: failure of Test from MWMODEM_run in 
MWMODEM_InformationCallback at package->num_channels!\n");
                return;
        }
 
@@ -53,25 +54,25 @@
 
        if (channel.modcode != 1)
        {
-               printf("Error: failure of Test from MWMODEM_run in 
MWMODEM_InformationCallback at package->channel[0]->modcode!");
+               printf("Error: failure of Test from MWMODEM_run in 
MWMODEM_InformationCallback at package->channel[0]->modcode!\n");
                return;
        }
        if (channel.queue != 10)
        {
-               printf("Error: failure of Test from MWMODEM_run in 
MWMODEM_InformationCallback at package->channel[0]->queue!");
+               printf("Error: failure of Test from MWMODEM_run in 
MWMODEM_InformationCallback at package->channel[0]->queue!\n");
                return;
        }
        if (channel.datasent != 10)
        {
-               printf("Error: failure of Test from MWMODEM_run in 
MWMODEM_InformationCallback at package->channel[0]->datasent!");
+               printf("Error: failure of Test from MWMODEM_run in 
MWMODEM_InformationCallback at package->channel[0]->datasent!\n");
                return;
        }
        if (channel.symbolratelimit != 10)
        {
-               printf("Error: failure of Test from MWMODEM_run in 
MWMODEM_InformationCallback at package->channel[0]->symbolratelimit!");
+               printf("Error: failure of Test from MWMODEM_run in 
MWMODEM_InformationCallback at package->channel[0]->symbolratelimit!\n");
                return;
        }
-       printf("Test of MWMODEM_run was successful!");
+       printf("Test of MWMODEM_run was successful!\n");
 }
 
 int testinit(struct MWMODEM_Context *context, int port)
@@ -81,40 +82,75 @@
 
        context = MWMODEM_init(port, AF_INET, cb, NULL);
 
-       return -1;
+       printf("Test of MWMODEM_init was successful!\n");
+
+       return 0;
 }
 
-int testgetsocket(struct MWMODEM_Context *context, int *socket)
+int testgetsocket(struct MWMODEM_Context *context)
 {
-       *socket = MWMODEM_get_select_socket(context);
+       int socket = MWMODEM_get_select_socket(context);
 
-       if (-1==*socket)
+       if (-1==socket)
        {
-               printf("Error: failure of Test from 
MWMODEM_get_select_socket!");
+               printf("Error: failure of Test from 
MWMODEM_get_select_socket!\n");
                return -1;
        }
        else
        {
-               printf("Test of MWMODEM_get_select_socket was successful!");
+               printf("Test of MWMODEM_get_select_socket was successful!\n");
                return 0;
        }
 }
 
-void generatedata(int socket)
+int generatedata()//TODO
 {
+       const struct sockaddr *address;
+       struct sockaddr_in address4;
+       socklen_t alen;
+       int s;
 
+       s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+
+       if (-1==s) return -1;
+
+       memset (&address4, 0, sizeof(address4));
+       address4.sin_family = AF_INET;
+
+       #if HAVE_SOCKADDR_IN_SIN_LEN
+                       address4.sin_len = (u_char) sizeof (struct sockaddr_in);
+       #endif
+
+       address4.sin_port = htons(MWMODEM_PORT);
+       address =(const struct sockaddr *) &address4;
+
+       alen = sizeof (address4);
+
+       if (-1==bind(s, address, alen))return -1;
+
+       return 0;
 }
 
-int testrun(struct MWMODEM_Context *context, int socket)
+int testrun(struct MWMODEM_Context *context)
 {
-       generatedata(socket);
+       if (-1 == generatedata())
+       {
+               printf("Test of MWMODEM_run failed!\n");
+               return -1;
+       }
        MWMODEM_run(context);
+
+       printf("Test of MWMODEM_run was successful!\n");
+
        return 0;
 }
 
 int testfree(struct MWMODEM_Context *context)
 {
        MWMODEM_free (context);
+
+       printf("Test of MWMODEM_free was successful!\n");
+
        return 0;
 }
 
@@ -122,18 +158,17 @@
 int main(void)
 {
        struct MWMODEM_Context *context;
-       int socket;
        context = malloc(sizeof(context));
 
        if (-1 == testinit(context, 0)) return -1;
 
-       if (-1 == testgetsocket(context, &socket)) return -1;
+       if (-1 == testgetsocket(context)) return -1;
 
-       if (-1 == testrun(context, socket)) return -1;
+       if (-1 == testrun(context)) return -1;
 
        if (-1 == testfree(context)) return -1;
 
-       printf("All tests for the library with ipv4 and default port was 
successful!");
+       printf("All tests for the library with ipv4 and default port was 
successful!\n");
 
        return 0;
 }

Modified: libmwmodem/src/tests/libmwmodem_test_ipv6.c
===================================================================
--- libmwmodem/src/tests/libmwmodem_test_ipv6.c 2011-12-20 14:43:53 UTC (rev 
18720)
+++ libmwmodem/src/tests/libmwmodem_test_ipv6.c 2011-12-20 15:41:11 UTC (rev 
18721)
@@ -81,6 +81,8 @@
 
        context = MWMODEM_init(port, AF_INET, cb, NULL);
 
+       printf("Test of MWMODEM_init was successful!\n");
+
        return -1;
 }
 
@@ -100,21 +102,27 @@
        }
 }
 
-void generatedata(int socket)
+void generatedata(int socket, int port)
 {
 
 }
 
-int testrun(struct MWMODEM_Context *context, int socket)
+int testrun(struct MWMODEM_Context *context, int socket, int port)
 {
-       generatedata(socket);
+       generatedata(socket, port);
        MWMODEM_run(context);
+
+       printf("Test of MWMODEM_run was successful!\n");
+
        return 0;
 }
 
 int testfree(struct MWMODEM_Context *context)
 {
        MWMODEM_free (context);
+
+       printf("Test of MWMODEM_free was successful!\n");
+
        return 0;
 }
 
@@ -129,7 +137,7 @@
 
        if (-1 == testgetsocket(context, &socket)) return -1;
 
-       if (-1 == testrun(context, socket)) return -1;
+       if (-1 == testrun(context, socket, 5)) return -1;
 
        if (-1 == testfree(context)) return -1;
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]