From: Stefan Bühler Date: Sat, 30 Dec 2017 15:34:50 +0000 (+0100) Subject: test-dnsrecords: refactor handling (binary) strings X-Git-Tag: dnsdist-1.3.0~122^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d0b06f3c50f7ed9ac3363a05748eb2a716fd0bba;p=pdns test-dnsrecords: refactor handling (binary) strings - also treat normal strings as "binary" (i.e. could contain '\0' bytes) - assume all test inputs are given as string literals (char arrays with trailing '\0') --- diff --git a/pdns/test-dnsrecords_cc.cc b/pdns/test-dnsrecords_cc.cc index 484811a74..77a5add40 100644 --- a/pdns/test-dnsrecords_cc.cc +++ b/pdns/test-dnsrecords_cc.cc @@ -17,7 +17,11 @@ namespace { }; } -#define _CASE_L(type, inval, zoneval, lineval, broken) case_t(type, std::string(inval), std::string(zoneval), std::string(lineval, sizeof(lineval)-1), broken) +// use a user-defined literal operator instead? should be supported in +// C++11, but only C++14 added the `s` suffix. +#define BINARY(s) (std::string(s, sizeof(s) - 1)) + +#define _CASE_L(type, inval, zoneval, lineval, broken) case_t(type, BINARY(inval), BINARY(zoneval), BINARY(lineval), broken) #define CASE_L(type, inval, zoneval, lineval) _CASE_L(type, inval, zoneval, lineval, broken_marker::WORKING) #define CASE_S(type, zoneval, lineval) _CASE_L(type, zoneval, zoneval, lineval, broken_marker::WORKING) #define BROKEN_CASE_L(type, inval, zoneval, lineval) _CASE_L(type, inval, zoneval, lineval, broken_marker::BROKEN) @@ -251,10 +255,10 @@ BOOST_AUTO_TEST_CASE(test_record_types_bad_values) { typedef boost::tuple case_t; typedef std::list cases_t; -#define ZONE_CASE(type, input) case_t(type, input, case_type_t::zone, broken_marker::WORKING) -#define WIRE_CASE(type, input) case_t(type, std::string(input, sizeof(input) - 1), case_type_t::wire, broken_marker::WORKING) -#define BROKEN_ZONE_CASE(type, input) case_t(type, input, case_type_t::zone, broken_marker::BROKEN) -#define BROKEN_WIRE_CASE(type, input) case_t(type, std::string(input, sizeof(input) - 1), case_type_t::wire, broken_marker::BROKEN) +#define ZONE_CASE(type, input) case_t(type, BINARY(input), case_type_t::zone, broken_marker::WORKING) +#define WIRE_CASE(type, input) case_t(type, BINARY(input), case_type_t::wire, broken_marker::WORKING) +#define BROKEN_ZONE_CASE(type, input) case_t(type, BINARY(input), case_type_t::zone, broken_marker::BROKEN) +#define BROKEN_WIRE_CASE(type, input) case_t(type, BINARY(input), case_type_t::wire, broken_marker::BROKEN) const cases_t cases = boost::assign::list_of (ZONE_CASE(QType::A, "932.521.256.42")) // hollywood IP