diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-01-09 10:27:22 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-01-17 10:07:10 +0200 |
commit | 2757ee9fe610e253e4ccc37423fa420004d0f388 (patch) | |
tree | a5a505f12a1c17cfab2001c2cbf43bd721633f0f /svl/qa | |
parent | ee2bd1ee97194f4d39d4d6ab95c9b926b5077cb8 (diff) |
used std::map in SfxItemSet
instead of naked array
SfxItemIter ended up needing to take copies of stuff because various
code likes to iterate over the items and delete items inside the loop.
The gdb pretty printer is no longer quite as pretty as it was before,
but it still prints useful info.
Change-Id: I59b07ea42f6b1c74798a15402970b9dbd8233dbe
Diffstat (limited to 'svl/qa')
-rw-r--r-- | svl/qa/unit/items/test_itempool.cxx | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/svl/qa/unit/items/test_itempool.cxx b/svl/qa/unit/items/test_itempool.cxx index 714c170b445b..38cbda3214da 100644 --- a/svl/qa/unit/items/test_itempool.cxx +++ b/svl/qa/unit/items/test_itempool.cxx @@ -8,6 +8,8 @@ */ #include <svl/itempool.hxx> +#include <svl/itemset.hxx> +#include <svl/itemiter.hxx> #include <poolio.hxx> #include <cppunit/TestAssert.h> @@ -21,13 +23,11 @@ class PoolItemTest : public CppUnit::TestFixture PoolItemTest() {} void testPool(); + void testItemSet(); - // Adds code needed to register the test suite CPPUNIT_TEST_SUITE(PoolItemTest); - CPPUNIT_TEST(testPool); - - // End of test suite definition + CPPUNIT_TEST(testItemSet); CPPUNIT_TEST_SUITE_END(); }; @@ -99,6 +99,52 @@ void PoolItemTest::testPool() CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), pImpl->maPoolItems[3]->maFree.size()); } +void PoolItemTest::testItemSet() +{ + SfxItemInfo aItems[] = + { { 1, false }, + { 2, false }, + { 3, false }, + { 4, false }, + { 5, false }, + { 6, false }, + { 7, false } + }; + + SfxItemPool *pPool = new SfxItemPool("testpool", 1, 7, aItems); + std::vector<SfxPoolItem*> aDefaults { + new SfxVoidItem(1), + new SfxVoidItem(2), + new SfxVoidItem(3), + new SfxVoidItem(4), + new SfxVoidItem(5), + new SfxVoidItem(6), + new SfxVoidItem(7) + }; + pPool->SetDefaults(&aDefaults); + + SfxItemSet aItemSet(*pPool, 1, 3, 5, 7, 0); + aItemSet.Put(SfxVoidItem(1)); + aItemSet.Put(SfxVoidItem(2)); + aItemSet.Put(SfxVoidItem(3)); + aItemSet.Put(SfxVoidItem(5)); + aItemSet.Put(SfxVoidItem(6)); + aItemSet.Put(SfxVoidItem(7)); + + SfxItemIter aIter(aItemSet); + + CPPUNIT_ASSERT_EQUAL((sal_uInt16)1, aIter.GetFirstWhich()); + CPPUNIT_ASSERT_EQUAL((sal_uInt16)7, aIter.GetLastWhich()); + CPPUNIT_ASSERT_EQUAL((sal_uInt16)1, aIter.FirstItem()->Which()); + CPPUNIT_ASSERT_EQUAL((sal_uInt16)2, aIter.NextItem()->Which()); + CPPUNIT_ASSERT_EQUAL((sal_uInt16)3, aIter.NextItem()->Which()); + CPPUNIT_ASSERT_EQUAL((sal_uInt16)5, aIter.NextItem()->Which()); + CPPUNIT_ASSERT_EQUAL((sal_uInt16)6, aIter.NextItem()->Which()); + CPPUNIT_ASSERT_EQUAL((sal_uInt16)7, aIter.NextItem()->Which()); + CPPUNIT_ASSERT_EQUAL(static_cast<const SfxPoolItem*>(nullptr), aIter.NextItem()); + CPPUNIT_ASSERT_EQUAL(true, aIter.IsAtEnd()); +} + CPPUNIT_TEST_SUITE_REGISTRATION(PoolItemTest); CPPUNIT_PLUGIN_IMPLEMENT(); |