diff options
| author | Alan Conway <aconway@apache.org> | 2006-10-16 13:50:26 +0000 | 
|---|---|---|
| committer | Alan Conway <aconway@apache.org> | 2006-10-16 13:50:26 +0000 | 
| commit | 8a6ab3aa61d441b9210c05c84dc9998acfc38737 (patch) | |
| tree | 1eb9d7f39b5c2d04a85a1f66caef3d398567b740 /cpp/test/unit/qpid/broker/TopicExchangeTest.cpp | |
| parent | 9a808fb13aba243d41bbdab75158dae5939a80a4 (diff) | |
| download | qpid-python-8a6ab3aa61d441b9210c05c84dc9998acfc38737.tar.gz | |
Build system reorg, see README and Makefile comments for details.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@464494 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/test/unit/qpid/broker/TopicExchangeTest.cpp')
| -rw-r--r-- | cpp/test/unit/qpid/broker/TopicExchangeTest.cpp | 184 | 
1 files changed, 184 insertions, 0 deletions
| diff --git a/cpp/test/unit/qpid/broker/TopicExchangeTest.cpp b/cpp/test/unit/qpid/broker/TopicExchangeTest.cpp new file mode 100644 index 0000000000..4066a4709f --- /dev/null +++ b/cpp/test/unit/qpid/broker/TopicExchangeTest.cpp @@ -0,0 +1,184 @@ +#include "../../src/qpid/broker/TopicExchange.h" +#include <qpid_test_plugin.h> + +using namespace qpid::broker; + +Tokens makeTokens(char** begin, 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)) + +// Allow CPPUNIT_EQUALS to print a Tokens. +// TODO aconway 2006-09-19: Make it a template and put it in a shared test lib. +// +CppUnit::OStringStream& operator <<(CppUnit::OStringStream& out, const Tokens& v) +{ +    out << "[ "; +    for (Tokens::const_iterator i = v.begin(); +         i != v.end(); ++i) +    { +        out << '"' << *i << '"' << (i+1 == v.end() ? "]" : ", "); +    } +    return out; +} + + +class TokensTest : public CppUnit::TestCase +{ +    CPPUNIT_TEST_SUITE(TokensTest); +    CPPUNIT_TEST(testTokens); +    CPPUNIT_TEST_SUITE_END(); + +  public: +    void testTokens()  +    { +        Tokens tokens("hello.world"); +        char* expect[] = {"hello", "world"}; +        CPPUNIT_ASSERT_EQUAL(TOKENS(expect), tokens); +         +        tokens = "a.b.c"; +        char* expect2[] = { "a", "b", "c" }; +        CPPUNIT_ASSERT_EQUAL(TOKENS(expect2), tokens); + +        tokens = ""; +        CPPUNIT_ASSERT(tokens.empty()); + +        tokens = "x"; +        char* expect3[] = { "x" }; +        CPPUNIT_ASSERT_EQUAL(TOKENS(expect3), tokens); + +        tokens = (".x"); +        char* expect4[] = { "", "x" }; +        CPPUNIT_ASSERT_EQUAL(TOKENS(expect4), tokens); + +        tokens = ("x."); +        char* expect5[] = { "x", "" }; +        CPPUNIT_ASSERT_EQUAL(TOKENS(expect5), tokens); + +        tokens = ("."); +        char* expect6[] = { "", "" }; +        CPPUNIT_ASSERT_EQUAL(TOKENS(expect6), tokens);         + +        tokens = (".."); +        char* expect7[] = { "", "", "" }; +        CPPUNIT_ASSERT_EQUAL(TOKENS(expect7), tokens);         +    } +     +}; + +#define ASSERT_NORMALIZED(expect, pattern) \ +    CPPUNIT_ASSERT_EQUAL(Tokens(expect), static_cast<Tokens>(TopicPattern(pattern))) +class TopicPatternTest : public CppUnit::TestCase  +{ +    CPPUNIT_TEST_SUITE(TopicPatternTest); +    CPPUNIT_TEST(testNormalize); +    CPPUNIT_TEST(testPlain); +    CPPUNIT_TEST(testStar); +    CPPUNIT_TEST(testHash); +    CPPUNIT_TEST(testMixed); +    CPPUNIT_TEST(testCombo); +    CPPUNIT_TEST_SUITE_END(); + +  public: + +    void testNormalize()  +    { +        CPPUNIT_ASSERT(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.*.#.*.#.*"); +    } +     +    void testPlain() { +        TopicPattern p("ab.cd.e"); +        CPPUNIT_ASSERT(p.match("ab.cd.e")); +        CPPUNIT_ASSERT(!p.match("abx.cd.e")); +        CPPUNIT_ASSERT(!p.match("ab.cd")); +        CPPUNIT_ASSERT(!p.match("ab.cd..e.")); +        CPPUNIT_ASSERT(!p.match("ab.cd.e.")); +        CPPUNIT_ASSERT(!p.match(".ab.cd.e")); + +        p = ""; +        CPPUNIT_ASSERT(p.match("")); + +        p = "."; +        CPPUNIT_ASSERT(p.match(".")); +    } + + +    void testStar()  +    { +        TopicPattern p("a.*.b"); +        CPPUNIT_ASSERT(p.match("a.xx.b")); +        CPPUNIT_ASSERT(!p.match("a.b")); + +        p = "*.x"; +        CPPUNIT_ASSERT(p.match("y.x")); +        CPPUNIT_ASSERT(p.match(".x")); +        CPPUNIT_ASSERT(!p.match("x")); + +        p = "x.x.*"; +        CPPUNIT_ASSERT(p.match("x.x.y")); +        CPPUNIT_ASSERT(p.match("x.x.")); +        CPPUNIT_ASSERT(!p.match("x.x")); +        CPPUNIT_ASSERT(!p.match("q.x.y")); +    } + +    void testHash()  +    { +        TopicPattern p("a.#.b"); +        CPPUNIT_ASSERT(p.match("a.b")); +        CPPUNIT_ASSERT(p.match("a.x.b")); +        CPPUNIT_ASSERT(p.match("a..x.y.zz.b")); +        CPPUNIT_ASSERT(!p.match("a.b.")); +        CPPUNIT_ASSERT(!p.match("q.x.b")); + +        p = "a.#"; +        CPPUNIT_ASSERT(p.match("a")); +        CPPUNIT_ASSERT(p.match("a.b")); +        CPPUNIT_ASSERT(p.match("a.b.c")); + +        p = "#.a"; +        CPPUNIT_ASSERT(p.match("a")); +        CPPUNIT_ASSERT(p.match("x.y.a")); +    } + +    void testMixed()  +    { +        TopicPattern p("*.x.#.y"); +        CPPUNIT_ASSERT(p.match("a.x.y")); +        CPPUNIT_ASSERT(p.match("a.x.p.qq.y")); +        CPPUNIT_ASSERT(!p.match("a.a.x.y")); +        CPPUNIT_ASSERT(!p.match("aa.x.b.c")); + +        p = "a.#.b.*"; +        CPPUNIT_ASSERT(p.match("a.b.x")); +        CPPUNIT_ASSERT(p.match("a.x.x.x.b.x")); +    } + +    void testCombo() { +        TopicPattern p("*.#.#.*.*.#"); +        CPPUNIT_ASSERT(p.match("x.y.z")); +        CPPUNIT_ASSERT(p.match("x.y.z.a.b.c")); +        CPPUNIT_ASSERT(!p.match("x.y")); +        CPPUNIT_ASSERT(!p.match("x")); +    } +}; + +     +// Make this test suite a plugin. +CPPUNIT_PLUGIN_IMPLEMENT(); +CPPUNIT_TEST_SUITE_REGISTRATION(TopicPatternTest); +CPPUNIT_TEST_SUITE_REGISTRATION(TokensTest); | 
