summaryrefslogtreecommitdiff
path: root/qpid/cpp/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'qpid/cpp/src/tests')
-rw-r--r--qpid/cpp/src/tests/InlineAllocator.cpp63
-rw-r--r--qpid/cpp/src/tests/InlineVector.cpp56
-rw-r--r--qpid/cpp/src/tests/Makefile.am5
-rw-r--r--qpid/cpp/src/tests/RangeSet.cpp117
4 files changed, 227 insertions, 14 deletions
diff --git a/qpid/cpp/src/tests/InlineAllocator.cpp b/qpid/cpp/src/tests/InlineAllocator.cpp
new file mode 100644
index 0000000000..fe6eaefaf4
--- /dev/null
+++ b/qpid/cpp/src/tests/InlineAllocator.cpp
@@ -0,0 +1,63 @@
+/*
+ *
+ * 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/InlineAllocator.h"
+#include "unit_test.h"
+
+QPID_AUTO_TEST_SUITE(InlineAllocatorTestSuite)
+
+using namespace qpid;
+using namespace std;
+
+QPID_AUTO_TEST_CASE(testAllocate) {
+ InlineAllocator<std::allocator<char>, 2> alloc;
+
+ char* p = alloc.allocate(1);
+ BOOST_CHECK(p == (char*)&alloc);
+ alloc.deallocate(p,1);
+
+ p = alloc.allocate(2);
+ BOOST_CHECK(p == (char*)&alloc);
+ alloc.deallocate(p,2);
+
+ p = alloc.allocate(3);
+ BOOST_CHECK(p != (char*)&alloc);
+ alloc.deallocate(p,3);
+}
+
+QPID_AUTO_TEST_CASE(testAllocateFull) {
+ InlineAllocator<std::allocator<char>, 1> alloc;
+
+ char* p = alloc.allocate(1);
+ BOOST_CHECK(p == (char*)&alloc);
+
+ char* q = alloc.allocate(1);
+ BOOST_CHECK(q != (char*)&alloc);
+
+ alloc.deallocate(p,1);
+ p = alloc.allocate(1);
+ BOOST_CHECK(p == (char*)&alloc);
+
+ alloc.deallocate(p,1);
+ alloc.deallocate(q,1);
+}
+
+QPID_AUTO_TEST_SUITE_END()
diff --git a/qpid/cpp/src/tests/InlineVector.cpp b/qpid/cpp/src/tests/InlineVector.cpp
index 5f1a08759f..7add920cb2 100644
--- a/qpid/cpp/src/tests/InlineVector.cpp
+++ b/qpid/cpp/src/tests/InlineVector.cpp
@@ -66,24 +66,54 @@ QPID_AUTO_TEST_CASE(testCtor) {
}
QPID_AUTO_TEST_CASE(testInsert) {
- Vec v;
- v.push_back(1);
- BOOST_CHECK_EQUAL(v.size(), 1u);
- BOOST_CHECK_EQUAL(v.back(), 1);
- BOOST_CHECK(isInline(v));
+ {
+ Vec v;
+ v.push_back(1);
+ BOOST_CHECK_EQUAL(v.size(), 1u);
+ BOOST_CHECK_EQUAL(v.back(), 1);
+ BOOST_CHECK(isInline(v));
- v.insert(v.begin(), 2);
- BOOST_CHECK_EQUAL(v.size(), 2u);
- BOOST_CHECK_EQUAL(v.back(), 1);
- BOOST_CHECK(isInline(v));
+ v.insert(v.begin(), 2);
+ BOOST_CHECK_EQUAL(v.size(), 2u);
+ BOOST_CHECK_EQUAL(v.back(), 1);
+ BOOST_CHECK(isInline(v));
- v.push_back(3);
- BOOST_CHECK(isInline(v));
+ v.push_back(3);
+ BOOST_CHECK(isInline(v));
- v.push_back(4);
- BOOST_CHECK_EQUAL(v.size(), 4u);
+ v.push_back(4);
+
+ BOOST_CHECK(!isInline(v));
+ }
+ {
+ Vec v(3,42);
+ v.insert(v.begin(), 9);
+ BOOST_CHECK_EQUAL(v.size(), 4u);
+ BOOST_CHECK(!isInline(v));
+ }
+ {
+ Vec v(3,42);
+ v.insert(v.begin()+1, 9);
+ BOOST_CHECK(!isInline(v));
+ BOOST_CHECK_EQUAL(v.size(), 4u);
+ }
+}
+
+QPID_AUTO_TEST_CASE(testAssign) {
+ Vec v(3,42);
+ Vec u;
+ u = v;
+ BOOST_CHECK(isInline(u));
+ u.push_back(4);
+ BOOST_CHECK(!isInline(u));
+ v = u;
BOOST_CHECK(!isInline(v));
}
+QPID_AUTO_TEST_CASE(testResize) {
+ Vec v;
+ v.resize(5);
+ BOOST_CHECK(!isInline(v));
+}
QPID_AUTO_TEST_SUITE_END()
diff --git a/qpid/cpp/src/tests/Makefile.am b/qpid/cpp/src/tests/Makefile.am
index b7fe79f56c..a6750a427a 100644
--- a/qpid/cpp/src/tests/Makefile.am
+++ b/qpid/cpp/src/tests/Makefile.am
@@ -36,6 +36,7 @@ unit_test_SOURCES= unit_test.cpp unit_test.h \
SessionState.cpp Blob.cpp logging.cpp \
Url.cpp Uuid.cpp \
Shlib.cpp FieldValue.cpp FieldTable.cpp Array.cpp \
+ InlineAllocator.cpp \
InlineVector.cpp \
ISList.cpp IList.cpp \
ClientSessionTest.cpp \
@@ -45,7 +46,9 @@ unit_test_SOURCES= unit_test.cpp unit_test.h \
amqp_0_10/apply.cpp \
IncompleteMessageList.cpp \
amqp_0_10/Map.cpp \
- amqp_0_10/handlers.cpp
+ amqp_0_10/handlers.cpp \
+ RangeSet.cpp
+
check_LTLIBRARIES += libshlibtest.la
libshlibtest_la_LDFLAGS = -module -rpath $(abs_builddir)
diff --git a/qpid/cpp/src/tests/RangeSet.cpp b/qpid/cpp/src/tests/RangeSet.cpp
new file mode 100644
index 0000000000..bc125ed4e2
--- /dev/null
+++ b/qpid/cpp/src/tests/RangeSet.cpp
@@ -0,0 +1,117 @@
+/*
+ *
+ * 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 "unit_test.h"
+#include "test_tools.h"
+#include "qpid/RangeSet.h"
+
+using namespace std;
+using namespace qpid;
+
+QPID_AUTO_TEST_SUITE(RangeSetTestSuite)
+
+typedef qpid::Range<int> Range;
+typedef qpid::RangeSet<int> RangeSet;
+
+QPID_AUTO_TEST_CASE(testEmptyRange) {
+ Range r;
+ BOOST_CHECK(r.empty());
+ BOOST_CHECK(!r.contains(0));
+ // BOOST_CHECK(r.contiguous(0));
+}
+
+QPID_AUTO_TEST_CASE(testRangeSetAddPoint) {
+ RangeSet r;
+ BOOST_CHECK(r.empty());
+ r += 3;
+ BOOST_CHECK_MESSAGE(r.contains(3), r);
+ BOOST_CHECK_MESSAGE(r.contains(Range(3,4)), r);
+ BOOST_CHECK(!r.empty());
+ r += 5;
+ BOOST_CHECK_MESSAGE(r.contains(5), r);
+ BOOST_CHECK_MESSAGE(r.contains(Range(5,6)), r);
+ BOOST_CHECK_MESSAGE(!r.contains(Range(3,6)), r);
+ r += 4;
+ BOOST_CHECK_MESSAGE(r.contains(Range(3,6)), r);
+}
+
+QPID_AUTO_TEST_CASE(testRangeSetAddRange) {
+ RangeSet r;
+ r += Range(0,3);
+ BOOST_CHECK(r.contains(Range(0,3)));
+ r += Range(4,6);
+ BOOST_CHECK_MESSAGE(r.contains(Range(4,6)), r);
+ r += 3;
+ BOOST_CHECK_MESSAGE(r.contains(Range(0,6)), r);
+ BOOST_CHECK(r.front() == 0);
+ BOOST_CHECK(r.back() == 6);
+}
+
+QPID_AUTO_TEST_CASE(testRangeSetIterate) {
+ RangeSet r;
+ (((r += 1) += 10) += Range(4,7)) += 2;
+ BOOST_MESSAGE(r);
+ std::vector<int> actual;
+ std::copy(r.begin(), r.end(), std::back_inserter(actual));
+ std::vector<int> expect = boost::assign::list_of(1)(2)(4)(5)(6)(10);
+ BOOST_CHECK_EQUAL(expect, actual);
+}
+
+QPID_AUTO_TEST_CASE(testRangeSetRemove) {
+ BOOST_CHECK_EQUAL(RangeSet(0,5)-3, RangeSet(0,3)+Range(4,5));
+ BOOST_CHECK_EQUAL(RangeSet(1,5)-5, RangeSet(1,5));
+ BOOST_CHECK_EQUAL(RangeSet(1,5)-0, RangeSet(1,5));
+
+ RangeSet r(RangeSet(0,5)+Range(10,15)+Range(20,25));
+
+ BOOST_CHECK_EQUAL(r-Range(0,5), RangeSet(10,15)+Range(20,25));
+ BOOST_CHECK_EQUAL(r-Range(10,15), RangeSet(0,5)+Range(20,25));
+ BOOST_CHECK_EQUAL(r-Range(20,25), RangeSet(0,5)+Range(10,15));
+
+ BOOST_CHECK_EQUAL(r-Range(-5, 30), RangeSet());
+
+ BOOST_CHECK_EQUAL(r-Range(-5, 7), RangeSet(10,15)+Range(20,25));
+ BOOST_CHECK_EQUAL(r-Range(8,19), RangeSet(0,5)+Range(20,25));
+ BOOST_CHECK_EQUAL(r-Range(17,30), RangeSet(0,5)+Range(10,15));
+
+ BOOST_CHECK_EQUAL(r-Range(-5, 5), RangeSet(10,15)+Range(20,25));
+ BOOST_CHECK_EQUAL(r-Range(10,19), RangeSet(0,5)+Range(20,25));
+ BOOST_CHECK_EQUAL(r-Range(18,25), RangeSet(0,5)+Range(10,15));
+
+ BOOST_CHECK_EQUAL(r-Range(-3, 3), RangeSet(3,5)+Range(10,15)+Range(20,25));
+ BOOST_CHECK_EQUAL(r-Range(3, 7), RangeSet(0,2)+Range(10,15)+Range(20,25));
+ BOOST_CHECK_EQUAL(r-Range(3, 12), RangeSet(0,3)+Range(12,15)+Range(20,25));
+ BOOST_CHECK_EQUAL(r-Range(3, 22), RangeSet(12,15)+Range(22,25));
+ BOOST_CHECK_EQUAL(r-Range(12, 22), RangeSet(0,5)+Range(10,11)+Range(22,25));
+}
+
+QPID_AUTO_TEST_CASE(testRangeContaining) {
+ RangeSet r;
+ (((r += 1) += Range(3,5)) += 7);
+ BOOST_CHECK_EQUAL(r.rangeContaining(0), Range(0,0));
+ BOOST_CHECK_EQUAL(r.rangeContaining(1), Range(1,2));
+ BOOST_CHECK_EQUAL(r.rangeContaining(2), Range(2,2));
+ BOOST_CHECK_EQUAL(r.rangeContaining(3), Range(3,5));
+ BOOST_CHECK_EQUAL(r.rangeContaining(4), Range(3,5));
+ BOOST_CHECK_EQUAL(r.rangeContaining(5), Range(5,5));
+ BOOST_CHECK_EQUAL(r.rangeContaining(6), Range(6,6));
+ BOOST_CHECK_EQUAL(r.rangeContaining(7), Range(7,8));
+}
+
+QPID_AUTO_TEST_SUITE_END()