testing: fix osx
[awesomized/libmemcached] / test / tests / memcached / cas.cpp
1 #include "test/lib/common.hpp"
2 #include "test/lib/MemcachedCluster.hpp"
3
4 TEST_CASE("memcached_cas") {
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 const char *keys[2] = {__func__, NULL};
13 size_t keylengths[2] = {strlen(__func__), 0};
14
15 REQUIRE_SUCCESS(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, true));
16 REQUIRE_SUCCESS(memcached_set(memc, S(__func__), S("we the people"), (time_t) 0, (uint32_t) 0));
17 REQUIRE_SUCCESS(memcached_mget(memc, keys, keylengths, 1));
18
19 memcached_result_st *results = memcached_result_create(memc, nullptr);
20 REQUIRE(results);
21
22 memcached_return_t rc;
23 results = memcached_fetch_result(memc, results, &rc);
24 REQUIRE(results);
25 REQUIRE_SUCCESS(rc);
26
27 REQUIRE(memcached_result_cas(results));
28 REQUIRE("we the people"s == string(memcached_result_value(results), memcached_result_length(results)));
29
30 uint64_t cas = memcached_result_cas(results);
31 REQUIRE(memcached_success(memcached_cas(memc, S(__func__), S("change the value"), 0, 0, cas)));
32
33 /*
34 * The item will have a new cas value, so try to set it again with the old
35 * value. This should fail!
36 */
37 REQUIRE_RC(MEMCACHED_DATA_EXISTS, memcached_cas(memc, S(__func__), S("change the value"), 0, 0, cas));
38
39 memcached_result_free(results);
40 }
41 }