cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=edfd621d0619353a2d17c61718cef72b425e7cf6

commit edfd621d0619353a2d17c61718cef72b425e7cf6
Author: vivek <[email protected]>
Date:   Tue Apr 28 23:34:34 2015 +0200

    eina: add test case for eina_hash_crc function.
    
    Summary:
    Added test case for eina_hash_crc function which uses crc32 for hashing
    algorithm
    
    Signed-off-by: vivek <[email protected]>
    
    Reviewers: cedric
    
    Subscribers: cedric
    
    Differential Revision: https://phab.enlightenment.org/D2296
    
    Signed-off-by: Cedric BAIL <[email protected]>
---
 src/tests/eina/eina_test_hash.c | 85 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 85 insertions(+)

diff --git a/src/tests/eina/eina_test_hash.c b/src/tests/eina/eina_test_hash.c
index 0471d5e..b2f9704 100644
--- a/src/tests/eina/eina_test_hash.c
+++ b/src/tests/eina/eina_test_hash.c
@@ -26,6 +26,29 @@
 
 #include "eina_suite.h"
 #include "Eina.h"
+#include "eina_hash.h"
+
+#define EINA_HASH_BUCKET_SIZE       8
+
+static unsigned int
+_eina_string_key_length(const char *key)
+{
+   if (!key)
+     return 0;
+
+   return (int)strlen(key) + 1;
+}
+
+static int
+_eina_string_key_cmp(const char *key1, int key1_length,
+                     const char *key2, int key2_length)
+{
+   int delta;
+
+   delta = key1_length - key2_length;
+   if (delta) return delta;
+   return strcmp(key1, key2);
+}
 
 static Eina_Bool
 eina_foreach_check(EINA_UNUSED const Eina_Hash *hash,
@@ -103,6 +126,67 @@ START_TEST(eina_hash_simple)
 }
 END_TEST
 
+START_TEST(eina_test_hash_crc)
+{
+   Eina_Hash *hash = NULL;
+   int *test;
+   int array[] = { 1, 42, 4, 5, 6 };
+
+   fail_if(eina_init() != 2);
+
+   hash = eina_hash_new(EINA_KEY_LENGTH(_eina_string_key_length),
+                        EINA_KEY_CMP(_eina_string_key_cmp),
+                        EINA_KEY_HASH(eina_hash_crc),
+                        NULL,
+                        EINA_HASH_BUCKET_SIZE);
+   fail_if(hash == NULL);
+
+   fail_if(eina_hash_add(hash, "1", &array[0]) != EINA_TRUE);
+   fail_if(eina_hash_add(hash, "42", &array[1]) != EINA_TRUE);
+   fail_if(eina_hash_direct_add(hash, "4", &array[2]) != EINA_TRUE);
+   fail_if(eina_hash_direct_add(hash, "5", &array[3]) != EINA_TRUE);
+   fail_if(eina_hash_add(hash, "", "") != EINA_TRUE);
+
+   test = eina_hash_find(hash, "4");
+   fail_if(!test);
+   fail_if(*test != 4);
+
+   test = eina_hash_find(hash, "42");
+   fail_if(!test);
+   fail_if(*test != 42);
+
+   eina_hash_foreach(hash, eina_foreach_check, NULL);
+
+   test = eina_hash_modify(hash, "5", &array[4]);
+   fail_if(!test);
+   fail_if(*test != 5);
+
+   test = eina_hash_find(hash, "5");
+   fail_if(!test);
+   fail_if(*test != 6);
+
+   fail_if(eina_hash_population(hash) != 5);
+
+   fail_if(eina_hash_find(hash, "120") != NULL);
+
+   fail_if(eina_hash_del(hash, "5", NULL) != EINA_TRUE);
+   fail_if(eina_hash_find(hash, "5") != NULL);
+
+   fail_if(eina_hash_del(hash, NULL, &array[2]) != EINA_TRUE);
+   fail_if(eina_hash_find(hash, "4") != NULL);
+
+   fail_if(eina_hash_del(hash, NULL, &array[2]) != EINA_FALSE);
+
+   fail_if(eina_hash_del(hash, "1", NULL) != EINA_TRUE);
+   fail_if(eina_hash_del(hash, "42", NULL) != EINA_TRUE);
+
+   eina_hash_free(hash);
+
+   /* Same comment as eina_init */
+        fail_if(eina_shutdown() != 1);
+}
+END_TEST
+
 START_TEST(eina_hash_extended)
 {
    Eina_Hash *hash = NULL;
@@ -337,6 +421,7 @@ END_TEST
 void eina_test_hash(TCase *tc)
 {
    tcase_add_test(tc, eina_hash_simple);
+   tcase_add_test(tc, eina_test_hash_crc);
    tcase_add_test(tc, eina_hash_extended);
    tcase_add_test(tc, eina_hash_double_item);
    tcase_add_test(tc, eina_hash_all_int);

-- 


Reply via email to