5 #include <mem_config.h>
7 #include <libtest/test.hpp>
13 #include <libhashkit-1.0/hashkit.hpp>
15 using namespace libtest
;
17 #include "tests/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_MURMUR3
:
134 #ifdef WORDS_BIGENDIAN
137 list
= murmur3_values
;
139 case HASHKIT_HASH_MURMUR
:
140 #ifdef WORDS_BIGENDIAN
146 case HASHKIT_HASH_JENKINS
:
147 list
= jenkins_values
;
150 case HASHKIT_HASH_CUSTOM
:
151 case HASHKIT_HASH_MAX
:
154 test_fail("We ended up on a non-existent hash");
157 // Now we make sure we did set the hash correctly.
160 for (ptr
= list_to_hash
, x
= 0; *ptr
; ptr
++, x
++)
164 hash_val
= hashk
.digest(*ptr
, strlen(*ptr
));
166 snprintf(buffer
, sizeof(buffer
), "%lu %lus %s", (unsigned long)list
[x
], (unsigned long)hash_val
, libhashkit_string_hash(*algo
));
167 test_compare(list
[x
], hash_val
);
174 static test_return_t
set_distribution_function_test(void *)
179 rc
= hashk
.set_distribution_function(HASHKIT_HASH_CUSTOM
);
180 test_true(rc
== HASHKIT_FAILURE
or rc
== HASHKIT_INVALID_ARGUMENT
);
182 test_compare(HASHKIT_SUCCESS
,
183 hashk
.set_distribution_function(HASHKIT_HASH_JENKINS
));
188 static test_return_t
compare_function_test(void *)
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(libtest::Framework
* world
)
224 world
->collections(collection
);