]> granicus.if.org Git - neomutt/commitdiff
test: add hash tests for degenerate cases
authorRichard Russon <rich@flatcap.org>
Mon, 29 Apr 2019 13:46:56 +0000 (14:46 +0100)
committerRichard Russon <rich@flatcap.org>
Tue, 30 Apr 2019 10:19:56 +0000 (11:19 +0100)
12 files changed:
test/hash/mutt_hash_delete.c
test/hash/mutt_hash_find.c
test/hash/mutt_hash_find_bucket.c
test/hash/mutt_hash_find_elem.c
test/hash/mutt_hash_free.c
test/hash/mutt_hash_insert.c
test/hash/mutt_hash_int_delete.c
test/hash/mutt_hash_int_find.c
test/hash/mutt_hash_int_insert.c
test/hash/mutt_hash_set_destructor.c
test/hash/mutt_hash_typed_insert.c
test/hash/mutt_hash_walk.c

index cc932248313ef20758194b1faad63bfbd4919a56..5d9c8165fcb4ed9b573d5e3acd806d58eb2a6255 100644 (file)
 void test_mutt_hash_delete(void)
 {
   // void mutt_hash_delete(struct Hash *table, const char *strkey, const void *data);
+
+  {
+    mutt_hash_delete(NULL, "apple", "banana");
+    TEST_CHECK_(1, "mutt_hash_delete(NULL, \"apple\", \"banana\")");
+  }
+
+  {
+    struct Hash *hash = mutt_hash_new(10, MUTT_HASH_NO_FLAGS);
+    mutt_hash_delete(hash, NULL, "banana");
+    TEST_CHECK_(1, "mutt_hash_delete(hash, NULL, \"banana\")");
+    mutt_hash_free(&hash);
+  }
+
+  {
+    struct Hash *hash = mutt_hash_new(10, MUTT_HASH_NO_FLAGS);
+    mutt_hash_delete(hash, "apple", NULL);
+    TEST_CHECK_(1, "mutt_hash_delete(hash, \"apple\", NULL)");
+    mutt_hash_free(&hash);
+  }
 }
index 07ad51cf898ded811a6ac28043660d0015cfae5c..f99b4e0503efb1bf326d474d58818604a77b7a5f 100644 (file)
 void test_mutt_hash_find(void)
 {
   // void *mutt_hash_find(const struct Hash *table, const char *strkey);
+
+  {
+    TEST_CHECK(!mutt_hash_find(NULL, "apple"));
+  }
+
+  {
+    struct Hash *hash = mutt_hash_new(10, MUTT_HASH_NO_FLAGS);
+    TEST_CHECK(!mutt_hash_find(hash, "apple"));
+    mutt_hash_free(&hash);
+  }
 }
index ff2cbed203071c4b581c2a2466d22666362f0085..bd1c866cc1e8cf5f1e052feeed828bbe84867939 100644 (file)
 void test_mutt_hash_find_bucket(void)
 {
   // struct HashElem *mutt_hash_find_bucket(const struct Hash *table, const char *strkey);
+
+  {
+    TEST_CHECK(!mutt_hash_find_bucket(NULL, "apple"));
+  }
+
+  {
+    struct Hash hash = { 0 };
+    TEST_CHECK(!mutt_hash_find_bucket(&hash, NULL));
+  }
 }
index c4aa65a71a58f2685f61a315e49c548b1df53a7e..9ed37f264b15280cc14cdace0e7a65b9341742d2 100644 (file)
 void test_mutt_hash_find_elem(void)
 {
   // struct HashElem *mutt_hash_find_elem(const struct Hash *table, const char *strkey);
+
+  {
+    TEST_CHECK(!mutt_hash_find_elem(NULL, "apple"));
+  }
+
+  {
+    struct Hash hash = { 0 };
+    TEST_CHECK(!mutt_hash_find_elem(&hash, NULL));
+  }
 }
index 13e9345de2cfe09be4ba12a92d1333eddc29501f..9abc34e5c119790c31f6c00dcaeb64d68d4ddc34 100644 (file)
 void test_mutt_hash_free(void)
 {
   // void mutt_hash_free(struct Hash **ptr);
+
+  {
+    mutt_hash_free(NULL);
+    TEST_CHECK_(1, "mutt_hash_free(NULL)");
+  }
+
+  {
+    struct Hash *hash = NULL;
+    mutt_hash_free(&hash);
+    TEST_CHECK_(1, "mutt_hash_free(&hash)");
+  }
 }
index dcb6dd2142f710606976415dc9063f6a19102c09..0416859d15be0ab01fe41175ad7ab9aa70d6fb71 100644 (file)
 void test_mutt_hash_insert(void)
 {
   // struct HashElem *mutt_hash_insert(struct Hash *table, const char *strkey, void *data);
+
+  {
+    TEST_CHECK(!mutt_hash_insert(NULL, "apple", "banana"));
+  }
+
+  {
+    struct Hash *hash = mutt_hash_new(10, MUTT_HASH_NO_FLAGS);
+    TEST_CHECK(!mutt_hash_insert(hash, NULL, "banana"));
+    mutt_hash_free(&hash);
+  }
+
+  {
+    struct Hash *hash = mutt_hash_new(10, MUTT_HASH_NO_FLAGS);
+    TEST_CHECK(mutt_hash_insert(hash, "apple", NULL) != NULL);
+    mutt_hash_free(&hash);
+  }
 }
