summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2014-11-18 20:12:25 +0100
committerSébastien Helleu <flashcode@flashtux.org>2014-11-18 20:12:25 +0100
commite253a2509ae648a358991103fafbd18d21bb06cd (patch)
tree9c86947135f13d37c445594794f896f5e1615874 /tests
parentdebfb57d0ffc6d7c35110a14bc2bda324170ffd5 (diff)
downloadweechat-e253a2509ae648a358991103fafbd18d21bb06cd.zip
tests: add hashtable tests with multiple items giving same hashed key
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/core/test-hashtable.cpp59
1 files changed, 58 insertions, 1 deletions
diff --git a/tests/unit/core/test-hashtable.cpp b/tests/unit/core/test-hashtable.cpp
index e92ea328f..d34e5cf07 100644
--- a/tests/unit/core/test-hashtable.cpp
+++ b/tests/unit/core/test-hashtable.cpp
@@ -264,9 +264,66 @@ TEST(Hashtable, SetGetRemove)
hashtable_remove_all (hashtable);
LONGS_EQUAL(0, hashtable->items_count);
- /* free hashtable */
+ /* free hashtables */
hashtable_free (hashtable);
hashtable_free (hashtable2);
+
+ /*
+ * create a hashtable with size 8, and add 6 items,
+ * to check if many items with same hashed key work fine,
+ * the expected htable inside hashtable is:
+ * +-----+
+ * | 0 |
+ * +-----+
+ * | 1 |
+ * +-----+
+ * | 2 | --> "extensible"
+ * +-----+
+ * | 3 | --> "fast" --> "light"
+ * +-----+
+ * | 4 |
+ * +-----+
+ * | 5 | --> "chat"
+ * +-----+
+ * | 6 | --> "client"
+ * +-----+
+ * | 7 | --> "weechat"
+ * +-----+
+ */
+ hashtable = hashtable_new (8,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL,
+ NULL);
+ LONGS_EQUAL(8, hashtable->size);
+ LONGS_EQUAL(0, hashtable->items_count);
+
+ item = hashtable_set (hashtable, "weechat", NULL);
+ CHECK(item);
+ POINTERS_EQUAL(item, hashtable->htable[7]);
+
+ item = hashtable_set (hashtable, "fast", NULL);
+ CHECK(item);
+ POINTERS_EQUAL(item, hashtable->htable[3]);
+
+ item = hashtable_set (hashtable, "light", NULL);
+ CHECK(item);
+ POINTERS_EQUAL(item, hashtable->htable[3]->next_item);
+
+ item = hashtable_set (hashtable, "extensible", NULL);
+ CHECK(item);
+ POINTERS_EQUAL(item, hashtable->htable[2]);
+
+ item = hashtable_set (hashtable, "chat", NULL);
+ CHECK(item);
+ POINTERS_EQUAL(item, hashtable->htable[5]);
+
+ item = hashtable_set (hashtable, "client", NULL);
+ CHECK(item);
+ POINTERS_EQUAL(item, hashtable->htable[6]);
+
+ /* free hashtable */
+ hashtable_free (hashtable);
}
/*