diff options
author | Alan Conway <aconway@apache.org> | 2007-08-20 17:18:52 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2007-08-20 17:18:52 +0000 |
commit | 16db1cb57501363fea65127cb5eee797399305ac (patch) | |
tree | 0cb547b44e87d5d7eaafb9923b28fe6806700990 /cpp/src/tests | |
parent | 6cc9fa34792b640df3283f4aa4021237f2ee4ae9 (diff) | |
download | qpid-python-16db1cb57501363fea65127cb5eee797399305ac.tar.gz |
Fixed Blob bug causing test crashes/hangs.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@567755 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/tests')
-rwxr-xr-x | cpp/src/tests/Blob | bin | 0 -> 223166 bytes | |||
-rw-r--r-- | cpp/src/tests/Blob.cpp | 125 | ||||
-rw-r--r-- | cpp/src/tests/Makefile.am | 13 |
3 files changed, 132 insertions, 6 deletions
diff --git a/cpp/src/tests/Blob b/cpp/src/tests/Blob Binary files differnew file mode 100755 index 0000000000..05e67dc01f --- /dev/null +++ b/cpp/src/tests/Blob diff --git a/cpp/src/tests/Blob.cpp b/cpp/src/tests/Blob.cpp new file mode 100644 index 0000000000..96861a3670 --- /dev/null +++ b/cpp/src/tests/Blob.cpp @@ -0,0 +1,125 @@ +/* + * + * 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/framing/Blob.h" + +#define BOOST_AUTO_TEST_MAIN +#include <boost/test/auto_unit_test.hpp> + +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 ; + +BOOST_AUTO_TEST_CASE(testCtor) { + { + 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); +} + + +BOOST_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.construct(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); +} + + +BOOST_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); +} diff --git a/cpp/src/tests/Makefile.am b/cpp/src/tests/Makefile.am index c9a08e6075..db9da392ea 100644 --- a/cpp/src/tests/Makefile.am +++ b/cpp/src/tests/Makefile.am @@ -19,6 +19,11 @@ CLEANFILES= # # Unit test programs. # +TESTS+=Blob +check_PROGRAMS+=Blob +Blob_SOURCES=Blob.cpp ../qpid/framing/Blob.cpp +Blob_LDADD=-lboost_unit_test_framework + TESTS+=logging check_PROGRAMS+=logging logging_SOURCES=logging.cpp test_tools.h @@ -120,13 +125,14 @@ check_PROGRAMS += $(testprogs) interop_runner TESTS_ENVIRONMENT = VALGRIND=$(VALGRIND) srcdir=$(srcdir) $(srcdir)/run_test -system_tests = client_test exception_test quick_topictest +system_tests = client_test exception_test quick_perftest quick_topictest TESTS += run-unit-tests start_broker $(system_tests) python_tests stop_broker EXTRA_DIST += \ test_env run_test vg_check \ run-unit-tests start_broker python_tests stop_broker \ quick_topictest \ + quick_perftest \ topictest \ .valgrind.supp-default \ .valgrindrc-default \ @@ -172,11 +178,6 @@ all-am: .valgrind.supp .valgrindrc .valgrind.supp: .valgrind.supp-default cp $^ $@ -# Tell GNU make not to build targets in this directory in parallel. -# This is necessary because with two or more identical and simultaneous -# ltmain invocations, one may corrupt the temporaries of the other. -.NOTPARALLEL: - CLEANFILES+=valgrind.out *.log *.vglog .valgrindrc .valgrind.supp dummy_test $(unit_wrappers) MAINTAINERCLEANFILES=gen.mk |