android: Update app-specific/MIME type icons
[LibreOffice.git] / svl / qa / unit / items / stylepool.cxx
blob94ff91aea73c0c599d546538543ca41b2df97290
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <unotest/bootstrapfixturebase.hxx>
12 #include <svl/itempool.hxx>
13 #include <svl/itemset.hxx>
14 #include <svl/stylepool.hxx>
15 #include <svl/stritem.hxx>
17 namespace
19 /// Tests svl StylePool.
20 class StylePoolTest : public CppUnit::TestFixture
24 CPPUNIT_TEST_FIXTURE(StylePoolTest, testIterationOrder)
26 // Set up a style pool with multiple parents.
27 SfxStringItem aDefault1(1);
28 std::vector<SfxPoolItem*> aDefaults{ &aDefault1 };
29 SfxItemInfo const aItems[] = { { 2, false } };
31 rtl::Reference<SfxItemPool> pPool = new SfxItemPool("test", 1, 1, aItems);
32 pPool->SetDefaults(&aDefaults);
34 // Set up parents in mixed order to make sure we do not sort by pointer address.
35 SfxItemSet aParent1(*pPool, svl::Items<1, 1>);
36 SfxItemSet aChild1(*pPool, svl::Items<1, 1>);
37 aChild1.SetParent(&aParent1);
38 SfxStringItem aItem1(1, "Item1");
39 aChild1.Put(aItem1);
41 SfxItemSet aParent3(*pPool, svl::Items<1, 1>);
42 SfxItemSet aChild3(*pPool, svl::Items<1, 1>);
43 aChild3.SetParent(&aParent3);
44 SfxStringItem aItem3(1, "Item3");
45 aChild3.Put(aItem3);
47 SfxItemSet aParent2(*pPool, svl::Items<1, 1>);
48 SfxItemSet aChild2(*pPool, svl::Items<1, 1>);
49 aChild2.SetParent(&aParent2);
50 SfxStringItem aItem2(1, "Item2");
51 aChild2.Put(aItem2);
53 // Insert item sets in alphabetical order.
54 StylePool aStylePool;
55 OUString aChild1Name("Child1");
56 aStylePool.insertItemSet(aChild1, &aChild1Name);
57 OUString aChild3Name("Child3");
58 aStylePool.insertItemSet(aChild3, &aChild3Name);
59 OUString aChild2Name("Child2");
60 aStylePool.insertItemSet(aChild2, &aChild2Name);
61 std::unique_ptr<IStylePoolIteratorAccess> pIter = aStylePool.createIterator();
62 std::shared_ptr<SfxItemSet> pStyle1 = pIter->getNext();
63 CPPUNIT_ASSERT(pStyle1);
64 const SfxStringItem* pItem1 = static_cast<const SfxStringItem*>(pStyle1->GetItem(1));
65 CPPUNIT_ASSERT_EQUAL(OUString("Item1"), pItem1->GetValue());
66 std::shared_ptr<SfxItemSet> pStyle2 = pIter->getNext();
67 CPPUNIT_ASSERT(pStyle2);
68 const SfxStringItem* pItem2 = static_cast<const SfxStringItem*>(pStyle2->GetItem(1));
69 // Without the accompanying fix in place, this test would have failed with 'Expected: Item2;
70 // Actual: Item3'. The iteration order depended on the pointer address on the pointer
71 // address of the parents.
72 CPPUNIT_ASSERT_EQUAL(OUString("Item2"), pItem2->GetValue());
73 std::shared_ptr<SfxItemSet> pStyle3 = pIter->getNext();
74 CPPUNIT_ASSERT(pStyle3);
75 const SfxStringItem* pItem3 = static_cast<const SfxStringItem*>(pStyle3->GetItem(1));
76 CPPUNIT_ASSERT_EQUAL(OUString("Item3"), pItem3->GetValue());
77 CPPUNIT_ASSERT(!pIter->getNext());
82 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */