From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- svl/qa/unit/items/test_itempool.cxx | 99 +++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 svl/qa/unit/items/test_itempool.cxx (limited to 'svl/qa/unit/items/test_itempool.cxx') diff --git a/svl/qa/unit/items/test_itempool.cxx b/svl/qa/unit/items/test_itempool.cxx new file mode 100644 index 000000000..6868999f0 --- /dev/null +++ b/svl/qa/unit/items/test_itempool.cxx @@ -0,0 +1,99 @@ +/* -*- 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 +#include + +#include +#include +#include +#include + +class PoolItemTest : public CppUnit::TestFixture +{ + public: + PoolItemTest() {} + + void testPool(); + + // Adds code needed to register the test suite + CPPUNIT_TEST_SUITE(PoolItemTest); + + CPPUNIT_TEST(testPool); + + // End of test suite definition + CPPUNIT_TEST_SUITE_END(); +}; + +void PoolItemTest::testPool() +{ + SfxItemInfo const aItems[] = + { { 4, true }, + { 3, false /* not poolable */ }, + { 2, false }, + { 1, false /* not poolable */} + }; + + rtl::Reference pPool = new SfxItemPool("testpool", 1, 4, aItems); + SfxItemPool_Impl *pImpl = SfxItemPool_Impl::GetImpl(pPool.get()); + CPPUNIT_ASSERT(pImpl != nullptr); + CPPUNIT_ASSERT_EQUAL(static_cast(4), pImpl->maPoolItemArrays.size()); + + // Poolable + SfxVoidItem aItemOne( 1 ); + SfxVoidItem aNotherOne( 1 ); + + { + CPPUNIT_ASSERT(pImpl->maPoolItemArrays[0].empty()); + const SfxPoolItem &rVal = pPool->Put(aItemOne); + CPPUNIT_ASSERT(bool(rVal == aItemOne)); + CPPUNIT_ASSERT(!pImpl->maPoolItemArrays[0].empty()); + const SfxPoolItem &rVal2 = pPool->Put(aNotherOne); + CPPUNIT_ASSERT(bool(rVal2 == rVal)); + CPPUNIT_ASSERT_EQUAL(&rVal, &rVal2); + + // Clones on Put ... + CPPUNIT_ASSERT(&rVal2 != &aItemOne); + CPPUNIT_ASSERT(&rVal2 != &aNotherOne); + CPPUNIT_ASSERT(&rVal != &aItemOne); + CPPUNIT_ASSERT(&rVal != &aNotherOne); + } + + // non-poolable + SfxVoidItem aItemTwo( 2 ); + SfxVoidItem aNotherTwo( 2 ); + { + CPPUNIT_ASSERT(pImpl->maPoolItemArrays[1].empty()); + const SfxPoolItem &rVal = pPool->Put(aItemTwo); + CPPUNIT_ASSERT(bool(rVal == aItemTwo)); + CPPUNIT_ASSERT(!pImpl->maPoolItemArrays[1].empty()); + + const SfxPoolItem &rVal2 = pPool->Put(aNotherTwo); + CPPUNIT_ASSERT(bool(rVal2 == rVal)); + CPPUNIT_ASSERT(&rVal2 != &rVal); + } + + // Test removal. + SfxVoidItem aRemoveFour(4); + SfxVoidItem aNotherFour(4); + const SfxPoolItem &rKeyFour = pPool->Put(aRemoveFour); + pPool->Put(aNotherFour); + CPPUNIT_ASSERT(pImpl->maPoolItemArrays[3].size() > 0); + CPPUNIT_ASSERT_EQUAL(static_cast(2), pImpl->maPoolItemArrays[3].size()); + pPool->Remove(rKeyFour); + CPPUNIT_ASSERT_EQUAL(static_cast(1), pImpl->maPoolItemArrays[3].size()); + pPool->Put(aNotherFour); + CPPUNIT_ASSERT_EQUAL(static_cast(2), pImpl->maPoolItemArrays[3].size()); + +} + + +CPPUNIT_TEST_SUITE_REGISTRATION(PoolItemTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); -- cgit v1.2.3