diff options
author | Alan Conway <aconway@apache.org> | 2009-01-22 20:29:12 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2009-01-22 20:29:12 +0000 |
commit | 3e26ae40844c3f9e612a0e3a2f98ba1576ee520c (patch) | |
tree | 42082fbc46a2f154995f7dc8f82f25be6b102377 /qpid/cpp/src/tests/Blob.cpp | |
parent | 9188e54f7e99991caad89f30ea488918efffc384 (diff) | |
download | qpid-python-3e26ae40844c3f9e612a0e3a2f98ba1576ee520c.tar.gz |
Removed BodyHolder: minor performance improvement, opens the way for more efficient memory management.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@736783 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/src/tests/Blob.cpp')
-rw-r--r-- | qpid/cpp/src/tests/Blob.cpp | 128 |
1 files changed, 0 insertions, 128 deletions
diff --git a/qpid/cpp/src/tests/Blob.cpp b/qpid/cpp/src/tests/Blob.cpp index c40e43b96e..e69de29bb2 100644 --- a/qpid/cpp/src/tests/Blob.cpp +++ b/qpid/cpp/src/tests/Blob.cpp @@ -1,128 +0,0 @@ -/* - * 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/Blob.h" - -#include "unit_test.h" - -QPID_AUTO_TEST_SUITE(BlobTestSuite) - -using namespace std; -using namespace qpid::framing; - -struct Base { - int id; - int magic; - - Base(int n) : id(n), magic(42) {} - Base(const Base& c) : id(c.id), magic(42) {} - ~Base() { BOOST_CHECK_EQUAL(42, magic); } // Detect random data. -}; - -template <class T> struct Count : public Base { - static int instances; - bool destroyed; - - Count(int n) : Base(n), destroyed(false) { ++instances; } - Count(const Count& c) : Base(c), destroyed(false) { ++instances; } - ~Count() { - BOOST_CHECK(!destroyed); // Detect double-destructor - destroyed=true; - BOOST_CHECK(--instances >= 0); - } -}; - -template <class T> int Count<T>::instances = 0; - -struct Foo : public Count<Foo> { Foo(int n) : Count<Foo>(n) {}; }; -struct Bar : public Count<Bar> { Bar(int n) : Count<Bar>(n) {}; }; - -typedef Blob<sizeof(Foo), Base> TestBlob ; - -QPID_AUTO_TEST_CASE(testBlobCtor) { - { - TestBlob empty; - BOOST_CHECK(empty.empty()); - BOOST_CHECK(empty.get() == 0); - - TestBlob empty2(empty); - BOOST_CHECK(empty2.empty()); - - TestBlob foo(in_place<Foo>(1)); - BOOST_CHECK(!foo.empty()); - BOOST_CHECK_EQUAL(1, foo.get()->id); - BOOST_CHECK_EQUAL(1, Foo::instances); - - TestBlob foo2(foo); - BOOST_CHECK(!foo2.empty()); - BOOST_CHECK_EQUAL(1, foo2.get()->id); - BOOST_CHECK_EQUAL(2, Foo::instances); - } - - BOOST_CHECK_EQUAL(0, Foo::instances); - BOOST_CHECK_EQUAL(0, Bar::instances); -} - - -QPID_AUTO_TEST_CASE(testAssign) { - { - TestBlob b; - b = Foo(2); - BOOST_CHECK_EQUAL(2, b.get()->id); - BOOST_CHECK_EQUAL(1, Foo::instances); - - TestBlob b2(b); - BOOST_CHECK_EQUAL(2, b.get()->id); - BOOST_CHECK_EQUAL(2, Foo::instances); - - b2 = Bar(3); - BOOST_CHECK_EQUAL(3, b2.get()->id); - BOOST_CHECK_EQUAL(1, Foo::instances); - BOOST_CHECK_EQUAL(1, Bar::instances); - - b2 = in_place<Foo>(4); - BOOST_CHECK_EQUAL(4, b2.get()->id); - BOOST_CHECK_EQUAL(2, Foo::instances); - BOOST_CHECK_EQUAL(0, Bar::instances); - - b2.clear(); - BOOST_CHECK(b2.empty()); - BOOST_CHECK_EQUAL(1, Foo::instances); - } - BOOST_CHECK_EQUAL(0, Foo::instances); - BOOST_CHECK_EQUAL(0, Bar::instances); -} - - -QPID_AUTO_TEST_CASE(testClear) { - TestBlob b(in_place<Foo>(5)); - TestBlob c(b); - BOOST_CHECK(!c.empty()); - BOOST_CHECK(!b.empty()); - BOOST_CHECK_EQUAL(2, Foo::instances); - - c.clear(); - BOOST_CHECK(c.empty()); - BOOST_CHECK_EQUAL(1, Foo::instances); - - b.clear(); - BOOST_CHECK(b.empty()); - BOOST_CHECK_EQUAL(0, Foo::instances); -} - -QPID_AUTO_TEST_SUITE_END() |