diff -r c75a2d5caae9 -r 66ec30bde5e5 librazor/test-hashtable.c --- a/librazor/test-hashtable.c Fri May 01 16:48:47 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2009 J. Ali Harlow - * - * 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 - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "config.h" - -#include -#include -#include -#include "razor-internal.h" - -uint32_t invalid; -struct array pool; -struct hashtable table; - -static int test_key(const char *key) -{ - uint32_t value; - - value = hashtable_insert(&table, key); - if (value == invalid) { - fprintf(stderr, - "%s: hashtable_insert returned invalid value\n", key); - return 1; - } else if (value >= pool.size) { - fprintf(stderr, "%s: hashtable_insert returned value outside " - "pool\n", key); - return 1; - } else if (pool.size - value <= strlen(key) || - strcmp(pool.data + value, key)) { - fprintf(stderr, "%s: value returned by hashtable_insert does " - "not match key\n", key); - return 1; - } else if (hashtable_lookup(&table, key) != value) { - fprintf(stderr, "%s: hashtable_lookup didn't return expected " - "value\n", key); - return 1; - } else if (hashtable_tokenize(&table, key) != value) { - fprintf(stderr, "%s: hashtable_tokenize didn't return expected " - "value\n", key); - return 1; - } - return 0; -} - -int main(int argc, char *argv[]) -{ - int errors = 0; - - array_init(&pool); - hashtable_init(&table, &pool); - invalid = hashtable_lookup(&table, "non-existant"); - - errors += test_key("key1"); - errors += test_key("key2"); - - hashtable_release(&table); - array_release(&pool); - - exit(errors ? 1 : 0); -}