src/vfer_test_datagram.c

Go to the documentation of this file.
00001 /*
00002  * Copyright 2005, 2006, Internet2
00003  * Legal conditions are in file LICENSE
00004  * (MD5 = c434f2e53b8089d8b4d0172c7ce07360).
00005  */
00006 /**
00007  *
00008  * @file   vfer_test_datagram.c
00009  * @author Ivan Beschastnikh
00010  * @brief  Tests the datagram list and datagram structures
00011  *
00012  * -     02/20/06        ivan            Added some tests
00013  * -     02/18/06        ivan            created
00014  */
00015 
00016 #include "vfer_datagram.h"
00017 #include "vfer_tests.h"
00018 
00019 const int N = 32;
00020 
00021 /**
00022  * Main
00023  */
00024 int main() {
00025         frame_list list;
00026         frame_link* fl;
00027         uint32_t i;
00028         int array[32];
00029         char buf[256];
00030         int ret;
00031         int mem;
00032         
00033         TEST_INIT("TEST_DATAGRAM", "test_datagram.c", stdout, stdout);
00034 
00035         /* initialize by hand for now */
00036         list.num = 0;
00037         list.first = list.last = NULL;
00038 
00039         mem = (int)(ReqMem);
00040 
00041         /* enqueue frames with index dependent data so that we can
00042          * check them for consistency and ordering when we dequeue
00043          * them in the following loop */
00044          
00045         for (i = 0; i < N; i++) {
00046                 array[i] = i;
00047 
00048                 TEST_CHECK((list.num == i), "List does not maintain frame count correctly on insert phantom");
00049                 
00050                 fl = Datagram_Insert_Phantom(&list, NULL, i);
00051                 TEST_CHECK((fl != 0), "Couldn't insert phantom datagram");
00052                 if (fl == 0) continue;
00053                 ALLOC(fl->frame.data, int*, int, 1);
00054                 TEST_CHECK((fl->frame.data != 0), "Couldn't alloc frame.data");
00055                 memcpy(fl->frame.data, &(array[i]), sizeof(int));
00056                 fl->frame.len                   = sizeof(int);
00057                 fl->frame.urgency               = -1*i;
00058                 fl->frame.done                  = i;
00059         }
00060 
00061         fl = list.first;
00062         i = N - 1;
00063         while (fl != NULL) {
00064                 TEST_CHECK((    memcmp(fl->frame.data, &(array[i]), sizeof(int)) == 0 && \
00065                                 fl->frame.len                   == sizeof(int) && \
00066                                 fl->frame.urgency               == -1*i && \
00067                                 fl->frame.done                  == i), "Frame list is inconsistent");
00068                 i--;
00069                 fl = fl->next;
00070         }
00071 
00072         for (i = 0; i < N; i++) {
00073                 TEST_CHECK((list.num == (32 - i)), "List does not maintain frame count correctly on dequeue");
00074                 ret = Datagram_Dequeue(&list, buf, 256);
00075                 TEST_CHECK((ret == sizeof(int)), "Failed to dequeue frame from list");
00076                 if (ret == -1) continue;
00077                 ret = memcmp(buf, &(array[31 - i]), sizeof(int));
00078                 TEST_CHECK((ret == 0), "Dequeue returned bad data");
00079         }
00080 
00081 //      TEST_CHECK((mem == (int)(ReqMem)), "Memory leak in datagram code");
00082         
00083         TEST_SUMMARY();
00084         return 0;
00085 } /* main() */

Generated on Tue Aug 8 16:07:19 2006 for VFER by  doxygen 1.4.7