Make sure x86 ATOMIC_CAS doesn't overwrite its own operands.
[mono-debugger.git] / eglib / test / queue.c
blob2855e19d20f4169923bdfb7cf88bb2c4127d5682
1 #include <stdio.h>
2 #include <string.h>
3 #include <glib.h>
4 #include "test.h"
6 RESULT
7 test_queue_push ()
9 GQueue *queue = g_queue_new ();
11 g_queue_push_head (queue, "foo");
12 g_queue_push_head (queue, "bar");
13 g_queue_push_head (queue, "baz");
15 if (queue->length != 3)
16 return FAILED ("push failed");
18 g_queue_free (queue);
19 return OK;
22 RESULT
23 test_queue_pop ()
25 GQueue *queue = g_queue_new ();
26 gpointer data;
28 g_queue_push_head (queue, "foo");
29 g_queue_push_head (queue, "bar");
30 g_queue_push_head (queue, "baz");
32 data = g_queue_pop_head (queue);
33 if (strcmp ("baz", data))
34 return FAILED ("expect baz.");
36 data = g_queue_pop_head (queue);
37 if (strcmp ("bar", data))
38 return FAILED ("expect bar.");
40 data = g_queue_pop_head (queue);
41 if (strcmp ("foo", data))
42 return FAILED ("expect foo.");
44 if (g_queue_is_empty (queue) == FALSE)
45 return FAILED ("expect is_empty.");
47 if (queue->length != 0)
48 return FAILED ("expect 0 length .");
50 g_queue_free (queue);
51 return OK;
54 RESULT
55 test_queue_new ()
57 GQueue *queue = g_queue_new ();
59 if (queue->length != 0)
60 return FAILED ("expect length == 0");
62 if (queue->head != NULL)
63 return FAILED ("expect head == NULL");
65 if (queue->tail != NULL)
66 return FAILED ("expect tail == NULL");
68 g_queue_free (queue);
69 return OK;
72 RESULT
73 test_queue_is_empty ()
75 GQueue *queue = g_queue_new ();
77 if (g_queue_is_empty (queue) == FALSE)
78 return FAILED ("new queue should be empty");
80 g_queue_push_head (queue, "foo");
82 if (g_queue_is_empty (queue) == TRUE)
83 return FAILED ("expected TRUE");
85 g_queue_free (queue);
87 return OK;
90 static Test queue_tests [] = {
91 { "push", test_queue_push},
92 { "pop", test_queue_pop},
93 { "new", test_queue_new},
94 {"is_empty", test_queue_is_empty},
95 {NULL, NULL}
98 DEFINE_TEST_GROUP_INIT(queue_tests_init, queue_tests)