1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <svl/itempool.hxx>
13 #include <cppunit/TestAssert.h>
14 #include <cppunit/TestFixture.h>
15 #include <cppunit/extensions/HelperMacros.h>
16 #include <cppunit/plugin/TestPlugIn.h>
18 class PoolItemTest
: public CppUnit::TestFixture
25 // Adds code needed to register the test suite
26 CPPUNIT_TEST_SUITE(PoolItemTest
);
28 CPPUNIT_TEST(testPool
);
30 // End of test suite definition
31 CPPUNIT_TEST_SUITE_END();
34 void PoolItemTest::testPool()
36 SfxItemInfo
const aItems
[] =
38 { 3, false /* not poolable */ },
40 { 1, false /* not poolable */}
43 rtl::Reference
<SfxItemPool
> pPool
= new SfxItemPool("testpool", 1, 4, aItems
);
44 SfxItemPool_Impl
*pImpl
= SfxItemPool_Impl::GetImpl(pPool
.get());
45 CPPUNIT_ASSERT(pImpl
!= nullptr);
46 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), pImpl
->maPoolItemArrays
.size());
49 SfxVoidItem
aItemOne( 1 );
50 SfxVoidItem
aNotherOne( 1 );
53 CPPUNIT_ASSERT(pImpl
->maPoolItemArrays
[0].empty());
54 const SfxPoolItem
&rVal
= pPool
->Put(aItemOne
);
55 CPPUNIT_ASSERT(bool(rVal
== aItemOne
));
56 CPPUNIT_ASSERT(!pImpl
->maPoolItemArrays
[0].empty());
57 const SfxPoolItem
&rVal2
= pPool
->Put(aNotherOne
);
58 CPPUNIT_ASSERT(bool(rVal2
== rVal
));
59 CPPUNIT_ASSERT_EQUAL(&rVal
, &rVal2
);
62 CPPUNIT_ASSERT(&rVal2
!= &aItemOne
);
63 CPPUNIT_ASSERT(&rVal2
!= &aNotherOne
);
64 CPPUNIT_ASSERT(&rVal
!= &aItemOne
);
65 CPPUNIT_ASSERT(&rVal
!= &aNotherOne
);
69 SfxVoidItem
aItemTwo( 2 );
70 SfxVoidItem
aNotherTwo( 2 );
72 CPPUNIT_ASSERT(pImpl
->maPoolItemArrays
[1].empty());
73 const SfxPoolItem
&rVal
= pPool
->Put(aItemTwo
);
74 CPPUNIT_ASSERT(bool(rVal
== aItemTwo
));
75 CPPUNIT_ASSERT(!pImpl
->maPoolItemArrays
[1].empty());
77 const SfxPoolItem
&rVal2
= pPool
->Put(aNotherTwo
);
78 CPPUNIT_ASSERT(bool(rVal2
== rVal
));
79 CPPUNIT_ASSERT(&rVal2
!= &rVal
);
83 SfxVoidItem
aRemoveFour(4);
84 SfxVoidItem
aNotherFour(4);
85 const SfxPoolItem
&rKeyFour
= pPool
->Put(aRemoveFour
);
86 pPool
->Put(aNotherFour
);
87 CPPUNIT_ASSERT(pImpl
->maPoolItemArrays
[3].size() > 0);
88 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), pImpl
->maPoolItemArrays
[3].size());
89 pPool
->Remove(rKeyFour
);
90 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pImpl
->maPoolItemArrays
[3].size());
91 pPool
->Put(aNotherFour
);
92 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), pImpl
->maPoolItemArrays
[3].size());
97 CPPUNIT_TEST_SUITE_REGISTRATION(PoolItemTest
);
99 CPPUNIT_PLUGIN_IMPLEMENT();