summaryrefslogtreecommitdiff
path: root/o3tl/qa
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2012-07-11 13:35:21 +0200
committerMichael Stahl <mstahl@redhat.com>2012-07-12 14:12:32 +0200
commit8b98a0c3a117ff3deb0f7b30d6cfd13906296c4b (patch)
treea42a50660a42304707a54f30e02d9cc790f84f3b /o3tl/qa
parent46a02d0ebf0babfa4027483ad7dc3958b725e698 (diff)
Create a template container class for sorted vector
We use this kind of container a lot, so creating a single implementation makes sense. Change-Id: I67ead58becd7d2a287812145c11d93ab1c593c0f
Diffstat (limited to 'o3tl/qa')
-rw-r--r--o3tl/qa/test-sorted_vector.cxx80
1 files changed, 80 insertions, 0 deletions
diff --git a/o3tl/qa/test-sorted_vector.cxx b/o3tl/qa/test-sorted_vector.cxx
new file mode 100644
index 000000000000..11732bd5f875
--- /dev/null
+++ b/o3tl/qa/test-sorted_vector.cxx
@@ -0,0 +1,80 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "cppunit/TestAssert.h"
+#include "cppunit/TestFixture.h"
+#include "cppunit/extensions/HelperMacros.h"
+
+#include <o3tl/sorted_vector.hxx>
+
+using namespace ::o3tl;
+
+
+// helper class
+class SwContent
+{
+public:
+ int x;
+
+ SwContent(int x_) : x(x_) {}
+
+ bool operator<( const SwContent &rCmp) const
+ {
+ return x < rCmp.x;
+ }
+};
+
+class sorted_vector_test : public CppUnit::TestFixture
+{
+public:
+ void testBasics()
+ {
+ o3tl::sorted_vector<SwContent*, o3tl::less_ptr_to<SwContent> > aVec;
+ SwContent *p1 = new SwContent(1);
+ SwContent *p2 = new SwContent(2);
+ SwContent *p3 = new SwContent(3);
+ SwContent *p4 = new SwContent(4);
+
+ CPPUNIT_ASSERT( aVec.insert(p3).second );
+ CPPUNIT_ASSERT( aVec.insert(p1).second );
+ CPPUNIT_ASSERT( !aVec.insert(p3).second );
+
+ CPPUNIT_ASSERT( aVec.size() == 2 );
+
+ CPPUNIT_ASSERT( aVec[0] == p1 );
+ CPPUNIT_ASSERT( aVec[1] == p3 );
+
+ CPPUNIT_ASSERT( aVec.find(p1) != aVec.end() );
+ CPPUNIT_ASSERT( aVec.find(p1) - aVec.begin() == 0 );
+ CPPUNIT_ASSERT( aVec.find(p3) != aVec.end() );
+ CPPUNIT_ASSERT( aVec.find(p3) - aVec.begin() == 1 );
+ CPPUNIT_ASSERT( aVec.find(p2) == aVec.end() );
+ CPPUNIT_ASSERT( aVec.find(p4) == aVec.end() );
+
+ CPPUNIT_ASSERT( aVec.erase(p1) == 1 );
+ CPPUNIT_ASSERT( aVec.size() == 1 );
+ CPPUNIT_ASSERT( aVec.erase(p2) == 0 );
+
+ aVec.DeleteAndDestroyAll();
+ }
+
+
+ // Change the following lines only, if you add, remove or rename
+ // member functions of the current class,
+ // because these macros are need by auto register mechanism.
+
+ CPPUNIT_TEST_SUITE(sorted_vector_test);
+ CPPUNIT_TEST(testBasics);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+// -----------------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION(sorted_vector_test);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */