ali@357: /* ali@357: * Copyright (C) 2009 J. Ali Harlow ali@357: * ali@357: * This program is free software; you can redistribute it and/or modify ali@357: * it under the terms of the GNU General Public License as published by ali@357: * the Free Software Foundation; either version 2 of the License, or ali@357: * (at your option) any later version. ali@357: * ali@357: * This program is distributed in the hope that it will be useful, ali@357: * but WITHOUT ANY WARRANTY; without even the implied warranty of ali@357: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ali@357: * GNU General Public License for more details. ali@357: * ali@357: * You should have received a copy of the GNU General Public License along ali@357: * with this program; if not, write to the Free Software Foundation, Inc., ali@357: * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ali@357: */ ali@357: ali@357: #include "config.h" ali@357: ali@357: #include ali@357: #include ali@357: #include ali@357: #include "razor-internal.h" ali@357: ali@357: uint32_t invalid; ali@357: struct array pool; ali@357: struct hashtable table; ali@357: ali@357: static int test_key(const char *key) ali@357: { ali@357: uint32_t value; ali@357: ali@357: value = hashtable_insert(&table, key); ali@357: if (value == invalid) { ali@357: fprintf(stderr, ali@357: "%s: hashtable_insert returned invalid value\n", key); ali@357: return 1; ali@357: } else if (value >= pool.size) { ali@357: fprintf(stderr, "%s: hashtable_insert returned value outside " ali@357: "pool\n", key); ali@357: return 1; ali@357: } else if (pool.size - value <= strlen(key) || ali@357: strcmp(pool.data + value, key)) { ali@357: fprintf(stderr, "%s: value returned by hashtable_insert does " ali@357: "not match key\n", key); ali@357: return 1; ali@357: } else if (hashtable_lookup(&table, key) != value) { ali@357: fprintf(stderr, "%s: hashtable_lookup didn't return expected " ali@357: "value\n", key); ali@357: return 1; ali@357: } else if (hashtable_tokenize(&table, key) != value) { ali@357: fprintf(stderr, "%s: hashtable_tokenize didn't return expected " ali@357: "value\n", key); ali@357: return 1; ali@357: } ali@357: return 0; ali@357: } ali@357: ali@357: int main(int argc, char *argv[]) ali@357: { ali@357: int errors = 0; ali@357: ali@357: array_init(&pool); ali@357: hashtable_init(&table, &pool); ali@357: invalid = hashtable_lookup(&table, "non-existant"); ali@357: ali@357: errors += test_key("key1"); ali@357: errors += test_key("key2"); ali@357: ali@357: hashtable_release(&table); ali@357: array_release(&pool); ali@357: ali@357: exit(errors ? 1 : 0); ali@357: }