index 21e6116bb9223f05456354b9c761ff476868a118..1af3dd65b66bf9a84cc3fc9b1ba42740dbb8ce52 100644 (file)
 void test_mutt_hash_int_delete(void)
 {
   // void mutt_hash_int_delete(struct Hash *table, unsigned int intkey, const void *data);
+
+  {
+    mutt_hash_int_delete(NULL, 0, "apple");
+    TEST_CHECK_(1, "mutt_hash_int_delete(NULL, 0, \"apple\")");
+  }
+
+  {
+    struct Hash *hash = mutt_hash_int_new(10, MUTT_HASH_NO_FLAGS);
+    mutt_hash_int_delete(hash, 0, NULL);
+    TEST_CHECK_(1, "mutt_hash_int_delete(hash, 0, NULL)");
+    mutt_hash_free(&hash);
+  }
 }
index 7fed41581a813234d737b05f18c0f635549a9925..0f494a2c0f135a61f92e10afe5308773ae5f201a 100644 (file)
@@ -28,4 +28,9 @@
 void test_mutt_hash_int_find(void)
 {
   // void *mutt_hash_int_find(const struct Hash *table, unsigned int intkey);
+
+  {
+    mutt_hash_int_find(NULL, 0);
+    TEST_CHECK_(1, "mutt_hash_int_find(NULL, 0)");
+  }
 }
index ac688a84856f34e4c985592b191425351d58ef09..5ce8dd5144263e153619764809428cb7a655056d 100644 (file)
 void test_mutt_hash_int_insert(void)
 {
   // struct HashElem *mutt_hash_int_insert(struct Hash *table, unsigned int intkey, void *data);
+
+  {
+    TEST_CHECK(!mutt_hash_int_insert(NULL, 0, "apple"));
+  }
+
+  {
+    struct Hash *hash = mutt_hash_int_new(10, MUTT_HASH_NO_FLAGS);
+    TEST_CHECK(mutt_hash_int_insert(hash, 0, NULL) != NULL);
+    mutt_hash_free(&hash);
+  }
 }
index 5565506410ef2f8547f0cf1a2c232e569b9f1b40..dadc1141a8b701f94874e6d7cb7aa2f0f9053510 100644 (file)
 #include "config.h"
 #include "mutt/mutt.h"
 
+void dummy_free(int type, void *obj, intptr_t data)
+{
+}
+
 void test_mutt_hash_set_destructor(void)
 {
   // void mutt_hash_set_destructor(struct Hash *table, hashelem_free_t fn, intptr_t fn_data);
+
+  {
+    hashelem_free_t fn = dummy_free;
+    mutt_hash_set_destructor(NULL, fn, (intptr_t) "apple");
+    TEST_CHECK_(1, "mutt_hash_set_destructor(NULL, fn, \"apple\")");
+  }
+
+  {
+    struct Hash hash = { 0 };
+    mutt_hash_set_destructor(&hash, NULL, (intptr_t) "apple");
+    TEST_CHECK_(1, "mutt_hash_set_destructor(&hash, NULL, \"apple\")");
+  }
+
+  {
+    struct Hash hash = { 0 };
+    hashelem_free_t fn = dummy_free;
+    mutt_hash_set_destructor(&hash, fn, 0);
+    TEST_CHECK_(1, "mutt_hash_set_destructor(&hash, fn, NULL)");
+  }
 }
index cdad30e1d0dafb9a3804a4d591b87025574bd9b6..a80a0e06fdd50091775e6c62af1a3931719ba7c0 100644 (file)
 void test_mutt_hash_typed_insert(void)
 {
   // struct HashElem *mutt_hash_typed_insert(struct Hash *table, const char *strkey, int type, void *data);
+
+  {
+    TEST_CHECK(!mutt_hash_typed_insert(NULL, "apple", 0, "banana"));
+  }
+
+  {
+    struct Hash hash = { 0 };
+    TEST_CHECK(!mutt_hash_typed_insert(&hash, NULL, 0, "banana"));
+  }
+
+  {
+    struct Hash *hash = mutt_hash_new(10, MUTT_HASH_NO_FLAGS);
+    TEST_CHECK(mutt_hash_typed_insert(hash, "apple", 0, NULL) != NULL);
+    mutt_hash_free(&hash);
+  }
 }
index bc14064f47834e06325a8ddc68ba311bf02f52e2..d640534a67ce14664e70b4a6d37b07c2faff141e 100644 (file)
 void test_mutt_hash_walk(void)
 {
   // struct HashElem *mutt_hash_walk(const struct Hash *table, struct HashWalkState *state);
+
+  {
+    struct HashWalkState hashwalkstate = { 0 };
+    TEST_CHECK(!mutt_hash_walk(NULL, &hashwalkstate));
+  }
+
+  {
+    struct Hash hash = { 0 };
+    TEST_CHECK(!mutt_hash_walk(&hash, NULL));
+  }
 }