7 #include <libtest/test.h>
13 #include <libhashkit/hashkit.hpp>
15 #include "hash_results.h"
17 static test_return_t
exists_test(void *obj
)
26 static test_return_t
new_test(void *obj
)
28 Hashkit
*hashk
= new Hashkit
;
38 static test_return_t
copy_test(void *obj
)
40 Hashkit
*hashk
= new Hashkit
;
51 static test_return_t
assign_test(void *obj
)
64 static test_return_t
digest_test(void *obj
)
70 value
= hashk
.digest("Foo", sizeof("Foo"));
75 static test_return_t
set_function_test(void *)
78 hashkit_hash_algorithm_t algo_list
[]= {
83 HASHKIT_HASH_FNV1A_64
,
85 HASHKIT_HASH_FNV1A_32
,
92 for (hashkit_hash_algorithm_t
*algo
= algo_list
; *algo
!= HASHKIT_HASH_MAX
; algo
++)
94 hashkit_return_t rc
= hashk
.set_function(*algo
);
96 test_true(rc
== HASHKIT_SUCCESS
);
101 case HASHKIT_HASH_DEFAULT
:
102 list
= one_at_a_time_values
;
104 case HASHKIT_HASH_MD5
:
107 case HASHKIT_HASH_CRC
:
110 case HASHKIT_HASH_FNV1_64
:
111 list
= fnv1_64_values
;
113 case HASHKIT_HASH_FNV1A_64
:
114 list
= fnv1a_64_values
;
116 case HASHKIT_HASH_FNV1_32
:
117 list
= fnv1_32_values
;
119 case HASHKIT_HASH_FNV1A_32
:
120 list
= fnv1a_32_values
;
122 case HASHKIT_HASH_HSIEH
:
123 #ifndef HAVE_HSIEH_HASH
128 case HASHKIT_HASH_MURMUR
:
129 #ifdef WORDS_BIGENDIAN
132 #ifndef HAVE_MURMUR_HASH
137 case HASHKIT_HASH_JENKINS
:
138 list
= jenkins_values
;
140 case HASHKIT_HASH_CUSTOM
:
141 case HASHKIT_HASH_MAX
:
144 test_fail("We ended up on a non-existent hash");
147 // Now we make sure we did set the hash correctly.
150 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
154 hash_val
= hashk
.digest(*ptr
, strlen(*ptr
));
156 snprintf(buffer
, sizeof(buffer
), "%lu %lus %s", (unsigned long)list
[x
], (unsigned long)hash_val
, libhashkit_string_hash(*algo
));
157 test_true_got(list
[x
] == hash_val
, buffer
);
164 static test_return_t
set_distribution_function_test(void *obj
)
170 rc
= hashk
.set_distribution_function(HASHKIT_HASH_CUSTOM
);
171 test_true_got(rc
== HASHKIT_FAILURE
or rc
== HASHKIT_INVALID_ARGUMENT
, hashkit_strerror(NULL
, rc
));
173 rc
= hashk
.set_distribution_function(HASHKIT_HASH_JENKINS
);
174 test_true(rc
== HASHKIT_SUCCESS
);
179 static test_return_t
compare_function_test(void *obj
)
188 b
.set_function(HASHKIT_HASH_MURMUR
);
198 { "exists", 0, reinterpret_cast<test_callback_fn
>(exists_test
) },
199 { "new", 0, reinterpret_cast<test_callback_fn
>(new_test
) },
200 { "copy", 0, reinterpret_cast<test_callback_fn
>(copy_test
) },
201 { "assign", 0, reinterpret_cast<test_callback_fn
>(assign_test
) },
202 { "digest", 0, reinterpret_cast<test_callback_fn
>(digest_test
) },
203 { "set_function", 0, reinterpret_cast<test_callback_fn
>(set_function_test
) },
204 { "set_distribution_function", 0, reinterpret_cast<test_callback_fn
>(set_distribution_function_test
) },
205 { "compare", 0, reinterpret_cast<test_callback_fn
>(compare_function_test
) },
209 collection_st collection
[] ={
210 {"basic", 0, 0, basic
},
214 void get_world(world_st
*world
)
216 world
->collections
= collection
;