diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/.gitignore | 1 | ||||
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/replacement.c | 63 |
3 files changed, 65 insertions, 0 deletions
diff --git a/tests/.gitignore b/tests/.gitignore index 6c96e28..41ca9e7 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -5,3 +5,4 @@ insert_and_lookup insert_many null_destroy random_entry +replacement diff --git a/tests/Makefile.am b/tests/Makefile.am index 83610ba..e681df1 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -29,6 +29,7 @@ TESTS = \ insert_many \ null_destroy \ random_entry \ + replacement \ $() EXTRA_PROGRAMS = $(TESTS) diff --git a/tests/replacement.c b/tests/replacement.c new file mode 100644 index 0000000..eb70906 --- /dev/null +++ b/tests/replacement.c @@ -0,0 +1,63 @@ +/* + * Copyright © 2011 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * Authors: + * Eric Anholt <eric@anholt.net> + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> +#include "hash_table.h" +#include "fnv_hash.h" + +int +main(int argc, char **argv) +{ + struct hash_table *ht; + char *str1 = strdup("test1"); + char *str2 = strdup("test1"); + uint32_t hash_str1 = fnv1_hash_string(str1); + uint32_t hash_str2 = fnv1_hash_string(str2); + struct hash_entry *entry; + + ht = hash_table_create(string_key_equals); + + hash_table_insert(ht, hash_str1, str1, str1); + hash_table_insert(ht, hash_str2, str2, str2); + + entry = hash_table_search(ht, hash_str1, str1); + assert(entry); + assert(entry->data == str2); + + hash_table_remove(ht, entry); + + entry = hash_table_search(ht, hash_str1, str1); + assert(!entry); + + hash_table_destroy(ht, NULL); + free(str1); + free(str2); + + return 0; +} |