4 #include <libtest/test.h>
10 #include <libhashkit/hashkit.h>
12 #include "hash_results.h"
14 static test_return_t
exists_test(void *obj
)
23 static test_return_t
new_test(void *obj
)
25 Hashkit
*hashk
= new Hashkit
;
35 static test_return_t
copy_test(void *obj
)
37 Hashkit
*hashk
= new Hashkit
;
48 static test_return_t
assign_test(void *obj
)
61 static test_return_t
digest_test(void *obj
)
67 value
= hashk
.digest("Foo", sizeof("Foo"));
72 static test_return_t
set_function_test(void *obj
)
75 hashkit_hash_algorithm_t algo_list
[]= {
80 HASHKIT_HASH_FNV1A_64
,
82 HASHKIT_HASH_FNV1A_32
,
87 hashkit_hash_algorithm_t
*algo
;
91 for (algo
= algo_list
; *algo
!= HASHKIT_HASH_MAX
; algo
++)
98 rc
= hashk
.set_function(*algo
);
100 test_true(rc
== HASHKIT_SUCCESS
);
104 case HASHKIT_HASH_DEFAULT
:
105 list
= one_at_a_time_values
;
107 case HASHKIT_HASH_MD5
:
110 case HASHKIT_HASH_CRC
:
113 case HASHKIT_HASH_FNV1_64
:
114 list
= fnv1_64_values
;
116 case HASHKIT_HASH_FNV1A_64
:
117 list
= fnv1a_64_values
;
119 case HASHKIT_HASH_FNV1_32
:
120 list
= fnv1_32_values
;
122 case HASHKIT_HASH_FNV1A_32
:
123 list
= fnv1a_32_values
;
125 case HASHKIT_HASH_HSIEH
:
128 case HASHKIT_HASH_MURMUR
:
131 case HASHKIT_HASH_JENKINS
:
132 list
= jenkins_values
;
134 case HASHKIT_HASH_CUSTOM
:
135 case HASHKIT_HASH_MAX
:
138 test_fail("We ended up on a non-existent hash");
141 // Now we make sure we did set the hash correctly.
142 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
146 hash_val
= hashk
.digest(*ptr
, strlen(*ptr
));
147 test_true(list
[x
] == hash_val
);
154 static test_return_t
set_distribution_function_test(void *obj
)
160 rc
= hashk
.set_distribution_function(HASHKIT_HASH_CUSTOM
);
161 test_true(rc
== HASHKIT_FAILURE
);
163 rc
= hashk
.set_distribution_function(HASHKIT_HASH_JENKINS
);
164 test_true(rc
== HASHKIT_SUCCESS
);
169 static test_return_t
compare_function_test(void *obj
)
178 b
.set_function(HASHKIT_HASH_MURMUR
);
188 { "exists", 0, reinterpret_cast<test_callback_fn
>(exists_test
) },
189 { "new", 0, reinterpret_cast<test_callback_fn
>(new_test
) },
190 { "copy", 0, reinterpret_cast<test_callback_fn
>(copy_test
) },
191 { "assign", 0, reinterpret_cast<test_callback_fn
>(assign_test
) },
192 { "digest", 0, reinterpret_cast<test_callback_fn
>(digest_test
) },
193 { "set_function", 0, reinterpret_cast<test_callback_fn
>(set_function_test
) },
194 { "set_distribution_function", 0, reinterpret_cast<test_callback_fn
>(set_distribution_function_test
) },
195 { "compare", 0, reinterpret_cast<test_callback_fn
>(compare_function_test
) },
199 collection_st collection
[] ={
200 {"basic", 0, 0, basic
},
204 void get_world(world_st
*world
)
206 world
->collections
= collection
;