summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2006-09-28 14:20:54 +0000
committerAlan Conway <aconway@apache.org>2006-09-28 14:20:54 +0000
commit48ceacbfc49c179f63931c5c10d0342f62a01413 (patch)
treef8985e5d476a3c8e232e047f0fe5bd40c73b302d /cpp
parentcaca23c5dc055d985fecfe188573104bc707ad9d (diff)
downloadqpid-python-48ceacbfc49c179f63931c5c10d0342f62a01413.tar.gz
New files missed from yesterdays checkin, apologies!
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@450861 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp')
-rw-r--r--cpp/broker/inc/HeadersExchange.h60
-rw-r--r--cpp/broker/test/HeadersExchangeTest.cpp115
-rw-r--r--cpp/broker/test/ValueTest.cpp99
-rw-r--r--cpp/common/framing/src/AMQBody.cpp33
-rw-r--r--cpp/common/framing/src/AMQHeartbeatBody.cpp26
5 files changed, 333 insertions, 0 deletions
diff --git a/cpp/broker/inc/HeadersExchange.h b/cpp/broker/inc/HeadersExchange.h
new file mode 100644
index 0000000000..08bf0bb735
--- /dev/null
+++ b/cpp/broker/inc/HeadersExchange.h
@@ -0,0 +1,60 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed 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 KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#ifndef _HeadersExchange_
+#define _HeadersExchange_
+
+#include <vector>
+#include "Exchange.h"
+#include "FieldTable.h"
+#include "Message.h"
+#include "MonitorImpl.h"
+#include "Queue.h"
+
+namespace qpid {
+namespace broker {
+
+
+class HeadersExchange : public virtual Exchange {
+ typedef std::pair<qpid::framing::FieldTable, Queue::shared_ptr> Binding;
+ typedef std::vector<Binding> Bindings;
+
+ Bindings bindings;
+ qpid::concurrent::MonitorImpl lock;
+
+ public:
+ static const std::string typeName;
+
+ HeadersExchange(const string& name);
+
+ virtual void bind(Queue::shared_ptr queue, const string& routingKey, qpid::framing::FieldTable* args);
+
+ virtual void unbind(Queue::shared_ptr queue, const string& routingKey, qpid::framing::FieldTable* args);
+
+ virtual void route(Message::shared_ptr& msg, const string& routingKey, qpid::framing::FieldTable* args);
+
+ virtual ~HeadersExchange();
+
+ static bool match(const qpid::framing::FieldTable& bindArgs, const qpid::framing::FieldTable& msgArgs);
+};
+
+
+
+}
+}
+
+#endif
diff --git a/cpp/broker/test/HeadersExchangeTest.cpp b/cpp/broker/test/HeadersExchangeTest.cpp
new file mode 100644
index 0000000000..82d3a292a8
--- /dev/null
+++ b/cpp/broker/test/HeadersExchangeTest.cpp
@@ -0,0 +1,115 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed 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 KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "HeadersExchange.h"
+#include "FieldTable.h"
+#include "Value.h"
+#include <cppunit/TestCase.h>
+#include <cppunit/TextTestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+using namespace qpid::broker;
+using namespace qpid::framing;
+
+class HeadersExchangeTest : public CppUnit::TestCase
+{
+ CPPUNIT_TEST_SUITE(HeadersExchangeTest);
+ CPPUNIT_TEST(testMatchAll);
+ CPPUNIT_TEST(testMatchAny);
+ CPPUNIT_TEST(testMatchEmptyValue);
+ CPPUNIT_TEST(testMatchEmptyArgs);
+ CPPUNIT_TEST(testMatchNoXMatch);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+
+ void testMatchAll()
+ {
+ FieldTable b, m;
+ b.setString("x-match", "all");
+ b.setString("foo", "FOO");
+ b.setInt("n", 42);
+ m.setString("foo", "FOO");
+ m.setInt("n", 42);
+ CPPUNIT_ASSERT(HeadersExchange::match(b, m));
+
+ // Ignore extras.
+ m.setString("extra", "x");
+ CPPUNIT_ASSERT(HeadersExchange::match(b, m));
+
+ // Fail mismatch, wrong value.
+ m.setString("foo", "NotFoo");
+ CPPUNIT_ASSERT(!HeadersExchange::match(b, m));
+
+ // Fail mismatch, missing value
+ m.erase("foo");
+ CPPUNIT_ASSERT(!HeadersExchange::match(b, m));
+ }
+
+ void testMatchAny()
+ {
+ FieldTable b, m;
+ b.setString("x-match", "any");
+ b.setString("foo", "FOO");
+ b.setInt("n", 42);
+ m.setString("foo", "FOO");
+ CPPUNIT_ASSERT(HeadersExchange::match(b, m));
+ m.erase("foo");
+ CPPUNIT_ASSERT(!HeadersExchange::match(b, m));
+ m.setInt("n", 42);
+ CPPUNIT_ASSERT(HeadersExchange::match(b, m));
+ }
+
+ void testMatchEmptyValue()
+ {
+ FieldTable b, m;
+ b.setString("x-match", "all");
+ b.getMap()["foo"] = FieldTable::ValuePtr(new EmptyValue());
+ b.getMap()["n"] = FieldTable::ValuePtr(new EmptyValue());
+ CPPUNIT_ASSERT(!HeadersExchange::match(b, m));
+ m.setString("foo", "blah");
+ m.setInt("n", 123);
+ }
+
+ void testMatchEmptyArgs()
+ {
+ FieldTable b, m;
+ m.setString("foo", "FOO");
+
+ b.setString("x-match", "all");
+ CPPUNIT_ASSERT(HeadersExchange::match(b, m));
+ b.setString("x-match", "any");
+ CPPUNIT_ASSERT(!HeadersExchange::match(b, m));
+ }
+
+
+ void testMatchNoXMatch()
+ {
+ FieldTable b, m;
+ b.setString("foo", "FOO");
+ m.setString("foo", "FOO");
+ CPPUNIT_ASSERT(!HeadersExchange::match(b, m));
+ }
+
+
+};
+
+// make this test suite a plugin.
+CPPUNIT_PLUGIN_IMPLEMENT();
+CPPUNIT_TEST_SUITE_REGISTRATION(HeadersExchangeTest);
diff --git a/cpp/broker/test/ValueTest.cpp b/cpp/broker/test/ValueTest.cpp
new file mode 100644
index 0000000000..181f0ced84
--- /dev/null
+++ b/cpp/broker/test/ValueTest.cpp
@@ -0,0 +1,99 @@
+#include "Value.h"
+#include <cppunit/TestCase.h>
+#include <cppunit/TextTestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+using namespace qpid::framing;
+
+
+// Allow CPPUNIT_EQUALS to print a Tokens.
+// TODO aconway 2006-09-19: Make it a template and put it in a shared test lib.
+//
+template <class T>
+CppUnit::OStringStream& operator <<(CppUnit::OStringStream& out,
+ const ValueOps<T>& v)
+{
+ out << v.getValue();
+ return out;
+}
+
+
+class ValueTest : public CppUnit::TestCase
+{
+ CPPUNIT_TEST_SUITE(ValueTest);
+ CPPUNIT_TEST(testStringValueEquals);
+ CPPUNIT_TEST(testIntegerValueEquals);
+ CPPUNIT_TEST(testDecimalValueEquals);
+ CPPUNIT_TEST(testFieldTableValueEquals);
+ CPPUNIT_TEST_SUITE_END();
+
+ StringValue s;
+ IntegerValue i;
+ DecimalValue d;
+ FieldTableValue ft;
+ EmptyValue e;
+
+ public:
+ ValueTest() :
+ s("abc"),
+ i(42),
+ d(1234,2)
+
+ {
+ ft.getValue().setString("foo", "FOO");
+ ft.getValue().setInt("magic", 7);
+ }
+
+ void testStringValueEquals()
+ {
+
+ CPPUNIT_ASSERT(StringValue("abc") == s);
+ CPPUNIT_ASSERT(s != StringValue("foo"));
+ CPPUNIT_ASSERT(s != e);
+ CPPUNIT_ASSERT(e != d);
+ CPPUNIT_ASSERT(e != ft);
+ }
+
+ void testIntegerValueEquals()
+ {
+ CPPUNIT_ASSERT(IntegerValue(42) == i);
+ CPPUNIT_ASSERT(IntegerValue(5) != i);
+ CPPUNIT_ASSERT(i != e);
+ CPPUNIT_ASSERT(i != d);
+ }
+
+ void testDecimalValueEquals()
+ {
+ CPPUNIT_ASSERT(DecimalValue(1234, 2) == d);
+ CPPUNIT_ASSERT(DecimalValue(12345, 2) != d);
+ CPPUNIT_ASSERT(DecimalValue(1234, 3) != d);
+ CPPUNIT_ASSERT(d != s);
+ }
+
+
+ void testFieldTableValueEquals()
+ {
+ CPPUNIT_ASSERT_EQUAL(std::string("FOO"),
+ ft.getValue().getString("foo"));
+ CPPUNIT_ASSERT_EQUAL(7, ft.getValue().getInt("magic"));
+
+ FieldTableValue f2;
+ CPPUNIT_ASSERT(ft != f2);
+ f2.getValue().setString("foo", "FOO");
+ CPPUNIT_ASSERT(ft != f2);
+ f2.getValue().setInt("magic", 7);
+ CPPUNIT_ASSERT_EQUAL(ft,f2);
+ CPPUNIT_ASSERT(ft == f2);
+ f2.getValue().setString("foo", "BAR");
+ CPPUNIT_ASSERT(ft != f2);
+ CPPUNIT_ASSERT(ft != i);
+ }
+
+};
+
+
+// Make this test suite a plugin.
+CPPUNIT_PLUGIN_IMPLEMENT();
+CPPUNIT_TEST_SUITE_REGISTRATION(ValueTest);
+
diff --git a/cpp/common/framing/src/AMQBody.cpp b/cpp/common/framing/src/AMQBody.cpp
new file mode 100644
index 0000000000..08f0b1d7ca
--- /dev/null
+++ b/cpp/common/framing/src/AMQBody.cpp
@@ -0,0 +1,33 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed 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 KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "AMQBody.h"
+#include <iostream>
+
+std::ostream& qpid::framing::operator<<(std::ostream& out, const qpid::framing::AMQBody& body)
+{
+ body.print(out);
+ return out;
+}
+
+
+qpid::framing::AMQBody::~AMQBody() {}
+
+void qpid::framing::AMQBody::print(std::ostream& out) const {
+ out << "unknown body";
+}
diff --git a/cpp/common/framing/src/AMQHeartbeatBody.cpp b/cpp/common/framing/src/AMQHeartbeatBody.cpp
new file mode 100644
index 0000000000..15cbfeda48
--- /dev/null
+++ b/cpp/common/framing/src/AMQHeartbeatBody.cpp
@@ -0,0 +1,26 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed 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 KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "AMQHeartbeatBody.h"
+#include <iostream>
+
+qpid::framing::AMQHeartbeatBody::~AMQHeartbeatBody() {}
+
+void qpid::framing::AMQHeartbeatBody::print(std::ostream& out) const {
+ out << "heartbeat";
+}