1 #include "test/lib/common.hpp"
2 #include "test/lib/MemcachedCluster.hpp"
4 #define TEST_KEY S("test")
5 #define INITIAL_VAL S("initial value, which is longer than AES_BLOCK_SIZE")
6 #define REPLACED_VAL S("replaced value, thich is longer than AES_BLOCK_SIZE")
8 static inline void check(memcached_st
*enc
, memcached_st
*raw
, const char *val
, size_t len
) {
9 memcached_return_t enc_rc
, raw_rc
;
10 size_t enc_length
, raw_length
;
11 Malloced
enc_value(memcached_get(enc
, TEST_KEY
, &enc_length
, nullptr, &enc_rc
));
12 Malloced
raw_value(memcached_get(raw
, TEST_KEY
, &raw_length
, nullptr, &raw_rc
));
14 REQUIRE(enc_rc
== MEMCACHED_SUCCESS
);
15 REQUIRE(raw_rc
== MEMCACHED_SUCCESS
);
16 REQUIRE_FALSE(enc_length
== raw_length
);
17 REQUIRE(memcmp(*raw_value
, *enc_value
, raw_length
));
18 REQUIRE(enc_length
== len
);
19 REQUIRE_FALSE(memcmp(val
, *enc_value
, enc_length
));
22 TEST_CASE("memcached_encoding_key") {
23 pair
<string
, MemcachedCluster
> tests
[]{
24 {"network", MemcachedCluster::network()},
25 {"socket", MemcachedCluster::socket()}
28 LOOPED_SECTION(tests
) {
29 auto memc
= &test
.memc
;
31 SECTION("accepts encoding key") {
32 MemcachedPtr
copy(memcached_clone(nullptr, memc
));
34 REQUIRE_SUCCESS(memcached_set_encoding_key(memc
, S(__func__
)));
36 SECTION("sets encoded value") {
37 REQUIRE_SUCCESS(memcached_set(memc
, TEST_KEY
, INITIAL_VAL
, 0, 0));
39 SECTION("gets encoded value") {
40 check(memc
, copy
.memc
, INITIAL_VAL
);
43 SECTION("cloned gets encoded value") {
44 MemcachedPtr
dupe(memcached_clone(nullptr, memc
));
46 check(dupe
.memc
, copy
.memc
, INITIAL_VAL
);
50 SECTION("adds encoded value") {
52 REQUIRE_SUCCESS(memcached_set(memc
, TEST_KEY
, INITIAL_VAL
, 0, 0));
53 REQUIRE_RC(MEMCACHED_NOTSTORED
, memcached_add(memc
, TEST_KEY
, REPLACED_VAL
, 0, 0));
55 check(memc
, copy
.memc
, INITIAL_VAL
);
59 REQUIRE_SUCCESS(memcached_add(memc
, TEST_KEY
, REPLACED_VAL
, 0, 0));
61 SECTION("gets encoded value") {
62 check(memc
, copy
.memc
, REPLACED_VAL
);
66 SECTION("replaces encoded value") {
67 REQUIRE_SUCCESS(memcached_set(memc
, TEST_KEY
, INITIAL_VAL
, 0, 0));
69 check(memc
, copy
.memc
, INITIAL_VAL
);
71 REQUIRE_SUCCESS(memcached_replace(memc
, TEST_KEY
, REPLACED_VAL
, 0, 0));
73 SECTION("gets encoded value") {
74 check(memc
, copy
.memc
, REPLACED_VAL
);
78 SECTION("unsupported") {
79 REQUIRE_RC(MEMCACHED_NOT_SUPPORTED
, memcached_increment(memc
, TEST_KEY
, 0, nullptr));
80 REQUIRE_RC(MEMCACHED_NOT_SUPPORTED
, memcached_decrement(memc
, TEST_KEY
, 0, nullptr));
81 REQUIRE_RC(MEMCACHED_NOT_SUPPORTED
, memcached_increment_with_initial(memc
, TEST_KEY
, 0, 0, 0, nullptr));
82 REQUIRE_RC(MEMCACHED_NOT_SUPPORTED
, memcached_decrement_with_initial(memc
, TEST_KEY
, 0, 0, 0, nullptr));
83 REQUIRE_RC(MEMCACHED_NOT_SUPPORTED
, memcached_append(memc
, TEST_KEY
, REPLACED_VAL
, 0, 0));
84 REQUIRE_RC(MEMCACHED_NOT_SUPPORTED
, memcached_prepend(memc
, TEST_KEY
, REPLACED_VAL
, 0, 0));