summaryrefslogtreecommitdiff
path: root/sw/qa
diff options
context:
space:
mode:
Diffstat (limited to 'sw/qa')
-rw-r--r--sw/qa/api/ApiTestBase.hxx30
-rw-r--r--sw/qa/api/BaseIndexTest.hxx164
-rw-r--r--sw/qa/api/DocumentIndexTest.hxx49
-rw-r--r--sw/qa/api/SwXDocumentIndex.cxx125
-rw-r--r--sw/qa/api/XDocumentIndexTest.hxx97
-rw-r--r--sw/qa/api/XTextContentTest.hxx62
6 files changed, 527 insertions, 0 deletions
diff --git a/sw/qa/api/ApiTestBase.hxx b/sw/qa/api/ApiTestBase.hxx
new file mode 100644
index 000000000000..76871111ff3f
--- /dev/null
+++ b/sw/qa/api/ApiTestBase.hxx
@@ -0,0 +1,30 @@
+/* -*- 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/.
+ */
+
+#ifndef INCLUDED_SW_QA_CORE_APITESTBASE_HXX
+#define INCLUDED_SW_QA_CORE_APITESTBASE_HXX
+
+#include <com/sun/star/uno/XInterface.hpp>
+
+#include <unordered_map>
+
+namespace apitest
+{
+class ApiTestBase
+{
+protected:
+ virtual ~ApiTestBase() {}
+
+ virtual std::unordered_map<OUString, css::uno::Reference<css::uno::XInterface>> init() = 0;
+};
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/api/BaseIndexTest.hxx b/sw/qa/api/BaseIndexTest.hxx
new file mode 100644
index 000000000000..997f91aa948f
--- /dev/null
+++ b/sw/qa/api/BaseIndexTest.hxx
@@ -0,0 +1,164 @@
+/* -*- 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/.
+ */
+
+#ifndef INCLUDED_SW_QA_API_BASEINDEXTEST_HXX
+#define INCLUDED_SW_QA_API_BASEINDEXTEST_HXX
+
+#include "ApiTestBase.hxx"
+
+#include <cppunit/TestAssert.h>
+#include <test/unoapi_property_testers.hxx>
+
+#include <com/sun/star/beans/XPropertySet.hpp>
+
+#include <com/sun/star/text/XTextColumns.hpp>
+#include <com/sun/star/text/XTextSection.hpp>
+#include <com/sun/star/graphic/XGraphic.hpp>
+
+#include <vcl/BitmapTools.hxx>
+#include <vcl/graph.hxx>
+#include <vcl/pngwrite.hxx>
+#include <unotools/tempfile.hxx>
+#include <tools/stream.hxx>
+
+namespace apitest
+{
+namespace
+{
+BitmapEx createExampleBitmap()
+{
+ vcl::bitmap::RawBitmap aRawBitmap(Size(4, 4), 24);
+ aRawBitmap.SetPixel(0, 0, COL_LIGHTBLUE);
+ aRawBitmap.SetPixel(0, 1, COL_LIGHTGREEN);
+ aRawBitmap.SetPixel(1, 0, COL_LIGHTRED);
+ aRawBitmap.SetPixel(1, 1, COL_LIGHTMAGENTA);
+ return vcl::bitmap::CreateFromData(std::move(aRawBitmap));
+}
+
+void writerFileWithBitmap(OUString const& rURL)
+{
+ BitmapEx aBitmapEx = createExampleBitmap();
+ SvFileStream aFileStream(rURL, StreamMode::READ | StreamMode::WRITE);
+ vcl::PNGWriter aWriter(aBitmapEx);
+ aWriter.Write(aFileStream);
+ aFileStream.Seek(STREAM_SEEK_TO_BEGIN);
+ aFileStream.Close();
+}
+
+} // end anonymous namespace
+
+class BaseIndexTest : public ApiTestBase
+{
+public:
+ void testBaseIndexProperties()
+ {
+ auto map = init();
+
+ css::uno::Reference<css::beans::XPropertySet> xBaseIndex(map["text::BaseIndex"],
+ css::uno::UNO_QUERY_THROW);
+ testStringProperty(xBaseIndex, "Title", "Value");
+ testBooleanProperty(xBaseIndex, "IsProtected");
+
+ testStringProperty(xBaseIndex, "ParaStyleHeading", "Value");
+ testStringProperty(xBaseIndex, "ParaStyleLevel1", "Value");
+ testStringOptionalProperty(xBaseIndex, "ParaStyleLevel2");
+ testStringOptionalProperty(xBaseIndex, "ParaStyleLevel3");
+ testStringOptionalProperty(xBaseIndex, "ParaStyleLevel4");
+ testStringOptionalProperty(xBaseIndex, "ParaStyleLevel5");
+ testStringOptionalProperty(xBaseIndex, "ParaStyleLevel6");
+ testStringOptionalProperty(xBaseIndex, "ParaStyleLevel7");
+ testStringOptionalProperty(xBaseIndex, "ParaStyleLevel8");
+ testStringOptionalProperty(xBaseIndex, "ParaStyleLevel9");
+ testStringOptionalProperty(xBaseIndex, "ParaStyleLevel10");
+ testStringOptionalProperty(xBaseIndex, "ParaStyleSeparator");
+
+ // [property] XTextColumns TextColumns;
+ {
+ OUString name = "TextColumns";
+
+ css::uno::Reference<css::text::XTextColumns> xGetTextColumns;
+ CPPUNIT_ASSERT(xBaseIndex->getPropertyValue(name) >>= xGetTextColumns);
+
+ xGetTextColumns->setColumnCount(xGetTextColumns->getColumnCount() + 1);
+ xBaseIndex->setPropertyValue(name, css::uno::makeAny(xGetTextColumns));
+
+ css::uno::Reference<css::text::XTextColumns> xSetTextColumns;
+ CPPUNIT_ASSERT(xBaseIndex->getPropertyValue(name) >>= xSetTextColumns);
+
+ //CPPUNIT_ASSERT_EQUAL(xGetTextColumns->getColumnCount(), xSetTextColumns->getColumnCount());
+ }
+
+ // [property] com::sun::star::graphic::XGraphic BackGraphic;
+ // [property] string BackGraphicURL;
+ {
+ OUString name = "BackGraphicURL";
+ bool bOK = false;
+ try
+ {
+ xBaseIndex->getPropertyValue(name);
+ }
+ catch (css::uno::RuntimeException const& /*ex*/)
+ {
+ bOK = true;
+ }
+ // BackGraphicURL is "set-only" attribute
+ CPPUNIT_ASSERT_MESSAGE("Expected RuntimeException wasn't thrown", bOK);
+
+ utl::TempFile aTempFile;
+ aTempFile.EnableKillingFile();
+ writerFileWithBitmap(aTempFile.GetURL());
+
+ css::uno::Reference<css::graphic::XGraphic> xGraphic;
+ CPPUNIT_ASSERT(xBaseIndex->getPropertyValue("BackGraphic") >>= xGraphic);
+ CPPUNIT_ASSERT(!xGraphic.is());
+
+ xBaseIndex->setPropertyValue(name, css::uno::makeAny(aTempFile.GetURL()));
+
+ CPPUNIT_ASSERT(xBaseIndex->getPropertyValue("BackGraphic") >>= xGraphic);
+ CPPUNIT_ASSERT(xGraphic.is());
+ }
+
+ testStringProperty(xBaseIndex, "BackGraphicFilter", "Value");
+
+ // [property] com::sun::star::style::GraphicLocation BackGraphicLocation;
+
+ testColorProperty(xBaseIndex, "BackColor");
+ testBooleanProperty(xBaseIndex, "BackTransparent");
+
+ // [optional, property] com::sun::star::container::XIndexReplace LevelFormat;
+
+ testBooleanOptionalProperty(xBaseIndex, "CreateFromChapter");
+
+ // [property] com::sun::star::text::XTextSection ContentSection;
+ {
+ OUString name = "ContentSection";
+
+ css::uno::Reference<css::text::XTextSection> xGetTextSection;
+ CPPUNIT_ASSERT_MESSAGE(name.toUtf8().getStr(),
+ xBaseIndex->getPropertyValue(name) >>= xGetTextSection);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(name.toUtf8().getStr(), OUString(""),
+ xGetTextSection->getAnchor()->getString());
+ }
+
+ // [property] com::sun::star::text::XTextSection HeaderSection;
+ {
+ OUString name = "HeaderSection";
+
+ css::uno::Reference<css::text::XTextSection> xGetTextSection;
+ if (xBaseIndex->getPropertyValue(name).hasValue())
+ CPPUNIT_ASSERT_MESSAGE(name.toUtf8().getStr(),
+ xBaseIndex->getPropertyValue(name) >>= xGetTextSection);
+ }
+ }
+};
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/api/DocumentIndexTest.hxx b/sw/qa/api/DocumentIndexTest.hxx
new file mode 100644
index 000000000000..0757c1dd492f
--- /dev/null
+++ b/sw/qa/api/DocumentIndexTest.hxx
@@ -0,0 +1,49 @@
+/* -*- 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/.
+ */
+
+#ifndef INCLUDED_SW_QA_API_DOCUMENTINDEXTEST_HXX
+#define INCLUDED_SW_QA_API_DOCUMENTINDEXTEST_HXX
+
+#include "ApiTestBase.hxx"
+
+#include <cppunit/TestAssert.h>
+#include <test/unoapi_property_testers.hxx>
+
+#include <com/sun/star/beans/XPropertySet.hpp>
+
+namespace apitest
+{
+class DocumentIndexTest : public ApiTestBase
+{
+public:
+ void testDocumentIndexProperties()
+ {
+ auto map = init();
+
+ css::uno::Reference<css::beans::XPropertySet> xDocumnetIndex(map["text::DocumentIndex"],
+ css::uno::UNO_QUERY_THROW);
+
+ testBooleanProperty(xDocumnetIndex, "UseAlphabeticalSeparators");
+ testBooleanProperty(xDocumnetIndex, "UseKeyAsEntry");
+ testBooleanProperty(xDocumnetIndex, "UseCombinedEntries");
+ testBooleanProperty(xDocumnetIndex, "IsCaseSensitive");
+ testBooleanProperty(xDocumnetIndex, "UsePP");
+ testBooleanProperty(xDocumnetIndex, "UseDash");
+ testBooleanProperty(xDocumnetIndex, "UseUpperCase");
+ testStringOptionalProperty(xDocumnetIndex, "MainEntryCharacterStyleName");
+ // [readonly, property] sequence <com::sun::star::text::XDocumentIndexMark> DocumentIndexMarks;
+ // [property] com::sun::star::lang::Locale Locale;
+ testStringProperty(xDocumnetIndex, "SortAlgorithm", "Value");
+ }
+};
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/api/SwXDocumentIndex.cxx b/sw/qa/api/SwXDocumentIndex.cxx
new file mode 100644
index 000000000000..297b3a5899d8
--- /dev/null
+++ b/sw/qa/api/SwXDocumentIndex.cxx
@@ -0,0 +1,125 @@
+/* -*- 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 "BaseIndexTest.hxx"
+#include "DocumentIndexTest.hxx"
+#include "XDocumentIndexTest.hxx"
+#include "XTextContentTest.hxx"
+
+#include <test/bootstrapfixture.hxx>
+#include <unotest/macros_test.hxx>
+
+#include <com/sun/star/frame/Desktop.hpp>
+#include <com/sun/star/frame/DispatchHelper.hpp>
+
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+
+#include <com/sun/star/text/XTextDocument.hpp>
+#include <com/sun/star/text/XTextContent.hpp>
+#include <com/sun/star/text/XText.hpp>
+#include <com/sun/star/text/XTextCursor.hpp>
+#include <com/sun/star/text/XDocumentIndex.hpp>
+
+#include <comphelper/processfactory.hxx>
+#include <comphelper/propertysequence.hxx>
+
+using namespace css;
+
+namespace
+{
+/**
+ * Test for Java API test of file com.sun.star.comp.office.SwXDocumentIndex.csv
+ */
+class SwXDocumentIndexTest : public test::BootstrapFixture,
+ public unotest::MacrosTest,
+ public apitest::XDocumentIndexTest,
+ public apitest::BaseIndexTest,
+ public apitest::DocumentIndexTest,
+ public apitest::XTextContentTest
+{
+ uno::Reference<uno::XComponentContext> mxComponentContext;
+ uno::Reference<lang::XComponent> mxComponent;
+
+public:
+ virtual void setUp() override;
+ virtual void tearDown() override;
+
+ std::unordered_map<OUString, uno::Reference<uno::XInterface>> init() override;
+
+ CPPUNIT_TEST_SUITE(SwXDocumentIndexTest);
+ CPPUNIT_TEST(testGetServiceName);
+ CPPUNIT_TEST(testUpdate);
+ CPPUNIT_TEST(testBaseIndexProperties);
+ CPPUNIT_TEST(testDocumentIndexProperties);
+ CPPUNIT_TEST(testAttach);
+ CPPUNIT_TEST(testGetAnchor);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+void SwXDocumentIndexTest::setUp()
+{
+ test::BootstrapFixture::setUp();
+
+ mxComponentContext.set(comphelper::getComponentContext(getMultiServiceFactory()));
+ mxDesktop.set(frame::Desktop::create(mxComponentContext));
+}
+
+void SwXDocumentIndexTest::tearDown()
+{
+ if (mxComponent.is())
+ mxComponent->dispose();
+
+ test::BootstrapFixture::tearDown();
+}
+
+std::unordered_map<OUString, uno::Reference<uno::XInterface>> SwXDocumentIndexTest::init()
+{
+ std::unordered_map<OUString, uno::Reference<uno::XInterface>> map;
+
+ mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
+ CPPUNIT_ASSERT(mxComponent.is());
+
+ uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY_THROW);
+ uno::Reference<lang::XMultiServiceFactory> xFactory(xTextDocument, uno::UNO_QUERY_THROW);
+
+ uno::Reference<text::XDocumentIndex> xDocumentIndex(
+ xFactory->createInstance("com.sun.star.text.DocumentIndex"), uno::UNO_QUERY_THROW);
+
+ uno::Reference<text::XTextContent> xTextContent(xDocumentIndex, uno::UNO_QUERY_THROW);
+
+ uno::Reference<text::XText> xText = xTextDocument->getText();
+ uno::Reference<text::XTextCursor> xTextCursor = xText->createTextCursor();
+ CPPUNIT_ASSERT(xTextCursor.is());
+ xText->insertTextContent(xTextCursor, xTextContent, false);
+ xTextCursor->gotoEnd(false);
+
+ uno::Reference<text::XDocumentIndex> xDocumentIndexInstance(
+ xFactory->createInstance("com.sun.star.text.DocumentIndex"), uno::UNO_QUERY_THROW);
+
+ // XDocumentIndexTest
+ map["text::XDocumentIndex"] = xDocumentIndex;
+ map["text::XTextDocument"] = xTextDocument;
+ // BaseIndexTest
+ map["text::BaseIndex"] = xDocumentIndex;
+ // DocumentIndex
+ map["text::DocumentIndex"] = xDocumentIndex;
+ // XTextContentTest
+ map["text::XTextRange"] = xTextCursor;
+ map["text::XTextContent"] = xDocumentIndex;
+ map["text::XTextContent#Instance"] = xDocumentIndexInstance;
+
+ return map;
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SwXDocumentIndexTest);
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/api/XDocumentIndexTest.hxx b/sw/qa/api/XDocumentIndexTest.hxx
new file mode 100644
index 000000000000..65c677864563
--- /dev/null
+++ b/sw/qa/api/XDocumentIndexTest.hxx
@@ -0,0 +1,97 @@
+/* -*- 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/.
+ */
+
+#ifndef INCLUDED_SW_QA_API_XDOCUMENTINDEXTEST_HXX
+#define INCLUDED_SW_QA_API_XDOCUMENTINDEXTEST_HXX
+
+#include "ApiTestBase.hxx"
+
+#include <cppunit/TestAssert.h>
+
+#include <test/unoapi_property_testers.hxx>
+
+#include <com/sun/star/text/XTextDocument.hpp>
+#include <com/sun/star/text/XTextContent.hpp>
+#include <com/sun/star/text/XText.hpp>
+#include <com/sun/star/text/XDocumentIndex.hpp>
+
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+
+namespace apitest
+{
+class XDocumentIndexTest : public ApiTestBase
+{
+public:
+ /**
+ * Test calls the method. <p>
+ * Has <b> OK </b> status if the returned service name
+ * is equal to 'com.sun.star.text.DocumentIndex'.
+ */
+ void testGetServiceName()
+ {
+ auto inputMap = init();
+
+ css::uno::Reference<css::text::XDocumentIndex> xDocumentIndex(
+ inputMap["text::XDocumentIndex"], css::uno::UNO_QUERY_THROW);
+ CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.text.DocumentIndex"),
+ xDocumentIndex->getServiceName());
+ }
+
+ /**
+ * Gets the document from relation and insert a new index mark.
+ * Then it stores the text content of document index before
+ * update and after.<p>
+ *
+ * Has <b> OK </b> status if index content is changed and
+ * new index contains index mark inserted. <p>
+ */
+ void testUpdate()
+ {
+ auto inputMap = init();
+
+ css::uno::Reference<css::text::XDocumentIndex> xDocumentIndex(
+ inputMap["text::XDocumentIndex"], css::uno::UNO_QUERY_THROW);
+ css::uno::Reference<css::text::XTextDocument> xTextDocument(inputMap["text::XTextDocument"],
+ css::uno::UNO_QUERY_THROW);
+
+ bool bOK = true;
+ try
+ {
+ css::uno::Reference<css::text::XText> xText = xTextDocument->getText();
+ css::uno::Reference<css::text::XTextRange> xTextRange = xText->getEnd();
+ xTextRange->setString("IndexMark");
+ css::uno::Reference<css::lang::XMultiServiceFactory> xFactory(
+ xTextDocument, css::uno::UNO_QUERY_THROW);
+ css::uno::Reference<css::text::XTextContent> xTextContentMark(
+ xFactory->createInstance("com.sun.star.text.DocumentIndexMark"),
+ css::uno::UNO_QUERY_THROW);
+ xText->insertTextContent(xTextRange, xTextContentMark, true);
+ }
+ catch (css::uno::Exception /*exception*/)
+ {
+ bOK = false;
+ }
+
+ CPPUNIT_ASSERT_MESSAGE("Couldn't create the document index mark", bOK);
+
+ OUString sContentBefore = xDocumentIndex->getAnchor()->getString();
+ xDocumentIndex->update();
+ OUString sContentAfter = xDocumentIndex->getAnchor()->getString();
+
+ CPPUNIT_ASSERT_MESSAGE("Before and after shouldn't be equal",
+ sContentBefore != sContentAfter);
+ CPPUNIT_ASSERT_MESSAGE("Content after should contain string 'IndexMark'",
+ sContentAfter.indexOf("IndexMark") >= 0);
+ }
+};
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/api/XTextContentTest.hxx b/sw/qa/api/XTextContentTest.hxx
new file mode 100644
index 000000000000..4cb52d29db9b
--- /dev/null
+++ b/sw/qa/api/XTextContentTest.hxx
@@ -0,0 +1,62 @@
+/* -*- 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/.
+ */
+
+#ifndef INCLUDED_SW_QA_API_XTEXTCONTENTTEST_HXX
+#define INCLUDED_SW_QA_API_XTEXTCONTENTTEST_HXX
+
+#include "ApiTestBase.hxx"
+
+#include <cppunit/TestAssert.h>
+
+#include <test/unoapi_property_testers.hxx>
+
+#include <com/sun/star/text/XTextContent.hpp>
+#include <com/sun/star/text/XTextRange.hpp>
+
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+
+namespace apitest
+{
+class XTextContentTest : public ApiTestBase
+{
+public:
+ /**
+ * Tries to attach the text content to the test range
+ * gotten with getAnchor(). If relations are found
+ * then they are used for testing. <p>
+ *
+ * The test is OK if the method works without error.
+ */
+ void testAttach()
+ {
+ auto map = init();
+ css::uno::Reference<css::text::XTextContent> xTextContent(
+ map["text::XTextContent#Instance"], css::uno::UNO_QUERY_THROW);
+ css::uno::Reference<css::text::XTextRange> xTextRange(map["text::XTextRange"],
+ css::uno::UNO_QUERY_THROW);
+
+ if (xTextContent.is())
+ {
+ xTextContent->attach(xTextRange);
+ }
+ }
+
+ void testGetAnchor()
+ {
+ auto map = init();
+ css::uno::Reference<css::text::XTextContent> xTextContent(map["text::XTextContent"],
+ css::uno::UNO_QUERY_THROW);
+ CPPUNIT_ASSERT_EQUAL(OUString(""), xTextContent->getAnchor()->getString());
+ }
+};
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */