9 #include <libhashkit/hashkit.h>
11 #include "hash_results.h"
13 static test_return_t
exists_test(void *obj
)
22 static test_return_t
new_test(void *obj
)
24 Hashkit
*hashk
= new Hashkit
;
34 static test_return_t
copy_test(void *obj
)
36 Hashkit
*hashk
= new Hashkit
;
47 static test_return_t
assign_test(void *obj
)
60 static test_return_t
digest_test(void *obj
)
66 value
= hashk
.digest("Foo", sizeof("Foo"));
71 static test_return_t
set_function_test(void *obj
)
74 hashkit_hash_algorithm_t algo_list
[]= {
79 HASHKIT_HASH_FNV1A_64
,
81 HASHKIT_HASH_FNV1A_32
,
86 hashkit_hash_algorithm_t
*algo
;
90 for (algo
= algo_list
; *algo
!= HASHKIT_HASH_MAX
; algo
++)
97 rc
= hashk
.set_function(*algo
);
99 test_true(rc
== HASHKIT_SUCCESS
);
103 case HASHKIT_HASH_DEFAULT
:
104 list
= one_at_a_time_values
;
106 case HASHKIT_HASH_MD5
:
109 case HASHKIT_HASH_CRC
:
112 case HASHKIT_HASH_FNV1_64
:
113 list
= fnv1_64_values
;
115 case HASHKIT_HASH_FNV1A_64
:
116 list
= fnv1a_64_values
;
118 case HASHKIT_HASH_FNV1_32
:
119 list
= fnv1_32_values
;
121 case HASHKIT_HASH_FNV1A_32
:
122 list
= fnv1a_32_values
;
124 case HASHKIT_HASH_HSIEH
:
127 case HASHKIT_HASH_MURMUR
:
130 case HASHKIT_HASH_JENKINS
:
131 list
= jenkins_values
;
133 case HASHKIT_HASH_CUSTOM
:
134 case HASHKIT_HASH_MAX
:
137 test_fail("We ended up on a non-existent hash");
140 // Now we make sure we did set the hash correctly.
141 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
145 hash_val
= hashk
.digest(*ptr
, strlen(*ptr
));
146 test_true(list
[x
] == hash_val
);
153 static test_return_t
set_distribution_function_test(void *obj
)
159 rc
= hashk
.set_distribution_function(HASHKIT_HASH_CUSTOM
);
160 test_true(rc
== HASHKIT_FAILURE
);
162 rc
= hashk
.set_distribution_function(HASHKIT_HASH_JENKINS
);
163 test_true(rc
== HASHKIT_SUCCESS
);
168 static test_return_t
compare_function_test(void *obj
)
177 b
.set_function(HASHKIT_HASH_MURMUR
);
187 { "exists", 0, reinterpret_cast<test_callback_fn
>(exists_test
) },
188 { "new", 0, reinterpret_cast<test_callback_fn
>(new_test
) },
189 { "copy", 0, reinterpret_cast<test_callback_fn
>(copy_test
) },
190 { "assign", 0, reinterpret_cast<test_callback_fn
>(assign_test
) },
191 { "digest", 0, reinterpret_cast<test_callback_fn
>(digest_test
) },
192 { "set_function", 0, reinterpret_cast<test_callback_fn
>(set_function_test
) },
193 { "set_distribution_function", 0, reinterpret_cast<test_callback_fn
>(set_distribution_function_test
) },
194 { "compare", 0, reinterpret_cast<test_callback_fn
>(compare_function_test
) },
198 collection_st collection
[] ={
199 {"basic", 0, 0, basic
},
203 void get_world(world_st
*world
)
205 world
->collections
= collection
;