summaryrefslogtreecommitdiff
path: root/o3tl/qa
diff options
context:
space:
mode:
Diffstat (limited to 'o3tl/qa')
-rw-r--r--o3tl/qa/cow_wrapper_clients.cxx180
-rw-r--r--o3tl/qa/cow_wrapper_clients.hxx128
-rw-r--r--o3tl/qa/export.map34
-rw-r--r--o3tl/qa/makefile.mk77
-rw-r--r--o3tl/qa/test-cow_wrapper.cxx127
-rw-r--r--o3tl/qa/test-heap_ptr.cxx165
-rw-r--r--o3tl/qa/test-range.cxx234
-rw-r--r--o3tl/qa/test-vector_pool.cxx69
8 files changed, 1014 insertions, 0 deletions
diff --git a/o3tl/qa/cow_wrapper_clients.cxx b/o3tl/qa/cow_wrapper_clients.cxx
new file mode 100644
index 000000000000..8c8c3eac04e1
--- /dev/null
+++ b/o3tl/qa/cow_wrapper_clients.cxx
@@ -0,0 +1,180 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "cow_wrapper_clients.hxx"
+
+namespace o3tltests {
+
+class cow_wrapper_client2_impl
+{
+public:
+ cow_wrapper_client2_impl() : mnValue(0) {}
+ explicit cow_wrapper_client2_impl( int nVal ) : mnValue(nVal) {}
+ void setValue( int nVal ) { mnValue = nVal; }
+ int getValue() const { return mnValue; }
+
+ bool operator==( const cow_wrapper_client2_impl& rRHS ) const { return mnValue == rRHS.mnValue; }
+ bool operator!=( const cow_wrapper_client2_impl& rRHS ) const { return mnValue != rRHS.mnValue; }
+ bool operator<( const cow_wrapper_client2_impl& rRHS ) const { return mnValue < rRHS.mnValue; }
+
+private:
+ int mnValue;
+};
+
+cow_wrapper_client2::cow_wrapper_client2() : maImpl()
+{
+}
+
+cow_wrapper_client2::cow_wrapper_client2( int nVal ) :
+ maImpl( cow_wrapper_client2_impl(nVal) )
+{
+}
+
+cow_wrapper_client2::~cow_wrapper_client2()
+{
+}
+
+cow_wrapper_client2::cow_wrapper_client2( const cow_wrapper_client2& rSrc ) :
+ maImpl(rSrc.maImpl)
+{
+}
+
+cow_wrapper_client2& cow_wrapper_client2::operator=( const cow_wrapper_client2& rSrc )
+{
+ maImpl = rSrc.maImpl;
+
+ return *this;
+}
+
+void cow_wrapper_client2::modify( int nVal )
+{
+ maImpl->setValue( nVal );
+}
+
+int cow_wrapper_client2::queryUnmodified() const
+{
+ return maImpl->getValue();
+}
+
+void cow_wrapper_client2::makeUnique()
+{
+ maImpl.make_unique();
+}
+bool cow_wrapper_client2::is_unique() const
+{
+ return maImpl.is_unique();
+}
+oslInterlockedCount cow_wrapper_client2::use_count() const
+{
+ return maImpl.use_count();
+}
+void cow_wrapper_client2::swap( cow_wrapper_client2& r )
+{
+ o3tl::swap(maImpl, r.maImpl);
+}
+
+bool cow_wrapper_client2::operator==( const cow_wrapper_client2& rRHS ) const
+{
+ return maImpl == rRHS.maImpl;
+}
+bool cow_wrapper_client2::operator!=( const cow_wrapper_client2& rRHS ) const
+{
+ return maImpl != rRHS.maImpl;
+}
+bool cow_wrapper_client2::operator<( const cow_wrapper_client2& rRHS ) const
+{
+ return maImpl < rRHS.maImpl;
+}
+
+// ---------------------------------------------------------------------------
+
+cow_wrapper_client3::cow_wrapper_client3() : maImpl()
+{
+}
+
+cow_wrapper_client3::cow_wrapper_client3( int nVal ) :
+ maImpl( cow_wrapper_client2_impl(nVal) )
+{
+}
+
+cow_wrapper_client3::~cow_wrapper_client3()
+{
+}
+
+cow_wrapper_client3::cow_wrapper_client3( const cow_wrapper_client3& rSrc ) :
+ maImpl(rSrc.maImpl)
+{
+}
+
+cow_wrapper_client3& cow_wrapper_client3::operator=( const cow_wrapper_client3& rSrc )
+{
+ maImpl = rSrc.maImpl;
+
+ return *this;
+}
+
+void cow_wrapper_client3::modify( int nVal )
+{
+ maImpl->setValue( nVal );
+}
+
+int cow_wrapper_client3::queryUnmodified() const
+{
+ return maImpl->getValue();
+}
+
+void cow_wrapper_client3::makeUnique()
+{
+ maImpl.make_unique();
+}
+bool cow_wrapper_client3::is_unique() const
+{
+ return maImpl.is_unique();
+}
+oslInterlockedCount cow_wrapper_client3::use_count() const
+{
+ return maImpl.use_count();
+}
+void cow_wrapper_client3::swap( cow_wrapper_client3& r )
+{
+ o3tl::swap(maImpl, r.maImpl);
+}
+
+bool cow_wrapper_client3::operator==( const cow_wrapper_client3& rRHS ) const
+{
+ return maImpl == rRHS.maImpl;
+}
+bool cow_wrapper_client3::operator!=( const cow_wrapper_client3& rRHS ) const
+{
+ return maImpl != rRHS.maImpl;
+}
+bool cow_wrapper_client3::operator<( const cow_wrapper_client3& rRHS ) const
+{
+ return maImpl < rRHS.maImpl;
+}
+
+} // namespace o3tltests
diff --git a/o3tl/qa/cow_wrapper_clients.hxx b/o3tl/qa/cow_wrapper_clients.hxx
new file mode 100644
index 000000000000..26e5d1adf2e3
--- /dev/null
+++ b/o3tl/qa/cow_wrapper_clients.hxx
@@ -0,0 +1,128 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef INCLUDED_COW_WRAPPER_CLIENTS_HXX
+#define INCLUDED_COW_WRAPPER_CLIENTS_HXX
+
+#include "o3tl/cow_wrapper.hxx"
+
+/* Definition of Cow_Wrapper_Clients classes */
+
+namespace o3tltests {
+
+/** This is a header and a separate compilation unit on purpose -
+ cow_wrapper needs destructor, copy constructor and assignment
+ operator to be outline, when pimpl idiom is used
+ */
+
+/// test non-opaque impl type
+class cow_wrapper_client1
+{
+public:
+ cow_wrapper_client1() : maImpl() {}
+ explicit cow_wrapper_client1( int nVal ) : maImpl(nVal) {}
+
+ void modify( int nVal ) { *maImpl = nVal; }
+ int queryUnmodified() const { return *maImpl; }
+
+ void makeUnique() { maImpl.make_unique(); }
+ bool is_unique() const { return maImpl.is_unique(); }
+ oslInterlockedCount use_count() const { return maImpl.use_count(); }
+ void swap( cow_wrapper_client1& r ) { o3tl::swap(maImpl, r.maImpl); }
+
+ bool operator==( const cow_wrapper_client1& rRHS ) const { return maImpl == rRHS.maImpl; }
+ bool operator!=( const cow_wrapper_client1& rRHS ) const { return maImpl != rRHS.maImpl; }
+ bool operator<( const cow_wrapper_client1& rRHS ) const { return maImpl < rRHS.maImpl; }
+
+private:
+ o3tl::cow_wrapper< int > maImpl;
+};
+
+
+class cow_wrapper_client2_impl;
+
+/** test opaque impl type - need to explicitely declare lifetime
+ methods
+ */
+class cow_wrapper_client2
+{
+public:
+ cow_wrapper_client2();
+ explicit cow_wrapper_client2( int nVal );
+ ~cow_wrapper_client2();
+
+ cow_wrapper_client2( const cow_wrapper_client2& );
+ cow_wrapper_client2& operator=( const cow_wrapper_client2& );
+
+ void modify( int nVal );
+ int queryUnmodified() const;
+
+ void makeUnique();
+ bool is_unique() const;
+ oslInterlockedCount use_count() const;
+ void swap( cow_wrapper_client2& r );
+
+ bool operator==( const cow_wrapper_client2& rRHS ) const;
+ bool operator!=( const cow_wrapper_client2& rRHS ) const;
+ bool operator<( const cow_wrapper_client2& rRHS ) const;
+
+private:
+ o3tl::cow_wrapper< cow_wrapper_client2_impl > maImpl;
+};
+
+/** test MT-safe cow_wrapper - basically the same as
+ cow_wrapper_client2, only with different refcounting policy
+ */
+class cow_wrapper_client3
+{
+public:
+ cow_wrapper_client3();
+ explicit cow_wrapper_client3( int nVal );
+ ~cow_wrapper_client3();
+
+ cow_wrapper_client3( const cow_wrapper_client3& );
+ cow_wrapper_client3& operator=( const cow_wrapper_client3& );
+
+ void modify( int nVal );
+ int queryUnmodified() const;
+
+ void makeUnique();
+ bool is_unique() const;
+ oslInterlockedCount use_count() const;
+ void swap( cow_wrapper_client3& r );
+
+ bool operator==( const cow_wrapper_client3& rRHS ) const;
+ bool operator!=( const cow_wrapper_client3& rRHS ) const;
+ bool operator<( const cow_wrapper_client3& rRHS ) const;
+
+private:
+ o3tl::cow_wrapper< cow_wrapper_client2_impl, o3tl::ThreadSafeRefCountingPolicy > maImpl;
+};
+
+} // namespace o3tltests
+
+#endif /* INCLUDED_COW_WRAPPER_CLIENTS_HXX */
diff --git a/o3tl/qa/export.map b/o3tl/qa/export.map
new file mode 100644
index 000000000000..3308588ef6f8
--- /dev/null
+++ b/o3tl/qa/export.map
@@ -0,0 +1,34 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+UDK_3_0_0 {
+ global:
+ cppunitTestPlugIn;
+
+ local:
+ *;
+};
diff --git a/o3tl/qa/makefile.mk b/o3tl/qa/makefile.mk
new file mode 100644
index 000000000000..3475aeeca9bb
--- /dev/null
+++ b/o3tl/qa/makefile.mk
@@ -0,0 +1,77 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+PRJ=..
+
+PRJNAME=o3tl
+TARGET=tests
+
+ENABLE_EXCEPTIONS=TRUE
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE : settings.mk
+
+CFLAGSCXX += $(CPPUNIT_CFLAGS)
+
+.IF "$(L10N_framework)"==""
+# --- Common ----------------------------------------------------------
+
+# BEGIN ----------------------------------------------------------------
+SHL1OBJS= \
+ $(SLO)$/cow_wrapper_clients.obj \
+ $(SLO)$/test-cow_wrapper.obj \
+ $(SLO)$/test-vector_pool.obj \
+ $(SLO)$/test-heap_ptr.obj \
+ $(SLO)$/test-range.obj
+
+SHL1TARGET= tests
+SHL1STDLIBS= $(SALLIB) \
+ $(CPPUNITLIB)
+
+SHL1IMPLIB= i$(SHL1TARGET)
+
+DEF1NAME =$(SHL1TARGET)
+SHL1VERSIONMAP = export.map
+SHL1RPATH = NONE
+
+# END ------------------------------------------------------------------
+
+#------------------------------- All object files -------------------------------
+# do this here, so we get right dependencies
+SLOFILES=$(SHL1OBJS)
+
+# --- Targets ------------------------------------------------------
+.ENDIF # L10N_framework
+
+.INCLUDE : target.mk
+
+# --- Enable test execution in normal build ------------------------
+.IF "$(L10N_framework)"==""
+.INCLUDE : _cppunit.mk
+.ENDIF # L10N_framework
+
diff --git a/o3tl/qa/test-cow_wrapper.cxx b/o3tl/qa/test-cow_wrapper.cxx
new file mode 100644
index 000000000000..84d615fca3db
--- /dev/null
+++ b/o3tl/qa/test-cow_wrapper.cxx
@@ -0,0 +1,127 @@
+// autogenerated file with codegen.pl
+
+#include "cppunit/TestAssert.h"
+#include "cppunit/TestFixture.h"
+#include "cppunit/extensions/HelperMacros.h"
+#include "cppunit/plugin/TestPlugIn.h"
+
+#include "cow_wrapper_clients.hxx"
+
+using namespace ::o3tl;
+using namespace ::o3tltests;
+
+
+class cow_wrapper_test : public CppUnit::TestFixture
+{
+public:
+ template< class T > void test( T& rTestObj1, T& rTestObj2, T& rTestObj3 )
+ {
+ CPPUNIT_ASSERT_MESSAGE("rTestObj1 is unique",
+ rTestObj1.is_unique() );
+ CPPUNIT_ASSERT_MESSAGE("rTestObj2 is unique",
+ rTestObj2.is_unique() );
+ CPPUNIT_ASSERT_MESSAGE("rTestObj3 is unique",
+ rTestObj3.is_unique() );
+
+ CPPUNIT_ASSERT_MESSAGE("rTestObj1 != rTestObj2",
+ rTestObj1 != rTestObj2 );
+ CPPUNIT_ASSERT_MESSAGE("rTestObj2 != rTestObj3",
+ rTestObj2 != rTestObj3 );
+ CPPUNIT_ASSERT_MESSAGE("rTestObj1 != rTestObj3",
+ rTestObj1 != rTestObj3 );
+ CPPUNIT_ASSERT_MESSAGE("rTestObj1 < rTestObj2",
+ rTestObj1 < rTestObj2 );
+ CPPUNIT_ASSERT_MESSAGE("rTestObj2 < rTestObj3",
+ rTestObj2 < rTestObj3 );
+
+ rTestObj2 = rTestObj1;
+ rTestObj3 = rTestObj1;
+ CPPUNIT_ASSERT_MESSAGE("rTestObj1 == rTestObj2",
+ rTestObj1 == rTestObj2 );
+ CPPUNIT_ASSERT_MESSAGE("rTestObj1 == rTestObj3",
+ rTestObj1 == rTestObj3 );
+ CPPUNIT_ASSERT_MESSAGE("rTestObj1.use_count() == 3",
+ rTestObj1.use_count() == 3 );
+ CPPUNIT_ASSERT_MESSAGE("rTestObj2.use_count() == 3",
+ rTestObj2.use_count() == 3 );
+ CPPUNIT_ASSERT_MESSAGE("rTestObj3.use_count() == 3",
+ rTestObj3.use_count() == 3 );
+
+ rTestObj2.makeUnique();
+ CPPUNIT_ASSERT_MESSAGE("rTestObj1 == rTestObj2",
+ rTestObj1 == rTestObj2 );
+ CPPUNIT_ASSERT_MESSAGE("rTestObj1 == rTestObj3",
+ rTestObj1 == rTestObj3 );
+ CPPUNIT_ASSERT_MESSAGE("rTestObj1.use_count() == 2",
+ rTestObj1.use_count() == 2 );
+ CPPUNIT_ASSERT_MESSAGE("rTestObj2.use_count() == 1",
+ rTestObj2.use_count() == 1 );
+ CPPUNIT_ASSERT_MESSAGE("rTestObj2.is_unique()",
+ rTestObj2.is_unique() );
+ CPPUNIT_ASSERT_MESSAGE("rTestObj3.use_count() == 2",
+ rTestObj3.use_count() == 2 );
+
+ rTestObj2.swap( rTestObj3 );
+ CPPUNIT_ASSERT_MESSAGE("rTestObj1 == rTestObj2",
+ rTestObj1 == rTestObj2 );
+ CPPUNIT_ASSERT_MESSAGE("rTestObj1 == rTestObj3",
+ rTestObj1 == rTestObj3 );
+ CPPUNIT_ASSERT_MESSAGE("rTestObj1.use_count() == 2",
+ rTestObj1.use_count() == 2 );
+ CPPUNIT_ASSERT_MESSAGE("rTestObj2.use_count() == 2",
+ rTestObj2.use_count() == 2 );
+ CPPUNIT_ASSERT_MESSAGE("rTestObj3.use_count() == 1",
+ rTestObj3.use_count() == 1 );
+ CPPUNIT_ASSERT_MESSAGE("rTestObj3.is_unique()",
+ rTestObj3.is_unique() );
+ }
+
+ void testCowWrapper()
+ {
+ // setup
+ cow_wrapper_client1 aTestObj1;
+ cow_wrapper_client1 aTestObj2;
+ cow_wrapper_client1 aTestObj3;
+
+ cow_wrapper_client2 aTestObj4;
+ cow_wrapper_client2 aTestObj5;
+ cow_wrapper_client2 aTestObj6;
+
+ cow_wrapper_client3 aTestObj7;
+ cow_wrapper_client3 aTestObj8;
+ cow_wrapper_client3 aTestObj9;
+
+ {
+ aTestObj1 = cow_wrapper_client1( 1 );
+ aTestObj2.modify( 2 );
+ aTestObj3.modify( 3 );
+
+ aTestObj4 = cow_wrapper_client2( 4 );
+ aTestObj5.modify( 5 );
+ aTestObj6.modify( 6 );
+
+ aTestObj7 = cow_wrapper_client3( 7 );
+ aTestObj8.modify( 8 );
+ aTestObj9.modify( 9 );
+ }
+ // all three temporaries are dead now
+
+ // test
+ test( aTestObj1, aTestObj2, aTestObj3 );
+ test( aTestObj4, aTestObj5, aTestObj6 );
+ test( aTestObj7, aTestObj8, aTestObj9 );
+ }
+
+ // 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(cow_wrapper_test);
+ CPPUNIT_TEST(testCowWrapper);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+// -----------------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION(cow_wrapper_test);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/o3tl/qa/test-heap_ptr.cxx b/o3tl/qa/test-heap_ptr.cxx
new file mode 100644
index 000000000000..fe2f78eec8af
--- /dev/null
+++ b/o3tl/qa/test-heap_ptr.cxx
@@ -0,0 +1,165 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "cppunit/TestAssert.h"
+#include "cppunit/TestFixture.h"
+#include "cppunit/extensions/HelperMacros.h"
+
+#include <o3tl/heap_ptr.hxx>
+
+
+
+
+using o3tl::heap_ptr;
+
+
+class Help
+{
+ public:
+ explicit Help(
+ int i_n )
+ : n(i_n) { ++nInstanceCount_; }
+ ~Help() { --nInstanceCount_; }
+ int Value() const { return n; }
+ static int InstanceCount_() { return nInstanceCount_; }
+
+ private:
+ int n;
+ static int nInstanceCount_;
+};
+int Help::nInstanceCount_ = 0;
+
+
+class heap_ptr_test : public CppUnit::TestFixture
+{
+ public:
+ void global()
+ {
+ // Construction
+ heap_ptr<Help>
+ t_empty;
+ const heap_ptr<Help>
+ t0( new Help(7000) );
+ heap_ptr<Help>
+ t1( new Help(10) );
+ heap_ptr<Help>
+ t2( new Help(20) );
+
+ int nHelpCount = 3;
+
+ CPPUNIT_ASSERT_MESSAGE("ctor1", ! t_empty.is());
+ CPPUNIT_ASSERT_MESSAGE("ctor2", t0.is());
+ CPPUNIT_ASSERT_MESSAGE("ctor3", (*t0).Value() == 7000 );
+ CPPUNIT_ASSERT_MESSAGE("ctor4", t0->Value() == 7000 );
+ CPPUNIT_ASSERT_MESSAGE("ctor5", t0.get() == t0.operator->() );
+ CPPUNIT_ASSERT_MESSAGE("ctor6", t0.get() == &(*t0) );
+
+ CPPUNIT_ASSERT_MESSAGE("ctor7", t1.is());
+ CPPUNIT_ASSERT_MESSAGE("ctor8", (*t1).Value() == 10 );
+ CPPUNIT_ASSERT_MESSAGE("ctor9", t1->Value() == 10 );
+ CPPUNIT_ASSERT_MESSAGE("ctor10", t1.get() == t1.operator->() );
+ CPPUNIT_ASSERT_MESSAGE("ctor11", t1.get() == &(*t1) );
+
+ CPPUNIT_ASSERT_MESSAGE("ctor12", t2.operator*().Value() == 20);
+ CPPUNIT_ASSERT_MESSAGE("ctor13", Help::InstanceCount_() == nHelpCount);
+
+
+ // Operator safe_bool() / bool()
+ CPPUNIT_ASSERT_MESSAGE("bool1", ! t_empty);
+ CPPUNIT_ASSERT_MESSAGE("bool2", t0);
+ CPPUNIT_ASSERT_MESSAGE("bool3", t1.is() == static_cast<bool>(t1));
+
+
+ // Assignment, reset() and release()
+ // Release
+ Help * hp = t1.release();
+ CPPUNIT_ASSERT_MESSAGE("release1", ! t1.is() );
+ CPPUNIT_ASSERT_MESSAGE("release2", t1.get() == 0 );
+ CPPUNIT_ASSERT_MESSAGE("release3", t1.operator->() == 0 );
+ CPPUNIT_ASSERT_MESSAGE("release4", Help::InstanceCount_() == nHelpCount);
+
+ // operator=()
+ t_empty = hp;
+ CPPUNIT_ASSERT_MESSAGE("assign1", t_empty.is() );
+ CPPUNIT_ASSERT_MESSAGE("assign2", Help::InstanceCount_() == nHelpCount);
+
+ t1 = t_empty.release();
+ CPPUNIT_ASSERT_MESSAGE("assign3", t1.is() );
+ CPPUNIT_ASSERT_MESSAGE("assign4", ! t_empty.is() );
+ CPPUNIT_ASSERT_MESSAGE("assign5", Help::InstanceCount_() == nHelpCount);
+
+ // reset()
+ hp = new Help(30);
+ ++nHelpCount;
+
+ t_empty.reset(hp);
+ CPPUNIT_ASSERT_MESSAGE("reset1", Help::InstanceCount_() == nHelpCount);
+ CPPUNIT_ASSERT_MESSAGE("reset2", t_empty.is() );
+ CPPUNIT_ASSERT_MESSAGE("reset3", t_empty.get() == hp );
+
+ // Ignore second assignment
+ t_empty = hp;
+ CPPUNIT_ASSERT_MESSAGE("selfassign1", Help::InstanceCount_() == nHelpCount);
+ CPPUNIT_ASSERT_MESSAGE("selfassign2", t_empty.is() );
+ CPPUNIT_ASSERT_MESSAGE("selfassign3", t_empty.get() == hp );
+
+ t_empty.reset(0);
+ hp = 0;
+ --nHelpCount;
+ CPPUNIT_ASSERT_MESSAGE("reset4", ! t_empty.is() );
+ CPPUNIT_ASSERT_MESSAGE("reset5", Help::InstanceCount_() == nHelpCount);
+
+
+ // swap
+ t1.swap(t2);
+ CPPUNIT_ASSERT_MESSAGE("swap1", t1->Value() == 20 );
+ CPPUNIT_ASSERT_MESSAGE("swap2", t2->Value() == 10 );
+ CPPUNIT_ASSERT_MESSAGE("swap3", Help::InstanceCount_() == nHelpCount);
+
+ o3tl::swap(t1,t2);
+ CPPUNIT_ASSERT_MESSAGE("swap4", t1->Value() == 10 );
+ CPPUNIT_ASSERT_MESSAGE("swap5", t2->Value() == 20 );
+ CPPUNIT_ASSERT_MESSAGE("swap6", Help::InstanceCount_() == nHelpCount);
+
+ // RAII
+ {
+ heap_ptr<Help>
+ t_raii( new Help(55) );
+ CPPUNIT_ASSERT_MESSAGE("raii1", Help::InstanceCount_() == nHelpCount + 1);
+ }
+ CPPUNIT_ASSERT_MESSAGE("raii2", Help::InstanceCount_() == nHelpCount);
+ }
+
+
+ // These macros are needed by auto register mechanism.
+ CPPUNIT_TEST_SUITE(heap_ptr_test);
+ CPPUNIT_TEST(global);
+ CPPUNIT_TEST_SUITE_END();
+}; // class heap_ptr_test
+
+// -----------------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION(heap_ptr_test);
diff --git a/o3tl/qa/test-range.cxx b/o3tl/qa/test-range.cxx
new file mode 100644
index 000000000000..31cf2aec7c10
--- /dev/null
+++ b/o3tl/qa/test-range.cxx
@@ -0,0 +1,234 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "cppunit/TestAssert.h"
+#include "cppunit/TestFixture.h"
+#include "cppunit/extensions/HelperMacros.h"
+
+#include <o3tl/range.hxx>
+#include <vector>
+#include <deque>
+
+
+
+using o3tl::range;
+using o3tl::make_range;
+using o3tl::range_of;
+using std::size_t;
+
+
+class range_test : public CppUnit::TestFixture
+{
+public:
+
+ void int_test()
+ {
+ range<int>
+ t1(12,88);
+ range<int>
+ t2(33,33);
+
+ // ctor
+ CPPUNIT_ASSERT_MESSAGE("int ctor1", t1.begin() == 12);
+ CPPUNIT_ASSERT_MESSAGE("int ctor2", t1.end() == 88);
+ CPPUNIT_ASSERT_MESSAGE("int ctor3", t2.begin() == 33);
+ CPPUNIT_ASSERT_MESSAGE("int ctor4", t2.end() == 33);
+
+ // make_range
+ CPPUNIT_ASSERT_MESSAGE("int make_range1", make_range(0,8).begin() == 0);
+ CPPUNIT_ASSERT_MESSAGE("int make_range2", make_range(0,8).end() == 8);
+
+ // size
+ CPPUNIT_ASSERT_MESSAGE("int size1", t1.size() == size_t(t1.end() - t1.begin()) );
+ CPPUNIT_ASSERT_MESSAGE("int size2", t2.size() == size_t(0) );
+
+ // contains
+ range<int> t3(0,10);
+ range<int> t4(7, 15);
+ range<int> t5(12, 12);
+ range<int> t6(13, 77);
+ range<int> t7(87, 87);
+ range<int> t8(87, 88);
+ range<int> t9(88, 88);
+ range<int> t10(33, 120);
+ range<int> t11(90, 100);
+ range<int> t12(200,200);
+
+ CPPUNIT_ASSERT_MESSAGE("int contains1", t1.contains(t1));
+ CPPUNIT_ASSERT_MESSAGE("int contains2", t1.contains(t2));
+ CPPUNIT_ASSERT_MESSAGE("int contains3", ! t1.contains(t3));
+ CPPUNIT_ASSERT_MESSAGE("int contains4", ! t1.contains(t4));
+ CPPUNIT_ASSERT_MESSAGE("int contains5", t1.contains(t5));
+ CPPUNIT_ASSERT_MESSAGE("int contains6", t1.contains(t6));
+ CPPUNIT_ASSERT_MESSAGE("int contains7", t1.contains(t7));
+ CPPUNIT_ASSERT_MESSAGE("int contains8", t1.contains(t8));
+ CPPUNIT_ASSERT_MESSAGE("int contains9", ! t1.contains(t9));
+ CPPUNIT_ASSERT_MESSAGE("int contains10", ! t1.contains(t10));
+ CPPUNIT_ASSERT_MESSAGE("int contains11", ! t1.contains(t11));
+ CPPUNIT_ASSERT_MESSAGE("int contains12", ! t1.contains(t12));
+
+ CPPUNIT_ASSERT_MESSAGE("int contains n1", t1.contains(50));
+ CPPUNIT_ASSERT_MESSAGE("int contains n2", t1.contains(12));
+ CPPUNIT_ASSERT_MESSAGE("int contains n3", t1.contains(87));
+ CPPUNIT_ASSERT_MESSAGE("int contains n4", ! t1.contains(3));
+ CPPUNIT_ASSERT_MESSAGE("int contains n5", ! t1.contains(11));
+ CPPUNIT_ASSERT_MESSAGE("int contains n6", ! t1.contains(88));
+ CPPUNIT_ASSERT_MESSAGE("int contains n7", ! t1.contains(100));
+
+ // overlaps
+ range<int> t13(88,99);
+
+ CPPUNIT_ASSERT_MESSAGE("int overlaps1", t1.overlaps(t1));
+ CPPUNIT_ASSERT_MESSAGE("int overlaps2", t1.overlaps(t2));
+ CPPUNIT_ASSERT_MESSAGE("int overlaps3", ! t1.overlaps(t3));
+ CPPUNIT_ASSERT_MESSAGE("int overlaps4", t1.overlaps(t4));
+ CPPUNIT_ASSERT_MESSAGE("int overlaps5", t1.overlaps(t5));
+ CPPUNIT_ASSERT_MESSAGE("int overlaps6", t1.overlaps(t6));
+ CPPUNIT_ASSERT_MESSAGE("int overlaps7", t1.overlaps(t7));
+ CPPUNIT_ASSERT_MESSAGE("int overlaps8", t1.overlaps(t8));
+ CPPUNIT_ASSERT_MESSAGE("int overlaps9", ! t1.overlaps(t9));
+ CPPUNIT_ASSERT_MESSAGE("int overlaps10", t1.overlaps(t10));
+ CPPUNIT_ASSERT_MESSAGE("int overlaps11", ! t1.overlaps(t11));
+ CPPUNIT_ASSERT_MESSAGE("int overlaps12", ! t1.overlaps(t12));
+ CPPUNIT_ASSERT_MESSAGE("int overlaps13", ! t1.overlaps(t13));
+
+ // distance_to
+ CPPUNIT_ASSERT_MESSAGE("int distance_to1", t1.distance_to(t13) == 0);
+ CPPUNIT_ASSERT_MESSAGE("int distance_to2", t1.distance_to(t9) == 0);
+ CPPUNIT_ASSERT_MESSAGE("int distance_to3", t1.distance_to(t11) == 2);
+ CPPUNIT_ASSERT_MESSAGE("int distance_to4", t1.distance_to(t8) == -1);
+ CPPUNIT_ASSERT_MESSAGE("int distance_to5", t1.distance_to(t3) == -88);
+ }
+
+ void iterator_test()
+ {
+ typedef std::vector<char>::const_iterator test_it;
+ const std::vector<char> hv(200,'x');
+
+
+ test_it hit1 = hv.begin() + 12;
+ test_it hit2 = hv.begin() + 88;
+
+ range<test_it>
+ t1(hit1, hit2);
+ range<test_it>
+ t2(hv.begin()+33, hv.begin()+33);
+
+ // ctor
+ CPPUNIT_ASSERT_MESSAGE("ivec ctor1", t1.begin() == hit1);
+ CPPUNIT_ASSERT_MESSAGE("ivec ctor2", t1.end() == hit2);
+ CPPUNIT_ASSERT_MESSAGE("ivec ctor3", t2.begin() == hv.begin()+33);
+ CPPUNIT_ASSERT_MESSAGE("ivec ctor4", t2.end() == hv.begin()+33);
+
+ // make_range
+ CPPUNIT_ASSERT_MESSAGE("ivec make_range1", make_range(hv.begin(), hv.begin()+8).begin() == hv.begin());
+ CPPUNIT_ASSERT_MESSAGE("ivec make_range2", make_range(hv.begin(), hv.begin()+8).end() == hv.begin()+8);
+
+ // size
+ CPPUNIT_ASSERT_MESSAGE("ivec size1", t1.size() == size_t(t1.end() - t1.begin()) );
+ CPPUNIT_ASSERT_MESSAGE("ivec size2", t2.size() == size_t(0) );
+
+ // contains
+ range<test_it> t3(hv.begin(), hv.begin() + 10);
+ range<test_it> t4(hv.begin() + 7, hv.begin() + 15);
+ range<test_it> t5(hit1, hit1);
+ range<test_it> t6(hv.begin() + 13, hv.begin() + 77);
+ range<test_it> t7(hv.begin() + 87, hv.begin() + 87);
+ range<test_it> t8(hv.begin() + 87, hit2);
+ range<test_it> t9(hit2, hit2);
+ range<test_it> t10(hv.begin() + 33, hv.begin() + 120);
+ range<test_it> t11(hv.begin() + 90, hv.begin() + 100);
+ range<test_it> t12(hv.begin() + 200,hv.begin() + 200);
+
+ CPPUNIT_ASSERT_MESSAGE("ivec contains1", t1.contains(t1));
+ CPPUNIT_ASSERT_MESSAGE("ivec contains2", t1.contains(t2));
+ CPPUNIT_ASSERT_MESSAGE("ivec contains3", ! t1.contains(t3));
+ CPPUNIT_ASSERT_MESSAGE("ivec contains4", ! t1.contains(t4));
+ CPPUNIT_ASSERT_MESSAGE("ivec contains5", t1.contains(t5));
+ CPPUNIT_ASSERT_MESSAGE("ivec contains6", t1.contains(t6));
+ CPPUNIT_ASSERT_MESSAGE("ivec contains7", t1.contains(t7));
+ CPPUNIT_ASSERT_MESSAGE("ivec contains8", t1.contains(t8));
+ CPPUNIT_ASSERT_MESSAGE("ivec contains9", ! t1.contains(t9));
+ CPPUNIT_ASSERT_MESSAGE("ivec contains10", ! t1.contains(t10));
+ CPPUNIT_ASSERT_MESSAGE("ivec contains11", ! t1.contains(t11));
+ CPPUNIT_ASSERT_MESSAGE("ivec contains12", ! t1.contains(t12));
+
+ CPPUNIT_ASSERT_MESSAGE("ivec contains n1", t1.contains(hv.begin() + 50));
+ CPPUNIT_ASSERT_MESSAGE("ivec contains n2", t1.contains(hit1));
+ CPPUNIT_ASSERT_MESSAGE("ivec contains n3", t1.contains(hv.begin() + 87));
+ CPPUNIT_ASSERT_MESSAGE("ivec contains n4", ! t1.contains(hv.begin() + 3));
+ CPPUNIT_ASSERT_MESSAGE("ivec contains n5", ! t1.contains(hv.begin() + 11));
+ CPPUNIT_ASSERT_MESSAGE("ivec contains n6", ! t1.contains(hit2));
+ CPPUNIT_ASSERT_MESSAGE("ivec contains n7", ! t1.contains(hv.begin() + 100));
+
+ // overlaps
+ range<test_it> t13(hit2, hv.begin() + 99);
+
+ CPPUNIT_ASSERT_MESSAGE("ivec overlaps1", t1.overlaps(t1));
+ CPPUNIT_ASSERT_MESSAGE("ivec overlaps2", t1.overlaps(t2));
+ CPPUNIT_ASSERT_MESSAGE("ivec overlaps3", ! t1.overlaps(t3));
+ CPPUNIT_ASSERT_MESSAGE("ivec overlaps4", t1.overlaps(t4));
+ CPPUNIT_ASSERT_MESSAGE("ivec overlaps5", t1.overlaps(t5));
+ CPPUNIT_ASSERT_MESSAGE("ivec overlaps6", t1.overlaps(t6));
+ CPPUNIT_ASSERT_MESSAGE("ivec overlaps7", t1.overlaps(t7));
+ CPPUNIT_ASSERT_MESSAGE("ivec overlaps8", t1.overlaps(t8));
+ CPPUNIT_ASSERT_MESSAGE("ivec overlaps9", ! t1.overlaps(t9));
+ CPPUNIT_ASSERT_MESSAGE("ivec overlaps10", t1.overlaps(t10));
+ CPPUNIT_ASSERT_MESSAGE("ivec overlaps11", ! t1.overlaps(t11));
+ CPPUNIT_ASSERT_MESSAGE("ivec overlaps12", ! t1.overlaps(t12));
+ CPPUNIT_ASSERT_MESSAGE("ivec overlaps13", ! t1.overlaps(t13));
+
+ // distance_to
+ CPPUNIT_ASSERT_MESSAGE("ivec distance_to1", t1.distance_to(t13) == 0);
+ CPPUNIT_ASSERT_MESSAGE("ivec distance_to2", t1.distance_to(t8) == -1);
+ CPPUNIT_ASSERT_MESSAGE("ivec distance_to3", t1.distance_to(t9) == 0);
+ CPPUNIT_ASSERT_MESSAGE("ivec distance_to4", t1.distance_to(t11) == 2);
+ CPPUNIT_ASSERT_MESSAGE("ivec distance_to5", t1.distance_to(t3) == -88);
+
+ const std::vector< int* > h2(20, (int*)0);
+ std::deque< double > h3(30, 0.0);
+
+ CPPUNIT_ASSERT_MESSAGE("range_of1", range_of(h2).begin() == h2.begin());
+ CPPUNIT_ASSERT_MESSAGE("range_of2", range_of(h3).end() == h3.end());
+ }
+
+ // insert your test code here.
+ void global()
+ {
+ int_test();
+ iterator_test();
+ }
+
+
+ // These macros are needed by auto register mechanism.
+ CPPUNIT_TEST_SUITE(range_test);
+ CPPUNIT_TEST(global);
+ CPPUNIT_TEST_SUITE_END();
+}; // class range_test
+
+// -----------------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION(range_test);
diff --git a/o3tl/qa/test-vector_pool.cxx b/o3tl/qa/test-vector_pool.cxx
new file mode 100644
index 000000000000..4efaebdd3414
--- /dev/null
+++ b/o3tl/qa/test-vector_pool.cxx
@@ -0,0 +1,69 @@
+// autogenerated file with codegen.pl
+
+#include "cppunit/TestAssert.h"
+#include "cppunit/TestFixture.h"
+#include "cppunit/extensions/HelperMacros.h"
+
+#include <o3tl/vector_pool.hxx>
+
+using namespace ::o3tl;
+
+class vector_pool_test : public CppUnit::TestFixture
+{
+public:
+ void testPoolBasics()
+ {
+ vector_pool<int> aPool;
+
+ std::ptrdiff_t nIdx1 = aPool.alloc();
+ std::ptrdiff_t nIdx2 = aPool.alloc();
+ std::ptrdiff_t nIdx3 = aPool.alloc();
+
+ CPPUNIT_ASSERT_MESSAGE("allocator idx order 1", nIdx1 < nIdx2 );
+ CPPUNIT_ASSERT_MESSAGE("allocator idx order 2", nIdx2 < nIdx3 );
+
+ aPool.free(nIdx2);
+ aPool.free(nIdx3);
+
+ nIdx2 = aPool.alloc();
+ nIdx3 = aPool.alloc();
+
+ CPPUNIT_ASSERT_MESSAGE("allocator idx order 1 after fragmentation", nIdx1 < nIdx3 );
+ CPPUNIT_ASSERT_MESSAGE("allocator idx order 2 after fragmentation", nIdx3 < nIdx2 );
+ }
+
+ void testPoolValueSemantics()
+ {
+ vector_pool<int> aPool;
+
+ std::ptrdiff_t nIdx1 = aPool.store(0);
+ CPPUNIT_ASSERT_MESSAGE("allocator value semantics 1", aPool.get(nIdx1) == 0 );
+
+ std::ptrdiff_t nIdx2 = aPool.store(1);
+ CPPUNIT_ASSERT_MESSAGE("allocator value semantics 2", aPool.get(nIdx2) == 1 );
+
+ std::ptrdiff_t nIdx3 = aPool.store(2);
+ CPPUNIT_ASSERT_MESSAGE("allocator value semantics 3", aPool.get(nIdx3) == 2 );
+
+ aPool.free(nIdx2);
+ aPool.free(nIdx3);
+
+ nIdx2 = aPool.store(1);
+ CPPUNIT_ASSERT_MESSAGE("allocator value semantics 2 after fragmentation", aPool.get(nIdx2) == 1 );
+
+ nIdx3 = aPool.store(2);
+ CPPUNIT_ASSERT_MESSAGE("allocator value semantics 3 after fragmentation", aPool.get(nIdx3) == 2 );
+ }
+
+ // 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(vector_pool_test);
+ CPPUNIT_TEST(testPoolBasics);
+ CPPUNIT_TEST(testPoolValueSemantics);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+// -----------------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION(vector_pool_test);