From 4d28227e5247f01d2bf9873af0dee5d28e4c5e97 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Tue, 7 Aug 2007 22:28:06 +0000 Subject: * Summary: new Frame type to replace AMQFrame. Instead of holding a shared_ptr to a heap-allocated AMQBody subclass, it holds the body in-line in a boost::variant of all the concrete AMQBody subclasses. Actually there are nested variants, the compiler does not cope well with a single variant of 130-some types. Creating, encoding and decoding a local Frame doess 0 heap allocation apart from that done by the concrete AMQBody::encode/decode - e.g. method bodies with std::string fields. for method bodies All variants contain type boost::blank. This guarantees 0 heap alloocation by the variant and represents the "uninitialized" state. variant.h provides NoBlankVisitor to help write visitors for variants containing blank. * src/qpid/framing/MethodHolder.h, .cpp: Holds a variant containing a method body. * src/qpid/framing/Frame.h, .cpp: New Frame holds body in a variant rather than via heap allocation. * src/qpid/framing/variant.h: Utilities for using boost::variant. * src/qpid/framing/amqp_types.h: Added FrameType typedef. * src/qpid/framing/AMQMethodBody.h: Friends with MethodHolder. * src/Makefile.am: - Improved ruby generation rule. - Run method_variants template. - Added new source files - Pre-compiled header rule for method_variants.h * rubygen/templates/method_variants.rb: Generate variants to hold methods of each class, and MethodVariant to hold all the class variants. * rubygen/cppgen.rb: variant, tuple methods. * MethodBodyClass.h.tmpl: Added default constructor to method bodies. * amqpgen.rb (AmqpRoot::merge): fix bug in merge. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@563683 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/tests/Frame.cpp | 77 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 qpid/cpp/src/tests/Frame.cpp (limited to 'qpid/cpp/src/tests/Frame.cpp') diff --git a/qpid/cpp/src/tests/Frame.cpp b/qpid/cpp/src/tests/Frame.cpp new file mode 100644 index 0000000000..f02564f5da --- /dev/null +++ b/qpid/cpp/src/tests/Frame.cpp @@ -0,0 +1,77 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * 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 + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#include "qpid/framing/Frame.h" + +#define BOOST_AUTO_TEST_MAIN // Must come before #include +#include +#include + +using namespace std; +using namespace qpid::framing; +using namespace boost; + +BOOST_AUTO_TEST_CASE(testContentBody) { + Frame f(42, AMQContentBody("foobar")); + AMQBody* body=f.getBody(); + BOOST_CHECK(dynamic_cast(body)); + Buffer b(f.size()); + f.encode(b); + b.flip(); + Frame g; + g.decode(b); + AMQContentBody* content=dynamic_cast(g.getBody()); + BOOST_REQUIRE(content); + BOOST_CHECK_EQUAL(content->getData(), "foobar"); +} + +BOOST_AUTO_TEST_CASE(testMethodBody) { + FieldTable args; + args.setString("foo", "bar"); + Frame f( + 42, QueueDeclareBody(ProtocolVersion(), 1, "q", "altex", + true, false, true, false, true, args)); + BOOST_CHECK_EQUAL(f.getChannel(), 42); + Buffer b(f.size()); + f.encode(b); + b.flip(); + Frame g; + g.decode(b); + BOOST_CHECK_EQUAL(f.getChannel(), g.getChannel()); + QueueDeclareBody* declare=dynamic_cast(g.getBody()); + BOOST_REQUIRE(declare); + BOOST_CHECK_EQUAL(declare->getAlternateExchange(), "altex"); + BOOST_CHECK_EQUAL(lexical_cast(*f.getBody()), lexical_cast(*g.getBody())); +} + +BOOST_AUTO_TEST_CASE(testLoop) { + // Run in a loop so heap profiler can spot any allocations. + Buffer b(1024); + for (int i = 0; i < 100; ++i) { + Frame ctor(2, AccessRequestOkBody(ProtocolVersion(), 42)); + Frame assign(3); + assign.body = AccessRequestOkBody(ProtocolVersion(), 42); + assign.encode(b); + b.flip(); + Frame g; + g.decode(b); + BOOST_REQUIRE(dynamic_cast(g.getBody())->getTicket() == 42); + } +} -- cgit v1.2.1 From 6ff9cc1db2af388c9fe00c140f555f7c30c5df6d Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Thu, 1 Nov 2007 00:38:58 +0000 Subject: Preparation for session thread safety overhaul: - simplified SessionState, responsibility for protocol states now in Handlers - qpid::RefCounted, qpid::intrusive_ptr reference counting support. - build boost unit tests as single exe, speeds up testing. - fixed leak in AsynchIOAcceptor.cpp git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@590869 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/tests/Frame.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'qpid/cpp/src/tests/Frame.cpp') diff --git a/qpid/cpp/src/tests/Frame.cpp b/qpid/cpp/src/tests/Frame.cpp index f02564f5da..c0839b67d7 100644 --- a/qpid/cpp/src/tests/Frame.cpp +++ b/qpid/cpp/src/tests/Frame.cpp @@ -20,9 +20,9 @@ */ #include "qpid/framing/Frame.h" -#define BOOST_AUTO_TEST_MAIN // Must come before #include -#include #include +#include +BOOST_AUTO_TEST_SUITE(Frame); using namespace std; using namespace qpid::framing; @@ -75,3 +75,5 @@ BOOST_AUTO_TEST_CASE(testLoop) { BOOST_REQUIRE(dynamic_cast(g.getBody())->getTicket() == 42); } } + +BOOST_AUTO_TEST_SUITE_END(); -- cgit v1.2.1 From acd260bce099be36b879826a0921daf9cb2fe140 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Wed, 28 Nov 2007 17:13:28 +0000 Subject: Fixed to build with boost 1.34 as well as boost 1.33 - boost::ptr_map API changed. - Boost.Test unit test framework changes. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@599067 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/tests/Frame.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'qpid/cpp/src/tests/Frame.cpp') diff --git a/qpid/cpp/src/tests/Frame.cpp b/qpid/cpp/src/tests/Frame.cpp index c0839b67d7..0484dc4b2a 100644 --- a/qpid/cpp/src/tests/Frame.cpp +++ b/qpid/cpp/src/tests/Frame.cpp @@ -21,8 +21,9 @@ #include "qpid/framing/Frame.h" #include -#include -BOOST_AUTO_TEST_SUITE(Frame); +#include "unit_test.h" + +QPID_AUTO_TEST_SUITE(FrameTestSuite) using namespace std; using namespace qpid::framing; @@ -76,4 +77,4 @@ BOOST_AUTO_TEST_CASE(testLoop) { } } -BOOST_AUTO_TEST_SUITE_END(); +QPID_AUTO_TEST_SUITE_END() -- cgit v1.2.1 From 1b4a961ec807e5e61cd232b08020a935a4f76f4c Mon Sep 17 00:00:00 2001 From: Andrew Stitcher Date: Thu, 17 Apr 2008 21:46:22 +0000 Subject: Patch for improved compatibility with gcc 3.4 and boost 1.33 git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@649294 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/tests/Frame.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'qpid/cpp/src/tests/Frame.cpp') diff --git a/qpid/cpp/src/tests/Frame.cpp b/qpid/cpp/src/tests/Frame.cpp index 0484dc4b2a..9ee3848b7b 100644 --- a/qpid/cpp/src/tests/Frame.cpp +++ b/qpid/cpp/src/tests/Frame.cpp @@ -29,7 +29,7 @@ using namespace std; using namespace qpid::framing; using namespace boost; -BOOST_AUTO_TEST_CASE(testContentBody) { +QPID_AUTO_TEST_CASE(testContentBody) { Frame f(42, AMQContentBody("foobar")); AMQBody* body=f.getBody(); BOOST_CHECK(dynamic_cast(body)); @@ -43,7 +43,7 @@ BOOST_AUTO_TEST_CASE(testContentBody) { BOOST_CHECK_EQUAL(content->getData(), "foobar"); } -BOOST_AUTO_TEST_CASE(testMethodBody) { +QPID_AUTO_TEST_CASE(testMethodBody) { FieldTable args; args.setString("foo", "bar"); Frame f( @@ -62,7 +62,7 @@ BOOST_AUTO_TEST_CASE(testMethodBody) { BOOST_CHECK_EQUAL(lexical_cast(*f.getBody()), lexical_cast(*g.getBody())); } -BOOST_AUTO_TEST_CASE(testLoop) { +QPID_AUTO_TEST_CASE(testLoop) { // Run in a loop so heap profiler can spot any allocations. Buffer b(1024); for (int i = 0; i < 100; ++i) { -- cgit v1.2.1 From 071fff099bd18bbbadbb90e344052ef877cefc32 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Tue, 7 Oct 2008 17:24:24 +0000 Subject: Rename size() to encodedSize() for encoded types to allow std collection interfaces for types like FieldTable and Array. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@702551 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/tests/Frame.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'qpid/cpp/src/tests/Frame.cpp') diff --git a/qpid/cpp/src/tests/Frame.cpp b/qpid/cpp/src/tests/Frame.cpp index 9ee3848b7b..11905911fa 100644 --- a/qpid/cpp/src/tests/Frame.cpp +++ b/qpid/cpp/src/tests/Frame.cpp @@ -33,7 +33,7 @@ QPID_AUTO_TEST_CASE(testContentBody) { Frame f(42, AMQContentBody("foobar")); AMQBody* body=f.getBody(); BOOST_CHECK(dynamic_cast(body)); - Buffer b(f.size()); + Buffer b(f.encodedSize(); f.encode(b); b.flip(); Frame g; @@ -50,7 +50,7 @@ QPID_AUTO_TEST_CASE(testMethodBody) { 42, QueueDeclareBody(ProtocolVersion(), 1, "q", "altex", true, false, true, false, true, args)); BOOST_CHECK_EQUAL(f.getChannel(), 42); - Buffer b(f.size()); + Buffer b(f.encodedSize(); f.encode(b); b.flip(); Frame g; -- cgit v1.2.1 From ffd20ee19a5fd027e0007c27a12dd402dbeca4f8 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Tue, 14 Jul 2009 14:32:39 +0000 Subject: Add directory to #include git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@793909 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/tests/Frame.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'qpid/cpp/src/tests/Frame.cpp') diff --git a/qpid/cpp/src/tests/Frame.cpp b/qpid/cpp/src/tests/Frame.cpp index 11905911fa..15fbaf137b 100644 --- a/qpid/cpp/src/tests/Frame.cpp +++ b/qpid/cpp/src/tests/Frame.cpp @@ -21,7 +21,7 @@ #include "qpid/framing/Frame.h" #include -#include "unit_test.h" +#include "tests/unit_test.h" QPID_AUTO_TEST_SUITE(FrameTestSuite) -- cgit v1.2.1 From 795b3bb9e5c033abf33635119694e21e7143fc0a Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Tue, 14 Jul 2009 14:41:22 +0000 Subject: Remove incorrect directory from #include git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@793912 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/tests/Frame.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'qpid/cpp/src/tests/Frame.cpp') diff --git a/qpid/cpp/src/tests/Frame.cpp b/qpid/cpp/src/tests/Frame.cpp index 15fbaf137b..11905911fa 100644 --- a/qpid/cpp/src/tests/Frame.cpp +++ b/qpid/cpp/src/tests/Frame.cpp @@ -21,7 +21,7 @@ #include "qpid/framing/Frame.h" #include -#include "tests/unit_test.h" +#include "unit_test.h" QPID_AUTO_TEST_SUITE(FrameTestSuite) -- cgit v1.2.1 From 9259c46ecb8c5f3e98441080a26914bdea59bffe Mon Sep 17 00:00:00 2001 From: Andrew Stitcher Date: Wed, 9 Sep 2009 19:46:56 +0000 Subject: Tidied up namespace usage Miscelleneous whitespace fixes git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@813094 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/tests/Frame.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'qpid/cpp/src/tests/Frame.cpp') diff --git a/qpid/cpp/src/tests/Frame.cpp b/qpid/cpp/src/tests/Frame.cpp index 11905911fa..1270eabba3 100644 --- a/qpid/cpp/src/tests/Frame.cpp +++ b/qpid/cpp/src/tests/Frame.cpp @@ -7,9 +7,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 @@ -23,6 +23,9 @@ #include #include "unit_test.h" +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(FrameTestSuite) using namespace std; @@ -78,3 +81,5 @@ QPID_AUTO_TEST_CASE(testLoop) { } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests -- cgit v1.2.1