7 #include <libtest/test.hpp>
13 #include <libhashkit-1.0/hashkit.hpp>
15 using namespace libtest
;
17 #include "hash_results.h"
19 static test_return_t
exists_test(void *)
27 static test_return_t
new_test(void *)
29 Hashkit
*hashk
= new Hashkit
;
38 static test_return_t
copy_test(void *)
40 Hashkit
*hashk
= new Hashkit
;
50 static test_return_t
assign_test(void *)
62 static test_return_t
digest_test(void *)
65 test_true(hashk
.digest("Foo", sizeof("Foo")));
70 static test_return_t
set_function_test(void *)
73 hashkit_hash_algorithm_t algo_list
[]= {
78 HASHKIT_HASH_FNV1A_64
,
80 HASHKIT_HASH_FNV1A_32
,
87 for (hashkit_hash_algorithm_t
*algo
= algo_list
; *algo
!= HASHKIT_HASH_MAX
; algo
++)
89 hashkit_return_t rc
= hashk
.set_function(*algo
);
91 if (rc
== HASHKIT_INVALID_ARGUMENT
)
96 test_compare(HASHKIT_SUCCESS
, rc
);
101 case HASHKIT_HASH_DEFAULT
:
102 list
= one_at_a_time_values
;
105 case HASHKIT_HASH_MD5
:
109 case HASHKIT_HASH_CRC
:
113 case HASHKIT_HASH_FNV1_64
:
114 list
= fnv1_64_values
;
117 case HASHKIT_HASH_FNV1A_64
:
118 list
= fnv1a_64_values
;
121 case HASHKIT_HASH_FNV1_32
:
122 list
= fnv1_32_values
;
125 case HASHKIT_HASH_FNV1A_32
:
126 list
= fnv1a_32_values
;
129 case HASHKIT_HASH_HSIEH
:
133 case HASHKIT_HASH_MURMUR
:
134 #ifdef WORDS_BIGENDIAN
140 case HASHKIT_HASH_JENKINS
:
141 list
= jenkins_values
;
144 case HASHKIT_HASH_CUSTOM
:
145 case HASHKIT_HASH_MAX
:
148 test_fail("We ended up on a non-existent hash");
151 // Now we make sure we did set the hash correctly.
154 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
158 hash_val
= hashk
.digest(*ptr
, strlen(*ptr
));
160 snprintf(buffer
, sizeof(buffer
), "%lu %lus %s", (unsigned long)list
[x
], (unsigned long)hash_val
, libhashkit_string_hash(*algo
));
161 test_true_got(list
[x
] == hash_val
, buffer
);
168 static test_return_t
set_distribution_function_test(void *)
173 rc
= hashk
.set_distribution_function(HASHKIT_HASH_CUSTOM
);
174 test_true_got(rc
== HASHKIT_FAILURE
or rc
== HASHKIT_INVALID_ARGUMENT
, hashkit_strerror(NULL
, rc
));
176 test_compare(HASHKIT_SUCCESS
,
177 hashk
.set_distribution_function(HASHKIT_HASH_JENKINS
));
182 static test_return_t
compare_function_test(void *)
190 b
.set_function(HASHKIT_HASH_MURMUR
);
200 { "exists", 0, reinterpret_cast<test_callback_fn
*>(exists_test
) },
201 { "new", 0, reinterpret_cast<test_callback_fn
*>(new_test
) },
202 { "copy", 0, reinterpret_cast<test_callback_fn
*>(copy_test
) },
203 { "assign", 0, reinterpret_cast<test_callback_fn
*>(assign_test
) },
204 { "digest", 0, reinterpret_cast<test_callback_fn
*>(digest_test
) },
205 { "set_function", 0, reinterpret_cast<test_callback_fn
*>(set_function_test
) },
206 { "set_distribution_function", 0, reinterpret_cast<test_callback_fn
*>(set_distribution_function_test
) },
207 { "compare", 0, reinterpret_cast<test_callback_fn
*>(compare_function_test
) },
211 collection_st collection
[] ={
212 {"basic", 0, 0, basic
},
216 void get_world(Framework
*world
)
218 world
->collections
= collection
;