1 /* Test the sash (string hash) class.
2 * By Richard W.M. Jones <rich@annexia.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 * $Id: test_sash.c,v 1.1 2001/02/08 12:51:32 rich Exp $
39 pool pool = new_pool (), pool2;
43 /* Create a string -> string hash. */
46 /* Insert some new values. */
47 if (sash_insert (h, "tomato", "red") != 0) abort ();
48 if (sash_insert (h, "orange", "orange") != 0) abort ();
49 if (sash_insert (h, "lemon", "yellow") != 0) abort ();
50 if (sash_insert (h, "lime", "green") != 0) abort ();
51 if (sash_insert (h, "peach", "orange") != 0) abort ();
52 if (sash_insert (h, "apple", "green") != 0) abort ();
53 if (sash_insert (h, "raspberry", "red") != 0) abort ();
55 /* This should replace existing values. */
56 if (sash_insert (h, "apple", "red") == 0) abort ();
57 if (sash_insert (h, "peach", "yellow") == 0) abort ();
59 /* Retrieve some values. */
60 if (sash_get (h, "apple", v) == 0 || strcmp (v, "red") != 0) abort ();
61 if (sash_get (h, "tomato", v) == 0 || strcmp (v, "red") != 0) abort ();
62 if (sash_get (h, "orange", v) == 0 || strcmp (v, "orange") != 0) abort ();
65 h = copy_sash (pool, h);
67 /* Erase a key and check that it no longer exists. */
68 if (sash_erase (h, "apple") == 0) abort ();
69 if (sash_get (h, "apple", v) != 0) abort ();
71 /* Get list of keys and values. */
73 values = sash_values (h);
75 printf ("keys = [ %s ]\n", pjoin (pool, keys, ", "));
76 printf ("values = [ %s ]\n", pjoin (pool, values, ", "));
78 /* Copy the sash into another pool, delete the old pool, check all
79 * keys and values have been copied across.
82 h = copy_sash (pool2, h);
86 values = sash_values (h);
88 printf ("keys = [ %s ]\n", pjoin (pool2, keys, ", "));
89 printf ("values = [ %s ]\n", pjoin (pool2, values, ", "));