diff options
author | Gordon Sim <gsim@apache.org> | 2006-10-30 19:27:54 +0000 |
---|---|---|
committer | Gordon Sim <gsim@apache.org> | 2006-10-30 19:27:54 +0000 |
commit | b0a120b4edfdb49a08bd7c8c2479e7b1cadc5233 (patch) | |
tree | d2b4ca0e774100285e116e5442bff9e55b4a3f92 /cpp/test | |
parent | f491af49008a2ed219ad4507cd507b4317afa4cb (diff) | |
download | qpid-python-b0a120b4edfdb49a08bd7c8c2479e7b1cadc5233.tar.gz |
Initial implementation for tx class.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@469242 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/test')
-rw-r--r-- | cpp/test/unit/qpid/broker/ChannelTest.cpp | 27 | ||||
-rw-r--r-- | cpp/test/unit/qpid/broker/ExchangeTest.cpp | 4 | ||||
-rw-r--r-- | cpp/test/unit/qpid/broker/MessageBuilderTest.cpp | 110 | ||||
-rw-r--r-- | cpp/test/unit/qpid/broker/RouterTest.cpp | 86 | ||||
-rw-r--r-- | cpp/test/unit/qpid/concurrent/APRBaseTest.cpp | 44 |
5 files changed, 157 insertions, 114 deletions
diff --git a/cpp/test/unit/qpid/broker/ChannelTest.cpp b/cpp/test/unit/qpid/broker/ChannelTest.cpp index b0907a40f3..5052d4127d 100644 --- a/cpp/test/unit/qpid/broker/ChannelTest.cpp +++ b/cpp/test/unit/qpid/broker/ChannelTest.cpp @@ -26,14 +26,6 @@ using namespace qpid::broker; using namespace qpid::framing; using namespace qpid::concurrent; -struct DummyRouter{ - Message::shared_ptr last; - - void operator()(Message::shared_ptr& msg){ - last = msg; - } -}; - struct DummyHandler : OutputHandler{ std::vector<AMQFrame*> frames; @@ -46,31 +38,12 @@ struct DummyHandler : OutputHandler{ class ChannelTest : public CppUnit::TestCase { CPPUNIT_TEST_SUITE(ChannelTest); - CPPUNIT_TEST(testIncoming); CPPUNIT_TEST(testConsumerMgmt); CPPUNIT_TEST(testDeliveryNoAck); CPPUNIT_TEST_SUITE_END(); public: - void testIncoming(){ - Channel channel(0, 0, 10000); - string routingKey("my_routing_key"); - channel.handlePublish(new Message(0, "test", routingKey, false, false)); - AMQHeaderBody::shared_ptr header(new AMQHeaderBody(BASIC)); - header->setContentSize(14); - string data1("abcdefg"); - string data2("hijklmn"); - AMQContentBody::shared_ptr part1(new AMQContentBody(data1)); - AMQContentBody::shared_ptr part2(new AMQContentBody(data2)); - - CPPUNIT_ASSERT(!channel.handleHeader(header, DummyRouter()).last); - CPPUNIT_ASSERT(!channel.handleContent(part1, DummyRouter()).last); - DummyRouter router = channel.handleContent(part2, DummyRouter()); - CPPUNIT_ASSERT(router.last); - CPPUNIT_ASSERT_EQUAL(routingKey, router.last->getRoutingKey()); - } - void testConsumerMgmt(){ Queue::shared_ptr queue(new Queue("my_queue")); Channel channel(0, 0, 0); diff --git a/cpp/test/unit/qpid/broker/ExchangeTest.cpp b/cpp/test/unit/qpid/broker/ExchangeTest.cpp index 40fa9cb032..2fb525312b 100644 --- a/cpp/test/unit/qpid/broker/ExchangeTest.cpp +++ b/cpp/test/unit/qpid/broker/ExchangeTest.cpp @@ -16,6 +16,7 @@ * */ +#include "qpid/broker/DeliverableMessage.h" #include "qpid/broker/DirectExchange.h" #include "qpid/broker/Exchange.h" #include "qpid/broker/Queue.h" @@ -50,7 +51,8 @@ class ExchangeTest : public CppUnit::TestCase queue.reset(); queue2.reset(); - Message::shared_ptr msg = Message::shared_ptr(new Message(0, "e", "A", true, true)); + Message::shared_ptr msgPtr(new Message(0, "e", "A", true, true)); + DeliverableMessage msg(msgPtr); topic.route(msg, "abc", 0); direct.route(msg, "abc", 0); diff --git a/cpp/test/unit/qpid/broker/MessageBuilderTest.cpp b/cpp/test/unit/qpid/broker/MessageBuilderTest.cpp new file mode 100644 index 0000000000..c432de7785 --- /dev/null +++ b/cpp/test/unit/qpid/broker/MessageBuilderTest.cpp @@ -0,0 +1,110 @@ +/* + * + * 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 "qpid/broker/Message.h" +#include "qpid/broker/MessageBuilder.h" +#include <qpid_test_plugin.h> +#include <iostream> +#include <memory> + +using namespace boost; +using namespace qpid::broker; +using namespace qpid::framing; +using namespace qpid::concurrent; + +class MessageBuilderTest : public CppUnit::TestCase +{ + struct DummyHandler : MessageBuilder::CompletionHandler{ + Message::shared_ptr msg; + + virtual void complete(Message::shared_ptr& _msg){ + msg = _msg; + } + }; + + + CPPUNIT_TEST_SUITE(MessageBuilderTest); + CPPUNIT_TEST(testHeaderOnly); + CPPUNIT_TEST(test1ContentFrame); + CPPUNIT_TEST(test2ContentFrames); + CPPUNIT_TEST_SUITE_END(); + + public: + + void testHeaderOnly(){ + DummyHandler handler; + MessageBuilder builder(&handler); + + Message::shared_ptr message(new Message(0, "test", "my_routing_key", false, false)); + AMQHeaderBody::shared_ptr header(new AMQHeaderBody(BASIC)); + header->setContentSize(0); + + builder.initialise(message); + CPPUNIT_ASSERT(!handler.msg); + builder.setHeader(header); + CPPUNIT_ASSERT(handler.msg); + CPPUNIT_ASSERT_EQUAL(message, handler.msg); + } + + void test1ContentFrame(){ + DummyHandler handler; + MessageBuilder builder(&handler); + + string data1("abcdefg"); + + Message::shared_ptr message(new Message(0, "test", "my_routing_key", false, false)); + AMQHeaderBody::shared_ptr header(new AMQHeaderBody(BASIC)); + header->setContentSize(7); + AMQContentBody::shared_ptr part1(new AMQContentBody(data1)); + + builder.initialise(message); + CPPUNIT_ASSERT(!handler.msg); + builder.setHeader(header); + CPPUNIT_ASSERT(!handler.msg); + builder.addContent(part1); + CPPUNIT_ASSERT(handler.msg); + CPPUNIT_ASSERT_EQUAL(message, handler.msg); + } + + void test2ContentFrames(){ + DummyHandler handler; + MessageBuilder builder(&handler); + + string data1("abcdefg"); + string data2("hijklmn"); + + Message::shared_ptr message(new Message(0, "test", "my_routing_key", false, false)); + AMQHeaderBody::shared_ptr header(new AMQHeaderBody(BASIC)); + header->setContentSize(14); + AMQContentBody::shared_ptr part1(new AMQContentBody(data1)); + AMQContentBody::shared_ptr part2(new AMQContentBody(data2)); + + builder.initialise(message); + CPPUNIT_ASSERT(!handler.msg); + builder.setHeader(header); + CPPUNIT_ASSERT(!handler.msg); + builder.addContent(part1); + CPPUNIT_ASSERT(!handler.msg); + builder.addContent(part2); + CPPUNIT_ASSERT(handler.msg); + CPPUNIT_ASSERT_EQUAL(message, handler.msg); + } +}; + +// Make this test suite a plugin. +CPPUNIT_PLUGIN_IMPLEMENT(); +CPPUNIT_TEST_SUITE_REGISTRATION(MessageBuilderTest); diff --git a/cpp/test/unit/qpid/broker/RouterTest.cpp b/cpp/test/unit/qpid/broker/RouterTest.cpp deleted file mode 100644 index f2c9f27abd..0000000000 --- a/cpp/test/unit/qpid/broker/RouterTest.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * - * 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 "qpid/broker/Channel.h" -#include "qpid/broker/Exchange.h" -#include "qpid/broker/ExchangeRegistry.h" -#include "qpid/broker/Message.h" -#include "qpid/broker/Router.h" -#include <qpid_test_plugin.h> -#include <iostream> -#include <memory> - -using namespace qpid::broker; -using namespace qpid::framing; -using namespace qpid::concurrent; - -struct TestExchange : public Exchange{ - Message::shared_ptr msg; - string routingKey; - FieldTable* args; - - TestExchange() : Exchange("test"), args(0) {} - - void bind(Queue::shared_ptr /*queue*/, const string& /*routingKey*/, FieldTable* /*args*/){} - - void unbind(Queue::shared_ptr /*queue*/, const string& /*routingKey*/, FieldTable* /*args*/){ } - - void route(Message::shared_ptr& _msg, const string& _routingKey, FieldTable* _args){ - msg = _msg; - routingKey = _routingKey; - args = _args; - } -}; - -class RouterTest : public CppUnit::TestCase -{ - CPPUNIT_TEST_SUITE(RouterTest); - CPPUNIT_TEST(test); - CPPUNIT_TEST_SUITE_END(); - - public: - - void test() - { - ExchangeRegistry registry; - TestExchange* exchange = new TestExchange(); - registry.declare(exchange); - - string routingKey("my_routing_key"); - string name("name"); - string value("value"); - Message::shared_ptr msg(new Message(0, "test", routingKey, false, false)); - AMQHeaderBody::shared_ptr header(new AMQHeaderBody(BASIC)); - - dynamic_cast<BasicHeaderProperties*>(header->getProperties())->getHeaders().setString(name, value); - msg->setHeader(header); - - Router router(registry); - router(msg); - - CPPUNIT_ASSERT(exchange->msg); - CPPUNIT_ASSERT_EQUAL(msg, exchange->msg); - CPPUNIT_ASSERT_EQUAL(routingKey, exchange->msg->getRoutingKey()); - CPPUNIT_ASSERT_EQUAL(routingKey, exchange->routingKey); - CPPUNIT_ASSERT_EQUAL(value, exchange->args->getString(name)); - } -}; - -// Make this test suite a plugin. -CPPUNIT_PLUGIN_IMPLEMENT(); -CPPUNIT_TEST_SUITE_REGISTRATION(RouterTest); - diff --git a/cpp/test/unit/qpid/concurrent/APRBaseTest.cpp b/cpp/test/unit/qpid/concurrent/APRBaseTest.cpp new file mode 100644 index 0000000000..0b4fd94e10 --- /dev/null +++ b/cpp/test/unit/qpid/concurrent/APRBaseTest.cpp @@ -0,0 +1,44 @@ +/* + * + * 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 "qpid/concurrent/APRBase.h" +#include <qpid_test_plugin.h> +#include <iostream> + +using namespace qpid::concurrent; + +class APRBaseTest : public CppUnit::TestCase +{ + CPPUNIT_TEST_SUITE(APRBaseTest); + CPPUNIT_TEST(testMe); + CPPUNIT_TEST_SUITE_END(); + + public: + + void testMe() + { + APRBase::increment(); + APRBase::increment(); + APRBase::decrement(); + APRBase::decrement(); + } +}; + +// Make this test suite a plugin. +CPPUNIT_PLUGIN_IMPLEMENT(); +CPPUNIT_TEST_SUITE_REGISTRATION(APRBaseTest); + |