diff options
Diffstat (limited to 'cpp/src/tests/TopicExchangeTest.cpp')
-rw-r--r-- | cpp/src/tests/TopicExchangeTest.cpp | 210 |
1 files changed, 85 insertions, 125 deletions
diff --git a/cpp/src/tests/TopicExchangeTest.cpp b/cpp/src/tests/TopicExchangeTest.cpp index af4263de34..c103620dbf 100644 --- a/cpp/src/tests/TopicExchangeTest.cpp +++ b/cpp/src/tests/TopicExchangeTest.cpp @@ -6,9 +6,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -21,147 +21,107 @@ #include "test_tools.h" using namespace qpid::broker; +using namespace std; -Tokens makeTokens(const char** begin, const char** end) -{ - Tokens t; - t.insert(t.end(), begin, end); - return t; -} - -// Calculate size of an array. -#define LEN(a) (sizeof(a)/sizeof(a[0])) - -// Convert array to token vector -#define TOKENS(a) makeTokens(a, a + LEN(a)) - -#define ASSERT_NORMALIZED(expect, pattern) \ - BOOST_CHECK_EQUAL(Tokens(expect), static_cast<Tokens>(TopicPattern(pattern))) - +namespace qpid { +namespace tests { QPID_AUTO_TEST_SUITE(TopicExchangeTestSuite) -QPID_AUTO_TEST_CASE(testTokens) -{ - Tokens tokens("hello.world"); - const char* expect[] = {"hello", "world"}; - BOOST_CHECK_EQUAL(TOKENS(expect), tokens); - - tokens = "a.b.c"; - const char* expect2[] = { "a", "b", "c" }; - BOOST_CHECK_EQUAL(TOKENS(expect2), tokens); - - tokens = ""; - BOOST_CHECK(tokens.empty()); - - tokens = "x"; - const char* expect3[] = { "x" }; - BOOST_CHECK_EQUAL(TOKENS(expect3), tokens); - - tokens = (".x"); - const char* expect4[] = { "", "x" }; - BOOST_CHECK_EQUAL(TOKENS(expect4), tokens); - - tokens = ("x."); - const char* expect5[] = { "x", "" }; - BOOST_CHECK_EQUAL(TOKENS(expect5), tokens); - - tokens = ("."); - const char* expect6[] = { "", "" }; - BOOST_CHECK_EQUAL(TOKENS(expect6), tokens); - - tokens = (".."); - const char* expect7[] = { "", "", "" }; - BOOST_CHECK_EQUAL(TOKENS(expect7), tokens); -} +#define CHECK_NORMALIZED(expect, pattern) BOOST_CHECK_EQUAL(expect, TopicExchange::normalize(pattern)); -QPID_AUTO_TEST_CASE(testNormalize) -{ - BOOST_CHECK(TopicPattern("").empty()); - ASSERT_NORMALIZED("a.b.c", "a.b.c"); - ASSERT_NORMALIZED("a.*.c", "a.*.c"); - ASSERT_NORMALIZED("#", "#"); - ASSERT_NORMALIZED("#", "#.#.#.#"); - ASSERT_NORMALIZED("*.*.*.#", "#.*.#.*.#.#.*"); - ASSERT_NORMALIZED("a.*.*.*.#", "a.*.#.*.#.*.#"); - ASSERT_NORMALIZED("a.*.*.*.#", "a.*.#.*.#.*"); -} - -QPID_AUTO_TEST_CASE(testPlain) +QPID_AUTO_TEST_CASE(testNormalize) { - TopicPattern p("ab.cd.e"); - BOOST_CHECK(p.match("ab.cd.e")); - BOOST_CHECK(!p.match("abx.cd.e")); - BOOST_CHECK(!p.match("ab.cd")); - BOOST_CHECK(!p.match("ab.cd..e.")); - BOOST_CHECK(!p.match("ab.cd.e.")); - BOOST_CHECK(!p.match(".ab.cd.e")); - - p = ""; - BOOST_CHECK(p.match("")); - - p = "."; - BOOST_CHECK(p.match(".")); + CHECK_NORMALIZED("", ""); + CHECK_NORMALIZED("a.b.c", "a.b.c"); + CHECK_NORMALIZED("a.*.c", "a.*.c"); + CHECK_NORMALIZED("#", "#"); + CHECK_NORMALIZED("#", "#.#.#.#"); + CHECK_NORMALIZED("*.*.*.#", "#.*.#.*.#.#.*"); + CHECK_NORMALIZED("a.*.*.*.#", "a.*.#.*.#.*.#"); + CHECK_NORMALIZED("a.*.*.*.#", "a.*.#.*.#.*"); + CHECK_NORMALIZED("*.*.*.#", "*.#.#.*.*.#"); } - -QPID_AUTO_TEST_CASE(testStar) +QPID_AUTO_TEST_CASE(testPlain) { - TopicPattern p("a.*.b"); - BOOST_CHECK(p.match("a.xx.b")); - BOOST_CHECK(!p.match("a.b")); - - p = "*.x"; - BOOST_CHECK(p.match("y.x")); - BOOST_CHECK(p.match(".x")); - BOOST_CHECK(!p.match("x")); - - p = "x.x.*"; - BOOST_CHECK(p.match("x.x.y")); - BOOST_CHECK(p.match("x.x.")); - BOOST_CHECK(!p.match("x.x")); - BOOST_CHECK(!p.match("q.x.y")); + string pattern("ab.cd.e"); + BOOST_CHECK(TopicExchange::match(pattern, "ab.cd.e")); + BOOST_CHECK(!TopicExchange::match(pattern, "abx.cd.e")); + BOOST_CHECK(!TopicExchange::match(pattern, "ab.cd")); + BOOST_CHECK(!TopicExchange::match(pattern, "ab.cd..e.")); + BOOST_CHECK(!TopicExchange::match(pattern, "ab.cd.e.")); + BOOST_CHECK(!TopicExchange::match(pattern, ".ab.cd.e")); + + pattern = ""; + BOOST_CHECK(TopicExchange::match(pattern, "")); + + pattern = "."; + BOOST_CHECK(TopicExchange::match(pattern, ".")); } -QPID_AUTO_TEST_CASE(testHash) + +QPID_AUTO_TEST_CASE(testStar) { - TopicPattern p("a.#.b"); - BOOST_CHECK(p.match("a.b")); - BOOST_CHECK(p.match("a.x.b")); - BOOST_CHECK(p.match("a..x.y.zz.b")); - BOOST_CHECK(!p.match("a.b.")); - BOOST_CHECK(!p.match("q.x.b")); - - p = "a.#"; - BOOST_CHECK(p.match("a")); - BOOST_CHECK(p.match("a.b")); - BOOST_CHECK(p.match("a.b.c")); - - p = "#.a"; - BOOST_CHECK(p.match("a")); - BOOST_CHECK(p.match("x.y.a")); + string pattern("a.*.b"); + BOOST_CHECK(TopicExchange::match(pattern, "a.xx.b")); + BOOST_CHECK(!TopicExchange::match(pattern, "a.b")); + + pattern = "*.x"; + BOOST_CHECK(TopicExchange::match(pattern, "y.x")); + BOOST_CHECK(TopicExchange::match(pattern, ".x")); + BOOST_CHECK(!TopicExchange::match(pattern, "x")); + + pattern = "x.x.*"; + BOOST_CHECK(TopicExchange::match(pattern, "x.x.y")); + BOOST_CHECK(TopicExchange::match(pattern, "x.x.")); + BOOST_CHECK(!TopicExchange::match(pattern, "x.x")); + BOOST_CHECK(!TopicExchange::match(pattern, "q.x.y")); } -QPID_AUTO_TEST_CASE(testMixed) +QPID_AUTO_TEST_CASE(testHash) { - TopicPattern p("*.x.#.y"); - BOOST_CHECK(p.match("a.x.y")); - BOOST_CHECK(p.match("a.x.p.qq.y")); - BOOST_CHECK(!p.match("a.a.x.y")); - BOOST_CHECK(!p.match("aa.x.b.c")); - - p = "a.#.b.*"; - BOOST_CHECK(p.match("a.b.x")); - BOOST_CHECK(p.match("a.x.x.x.b.x")); + string pattern("a.#.b"); + BOOST_CHECK(TopicExchange::match(pattern, "a.b")); + BOOST_CHECK(TopicExchange::match(pattern, "a.x.b")); + BOOST_CHECK(TopicExchange::match(pattern, "a..x.y.zz.b")); + BOOST_CHECK(!TopicExchange::match(pattern, "a.b.")); + BOOST_CHECK(!TopicExchange::match(pattern, "q.x.b")); + + pattern = "a.#"; + BOOST_CHECK(TopicExchange::match(pattern, "a")); + BOOST_CHECK(TopicExchange::match(pattern, "a.b")); + BOOST_CHECK(TopicExchange::match(pattern, "a.b.c")); + + pattern = "#.a"; + BOOST_CHECK(TopicExchange::match(pattern, "a")); + BOOST_CHECK(TopicExchange::match(pattern, "x.y.a")); + + pattern = "a.#.b.#.c"; + BOOST_CHECK(TopicExchange::match(pattern, "a.b.c")); + BOOST_CHECK(TopicExchange::match(pattern, "a.x.b.y.c")); + BOOST_CHECK(TopicExchange::match(pattern, "a.x.x.b.y.y.c")); } -QPID_AUTO_TEST_CASE(testCombo) +QPID_AUTO_TEST_CASE(testMixed) { - TopicPattern p("*.#.#.*.*.#"); - BOOST_CHECK(p.match("x.y.z")); - BOOST_CHECK(p.match("x.y.z.a.b.c")); - BOOST_CHECK(!p.match("x.y")); - BOOST_CHECK(!p.match("x")); + string pattern("*.x.#.y"); + BOOST_CHECK(TopicExchange::match(pattern, "a.x.y")); + BOOST_CHECK(TopicExchange::match(pattern, "a.x.p.qq.y")); + BOOST_CHECK(!TopicExchange::match(pattern, "a.a.x.y")); + BOOST_CHECK(!TopicExchange::match(pattern, "aa.x.b.c")); + + pattern = "a.#.b.*"; + BOOST_CHECK(TopicExchange::match(pattern, "a.b.x")); + BOOST_CHECK(TopicExchange::match(pattern, "a.x.x.x.b.x")); + + pattern = "*.*.*.#"; + BOOST_CHECK(TopicExchange::match(pattern, "x.y.z")); + BOOST_CHECK(TopicExchange::match(pattern, "x.y.z.a.b.c")); + BOOST_CHECK(!TopicExchange::match(pattern, "x.y")); + BOOST_CHECK(!TopicExchange::match(pattern, "x")); } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests |