1 #include <search.h>
2 #include <stdio.h>
3 #include <string.h>
4 
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)
13 
14 static int
do_test(void)15 do_test (void)
16 {
17   struct qelem elements[4];
18   int ret = 0;
19 
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);
38 
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]);
56 
57   return ret;
58 }
59 
60 #define TEST_FUNCTION do_test ()
61 #include "../test-skeleton.c"
62