summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2013-10-25 13:38:37 -0700
committerEric Anholt <eric@anholt.net>2013-10-25 15:21:08 -0700
commit9dd53079a431768b76431fa632a5ea086d0c54e9 (patch)
treea9fbcd05ec2d50532485b3dc15464ba41794002b /tests
parentf9d22af764336897158a3477ab648a5bdaa26cf2 (diff)
Add new convenience function 'remove' (renaming former to 'remove_entry')
The new 'remove' function provides a parallel interface to that of search, (removing an entry matching the provided data). The former remove function (which accepts a pointer to a known entry) is renamed to 'remove_entry'. This new 'remove' is a simple convenience function which calls 'search' and then 'remove_entry'. As can be seen in the updates to the test suite, there are cases where the caller was already doing exactly that, so the new interface simplifies such uses. v2: Whitespace consistency change (by anholt)
Diffstat (limited to 'tests')
-rw-r--r--tests/collision.c2
-rw-r--r--tests/delete_and_lookup.c14
-rw-r--r--tests/delete_management.c4
-rw-r--r--tests/int-set/delete_and_lookup.c19
-rw-r--r--tests/int-set/delete_management.c4
-rw-r--r--tests/int-set/null_remove.c2
-rw-r--r--tests/int-set/replacement.c2
-rw-r--r--tests/remove_null.c2
-rw-r--r--tests/replacement.c2
-rw-r--r--tests/set/delete_and_lookup.c14
-rw-r--r--tests/set/delete_management.c3
-rw-r--r--tests/set/null_remove.c2
-rw-r--r--tests/set/replacement.c2
13 files changed, 48 insertions, 24 deletions
diff --git a/tests/collision.c b/tests/collision.c
index 6518e04..2497fd9 100644
--- a/tests/collision.c
+++ b/tests/collision.c
@@ -57,7 +57,7 @@ main(int argc, char **argv)
assert(entry1->key == str1);
/* Remove the collided entry and look again. */
- hash_table_remove(ht, entry1);
+ hash_table_remove_entry(ht, entry1);
entry2 = hash_table_search(ht, bad_hash, str2);
assert(entry2->key == str2);
diff --git a/tests/delete_and_lookup.c b/tests/delete_and_lookup.c
index 8428ccb..1a07881 100644
--- a/tests/delete_and_lookup.c
+++ b/tests/delete_and_lookup.c
@@ -46,14 +46,20 @@ main(int argc, char **argv)
struct hash_table *ht;
const char *str1 = "test1";
const char *str2 = "test2";
+ const char *str3 = "test3";
uint32_t hash_str1 = badhash(str1);
uint32_t hash_str2 = badhash(str2);
+ uint32_t hash_str3 = badhash(str3);
struct hash_entry *entry;
ht = hash_table_create(string_key_equals);
hash_table_insert(ht, hash_str1, str1, NULL);
hash_table_insert(ht, hash_str2, str2, NULL);
+ hash_table_insert(ht, hash_str3, str3, NULL);
+
+ entry = hash_table_search(ht, hash_str3, str3);
+ assert(strcmp(entry->key, str3) == 0);
entry = hash_table_search(ht, hash_str2, str2);
assert(strcmp(entry->key, str2) == 0);
@@ -61,13 +67,17 @@ main(int argc, char **argv)
entry = hash_table_search(ht, hash_str1, str1);
assert(strcmp(entry->key, str1) == 0);
- hash_table_remove(ht, entry);
+ hash_table_remove_entry(ht, entry);
+ hash_table_remove(ht, hash_str2, str2);
entry = hash_table_search(ht, hash_str1, str1);
assert(entry == NULL);
entry = hash_table_search(ht, hash_str2, str2);
- assert(strcmp(entry->key, str2) == 0);
+ assert(entry == NULL);
+
+ entry = hash_table_search(ht, hash_str3, str3);
+ assert(strcmp(entry->key, str3) == 0);
hash_table_destroy(ht, NULL);
diff --git a/tests/delete_management.c b/tests/delete_management.c
index 6203156..6a15691 100644
--- a/tests/delete_management.c
+++ b/tests/delete_management.c
@@ -61,9 +61,7 @@ main(int argc, char **argv)
if (i >= 100) {
uint32_t delete_value = i - 100;
- entry = hash_table_search(ht, delete_value,
- &delete_value);
- hash_table_remove(ht, entry);
+ hash_table_remove(ht, delete_value, &delete_value);
}
}
diff --git a/tests/int-set/delete_and_lookup.c b/tests/int-set/delete_and_lookup.c
index 8810b5a..f37cd0f 100644
--- a/tests/int-set/delete_and_lookup.c
+++ b/tests/int-set/delete_and_lookup.c
@@ -42,26 +42,35 @@ main(int argc, char **argv)
* behavior for chained objects. */
uint32_t value1 = 0x00000123;
uint32_t value2 = 0x10000123;
+ uint32_t value3 = 0x20000123;
struct int_set_entry *entry;
set = int_set_create();
int_set_add(set, value1);
int_set_add(set, value2);
+ int_set_add(set, value3);
- entry = int_set_search(set, value1);
- assert(entry->value == value1);
+ entry = int_set_search(set, value3);
+ assert(entry->value == value3);
entry = int_set_search(set, value2);
assert(entry->value == value2);
- int_set_remove(set, entry);
+ entry = int_set_search(set, value1);
+ assert(entry->value == value1);
+
+ int_set_remove_entry(set, entry);
+ int_set_remove(set, value2);
+
+ entry = int_set_search(set, value1);
+ assert(entry == NULL);
entry = int_set_search(set, value2);
assert(entry == NULL);
- entry = int_set_search(set, value1);
- assert(entry->value == value1);
+ entry = int_set_search(set, value3);
+ assert(entry->value == value3);
int_set_destroy(set);
diff --git a/tests/int-set/delete_management.c b/tests/int-set/delete_management.c
index cc0ea9d..0d4bfe3 100644
--- a/tests/int-set/delete_management.c
+++ b/tests/int-set/delete_management.c
@@ -46,9 +46,7 @@ main(int argc, char **argv)
int_set_add(set, i);
if (i >= 100) {
- uint32_t delete_value = i - 100;
- entry = int_set_search(set, delete_value);
- int_set_remove(set, entry);
+ int_set_remove(set, i - 100);
}
}
diff --git a/tests/int-set/null_remove.c b/tests/int-set/null_remove.c
index 318c570..a8c1340 100644
--- a/tests/int-set/null_remove.c
+++ b/tests/int-set/null_remove.c
@@ -38,7 +38,7 @@ main(int argc, char **argv)
set = int_set_create();
- int_set_remove(set, NULL);
+ int_set_remove_entry(set, NULL);
int_set_destroy(set);
diff --git a/tests/int-set/replacement.c b/tests/int-set/replacement.c
index 71436bb..ef9faaa 100644
--- a/tests/int-set/replacement.c
+++ b/tests/int-set/replacement.c
@@ -47,7 +47,7 @@ main(int argc, char **argv)
assert(entry);
assert(entry->value == value);
- int_set_remove(set, entry);
+ int_set_remove_entry(set, entry);
entry = int_set_search(set, value);
assert(!entry);
diff --git a/tests/remove_null.c b/tests/remove_null.c
index 1be8f84..0d9066d 100644
--- a/tests/remove_null.c
+++ b/tests/remove_null.c
@@ -38,7 +38,7 @@ main(int argc, char **argv)
ht = hash_table_create(string_key_equals);
- hash_table_remove(ht, NULL);
+ hash_table_remove_entry(ht, NULL);
hash_table_destroy(ht, NULL);
diff --git a/tests/replacement.c b/tests/replacement.c
index eb70906..a78fb81 100644
--- a/tests/replacement.c
+++ b/tests/replacement.c
@@ -50,7 +50,7 @@ main(int argc, char **argv)
assert(entry);
assert(entry->data == str2);
- hash_table_remove(ht, entry);
+ hash_table_remove_entry(ht, entry);
entry = hash_table_search(ht, hash_str1, str1);
assert(!entry);
diff --git a/tests/set/delete_and_lookup.c b/tests/set/delete_and_lookup.c
index d05c819..6ad6209 100644
--- a/tests/set/delete_and_lookup.c
+++ b/tests/set/delete_and_lookup.c
@@ -46,14 +46,20 @@ main(int argc, char **argv)
struct set *set;
const char *str1 = "test1";
const char *str2 = "test2";
+ const char *str3 = "test3";
uint32_t hash_str1 = badhash(str1);
uint32_t hash_str2 = badhash(str2);
+ uint32_t hash_str3 = badhash(str3);
struct set_entry *entry;
set = set_create(string_key_equals);
set_add(set, hash_str1, str1);
set_add(set, hash_str2, str2);
+ set_add(set, hash_str2, str3);
+
+ entry = set_search(set, hash_str3, str3);
+ assert(strcmp(entry->key, str3) == 0);
entry = set_search(set, hash_str2, str2);
assert(strcmp(entry->key, str2) == 0);
@@ -61,13 +67,17 @@ main(int argc, char **argv)
entry = set_search(set, hash_str1, str1);
assert(strcmp(entry->key, str1) == 0);
- set_remove(set, entry);
+ set_remove_entry(set, entry);
+ set_remove(set, hash_str2, str2);
entry = set_search(set, hash_str1, str1);
assert(entry == NULL);
entry = set_search(set, hash_str2, str2);
- assert(strcmp(entry->key, str2) == 0);
+ assert(entry == NULL);
+
+ entry = set_search(set, hash_str3, str3);
+ assert(strcmp(entry->key, str3) == 0);
set_destroy(set, NULL);
diff --git a/tests/set/delete_management.c b/tests/set/delete_management.c
index b5c16fe..f54c9c5 100644
--- a/tests/set/delete_management.c
+++ b/tests/set/delete_management.c
@@ -61,8 +61,7 @@ main(int argc, char **argv)
if (i >= 100) {
uint32_t delete_value = i - 100;
- entry = set_search(set, delete_value, &delete_value);
- set_remove(set, entry);
+ set_remove(set, delete_value, &delete_value);
}
}
diff --git a/tests/set/null_remove.c b/tests/set/null_remove.c
index e607062..8b8ba89 100644
--- a/tests/set/null_remove.c
+++ b/tests/set/null_remove.c
@@ -38,7 +38,7 @@ main(int argc, char **argv)
set = set_create(string_key_equals);
- set_remove(set, NULL);
+ set_remove_entry(set, NULL);
set_destroy(set, NULL);
diff --git a/tests/set/replacement.c b/tests/set/replacement.c
index 1d6d924..8723ecb 100644
--- a/tests/set/replacement.c
+++ b/tests/set/replacement.c
@@ -50,7 +50,7 @@ main(int argc, char **argv)
assert(entry);
assert(entry->key == str2);
- set_remove(set, entry);
+ set_remove_entry(set, entry);
entry = set_search(set, hash_str1, str1);
assert(!entry);