Back to index

glibc  2.9
tst-insremque.c
Go to the documentation of this file.
00001 #include <search.h>
00002 #include <stdio.h>
00003 #include <string.h>
00004 
00005 #define CHECK(cond) \
00006   do                                                           \
00007     if (! (cond))                                              \
00008       {                                                               \
00009        printf ("Condition " #cond " not true on line %d\n", __LINE__);       \
00010        ret = 1;                                                \
00011       }                                                               \
00012   while (0)
00013 
00014 static int
00015 do_test (void)
00016 {
00017   struct qelem elements[4];
00018   int ret = 0;
00019 
00020   /* Linear list.  */
00021   memset (elements, 0xff, sizeof (elements));
00022   insque (&elements[0], NULL);
00023   remque (&elements[0]);
00024   insque (&elements[0], NULL);
00025   insque (&elements[2], &elements[0]);
00026   insque (&elements[1], &elements[0]);
00027   insque (&elements[3], &elements[2]);
00028   remque (&elements[2]);
00029   insque (&elements[2], &elements[0]);
00030   CHECK (elements[0].q_back == NULL);
00031   CHECK (elements[0].q_forw == &elements[2]);
00032   CHECK (elements[1].q_back == &elements[2]);
00033   CHECK (elements[1].q_forw == &elements[3]);
00034   CHECK (elements[2].q_back == &elements[0]);
00035   CHECK (elements[2].q_forw == &elements[1]);
00036   CHECK (elements[3].q_back == &elements[1]);
00037   CHECK (elements[3].q_forw == NULL);
00038 
00039   /* Circular list.  */
00040   memset (elements, 0xff, sizeof (elements));
00041   elements[0].q_back = &elements[0];
00042   elements[0].q_forw = &elements[0];
00043   insque (&elements[2], &elements[0]);
00044   insque (&elements[1], &elements[0]);
00045   insque (&elements[3], &elements[2]);
00046   remque (&elements[2]);
00047   insque (&elements[2], &elements[0]);
00048   CHECK (elements[0].q_back == &elements[3]);
00049   CHECK (elements[0].q_forw == &elements[2]);
00050   CHECK (elements[1].q_back == &elements[2]);
00051   CHECK (elements[1].q_forw == &elements[3]);
00052   CHECK (elements[2].q_back == &elements[0]);
00053   CHECK (elements[2].q_forw == &elements[1]);
00054   CHECK (elements[3].q_back == &elements[1]);
00055   CHECK (elements[3].q_forw == &elements[0]);
00056 
00057   return ret;
00058 }
00059 
00060 #define TEST_FUNCTION do_test ()
00061 #include "../test-skeleton.c"