glibc 2.11.1 release
[glibc.git] / misc / tst-insremque.c
blob9f17055ef545ba125e719ec721f7bedc7b6bed6f
1 #include <search.h>
2 #include <stdio.h>
3 #include <string.h>
5 #define CHECK(cond) \
6 do \
7 if (! (cond)) \
8 { \
9 printf ("Condition " #cond " not true on line %d\n", __LINE__); \
10 ret = 1; \
11 } \
12 while (0)
14 static int
15 do_test (void)
17 struct qelem elements[4];
18 int ret = 0;
20 /* Linear list. */
21 memset (elements, 0xff, sizeof (elements));
22 insque (&elements[0], NULL);
23 remque (&elements[0]);
24 insque (&elements[0], NULL);
25 insque (&elements[2], &elements[0]);
26 insque (&elements[1], &elements[0]);
27 insque (&elements[3], &elements[2]);
28 remque (&elements[2]);
29 insque (&elements[2], &elements[0]);
30 CHECK (elements[0].q_back == NULL);
31 CHECK (elements[0].q_forw == &elements[2]);
32 CHECK (elements[1].q_back == &elements[2]);
33 CHECK (elements[1].q_forw == &elements[3]);
34 CHECK (elements[2].q_back == &elements[0]);
35 CHECK (elements[2].q_forw == &elements[1]);
36 CHECK (elements[3].q_back == &elements[1]);
37 CHECK (elements[3].q_forw == NULL);
39 /* Circular list. */
40 memset (elements, 0xff, sizeof (elements));
41 elements[0].q_back = &elements[0];
42 elements[0].q_forw = &elements[0];
43 insque (&elements[2], &elements[0]);
44 insque (&elements[1], &elements[0]);
45 insque (&elements[3], &elements[2]);
46 remque (&elements[2]);
47 insque (&elements[2], &elements[0]);
48 CHECK (elements[0].q_back == &elements[3]);
49 CHECK (elements[0].q_forw == &elements[2]);
50 CHECK (elements[1].q_back == &elements[2]);
51 CHECK (elements[1].q_forw == &elements[3]);
52 CHECK (elements[2].q_back == &elements[0]);
53 CHECK (elements[2].q_forw == &elements[1]);
54 CHECK (elements[3].q_back == &elements[1]);
55 CHECK (elements[3].q_forw == &elements[0]);
57 return ret;
60 #define TEST_FUNCTION do_test ()
61 #include "../test-skeleton.c"