bin: consolidate clients
[awesomized/libmemcached] / test / tests / memcached / simple.cpp
1 #include "test/lib/common.hpp"
2 #include "test/lib/MemcachedCluster.hpp"
3
4 TEST_CASE("memcached_simple") {
5 pair<string, MemcachedCluster> tests[] = {
6 {"network", MemcachedCluster::network()},
7 {"socket", MemcachedCluster::socket()}
8 };
9
10 LOOPED_SECTION(tests) {
11 auto memc = &test.memc;
12
13 SECTION("flush") {
14 uint64_t id = memcached_query_id(memc);
15 REQUIRE_SUCCESS(memcached_flush(memc, 0));
16 REQUIRE(id + 1 == memcached_query_id(memc));
17 }
18
19 uint64_t buffered = GENERATE(0, 1);
20 uint64_t binary = GENERATE(0, 1);
21
22 REQUIRE_SUCCESS(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, buffered));
23 REQUIRE_SUCCESS(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, binary));
24
25 DYNAMIC_SECTION("set (buffered=" << buffered << ",binary=" << binary << ")") {
26 for (auto i = 0; i < 10; ++i) {
27 REQUIRE_RC(buffered ? MEMCACHED_BUFFERED : MEMCACHED_SUCCESS,
28 memcached_set(memc, S(__func__), S(__func__), 0, 0));
29 }
30 }
31
32 DYNAMIC_SECTION("add (buffered=" << buffered << ",binary=" << binary << ")") {
33 memcached_return_t rc;
34
35 Malloced empty(memcached_get(memc, S(__func__), nullptr, nullptr, &rc));
36 REQUIRE_FALSE(*empty);
37 REQUIRE_RC(MEMCACHED_NOTFOUND, rc);
38
39 REQUIRE_RC(buffered ? MEMCACHED_BUFFERED : MEMCACHED_SUCCESS,
40 memcached_set(memc, S(__func__), S(__func__), 0, 0));
41
42 // flush any pending requests
43 memcached_quit(memc);
44
45 uint32_t flags;
46 size_t len;
47 Malloced val(memcached_get(memc, S(__func__), &len, &flags, &rc));
48
49 REQUIRE(*val);
50 REQUIRE(string(__func__) == string(*val, len));
51
52 REQUIRE_RC(binary ? MEMCACHED_DATA_EXISTS : MEMCACHED_NOTSTORED,
53 memcached_add(memc, S(__func__), S("update"), 0, 0));
54 }
55
56 DYNAMIC_SECTION("replace (buffered=" << buffered << ",binary=" << binary << ")") {
57 REQUIRE_RC(buffered ? MEMCACHED_BUFFERED : MEMCACHED_SUCCESS,
58 memcached_set(memc, S(__func__), S(__func__), 0, 0));
59
60 REQUIRE_SUCCESS(memcached_replace(memc, S(__func__), S("replaced"), 0, 0));
61 }
62
63 DYNAMIC_SECTION("not found (buffered=" << buffered << ",binary=" << binary << ")") {
64 memcached_return_t rc;
65 Malloced val(memcached_get(memc, S("not-found"), nullptr, nullptr, &rc));
66 REQUIRE_RC(MEMCACHED_NOTFOUND, rc);
67 REQUIRE_FALSE(*val);
68
69 val = memcached_get_by_key(memc, S("not-found"), S("not-found"), nullptr, nullptr, &rc);
70 REQUIRE_RC(MEMCACHED_NOTFOUND, rc);
71 REQUIRE_FALSE(*val);
72 }
73
74 DYNAMIC_SECTION("verbosity (buffered=" << buffered << ",binary=" << binary << ")") {
75 REQUIRE_SUCCESS(memcached_verbosity(memc, 0));
76 }
77
78 DYNAMIC_SECTION("version (buffered=" << buffered << ",binary=" << binary << ")") {
79 REQUIRE_SUCCESS(memcached_version(memc));
80 }
81 }
82 }