7 #include <libtest/test.hpp>
13 #include <libhashkit/hashkit.hpp>
15 using namespace libtest
;
17 #include "hash_results.h"
19 static test_return_t
exists_test(void *obj
)
28 static test_return_t
new_test(void *obj
)
30 Hashkit
*hashk
= new Hashkit
;
40 static test_return_t
copy_test(void *obj
)
42 Hashkit
*hashk
= new Hashkit
;
53 static test_return_t
assign_test(void *obj
)
66 static test_return_t
digest_test(void *)
69 test_true(hashk
.digest("Foo", sizeof("Foo")));
74 static test_return_t
set_function_test(void *)
77 hashkit_hash_algorithm_t algo_list
[]= {
82 HASHKIT_HASH_FNV1A_64
,
84 HASHKIT_HASH_FNV1A_32
,
91 for (hashkit_hash_algorithm_t
*algo
= algo_list
; *algo
!= HASHKIT_HASH_MAX
; algo
++)
93 hashkit_return_t rc
= hashk
.set_function(*algo
);
95 test_compare(HASHKIT_SUCCESS
, rc
);
100 case HASHKIT_HASH_DEFAULT
:
101 list
= one_at_a_time_values
;
104 case HASHKIT_HASH_MD5
:
108 case HASHKIT_HASH_CRC
:
112 case HASHKIT_HASH_FNV1_64
:
113 list
= fnv1_64_values
;
116 case HASHKIT_HASH_FNV1A_64
:
117 list
= fnv1a_64_values
;
120 case HASHKIT_HASH_FNV1_32
:
121 list
= fnv1_32_values
;
124 case HASHKIT_HASH_FNV1A_32
:
125 list
= fnv1a_32_values
;
128 case HASHKIT_HASH_HSIEH
:
129 #ifndef HAVE_HSIEH_HASH
135 case HASHKIT_HASH_MURMUR
:
136 #ifdef WORDS_BIGENDIAN
139 #ifndef HAVE_MURMUR_HASH
145 case HASHKIT_HASH_JENKINS
:
146 list
= jenkins_values
;
149 case HASHKIT_HASH_CUSTOM
:
150 case HASHKIT_HASH_MAX
:
153 test_fail("We ended up on a non-existent hash");
156 // Now we make sure we did set the hash correctly.
159 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
163 hash_val
= hashk
.digest(*ptr
, strlen(*ptr
));
165 snprintf(buffer
, sizeof(buffer
), "%lu %lus %s", (unsigned long)list
[x
], (unsigned long)hash_val
, libhashkit_string_hash(*algo
));
166 test_true_got(list
[x
] == hash_val
, buffer
);
173 static test_return_t
set_distribution_function_test(void *obj
)
179 rc
= hashk
.set_distribution_function(HASHKIT_HASH_CUSTOM
);
180 test_true_got(rc
== HASHKIT_FAILURE
or rc
== HASHKIT_INVALID_ARGUMENT
, hashkit_strerror(NULL
, rc
));
182 rc
= hashk
.set_distribution_function(HASHKIT_HASH_JENKINS
);
183 test_true(rc
== HASHKIT_SUCCESS
);
188 static test_return_t
compare_function_test(void *obj
)
197 b
.set_function(HASHKIT_HASH_MURMUR
);
207 { "exists", 0, reinterpret_cast<test_callback_fn
*>(exists_test
) },
208 { "new", 0, reinterpret_cast<test_callback_fn
*>(new_test
) },
209 { "copy", 0, reinterpret_cast<test_callback_fn
*>(copy_test
) },
210 { "assign", 0, reinterpret_cast<test_callback_fn
*>(assign_test
) },
211 { "digest", 0, reinterpret_cast<test_callback_fn
*>(digest_test
) },
212 { "set_function", 0, reinterpret_cast<test_callback_fn
*>(set_function_test
) },
213 { "set_distribution_function", 0, reinterpret_cast<test_callback_fn
*>(set_distribution_function_test
) },
214 { "compare", 0, reinterpret_cast<test_callback_fn
*>(compare_function_test
) },
218 collection_st collection
[] ={
219 {"basic", 0, 0, basic
},
223 void get_world(Framework
*world
)
225 world
->collections
= collection
;