1 #include "test/lib/common.hpp"
2 #include "test/fixtures/hashes.hpp"
4 static constexpr const uint32_t md5_hosts
[] = {4U, 1U, 0U, 1U, 4U, 2U, 0U, 3U, 0U, 0U, 3U, 1U, 0U, 0U, 1U, 3U, 0U, 0U, 0U, 3U, 1U, 0U, 4U, 4U, 3U, 1U};
5 static constexpr const uint32_t crc_hosts
[] = {2U, 4U, 1U, 0U, 2U, 4U, 4U, 4U, 1U, 2U, 3U, 4U, 3U, 4U, 1U, 3U, 3U, 2U, 0U, 0U, 0U, 1U, 2U, 4U, 0U, 4U};
6 static constexpr const uint32_t *hosts
[] = {nullptr, md5_hosts
, crc_hosts
};
8 TEST_CASE("memcached_generate_hash") {
9 MemcachedPtr
memc(memcached(S("--server=localhost:1 --server=localhost:2 --server=localhost:3 --server=localhost:4 --server=localhost5 --DISTRIBUTION=modula")));
13 SECTION("generate hash value") {
14 for (int f
= MEMCACHED_HASH_DEFAULT
; f
< MEMCACHED_HASH_MAX
; ++f
) {
15 auto h
= static_cast<memcached_hash_t
>(f
);
17 if (h
== MEMCACHED_HASH_CUSTOM
) {
20 if (MEMCACHED_SUCCESS
!= memcached_behavior_set_key_hash(*memc
, h
)) {
21 WARN("hash algorithm not enabled: " << libmemcached_string_hash(h
) << " (" << f
<< ")");
25 INFO("hash: " << libmemcached_string_hash(h
));
28 for (auto i
: input
) {
29 CHECK(output
[f
][n
] == memcached_generate_hash_value(S(i
), h
));
35 SECTION("generate hash") {
36 auto hash
= GENERATE(as
<memcached_hash_t
>{}, MEMCACHED_HASH_MD5
, MEMCACHED_HASH_CRC
);
38 INFO("hash: " << libmemcached_string_hash(hash
));
39 REQUIRE(MEMCACHED_SUCCESS
== memcached_behavior_set_key_hash(*memc
, hash
));
42 for (auto i
: input
) {
43 CHECK(hosts
[hash
][n
] == memcached_generate_hash(*memc
, S(i
)));