2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file util/test_container_slist.c
23 * @brief Testcases for singly linked lists
28 #include "gnunet_common.h"
29 #include "gnunet_container_lib.h"
31 #define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); return 1; }
32 #define CHECK(c) { if (! (c)) ABORT(); }
35 main (int argc, char *argv[])
37 struct GNUNET_CONTAINER_SList *l;
38 struct GNUNET_CONTAINER_SList_Iterator *it;
42 GNUNET_log_setup ("test-container-slist", "WARNING", NULL);
44 l = GNUNET_CONTAINER_slist_create ();
46 CHECK (GNUNET_CONTAINER_slist_count (l) == 0);
48 for (i = 0; i < 100; i++)
49 GNUNET_CONTAINER_slist_add (l, GNUNET_MEM_DISP_TRANSIENT, &i, sizeof (i));
50 CHECK (GNUNET_CONTAINER_slist_count (l) == 100);
52 for (it = GNUNET_CONTAINER_slist_begin (l), i = 99;
53 GNUNET_CONTAINER_slist_end (it) != GNUNET_YES;
54 GNUNET_CONTAINER_slist_next (it), i--)
56 p = GNUNET_CONTAINER_slist_get (it, &s);
60 CHECK (s == sizeof (i));
63 GNUNET_CONTAINER_slist_insert (it, GNUNET_MEM_DISP_TRANSIENT, &j,
67 CHECK (GNUNET_CONTAINER_slist_count (l) == 200);
69 CHECK (GNUNET_CONTAINER_slist_contains (l, &i, sizeof (i)));
71 for (it = GNUNET_CONTAINER_slist_begin (l);
72 GNUNET_CONTAINER_slist_end (it) != GNUNET_YES;)
74 p = GNUNET_CONTAINER_slist_get (it, &s);
76 CHECK (s == sizeof (i));
79 CHECK (GNUNET_CONTAINER_slist_next (it) == GNUNET_YES);
80 CHECK (GNUNET_CONTAINER_slist_end (it) != GNUNET_YES);
82 p = GNUNET_CONTAINER_slist_get (it, &s);
84 CHECK (s == sizeof (j));
89 GNUNET_CONTAINER_slist_erase (it);
92 CHECK (GNUNET_CONTAINER_slist_count (l) == 100);
94 CHECK (GNUNET_CONTAINER_slist_contains (l, &i, sizeof (i)) == GNUNET_NO);
96 CHECK (GNUNET_CONTAINER_slist_contains (l, &i, sizeof (i)));
98 GNUNET_CONTAINER_slist_clear (l);
99 CHECK (GNUNET_CONTAINER_slist_count (l) == 0);
101 for (i = 0; i < 100; i++)
102 GNUNET_CONTAINER_slist_add (l, GNUNET_MEM_DISP_TRANSIENT, &i, sizeof (i));
104 GNUNET_CONTAINER_slist_destroy (l);