X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=tests%2Flibpspp%2Fhmap-test.c;h=bbe341388a3ce530b26957afd8e89a3df586d6c1;hb=b3e38130c172738f79f180fb4d459e4d5d2d88a6;hp=64511b7bbf1d1c7dafb79857fc811b014d6e9af2;hpb=7c08a6e1009cf60847e770a77a73c650e9326379;p=pspp diff --git a/tests/libpspp/hmap-test.c b/tests/libpspp/hmap-test.c index 64511b7bbf..bbe341388a 100644 --- a/tests/libpspp/hmap-test.c +++ b/tests/libpspp/hmap-test.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc. + Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -666,6 +666,10 @@ test_insert_ordered (int max_elems, hash_function *hash) struct hmap hmap; int i; +#if __GNUC__ == 4 && __GNUC_MINOR__ == 3 + return; +#endif /* GCC 4.3 */ + hmap_init (&hmap); elements = xnmalloc (max_elems, sizeof *elements); values = xnmalloc (max_elems, sizeof *values); @@ -911,6 +915,45 @@ test_swap_random_hash (void) test_swap (128, random_hash); } +/* Inserts elements into an hmap in ascending order, then clears the hash table + using hmap_clear(). */ +static void +test_clear (void) +{ + const int max_elems = 128; + struct element *elements; + int *values; + struct hmap hmap; + int cnt; + +#if __GNUC__ == 4 && __GNUC_MINOR__ == 3 + return; +#endif /* GCC 4.3 */ + + elements = xnmalloc (max_elems, sizeof *elements); + values = xnmalloc (max_elems, sizeof *values); + + for (cnt = 0; cnt <= max_elems; cnt++) + { + int i; + + hmap_init (&hmap); + for (i = 0; i < cnt; i++) + { + values[i] = elements[i].data = i; + hmap_insert (&hmap, &elements[i].node, + random_hash (elements[i].data)); + check_hmap (&hmap, values, i + 1, random_hash); + } + hmap_clear (&hmap); + check_hmap (&hmap, NULL, 0, random_hash); + hmap_destroy (&hmap); + } + + free (elements); + free (values); +} + static void test_destroy_null (void) { @@ -995,6 +1038,8 @@ main (void) run_test (test_swap_random_hash, "test swapping tables"); + run_test (test_clear, "test clearing hash table"); + run_test (test_destroy_null, "test destroying null table"); run_test (test_shrink_empty, "test shrinking an empty table");