summaryrefslogtreecommitdiff
path: root/svl/qa
diff options
context:
space:
mode:
authorTobias Lippert <drtl@fastmail.fm>2014-03-05 20:06:39 +0100
committerCaolán McNamara <caolanm@redhat.com>2014-03-11 08:54:37 -0500
commit0c17ccc493d0c7a80f37600dae76a09a119bef78 (patch)
tree70fd1963d59bbb8dba95ed4d92053f2c9f3115cb /svl/qa
parente3e1f9f30d80961fd282f9ce765ffb1111201344 (diff)
fdo#30770 - Speed up xslx import
Conflicts: include/svl/style.hxx Change-Id: Ie3d855923c651b6e05c0054c8e30155218279045 Reviewed-on: https://gerrit.libreoffice.org/8485 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'svl/qa')
-rw-r--r--svl/qa/unit/items/test_IndexedStyleSheets.cxx160
1 files changed, 160 insertions, 0 deletions
diff --git a/svl/qa/unit/items/test_IndexedStyleSheets.cxx b/svl/qa/unit/items/test_IndexedStyleSheets.cxx
new file mode 100644
index 000000000000..ec8d82dcd5fd
--- /dev/null
+++ b/svl/qa/unit/items/test_IndexedStyleSheets.cxx
@@ -0,0 +1,160 @@
+/* -*- 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 <svl/IndexedStyleSheets.hxx>
+
+// for SfxStyleSheetBase
+#include <svl/style.hxx>
+
+#include <cppunit/TestAssert.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+using namespace svl;
+
+class MockedStyleSheet : public SfxStyleSheetBase
+{
+ public:
+ MockedStyleSheet(const rtl::OUString& name)
+ : SfxStyleSheetBase(name, NULL, SFX_STYLE_FAMILY_CHAR, 0)
+ {;}
+
+};
+
+class IndexedStyleSheetsTest : public CppUnit::TestFixture
+{
+ void InstantiationWorks();
+ void AddedStylesheetsCanBeFoundAndRetrievedByPosition();
+ void AddingSameStylesheetTwiceHasNoEffect();
+ void RemovedStyleSheetIsNotFound();
+ void RemovingStyleSheetWhichIsNotAvailableHasNoEffect();
+ void StyleSheetsCanBeRetrievedByTheirName();
+ void KnowsThatItStoresAStyleSheet();
+
+ // Adds code needed to register the test suite
+ CPPUNIT_TEST_SUITE(IndexedStyleSheetsTest);
+
+ CPPUNIT_TEST(InstantiationWorks);
+ CPPUNIT_TEST(AddedStylesheetsCanBeFoundAndRetrievedByPosition);
+ CPPUNIT_TEST(AddingSameStylesheetTwiceHasNoEffect);
+ CPPUNIT_TEST(RemovedStyleSheetIsNotFound);
+ CPPUNIT_TEST(RemovingStyleSheetWhichIsNotAvailableHasNoEffect);
+ CPPUNIT_TEST(StyleSheetsCanBeRetrievedByTheirName);
+ CPPUNIT_TEST(KnowsThatItStoresAStyleSheet);
+
+ // End of test suite definition
+ CPPUNIT_TEST_SUITE_END();
+
+};
+
+void IndexedStyleSheetsTest::InstantiationWorks()
+{
+ IndexedStyleSheets iss;
+}
+
+void IndexedStyleSheetsTest::AddedStylesheetsCanBeFoundAndRetrievedByPosition()
+{
+ rtl::OUString name1("name1");
+ rtl::OUString name2("name2");
+ rtl::Reference<SfxStyleSheetBase> sheet1(new MockedStyleSheet(name1));
+ rtl::Reference<SfxStyleSheetBase> sheet2(new MockedStyleSheet(name2));
+ IndexedStyleSheets iss;
+ iss.AddStyleSheet(sheet1);
+ iss.AddStyleSheet(sheet2);
+ unsigned pos = iss.FindStyleSheetPosition(*sheet2);
+ rtl::Reference<SfxStyleSheetBase> retrieved = iss.GetStyleSheetByPosition(pos);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("retrieved sheet is that which has been inserted.", sheet2.get(), retrieved.get());
+}
+
+void IndexedStyleSheetsTest::AddingSameStylesheetTwiceHasNoEffect()
+{
+ rtl::Reference<SfxStyleSheetBase> sheet1(new MockedStyleSheet(rtl::OUString("sheet1")));
+ IndexedStyleSheets iss;
+ iss.AddStyleSheet(sheet1);
+ CPPUNIT_ASSERT_EQUAL(1u, iss.GetNumberOfStyleSheets());
+ iss.AddStyleSheet(sheet1);
+ CPPUNIT_ASSERT_EQUAL(1u, iss.GetNumberOfStyleSheets());
+}
+
+void IndexedStyleSheetsTest::RemovedStyleSheetIsNotFound()
+{
+ rtl::OUString name1("name1");
+ rtl::OUString name2("name2");
+ rtl::Reference<SfxStyleSheetBase> sheet1(new MockedStyleSheet(name1));
+ rtl::Reference<SfxStyleSheetBase> sheet2(new MockedStyleSheet(name2));
+ IndexedStyleSheets iss;
+ iss.AddStyleSheet(sheet1);
+ iss.AddStyleSheet(sheet2);
+ iss.RemoveStyleSheet(sheet1);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Removed style sheet is not found.",
+ false, iss.HasStyleSheet(sheet1));
+}
+
+void IndexedStyleSheetsTest::RemovingStyleSheetWhichIsNotAvailableHasNoEffect()
+{
+ rtl::Reference<SfxStyleSheetBase> sheet1(new MockedStyleSheet(rtl::OUString("sheet1")));
+ rtl::Reference<SfxStyleSheetBase> sheet2(new MockedStyleSheet(rtl::OUString("sheet2")));
+ IndexedStyleSheets iss;
+ iss.AddStyleSheet(sheet1);
+ CPPUNIT_ASSERT_EQUAL(1u, iss.GetNumberOfStyleSheets());
+ iss.RemoveStyleSheet(sheet2);
+ CPPUNIT_ASSERT_EQUAL(1u, iss.GetNumberOfStyleSheets());
+}
+
+void IndexedStyleSheetsTest::StyleSheetsCanBeRetrievedByTheirName()
+{
+ rtl::OUString name1("name1");
+ rtl::OUString name2("name2");
+ rtl::Reference<SfxStyleSheetBase> sheet1(new MockedStyleSheet(name1));
+ rtl::Reference<SfxStyleSheetBase> sheet2(new MockedStyleSheet(name2));
+ rtl::Reference<SfxStyleSheetBase> sheet3(new MockedStyleSheet(name1));
+ IndexedStyleSheets iss;
+ iss.AddStyleSheet(sheet1);
+ iss.AddStyleSheet(sheet2);
+ iss.AddStyleSheet(sheet3);
+
+ std::vector<unsigned> r = iss.FindPositionsByName(name1);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Two style sheets are found by 'name1'",
+ 2u, static_cast<unsigned>(r.size()));
+ CPPUNIT_ASSERT_EQUAL(0u, r.at(0));
+ CPPUNIT_ASSERT_EQUAL(2u, r.at(1));
+
+ r = iss.FindPositionsByName(name2);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("One style sheets is found by 'name2'",
+ 1u, static_cast<unsigned>(r.size()));
+ CPPUNIT_ASSERT_EQUAL(1u, r.at(0));
+}
+
+void IndexedStyleSheetsTest::KnowsThatItStoresAStyleSheet()
+{
+ rtl::OUString name1("name1");
+ rtl::OUString name2("name2");
+ rtl::Reference<SfxStyleSheetBase> sheet1(new MockedStyleSheet(name1));
+ rtl::Reference<SfxStyleSheetBase> sheet2(new MockedStyleSheet(name1));
+ rtl::Reference<SfxStyleSheetBase> sheet3(new MockedStyleSheet(name2));
+ rtl::Reference<SfxStyleSheetBase> sheet4(new MockedStyleSheet(name1));
+ IndexedStyleSheets iss;
+ iss.AddStyleSheet(sheet1);
+ iss.AddStyleSheet(sheet2);
+ iss.AddStyleSheet(sheet3);
+ // do not add sheet 4
+
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Finds first stored style sheet even though two style sheets have the same name.",
+ true, iss.HasStyleSheet(sheet1));
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Finds second stored style sheet even though two style sheets have the same name.",
+ true, iss.HasStyleSheet(sheet2));
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Does not find style sheet which is not stored and has the same name as a stored.",
+ false, iss.HasStyleSheet(sheet4));
+
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(IndexedStyleSheetsTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();