aboutsummaryrefslogtreecommitdiffstats
path: root/src/libcharon/plugins
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2013-03-26 16:38:27 +0100
committerTobias Brunner <tobias@strongswan.org>2013-06-11 11:03:10 +0200
commite09461bf77df9db40f15d9bcf1a64a959e8d7fb6 (patch)
treedbc5448e6a01d6ebfef9626fe0d6c24a8d201e15 /src/libcharon/plugins
parent0298be570504948754444a3c287c622d9c566e33 (diff)
downloadstrongswan-e09461bf77df9db40f15d9bcf1a64a959e8d7fb6.tar.bz2
strongswan-e09461bf77df9db40f15d9bcf1a64a959e8d7fb6.tar.xz
Converted and added tests for hashtable_t
Diffstat (limited to 'src/libcharon/plugins')
-rw-r--r--src/libcharon/plugins/unit_tester/Makefile.am3
-rw-r--r--src/libcharon/plugins/unit_tester/tests.h1
-rw-r--r--src/libcharon/plugins/unit_tester/tests/test_hashtable.c111
3 files changed, 1 insertions, 114 deletions
diff --git a/src/libcharon/plugins/unit_tester/Makefile.am b/src/libcharon/plugins/unit_tester/Makefile.am
index 84e717034..b597b928b 100644
--- a/src/libcharon/plugins/unit_tester/Makefile.am
+++ b/src/libcharon/plugins/unit_tester/Makefile.am
@@ -22,7 +22,6 @@ libstrongswan_unit_tester_la_SOURCES = \
tests/test_med_db.c \
tests/test_chunk.c \
tests/test_pool.c \
- tests/test_agent.c \
- tests/test_hashtable.c
+ tests/test_agent.c
libstrongswan_unit_tester_la_LDFLAGS = -module -avoid-version
diff --git a/src/libcharon/plugins/unit_tester/tests.h b/src/libcharon/plugins/unit_tester/tests.h
index fc7761bb5..527bb2572 100644
--- a/src/libcharon/plugins/unit_tester/tests.h
+++ b/src/libcharon/plugins/unit_tester/tests.h
@@ -18,7 +18,6 @@
* @{ @ingroup unit_tester
*/
-DEFINE_TEST("hashtable_t->remove_at()", test_hashtable_remove_at, FALSE)
DEFINE_TEST("auth cfg", test_auth_cfg, FALSE)
DEFINE_TEST("CURL get", test_curl_get, FALSE)
DEFINE_TEST("MySQL operations", test_mysql, FALSE)
diff --git a/src/libcharon/plugins/unit_tester/tests/test_hashtable.c b/src/libcharon/plugins/unit_tester/tests/test_hashtable.c
deleted file mode 100644
index 5513f6707..000000000
--- a/src/libcharon/plugins/unit_tester/tests/test_hashtable.c
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (C) 2010 Tobias Brunner
- * Hochschule fuer Technik Rapperswil
- *
- * 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. See <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * 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.
- */
-
-#include <library.h>
-#include <collections/hashtable.h>
-
-static u_int hash(char *key)
-{
- return chunk_hash(chunk_create(key, strlen(key)));
-}
-
-static u_int equals(char *key1, char *key2)
-{
- return streq(key1, key2);
-}
-
-/**
- * Test the remove_at method
- */
-bool test_hashtable_remove_at()
-{
- char *k1 = "key1", *k2 = "key2", *k3 = "key3", *key;
- char *v1 = "val1", *v2 = "val2", *v3 = "val3", *value;
- enumerator_t *enumerator;
- hashtable_t *ht = hashtable_create((hashtable_hash_t)hash,
- (hashtable_equals_t)equals, 0);
-
- ht->put(ht, k1, v1);
- ht->put(ht, k2, v2);
- ht->put(ht, k3, v3);
-
- if (ht->get_count(ht) != 3)
- {
- return FALSE;
- }
-
- enumerator = ht->create_enumerator(ht);
- while (enumerator->enumerate(enumerator, &key, &value))
- {
- if (streq(key, k2))
- {
- ht->remove_at(ht, enumerator);
- }
- }
- enumerator->destroy(enumerator);
-
- if (ht->get_count(ht) != 2)
- {
- return FALSE;
- }
-
- if (ht->get(ht, k1) == NULL ||
- ht->get(ht, k3) == NULL)
- {
- return FALSE;
- }
-
- if (ht->get(ht, k2) != NULL)
- {
- return FALSE;
- }
-
- ht->put(ht, k2, v2);
-
- if (ht->get_count(ht) != 3)
- {
- return FALSE;
- }
-
- if (ht->get(ht, k1) == NULL ||
- ht->get(ht, k2) == NULL ||
- ht->get(ht, k3) == NULL)
- {
- return FALSE;
- }
-
- enumerator = ht->create_enumerator(ht);
- while (enumerator->enumerate(enumerator, &key, &value))
- {
- ht->remove_at(ht, enumerator);
- }
- enumerator->destroy(enumerator);
-
- if (ht->get_count(ht) != 0)
- {
- return FALSE;
- }
-
- if (ht->get(ht, k1) != NULL ||
- ht->get(ht, k2) != NULL ||
- ht->get(ht, k3) != NULL)
- {
- return FALSE;
- }
-
- ht->destroy(ht);
-
- return TRUE;
-}