1 #include "testing/lib/common.hpp"
2 #include "testing/fixtures/hashes.hpp"
4 #include "libhashkit-1.0/hashkit.hpp"
7 hashkit_st st
, *hp
= hashkit_create(nullptr);
9 Hashkit
*heap
= new Hashkit
;
11 REQUIRE(hashkit_create(&st
));
15 Hashkit
stack_copy(stack
);
16 Hashkit
*heap_copy(heap
);
17 hashkit_st st_copy
, *st_ptr
;
22 st_ptr
= hashkit_clone(&st_copy
, &st
);
23 REQUIRE(st_ptr
== &st_copy
);
24 REQUIRE(hashkit_compare(st_ptr
, &st_copy
));
29 SECTION("can assign") {
38 SECTION("can digest default") {
39 REQUIRE(2297466611U == stack
.digest(S("apple")));
40 REQUIRE(2297466611U == hashkit_digest(&st
, S("apple")));
43 SECTION("can set hash function") {
44 for (int f
= HASHKIT_HASH_DEFAULT
; f
< HASHKIT_HASH_MAX
; ++f
) {
45 auto h
= static_cast<hashkit_hash_algorithm_t
>(f
);
47 if (h
== HASHKIT_HASH_CUSTOM
) {
50 if (!libhashkit_has_algorithm(h
)) {
51 WARN("hashkit algorithm not enabled: " << libhashkit_string_hash(h
) << " (" << f
<< ")");
55 INFO("hash: " << libhashkit_string_hash(h
));
57 REQUIRE(HASHKIT_SUCCESS
== stack
.set_function(h
));
58 REQUIRE(HASHKIT_SUCCESS
== hashkit_set_function(&st
, h
));
60 DYNAMIC_SECTION("can digest hash function: " << libhashkit_string_hash(h
)) {
63 for (auto i
: input
) {
64 CHECK(output
[f
][n
] == stack
.digest(S(i
)));
65 CHECK(output
[f
][n
] == hashkit_digest(&st
, S(i
)));
66 CHECK(output
[f
][n
] == libhashkit_digest(S(i
), h
));
73 SECTION("is comparable") {
74 REQUIRE(*heap
== stack
);
75 REQUIRE(hashkit_compare(&st
, hp
));
77 stack
.set_function(HASHKIT_HASH_MD5
);
78 hashkit_set_function(&st
, HASHKIT_HASH_MD5
);
80 REQUIRE_FALSE(*heap
== stack
);
81 REQUIRE_FALSE(hashkit_compare(&st
, hp
));