1 /* $Id: test_strmap.c,v 1.3 2007-12-03 17:09:01 adam Exp $
2 Copyright (C) 1995-2007
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <zebra_strmap.h>
28 static void test1(void)
31 zebra_strmap_t sm = zebra_strmap_create();
33 zebra_strmap_destroy(sm);
39 zebra_strmap_t sm = zebra_strmap_create();
40 YAZ_CHECK(!zebra_strmap_lookup(sm, "a", 0, 0));
42 zebra_strmap_add(sm, "a", &v, sizeof v);
43 data_buf = zebra_strmap_lookup(sm, "a", 0, &data_len);
44 YAZ_CHECK(data_buf && data_len == sizeof v
45 && v == *((int*) data_buf));
47 zebra_strmap_remove(sm, "a");
48 data_buf = zebra_strmap_lookup(sm, "a", 0, &data_len);
49 YAZ_CHECK(data_buf == 0);
52 zebra_strmap_add(sm, "a", &v, sizeof v);
55 zebra_strmap_add(sm, "b", &v, sizeof v);
58 zebra_strmap_add(sm, "c", &v, sizeof v);
61 zebra_strmap_it it = zebra_strmap_it_create(sm);
64 while ((name = zebra_strmap_it_next(it, &data_buf, &data_len)))
66 YAZ_CHECK(!strcmp(name, "a") || !strcmp(name, "b") ||
71 zebra_strmap_it_destroy(it);
73 zebra_strmap_destroy(sm);
77 static void test2(int no_iter)
79 zebra_strmap_t sm = zebra_strmap_create();
83 for (i = 0; i < no_iter; i++)
89 for (j = 0; j < sizeof(str)-1; j++)
90 str[j] = rand() & 255;
93 zebra_strmap_add(sm, str, &v, sizeof v);
100 for (i = 0; i < no_iter; i++)
108 for (j = 0; j < sizeof(str)-1; j++)
109 str[j] = rand() & 255;
113 while ((data_buf = zebra_strmap_lookup(sm, str, j, &data_len)))
115 if (data_len == sizeof v && v == *((int*) data_buf))
119 if (!(data_buf && data_len == sizeof v
120 && v == *((int*) data_buf)))
124 YAZ_CHECK_EQ(failed, 0);
126 zebra_strmap_destroy(sm);
129 int main (int argc, char **argv)
131 YAZ_CHECK_INIT(argc, argv);
140 * indent-tabs-mode: nil
142 * vim: shiftwidth=4 tabstop=8 expandtab