bin: consolidate clients
[awesomized/libmemcached] / test / tests / memcached / append.cpp
1 #include "test/lib/common.hpp"
2 #include "test/lib/MemcachedCluster.hpp"
3
4 TEST_CASE("memcached_append") {
5 pair<string, MemcachedCluster> tests[] = {
6 {"bin_mixed", MemcachedCluster::mixed()},
7 {"mixed", MemcachedCluster::mixed()}
8 };
9
10 tests[0].second.enableBinaryProto();
11
12 LOOPED_SECTION(tests) {
13 auto memc = &test.memc;
14
15 SECTION("text") {
16 const char *values[] = {
17 "one", "two", "three", "four"
18 };
19
20 for (auto key : values) {
21 string cmp{key};
22
23 REQUIRE_SUCCESS(memcached_set(memc, S(key), S(key), 0, 0));
24 for (auto value : values) {
25 REQUIRE_SUCCESS(memcached_append(memc, S(key), S(value), 0, 0));
26 cmp += value;
27 }
28
29 memcached_return_t rc;
30 size_t len;
31 uint32_t flags;
32 Malloced got(memcached_get(memc, S(key), &len, &flags, &rc));
33
34 REQUIRE(cmp == *got);
35 REQUIRE_SUCCESS(rc);
36 }
37 }
38
39 SECTION("bytes") {
40 vector<uint32_t> store_list{ 23, 56, 499, 98, 32847, 0 };
41 const size_t raw_len = sizeof(decltype(store_list)::value_type) * store_list.size();
42 const char *raw_ptr = reinterpret_cast<char *>(store_list.data());
43
44 REQUIRE_SUCCESS(memcached_set(memc, S(__func__), nullptr, 0, 0, 0));
45
46 for (auto item : store_list) {
47 auto val = reinterpret_cast<char *>(&item);
48 REQUIRE_SUCCESS(memcached_append(memc, S(__func__), val, sizeof(item), 0, 0));
49 }
50
51 memcached_return_t rc;
52 size_t len;
53 uint32_t flags;
54 Malloced got(memcached_get(memc, S(__func__), &len, &flags, &rc));
55
56 REQUIRE(len == raw_len);
57 REQUIRE(string{raw_ptr, raw_len} == string{*got, len});
58 REQUIRE_SUCCESS(rc);
59 }
60 }
61 }