1 #include "test/lib/common.hpp"
2 #include "test/fixtures/hashes.hpp"
4 #include "libhashkit-1.0/hashkit.hpp"
7 hashkit_st st
, *hp
= hashkit_create(nullptr);
9 Hashkit
*heap
= new Hashkit
;
10 auto newed
= unique_ptr
<Hashkit
>(heap
);
12 REQUIRE(hashkit_create(&st
));
16 Hashkit
stack_copy(stack
);
17 Hashkit
*heap_copy(heap
);
18 hashkit_st st_copy
, *st_ptr
;
23 st_ptr
= hashkit_clone(&st_copy
, &st
);
24 REQUIRE(st_ptr
== &st_copy
);
25 REQUIRE(hashkit_compare(st_ptr
, &st_copy
));
30 SECTION("can assign") {
39 SECTION("can digest default") {
40 REQUIRE(2297466611U == stack
.digest(S("apple")));
41 REQUIRE(2297466611U == hashkit_digest(&st
, S("apple")));
44 SECTION("can set hash function") {
45 for (int f
= HASHKIT_HASH_DEFAULT
; f
< HASHKIT_HASH_MAX
; ++f
) {
46 auto h
= static_cast<hashkit_hash_algorithm_t
>(f
);
48 if (h
== HASHKIT_HASH_CUSTOM
) {
51 if (!libhashkit_has_algorithm(h
)) {
52 WARN("hashkit algorithm not enabled: " << libhashkit_string_hash(h
) << " (" << f
<< ")");
56 INFO("hash: " << libhashkit_string_hash(h
));
58 REQUIRE(HASHKIT_SUCCESS
== stack
.set_function(h
));
59 REQUIRE(HASHKIT_SUCCESS
== hashkit_set_function(&st
, h
));
62 for (auto i
: input
) {
63 CHECK(output
[f
][n
] == stack
.digest(S(i
)));
64 CHECK(output
[f
][n
] == hashkit_digest(&st
, S(i
)));
65 CHECK(output
[f
][n
] == libhashkit_digest(S(i
), h
));
71 SECTION("is comparable") {
72 REQUIRE(*heap
== stack
);
73 REQUIRE(hashkit_compare(&st
, hp
));
75 stack
.set_function(HASHKIT_HASH_MD5
);
76 hashkit_set_function(&st
, HASHKIT_HASH_MD5
);
78 REQUIRE_FALSE(*heap
== stack
);
79 REQUIRE_FALSE(hashkit_compare(&st
, hp
));
83 auto bad_str
= string
{hashkit_strerror(hp
, HASHKIT_MAXIMUM_RETURN
)};
84 for (int h
= HASHKIT_SUCCESS
; h
< HASHKIT_MAXIMUM_RETURN
; ++h
) {
85 auto r
= static_cast<hashkit_return_t
>(h
);
86 REQUIRE(bad_str
!= hashkit_strerror(hp
, r
));