summaryrefslogtreecommitdiff
path: root/o3tl
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-09-19 08:55:09 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-09-19 10:33:28 +0200
commit0bc059f2a893d812e29d6a72d4f988428b5ea346 (patch)
tree62ff7c996c784b563eb840e18002da4ce985cd0d /o3tl
parentae3150b1e1863e854224c2e41c7e50991f945dad (diff)
implement find(T*) for o3tl::sorted_vector when it contains unique_ptr<T>
and add some unit tests Change-Id: I9a01c9fa2fbbf3a553663a980ee6e958f9819645 Reviewed-on: https://gerrit.libreoffice.org/60737 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'o3tl')
-rw-r--r--o3tl/qa/test-sorted_vector.cxx48
1 files changed, 48 insertions, 0 deletions
diff --git a/o3tl/qa/test-sorted_vector.cxx b/o3tl/qa/test-sorted_vector.cxx
index 3de3f005f6c6..dd622e0cea0d 100644
--- a/o3tl/qa/test-sorted_vector.cxx
+++ b/o3tl/qa/test-sorted_vector.cxx
@@ -12,7 +12,9 @@
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
+#include <o3tl/make_unique.hxx>
#include <o3tl/sorted_vector.hxx>
+#include <rtl/ustring.hxx>
using namespace ::o3tl;
@@ -250,6 +252,50 @@ public:
CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(0), aVec.size() );
}
+ void testUniquePtr1()
+ {
+ o3tl::sorted_vector<std::unique_ptr<OUString>, o3tl::less_uniqueptr_to<OUString>> aVec;
+
+ auto str_c = aVec.insert(o3tl::make_unique<OUString>("c")).first->get();
+ auto str_b1 = aVec.insert(o3tl::make_unique<OUString>("b")).first->get();
+ CPPUNIT_ASSERT(!aVec.insert(o3tl::make_unique<OUString>("b")).second);
+ aVec.insert(o3tl::make_unique<OUString>("a"));
+ CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(3), aVec.size() );
+ CPPUNIT_ASSERT_EQUAL( OUString("a"), *aVec[0] );
+ CPPUNIT_ASSERT_EQUAL( OUString("b"), *aVec[1] );
+ CPPUNIT_ASSERT_EQUAL( OUString("c"), *aVec[2] );
+
+ CPPUNIT_ASSERT( aVec.find(str_c) != aVec.end() );
+ CPPUNIT_ASSERT( aVec.find(str_b1) != aVec.end() );
+
+ OUString tmp("b");
+ CPPUNIT_ASSERT( aVec.find(&tmp) != aVec.end() );
+ OUString tmp2("z");
+ CPPUNIT_ASSERT( bool(aVec.find(&tmp2) == aVec.end()) );
+ }
+
+ void testUniquePtr2()
+ {
+ o3tl::sorted_vector<std::unique_ptr<OUString>, o3tl::less_uniqueptr_to<OUString>,
+ o3tl::find_partialorder_ptrequals> aVec;
+
+ auto str_c = aVec.insert(o3tl::make_unique<OUString>("c")).first->get();
+ auto str_b1 = aVec.insert(o3tl::make_unique<OUString>("b")).first->get();
+ auto str_b2 = aVec.insert(o3tl::make_unique<OUString>("b")).first->get();
+ aVec.insert(o3tl::make_unique<OUString>("a"));
+ CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(4), aVec.size() );
+ CPPUNIT_ASSERT_EQUAL( OUString("a"), *aVec[0] );
+ CPPUNIT_ASSERT_EQUAL( OUString("b"), *aVec[1] );
+ CPPUNIT_ASSERT_EQUAL( OUString("b"), *aVec[2] );
+ CPPUNIT_ASSERT_EQUAL( OUString("c"), *aVec[3] );
+
+ CPPUNIT_ASSERT( aVec.find(str_c) != aVec.end() );
+ CPPUNIT_ASSERT( aVec.find(str_b1) != aVec.end() );
+ CPPUNIT_ASSERT( aVec.find(str_b2) != aVec.end() );
+
+ OUString tmp2("z");
+ CPPUNIT_ASSERT( bool(aVec.find(&tmp2) == aVec.end()) );
+ }
// Change the following lines only, if you add, remove or rename
// member functions of the current class,
@@ -262,6 +308,8 @@ public:
CPPUNIT_TEST(testLowerBound);
CPPUNIT_TEST(testBasics_FindPtr);
CPPUNIT_TEST(testErase_FindPtr);
+ CPPUNIT_TEST(testUniquePtr1);
+ CPPUNIT_TEST(testUniquePtr2);
CPPUNIT_TEST_SUITE_END();
};