[bcl] Update BCL Linked Size
[mono-project.git] / mono / eglib / test / queue.c
blob200952199a8de9c0fbddd6485a0e0d71aec12c9a
1 #include <stdio.h>
2 #include <string.h>
3 #include <glib.h>
4 #include "test.h"
6 static RESULT
7 test_queue_push (void)
9 GQueue *queue = g_queue_new ();
11 g_queue_push_head (queue, (char*)"foo");
12 g_queue_push_head (queue, (char*)"bar");
13 g_queue_push_head (queue, (char*)"baz");
15 if (queue->length != 3)
16 return FAILED ("push failed");
18 if (NULL != queue->head->prev)
19 return FAILED ("HEAD: prev is wrong");
20 if (strcmp ("baz", queue->head->data))
21 return FAILED ("HEAD: First element is wrong");
22 if (strcmp ("bar", queue->head->next->data))
23 return FAILED ("HEAD: Second element is wrong");
24 if (strcmp ("foo", queue->head->next->next->data))
25 return FAILED ("HEAD: Third element is wrong");
26 if (NULL != queue->head->next->next->next)
27 return FAILED ("HEAD: End is wrong");
29 if (NULL != queue->tail->next)
30 return FAILED ("TAIL: next is wrong");
31 if (strcmp ("foo", queue->tail->data))
32 return FAILED ("TAIL: Third element is wrong");
33 if (strcmp ("bar", queue->tail->prev->data))
34 return FAILED ("TAIL: Second element is wrong");
35 if (strcmp ("baz", queue->tail->prev->prev->data))
36 return FAILED ("TAIL: First element is wrong");
37 if (NULL != queue->tail->prev->prev->prev)
38 return FAILED ("TAIL: End is wrong");
40 g_queue_free (queue);
41 return OK;
44 static RESULT
45 test_queue_push_tail (void)
47 GQueue *queue = g_queue_new ();
49 g_queue_push_tail (queue, (char*)"baz");
50 g_queue_push_tail (queue, (char*)"bar");
51 g_queue_push_tail (queue, (char*)"foo");
53 if (queue->length != 3)
54 return FAILED ("push failed");
56 if (NULL != queue->head->prev)
57 return FAILED ("HEAD: prev is wrong");
58 if (strcmp ("baz", queue->head->data))
59 return FAILED ("HEAD: First element is wrong");
60 if (strcmp ("bar", queue->head->next->data))
61 return FAILED ("HEAD: Second element is wrong");
62 if (strcmp ("foo", queue->head->next->next->data))
63 return FAILED ("HEAD: Third element is wrong");
64 if (NULL != queue->head->next->next->next)
65 return FAILED ("HEAD: End is wrong");
67 if (NULL != queue->tail->next)
68 return FAILED ("TAIL: next is wrong");
69 if (strcmp ("foo", queue->tail->data))
70 return FAILED ("TAIL: Third element is wrong");
71 if (strcmp ("bar", queue->tail->prev->data))
72 return FAILED ("TAIL: Second element is wrong");
73 if (strcmp ("baz", queue->tail->prev->prev->data))
74 return FAILED ("TAIL: First element is wrong");
75 if (NULL != queue->tail->prev->prev->prev)
76 return FAILED ("TAIL: End is wrong");
78 g_queue_free (queue);
79 return OK;
82 static RESULT
83 test_queue_pop (void)
85 GQueue *queue = g_queue_new ();
86 gpointer data;
88 g_queue_push_head (queue, (char*)"foo");
89 g_queue_push_head (queue, (char*)"bar");
90 g_queue_push_head (queue, (char*)"baz");
92 data = g_queue_pop_head (queue);
93 if (strcmp ("baz", data))
94 return FAILED ("expect baz.");
96 data = g_queue_pop_head (queue);
97 if (strcmp ("bar", data))
98 return FAILED ("expect bar.");
100 data = g_queue_pop_head (queue);
101 if (strcmp ("foo", data))
102 return FAILED ("expect foo.");
104 if (g_queue_is_empty (queue) == FALSE)
105 return FAILED ("expect is_empty.");
107 if (queue->length != 0)
108 return FAILED ("expect 0 length .");
110 g_queue_push_head (queue, (char*)"foo");
111 g_queue_push_head (queue, (char*)"bar");
112 g_queue_push_head (queue, (char*)"baz");
114 g_queue_pop_head (queue);
116 if (NULL != queue->head->prev)
117 return FAILED ("HEAD: prev is wrong");
118 if (strcmp ("bar", queue->head->data))
119 return FAILED ("HEAD: Second element is wrong");
120 if (strcmp ("foo", queue->head->next->data))
121 return FAILED ("HEAD: Third element is wrong");
122 if (NULL != queue->head->next->next)
123 return FAILED ("HEAD: End is wrong");
125 if (NULL != queue->tail->next)
126 return FAILED ("TAIL: next is wrong");
127 if (strcmp ("foo", queue->tail->data))
128 return FAILED ("TAIL: Second element is wrong");
129 if (strcmp ("bar", queue->tail->prev->data))
130 return FAILED ("TAIL: First element is wrong");
131 if (NULL != queue->tail->prev->prev)
132 return FAILED ("TAIL: End is wrong");
134 g_queue_free (queue);
135 return OK;
138 static RESULT
139 test_queue_new (void)
141 GQueue *queue = g_queue_new ();
143 if (queue->length != 0)
144 return FAILED ("expect length == 0");
146 if (queue->head != NULL)
147 return FAILED ("expect head == NULL");
149 if (queue->tail != NULL)
150 return FAILED ("expect tail == NULL");
152 g_queue_free (queue);
153 return OK;
156 static RESULT
157 test_queue_is_empty (void)
159 GQueue *queue = g_queue_new ();
161 if (g_queue_is_empty (queue) == FALSE)
162 return FAILED ("new queue should be empty");
164 g_queue_push_head (queue, (char*)"foo");
166 if (g_queue_is_empty (queue) == TRUE)
167 return FAILED ("expected TRUE");
169 g_queue_free (queue);
171 return OK;
174 static Test queue_tests [] = {
175 { "push", test_queue_push},
176 {"push_tail", test_queue_push_tail},
177 { "pop", test_queue_pop},
178 { "new", test_queue_new},
179 {"is_empty", test_queue_is_empty},
180 {NULL, NULL}
183 DEFINE_TEST_GROUP_INIT(queue_tests_init, queue_tests)