Remove unused pkg dependancy
[platform/upstream/iotivity.git] / extlibs / tinydtls / tests / netq-test.c
1 #include <string.h>
2 #include <netinet/in.h>
3
4 #include "netq.h" 
5
6 #ifndef NDEBUG
7 extern void nq_dump(struct netq_t *);
8 #endif
9
10 int main(int argc, char **argv) {
11 #ifndef NDEBUG
12   struct netq_t *nq;
13
14   struct sockaddr_in6 dst = { AF_INET6, htons(20220), 0, IN6ADDR_ANY_INIT, 0 };
15   struct packet_t *p;
16
17   char *pkt[20] = { 
18     "Packet #1",
19     "This is packet #2",
20     "The third packet #3 is the largest",
21     "Packet #4",
22     "Packet #5",
23     "Packet #6",
24     "Packet #7"
25   };
26
27   nq = nq_new(200);
28
29   if (!nq) {
30     fprintf(stderr, "E: cannot create network packet queue\n");
31     return -1;
32   }
33
34   if (!nq_new_packet(nq, (struct sockaddr *)&dst, sizeof(dst), 
35                      0, pkt[0], strlen(pkt[0]))) {
36     fprintf(stderr, "E: cannot add packet #1\n");
37   }
38
39   nq_dump(nq);
40
41   if (!nq_new_packet(nq, (struct sockaddr *)&dst, sizeof(dst), 
42                      0, pkt[1], strlen(pkt[1]))) {
43     fprintf(stderr, "E: cannot add packet #2\n");
44   }
45
46   nq_dump(nq);
47
48   if (!nq_new_packet(nq, (struct sockaddr *)&dst, sizeof(dst), 
49                      0, pkt[2], strlen(pkt[2]))) {
50     fprintf(stderr, "E: cannot add packet #3\n");
51   }
52
53   nq_dump(nq);
54
55   p = nq_pop(nq);
56   if (!p) {
57     fprintf(stderr, "E: no packet\n");
58   }
59
60   if (!nq_new_packet(nq, (struct sockaddr *)&dst, sizeof(dst), 
61                      0, pkt[3], strlen(pkt[3]))) {
62     fprintf(stderr, "E: cannot add packet #4\n");
63   }
64
65   nq_dump(nq);
66
67   if (!nq_new_packet(nq, (struct sockaddr *)&dst, sizeof(dst), 
68                      0, pkt[4], strlen(pkt[4]))) {
69     fprintf(stderr, "E: cannot add packet #5\n");
70   }
71
72   nq_dump(nq);
73
74   p = nq_pop(nq);
75   if (!p) {
76     fprintf(stderr, "E: no packet\n");
77   }
78
79   if (!nq_new_packet(nq, (struct sockaddr *)&dst, sizeof(dst), 
80                      0, pkt[5], strlen(pkt[5]))) {
81     fprintf(stderr, "E: cannot add packet #6\n");
82   }
83
84   nq_dump(nq);
85
86   p = nq_pop(nq);
87   p = nq_pop(nq);
88   p = nq_pop(nq);
89   p = nq_pop(nq);
90   p = nq_pop(nq);
91   p = nq_pop(nq);
92   p = nq_pop(nq);
93
94   if (!nq_new_packet(nq, (struct sockaddr *)&dst, sizeof(dst), 
95                      0, pkt[6], strlen(pkt[6]))) {
96     fprintf(stderr, "E: cannot add packet #7\n");
97   }
98
99   nq_dump(nq);
100 #endif
101
102   return 0;
103 }