X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=test%2Ffixtures%2Fparser.hpp;h=349e3986caaa9bcd382a3affecdb30c647a176a8;hb=eee6dc552da08a46e7f086b37cc697dacdc4627b;hp=2c72302ddb76db2776c7c3d3d282f88a24af8b88;hpb=7e2b466107a65e22f1cc258ca8643922dbb60352;p=awesomized%2Flibmemcached diff --git a/test/fixtures/parser.hpp b/test/fixtures/parser.hpp index 2c72302d..349e3986 100644 --- a/test/fixtures/parser.hpp +++ b/test/fixtures/parser.hpp @@ -1,3 +1,18 @@ +/* + +--------------------------------------------------------------------+ + | libmemcached - C/C++ Client Library for memcached | + +--------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted under the terms of the BSD license. | + | You should have received a copy of the license in a bundled file | + | named LICENSE; in case you did not receive a copy you can review | + | the terms online at: https://opensource.org/licenses/BSD-3-Clause | + +--------------------------------------------------------------------+ + | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ | + | Copyright (c) 2020 Michael Wallner | + +--------------------------------------------------------------------+ +*/ + #pragma once #include @@ -12,14 +27,9 @@ struct c_string { c_string(const char *s, size_t l) noexcept : c_str{s} - , size{l} - {} - bool operator ==(const c_string &cs) const noexcept { - return !strcmp(c_str, cs.c_str); - } - bool operator ==(const char *p) const noexcept { - return !strcmp(c_str, p); - } + , size{l} {} + bool operator==(const c_string &cs) const noexcept { return !strcmp(c_str, cs.c_str); } + bool operator==(const char *p) const noexcept { return !strcmp(c_str, p); } }; static c_string null_c_string{nullptr, 0}; @@ -33,23 +43,19 @@ struct test_case { test_case(c_string o, c_string r) noexcept : option{o} - , result{r} - {} + , result{r} {} test_case(const char *os, size_t ol, const char *rs, size_t rl) noexcept : option{os, ol} - , result{c_string{rs, rl}} - {} + , result{c_string{rs, rl}} {} test_case(const char *os, size_t ol, memcached_behavior_t b, uint64_t v) noexcept - : option{os, ol} - , result{setting_t{b, v}} - {} + : option{os, ol} + , result{setting_t{b, v}} {} test_case(const char *os, size_t ol, memcached_flag_t f, uint64_t v) noexcept - : option{os, ol} - , result{setting_t{f, v}} - {} + : option{os, ol} + , result{setting_t{f, v}} {} }; -#define test_count(tca) (sizeof(tca)/sizeof(tca[0])) +#define test_count(tca) (sizeof(tca) / sizeof(tca[0])) struct test_group { using check_func = function; @@ -62,36 +68,35 @@ struct test_group { : name{name_} , check{move(check_)} , tests{tests_} - , ntests{ntests_} - {} + , ntests{ntests_} {} }; static test_case host_string_tests[] = { - {S("--server=localhost"), S("localhost")}, - {S("--server=10.0.2.1"), S("10.0.2.1")}, - {S("--server=example.com"), S("example.com")}, - {S("--server=localhost:30"), S("localhost")}, - {S("--server=10.0.2.1:20"), S("10.0.2.1")}, - {S("--server=example.com:1024"), S("example.com")}, - {S("--server=10.0.2.1:30/?40"), S("10.0.2.1")}, - {S("--server=example.com:1024/?30"), S("example.com")}, - {S("--server=10.0.2.1/?20"), S("10.0.2.1")}, - {S("--server=example.com/?10"), S("example.com")}, + {S("--server=localhost"), S("localhost")}, + {S("--server=10.0.2.1"), S("10.0.2.1")}, + {S("--server=example.com"), S("example.com")}, + {S("--server=localhost:30"), S("localhost")}, + {S("--server=10.0.2.1:20"), S("10.0.2.1")}, + {S("--server=example.com:1024"), S("example.com")}, + {S("--server=10.0.2.1:30/?40"), S("10.0.2.1")}, + {S("--server=example.com:1024/?30"), S("example.com")}, + {S("--server=10.0.2.1/?20"), S("10.0.2.1")}, + {S("--server=example.com/?10"), S("example.com")}, }; static test_group test_host_strings{ - "host strings", - [](memcached_st *memc, const test_case::result_t &result) { - auto instance = memcached_server_instance_by_position(memc, 0); - REQUIRE(instance); - REQUIRE(get(result) == memcached_server_name(instance)); - }, - host_string_tests, - test_count(host_string_tests) -}; + "host strings", + [](memcached_st *memc, const test_case::result_t &result) { + auto instance = memcached_server_instance_by_position(memc, 0); + REQUIRE(instance); + REQUIRE(get(result) == memcached_server_name(instance)); + }, + host_string_tests, test_count(host_string_tests)}; static test_case bad_host_string_tests[] = { - {{S("-servers=localhost:11221,localhost:11222,localhost:11223,localhost:11224,localhost:11225")}, null_c_string}, + {{S("-servers=localhost:11221,localhost:11222,localhost:11223,localhost:11224,localhost:" + "11225")}, + null_c_string}, {{S("-- servers=a.example.com:81,localhost:82,b.example.com")}, null_c_string}, {{S("--servers=localhost:+80")}, null_c_string}, // all of the following should not fail IMO @@ -101,13 +106,9 @@ static test_case bad_host_string_tests[] = { }; static test_group test_bad_host_strings{ - "bad host strings", - [](memcached_st *memc, const test_case::result_t &) { - REQUIRE_FALSE(memc); - }, - bad_host_string_tests, - test_count(bad_host_string_tests) -}; + "bad host strings", + [](memcached_st *memc, const test_case::result_t &) { REQUIRE_FALSE(memc); }, + bad_host_string_tests, test_count(bad_host_string_tests)}; static test_case behavior_tests[] = { {S("--CONNECT-TIMEOUT=456"), MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT, 456}, @@ -133,10 +134,14 @@ static test_case behavior_tests[] = { {S("--TCP-KEEPIDLE"), MEMCACHED_BEHAVIOR_TCP_KEEPIDLE, 1}, {S("--USE-UDP"), MEMCACHED_BEHAVIOR_USE_UDP, 1}, {S("--VERIFY-KEY"), MEMCACHED_BEHAVIOR_VERIFY_KEY, 1}, - {S("--DISTRIBUTION=consistent"), MEMCACHED_BEHAVIOR_DISTRIBUTION, MEMCACHED_DISTRIBUTION_CONSISTENT}, - {S("--DISTRIBUTION=consistent,CRC"), MEMCACHED_BEHAVIOR_DISTRIBUTION, MEMCACHED_DISTRIBUTION_CONSISTENT}, - {S("--DISTRIBUTION=consistent,MD5"), MEMCACHED_BEHAVIOR_DISTRIBUTION, MEMCACHED_DISTRIBUTION_CONSISTENT}, - {S("--DISTRIBUTION=consistent,JENKINS"), MEMCACHED_BEHAVIOR_KETAMA_HASH, MEMCACHED_HASH_JENKINS}, + {S("--DISTRIBUTION=consistent"), MEMCACHED_BEHAVIOR_DISTRIBUTION, + MEMCACHED_DISTRIBUTION_CONSISTENT}, + {S("--DISTRIBUTION=consistent,CRC"), MEMCACHED_BEHAVIOR_DISTRIBUTION, + MEMCACHED_DISTRIBUTION_CONSISTENT}, + {S("--DISTRIBUTION=consistent,MD5"), MEMCACHED_BEHAVIOR_DISTRIBUTION, + MEMCACHED_DISTRIBUTION_CONSISTENT}, + {S("--DISTRIBUTION=consistent,JENKINS"), MEMCACHED_BEHAVIOR_KETAMA_HASH, + MEMCACHED_HASH_JENKINS}, {S("--DISTRIBUTION=random"), MEMCACHED_BEHAVIOR_DISTRIBUTION, MEMCACHED_DISTRIBUTION_RANDOM}, {S("--DISTRIBUTION=modula"), MEMCACHED_BEHAVIOR_DISTRIBUTION, MEMCACHED_DISTRIBUTION_MODULA}, {S("--HASH=CRC"), MEMCACHED_BEHAVIOR_HASH, MEMCACHED_HASH_CRC}, @@ -148,16 +153,14 @@ static test_case behavior_tests[] = { }; static test_group test_behaviors{ - "behaviors", - [](memcached_st *memc, const test_case::result_t &result) { - auto setting = get(result); - REQUIRE(memc); - REQUIRE(setting.second == - memcached_behavior_get(memc, get(setting.first))); - }, - behavior_tests, - test_count(behavior_tests) -}; + "behaviors", + [](memcached_st *memc, const test_case::result_t &result) { + auto setting = get(result); + REQUIRE(memc); + REQUIRE(setting.second + == memcached_behavior_get(memc, get(setting.first))); + }, + behavior_tests, test_count(behavior_tests)}; static test_case flag_tests[] = { {S("--FETCH-VERSION"), MEMCACHED_FLAG_IS_FETCHING_VERSION, 1}, @@ -165,32 +168,28 @@ static test_case flag_tests[] = { }; static test_group test_flags{ - "flags", - [](memcached_st *memc, const test_case::result_t &result) { - auto setting = get(result); - REQUIRE(memc); - REQUIRE(setting.second == memcached_flag(*memc, get(setting.first))); - }, - flag_tests, - test_count(flag_tests) -}; + "flags", + [](memcached_st *memc, const test_case::result_t &result) { + auto setting = get(result); + REQUIRE(memc); + REQUIRE(setting.second == memcached_flag(*memc, get(setting.first))); + }, + flag_tests, test_count(flag_tests)}; static test_case namespace_tests[] = { {S("--NAMESPACE=foo"), S("foo")}, {S("--NAMESPACE=\"foo\""), S("foo")}, - {S("--NAMESPACE=\"The quick brown fox jumps over the lazy dog\""), S("The quick brown fox jumps over the lazy dog")}, + {S("--NAMESPACE=\"The quick brown fox jumps over the lazy dog\""), + S("The quick brown fox jumps over the lazy dog")}, }; -static test_group test_namespace{ - "namespace", - [](memcached_st *memc, const test_case::result_t &result) { - auto ns = get(result); - REQUIRE(memc); - REQUIRE(ns == memcached_get_namespace(*memc)); - }, - namespace_tests, - test_count(namespace_tests) -}; +static test_group test_namespace{"namespace", + [](memcached_st *memc, const test_case::result_t &result) { + auto ns = get(result); + REQUIRE(memc); + REQUIRE(ns == memcached_get_namespace(*memc)); + }, + namespace_tests, test_count(namespace_tests)}; static test_group tests[] = { test_host_strings,