9 #include <libhashkit/hashkit.h>
11 #include "hash_results.h"
13 static test_return_t
exists_test(void *obj
)
21 static test_return_t
new_test(void *obj
)
23 Hashkit
*hashk
= new Hashkit
;
33 static test_return_t
copy_test(void *obj
)
35 Hashkit
*hashk
= new Hashkit
;
46 static test_return_t
assign_test(void *obj
)
59 static test_return_t
digest_test(void *obj
)
65 value
= hashk
.digest("Foo", sizeof("Foo"));
70 static test_return_t
set_function_test(void *obj
)
73 hashkit_hash_algorithm_t algo_list
[]= {
78 HASHKIT_HASH_FNV1A_64
,
80 HASHKIT_HASH_FNV1A_32
,
85 hashkit_hash_algorithm_t
*algo
;
89 for (algo
= algo_list
; *algo
!= HASHKIT_HASH_MAX
; algo
++)
96 rc
= hashk
.set_function(*algo
);
98 test_true(rc
== HASHKIT_SUCCESS
);
102 case HASHKIT_HASH_DEFAULT
:
103 list
= one_at_a_time_values
;
105 case HASHKIT_HASH_MD5
:
108 case HASHKIT_HASH_CRC
:
111 case HASHKIT_HASH_FNV1_64
:
112 list
= fnv1_64_values
;
114 case HASHKIT_HASH_FNV1A_64
:
115 list
= fnv1a_64_values
;
117 case HASHKIT_HASH_FNV1_32
:
118 list
= fnv1_32_values
;
120 case HASHKIT_HASH_FNV1A_32
:
121 list
= fnv1a_32_values
;
123 case HASHKIT_HASH_HSIEH
:
126 case HASHKIT_HASH_MURMUR
:
129 case HASHKIT_HASH_JENKINS
:
130 list
= jenkins_values
;
132 case HASHKIT_HASH_CUSTOM
:
133 case HASHKIT_HASH_MAX
:
136 test_fail("We ended up on a non-existent hash");
139 // Now we make sure we did set the hash correctly.
140 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
144 hash_val
= hashk
.digest(*ptr
, strlen(*ptr
));
145 test_true(list
[x
] == hash_val
);
152 static test_return_t
set_distribution_function_test(void *obj
)
158 rc
= hashk
.set_distribution_function(HASHKIT_HASH_CUSTOM
);
159 test_true(rc
== HASHKIT_FAILURE
);
161 rc
= hashk
.set_distribution_function(HASHKIT_HASH_JENKINS
);
162 test_true(rc
== HASHKIT_SUCCESS
);
167 static test_return_t
compare_function_test(void *obj
)
176 b
.set_function(HASHKIT_HASH_MURMUR
);
186 { "exists", 0, reinterpret_cast<test_callback_fn
>(exists_test
) },
187 { "new", 0, reinterpret_cast<test_callback_fn
>(new_test
) },
188 { "copy", 0, reinterpret_cast<test_callback_fn
>(copy_test
) },
189 { "assign", 0, reinterpret_cast<test_callback_fn
>(assign_test
) },
190 { "digest", 0, reinterpret_cast<test_callback_fn
>(digest_test
) },
191 { "set_function", 0, reinterpret_cast<test_callback_fn
>(set_function_test
) },
192 { "set_distribution_function", 0, reinterpret_cast<test_callback_fn
>(set_distribution_function_test
) },
193 { "compare", 0, reinterpret_cast<test_callback_fn
>(compare_function_test
) },
197 collection_st collection
[] ={
198 {"basic", 0, 0, basic
},
202 void get_world(world_st
*world
)
204 world
->collections
= collection
;