testing: parser
[m6w6/libmemcached] / test / tests / memcached / parser.cpp
1 #include "test/lib/common.hpp"
2 #include "test/lib/env.hpp"
3
4 #include "libmemcached/common.h"
5 #include "test/fixtures/parser.hpp"
6
7 TEST_CASE("memcached_parser") {
8 SECTION("fail: null string") {
9 REQUIRE_FALSE(memcached(nullptr, 123));
10 }
11 SECTION("fail: zero length") {
12 REQUIRE_FALSE(memcached("123", 0));
13 }
14 SECTION("success: localhost") {
15 auto mc = memcached(S("--server=localhost"));
16 REQUIRE(mc);
17 memcached_free(mc);
18 }
19 SECTION("env") {
20 SECTION("success: localhost") {
21 SET_ENV(success_localhost, "LIBMEMCACHED", "--server=localhost");
22 auto mc = memcached(nullptr, 0);
23 REQUIRE(mc);
24 memcached_free(mc);
25 }
26 SECTION("success: empty string") {
27 SET_ENV(success_empty_string, "LIBMEMCACHED", "");
28 auto mc = memcached(nullptr, 0);
29 REQUIRE(mc);
30 memcached_free(mc);
31 }
32 SECTION("fail: extra quotes") {
33 SET_ENV(fail_extra_quotes, "LIBMEMCACHED", "\"--server=localhost\"");
34 REQUIRE_FALSE(memcached(nullptr, 0));
35 }
36 }
37
38 SECTION("fixtures") {
39 for (const auto &test : tests) {
40 DYNAMIC_SECTION(test.name) {
41 for (size_t i = 0; i < test.ntests; ++i) {
42 auto &tc = test.tests[i];
43 DYNAMIC_SECTION(tc.option.c_str) {
44 MemcachedPtr memc(memcached(tc.option.c_str, tc.option.size));
45 test.check(*memc, tc.result);
46 }
47 }
48 }
49 }
50 }
51 }