00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "vfer_datagram.h"
00017 #include "vfer_tests.h"
00018
00019 const int N = 32;
00020
00021
00022
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
00036 list.num = 0;
00037 list.first = list.last = NULL;
00038
00039 mem = (int)(ReqMem);
00040
00041
00042
00043
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
00082
00083 TEST_SUMMARY();
00084 return 0;
00085 }