5 #include <libtest/common.h>
11 #include <libhashkit/hashkit.hpp>
13 #include "hash_results.h"
15 static test_return_t
exists_test(void *obj
)
24 static test_return_t
new_test(void *obj
)
26 Hashkit
*hashk
= new Hashkit
;
36 static test_return_t
copy_test(void *obj
)
38 Hashkit
*hashk
= new Hashkit
;
49 static test_return_t
assign_test(void *obj
)
62 static test_return_t
digest_test(void *obj
)
68 value
= hashk
.digest("Foo", sizeof("Foo"));
73 static test_return_t
set_function_test(void *)
76 hashkit_hash_algorithm_t algo_list
[]= {
81 HASHKIT_HASH_FNV1A_64
,
83 HASHKIT_HASH_FNV1A_32
,
90 for (hashkit_hash_algorithm_t
*algo
= algo_list
; *algo
!= HASHKIT_HASH_MAX
; algo
++)
92 hashkit_return_t rc
= hashk
.set_function(*algo
);
94 test_compare(HASHKIT_SUCCESS
, rc
);
99 case HASHKIT_HASH_DEFAULT
:
100 list
= one_at_a_time_values
;
103 case HASHKIT_HASH_MD5
:
107 case HASHKIT_HASH_CRC
:
111 case HASHKIT_HASH_FNV1_64
:
112 list
= fnv1_64_values
;
115 case HASHKIT_HASH_FNV1A_64
:
116 list
= fnv1a_64_values
;
119 case HASHKIT_HASH_FNV1_32
:
120 list
= fnv1_32_values
;
123 case HASHKIT_HASH_FNV1A_32
:
124 list
= fnv1a_32_values
;
127 case HASHKIT_HASH_HSIEH
:
128 #ifndef HAVE_HSIEH_HASH
134 case HASHKIT_HASH_MURMUR
:
135 #ifdef WORDS_BIGENDIAN
138 #ifndef HAVE_MURMUR_HASH
144 case HASHKIT_HASH_JENKINS
:
145 list
= jenkins_values
;
148 case HASHKIT_HASH_CUSTOM
:
149 case HASHKIT_HASH_MAX
:
152 test_fail("We ended up on a non-existent hash");
155 // Now we make sure we did set the hash correctly.
158 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
162 hash_val
= hashk
.digest(*ptr
, strlen(*ptr
));
164 snprintf(buffer
, sizeof(buffer
), "%lu %lus %s", (unsigned long)list
[x
], (unsigned long)hash_val
, libhashkit_string_hash(*algo
));
165 test_true_got(list
[x
] == hash_val
, buffer
);
172 static test_return_t
set_distribution_function_test(void *obj
)
178 rc
= hashk
.set_distribution_function(HASHKIT_HASH_CUSTOM
);
179 test_true_got(rc
== HASHKIT_FAILURE
or rc
== HASHKIT_INVALID_ARGUMENT
, hashkit_strerror(NULL
, rc
));
181 rc
= hashk
.set_distribution_function(HASHKIT_HASH_JENKINS
);
182 test_true(rc
== HASHKIT_SUCCESS
);
187 static test_return_t
compare_function_test(void *obj
)
196 b
.set_function(HASHKIT_HASH_MURMUR
);
206 { "exists", 0, reinterpret_cast<test_callback_fn
*>(exists_test
) },
207 { "new", 0, reinterpret_cast<test_callback_fn
*>(new_test
) },
208 { "copy", 0, reinterpret_cast<test_callback_fn
*>(copy_test
) },
209 { "assign", 0, reinterpret_cast<test_callback_fn
*>(assign_test
) },
210 { "digest", 0, reinterpret_cast<test_callback_fn
*>(digest_test
) },
211 { "set_function", 0, reinterpret_cast<test_callback_fn
*>(set_function_test
) },
212 { "set_distribution_function", 0, reinterpret_cast<test_callback_fn
*>(set_distribution_function_test
) },
213 { "compare", 0, reinterpret_cast<test_callback_fn
*>(compare_function_test
) },
217 collection_st collection
[] ={
218 {"basic", 0, 0, basic
},
222 void get_world(Framework
*world
)
224 world
->collections
= collection
;