summaryrefslogtreecommitdiff
path: root/sw/qa/api
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2019-01-06 21:59:21 +0100
committerTomaž Vajngerl <quikee@gmail.com>2019-01-10 20:11:21 +0100
commit4631c5d4c129b826df1cc29af1a558149b823667 (patch)
tree202dbb3ff7016f25360d9488f1860cd198f8f091 /sw/qa/api
parent647ad220295e16e05333e4eb801e1c8eac2d77f9 (diff)
DocumentSettings Writer UNO API test (converted from Java test)
Change-Id: Id9a691b1aae62f37ef7f865c5ed015b7c6a13976 Reviewed-on: https://gerrit.libreoffice.org/65909 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sw/qa/api')
-rw-r--r--sw/qa/api/ApiTestBase.hxx29
-rw-r--r--sw/qa/api/DocumentSettings.cxx99
-rw-r--r--sw/qa/api/DocumentSettingsTest.hxx49
-rw-r--r--sw/qa/api/PrinterSettingsTest.hxx81
-rw-r--r--sw/qa/api/SettingsTest.hxx140
5 files changed, 398 insertions, 0 deletions
diff --git a/sw/qa/api/ApiTestBase.hxx b/sw/qa/api/ApiTestBase.hxx
index 76871111ff3f..fc25bc3122be 100644
--- a/sw/qa/api/ApiTestBase.hxx
+++ b/sw/qa/api/ApiTestBase.hxx
@@ -11,6 +11,9 @@
#define INCLUDED_SW_QA_CORE_APITESTBASE_HXX
#include <com/sun/star/uno/XInterface.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/beans/XPropertySetInfo.hpp>
+#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <unordered_map>
@@ -19,6 +22,32 @@ namespace apitest
class ApiTestBase
{
protected:
+ static bool extstsProperty(css::uno::Reference<css::beans::XPropertySet> const& rxPropertySet,
+ OUString const& rPropertyName)
+ {
+ css::uno::Reference<css::beans::XPropertySetInfo> xPropertySetInfo(
+ rxPropertySet->getPropertySetInfo());
+ return xPropertySetInfo->hasPropertyByName(rPropertyName);
+ }
+
+ static bool
+ isPropertyReadOnly(css::uno::Reference<css::beans::XPropertySet> const& rxPropertySet,
+ OUString const& rPropertyName)
+ {
+ css::uno::Reference<css::beans::XPropertySetInfo> xPropertySetInfo(
+ rxPropertySet->getPropertySetInfo());
+ css::uno::Sequence<css::beans::Property> xProperties = xPropertySetInfo->getProperties();
+
+ for (auto const& rProperty : xProperties)
+ {
+ if (rProperty.Name == rPropertyName)
+ return (rProperty.Attributes & com::sun::star::beans::PropertyAttribute::READONLY)
+ != 0;
+ }
+
+ return false;
+ }
+
virtual ~ApiTestBase() {}
virtual std::unordered_map<OUString, css::uno::Reference<css::uno::XInterface>> init() = 0;
diff --git a/sw/qa/api/DocumentSettings.cxx b/sw/qa/api/DocumentSettings.cxx
new file mode 100644
index 000000000000..901730d0d65d
--- /dev/null
+++ b/sw/qa/api/DocumentSettings.cxx
@@ -0,0 +1,99 @@
+/* -*- 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 <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/uno/XInterface.hpp>
+
+#include <comphelper/processfactory.hxx>
+
+#include "DocumentSettingsTest.hxx"
+#include "SettingsTest.hxx"
+#include "PrinterSettingsTest.hxx"
+
+using namespace css;
+
+namespace
+{
+/**
+ * Test for Java API test of file com.sun.star.comp.Writer.DocumentSettings.csv
+ */
+class DocumentSettingsTest : public test::BootstrapFixture,
+ public unotest::MacrosTest,
+ public apitest::DocumentSettingsTest,
+ public apitest::SettingsTest,
+ public apitest::PrinterSettingsTest
+{
+private:
+ 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(DocumentSettingsTest);
+ CPPUNIT_TEST(testDocumentSettingsProperties);
+ CPPUNIT_TEST(testSettingsProperties);
+ CPPUNIT_TEST(testPrinterSettingsProperties);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+void DocumentSettingsTest::setUp()
+{
+ test::BootstrapFixture::setUp();
+
+ mxComponentContext.set(comphelper::getComponentContext(getMultiServiceFactory()));
+ mxDesktop.set(frame::Desktop::create(mxComponentContext));
+}
+
+void DocumentSettingsTest::tearDown()
+{
+ if (mxComponent.is())
+ mxComponent->dispose();
+
+ test::BootstrapFixture::tearDown();
+}
+
+std::unordered_map<OUString, uno::Reference<uno::XInterface>> DocumentSettingsTest::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<uno::XInterface> xDocumentSettings(
+ xFactory->createInstance("com.sun.star.text.DocumentSettings"), uno::UNO_QUERY_THROW);
+
+ // DocumentSettings
+ map["text::DocumentSettings"] = xDocumentSettings;
+ // Settings
+ map["document::Settings"] = xDocumentSettings;
+ // Printer Settings
+ map["text::PrinterSettings"] = xDocumentSettings;
+ return map;
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(DocumentSettingsTest);
+
+} // end anonymous namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/api/DocumentSettingsTest.hxx b/sw/qa/api/DocumentSettingsTest.hxx
new file mode 100644
index 000000000000..35508e0d74a6
--- /dev/null
+++ b/sw/qa/api/DocumentSettingsTest.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_DOCUMENTSETTINGSTEST_HXX
+#define INCLUDED_SW_QA_API_DOCUMENTSETTINGSTEST_HXX
+
+#include "ApiTestBase.hxx"
+
+#include <cppunit/TestAssert.h>
+#include <test/unoapi_property_testers.hxx>
+
+#include <com/sun/star/beans/XPropertySet.hpp>
+
+namespace apitest
+{
+class DocumentSettingsTest : public ApiTestBase
+{
+public:
+ void testDocumentSettingsProperties()
+ {
+ auto map = init();
+
+ css::uno::Reference<css::beans::XPropertySet> xDocumentSettings(
+ map["text::DocumentSettings"], css::uno::UNO_QUERY_THROW);
+
+ testBooleanOptionalProperty(xDocumentSettings, "ChartAutoUpdate");
+ testBooleanOptionalProperty(xDocumentSettings, "AddParaTableSpacing");
+ testBooleanOptionalProperty(xDocumentSettings, "AddParaTableSpacingAtStart");
+ testBooleanOptionalProperty(xDocumentSettings, "AlignTabStopPosition");
+ testBooleanOptionalProperty(xDocumentSettings, "SaveGlobalDocumentLinks");
+ testBooleanOptionalProperty(xDocumentSettings, "IsLabelDocument");
+ testBooleanOptionalProperty(xDocumentSettings, "UseFormerLineSpacing");
+ testBooleanOptionalProperty(xDocumentSettings, "AddParaSpacingToTableCells");
+ testBooleanOptionalProperty(xDocumentSettings, "UseFormerObjectPositioning");
+ testBooleanOptionalProperty(xDocumentSettings, "ConsiderTextWrapOnObjPos");
+ testBooleanOptionalProperty(xDocumentSettings, "MathBaselineAlignment");
+ }
+};
+} // end namespace apitest
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/api/PrinterSettingsTest.hxx b/sw/qa/api/PrinterSettingsTest.hxx
new file mode 100644
index 000000000000..7e8e157af0b2
--- /dev/null
+++ b/sw/qa/api/PrinterSettingsTest.hxx
@@ -0,0 +1,81 @@
+/* -*- 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_PRINTERSETTINGSTEST_HXX
+#define INCLUDED_SW_QA_API_PRINTERSETTINGSTEST_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/NotePrintMode.hpp>
+
+namespace apitest
+{
+class PrinterSettingsTest : public ApiTestBase
+{
+ static void
+ testPrintAnnotationMode(css::uno::Reference<css::beans::XPropertySet> const& rxPrinterSettings)
+ {
+ const OUString rPropertyName = "PrintAnnotationMode";
+
+ // This property is not optional but it's not set in some cases
+ if (!extstsProperty(rxPrinterSettings, rPropertyName))
+ return;
+
+ /*css::text::NotePrintMode aNotePrintMode_Get;
+
+ CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue",
+ rxPrinterSettings->getPropertyValue(rPropertyName)
+ >>= aNotePrintMode_Get);
+
+ css::text::NotePrintMode aNotePrintMode_Set;
+ css::uno::Any aNewValue;
+ aNewValue <<= css::text::NotePrintMode_ONLY;
+ rxPrinterSettings->setPropertyValue(rPropertyName, aNewValue);
+
+ CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue",
+ rxPrinterSettings->getPropertyValue(rPropertyName)
+ >>= aNotePrintMode_Set);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue", css::text::NotePrintMode_ONLY,
+ aNotePrintMode_Set);*/
+ }
+
+public:
+ void testPrinterSettingsProperties()
+ {
+ auto map = init();
+
+ css::uno::Reference<css::beans::XPropertySet> xPrinterSettings(map["text::PrinterSettings"],
+ css::uno::UNO_QUERY_THROW);
+
+ testBooleanProperty(xPrinterSettings, "PrintGraphics");
+ testBooleanProperty(xPrinterSettings, "PrintTables");
+ testBooleanProperty(xPrinterSettings, "PrintDrawings");
+ testBooleanProperty(xPrinterSettings, "PrintLeftPages");
+ testBooleanProperty(xPrinterSettings, "PrintRightPages");
+ testBooleanProperty(xPrinterSettings, "PrintControls");
+ testBooleanProperty(xPrinterSettings, "PrintReversed");
+ testBooleanProperty(xPrinterSettings, "PrintControls");
+ testStringProperty(xPrinterSettings, "PrintFaxName", "FaxName");
+ testPrintAnnotationMode(
+ xPrinterSettings); // it's not set in this case but it's not optional - bug?
+ testBooleanProperty(xPrinterSettings, "PrintProspect");
+ testBooleanProperty(xPrinterSettings, "PrintPageBackground");
+ testBooleanProperty(xPrinterSettings, "PrintBlackFonts");
+ testBooleanOptionalProperty(xPrinterSettings, "PrintEmptyPages");
+ }
+};
+} // end namespace apitest
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/api/SettingsTest.hxx b/sw/qa/api/SettingsTest.hxx
new file mode 100644
index 000000000000..73cfcfddecf2
--- /dev/null
+++ b/sw/qa/api/SettingsTest.hxx
@@ -0,0 +1,140 @@
+/* -*- 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_SETTINGSTEST_HXX
+#define INCLUDED_SW_QA_API_SETTINGSTEST_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/i18n/XForbiddenCharacters.hpp>
+
+namespace apitest
+{
+class SettingsTest : public ApiTestBase
+{
+ // [property] string PrinterName;
+ static void testPrinterName(css::uno::Reference<css::beans::XPropertySet> const& rxSettings)
+ {
+ const OUString rPropertyName("PrinterName");
+
+ if (!extstsProperty(rxSettings, rPropertyName))
+ return; // Property is sometimes not set - bug? it is not defined as optional
+
+ OUString aPrinterName_Get;
+
+ CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue",
+ rxSettings->getPropertyValue(rPropertyName) >>= aPrinterName_Get);
+
+ OUString aPrinterName_Set;
+ css::uno::Any aNewValue;
+ aNewValue <<= aPrinterName_Get;
+ rxSettings->setPropertyValue(rPropertyName, aNewValue);
+
+ CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue",
+ rxSettings->getPropertyValue(rPropertyName) >>= aPrinterName_Set);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue", aPrinterName_Get,
+ aPrinterName_Set);
+ }
+
+ // [optional, property] short PrinterIndependentLayout;
+ static void
+ testPrinterIndependentLayout(css::uno::Reference<css::beans::XPropertySet> const& rxSettings)
+ {
+ const OUString rPropertyName("PrinterIndependentLayout");
+
+ if (!extstsProperty(rxSettings, rPropertyName))
+ return; // Property is optional
+
+ sal_Int16 aValue_Get;
+
+ CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue",
+ rxSettings->getPropertyValue(rPropertyName) >>= aValue_Get);
+
+ sal_Int16 aValue_New;
+ aValue_New = (aValue_Get == 1 ? 3 : 1);
+ rxSettings->setPropertyValue(rPropertyName, css::uno::Any(aValue_New));
+
+ sal_Int16 aValue_Set;
+
+ CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue",
+ rxSettings->getPropertyValue(rPropertyName) >>= aValue_Set);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue", aValue_New, aValue_Set);
+ }
+
+ // [optional, property] com::sun::star::i18n::XForbiddenCharacters ForbiddenCharacters;
+ static void
+ testForbiddenCharacters(css::uno::Reference<css::beans::XPropertySet> const& rxSettings)
+ {
+ const OUString rPropertyName("ForbiddenCharacters");
+
+ if (!extstsProperty(rxSettings, rPropertyName))
+ return; // Property is optional
+
+ CPPUNIT_ASSERT_MESSAGE("Property is read-only but shouldn't be",
+ !isPropertyReadOnly(rxSettings, rPropertyName));
+
+ css::uno::Reference<css::i18n::XForbiddenCharacters> aValue_Get;
+
+ CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue",
+ rxSettings->getPropertyValue(rPropertyName) >>= aValue_Get);
+ CPPUNIT_ASSERT_MESSAGE("Empty reference to XForbiddenCharacters", aValue_Get.is());
+ }
+
+public:
+ void testSettingsProperties()
+ {
+ auto map = init();
+
+ css::uno::Reference<css::beans::XPropertySet> xSettings(map["document::Settings"],
+ css::uno::UNO_QUERY_THROW);
+
+ testForbiddenCharacters(xSettings);
+ //testShortOptionalProperty(xSettings, "LinkUpdateMode");
+ testPrinterName(xSettings);
+ // [property] sequence< byte > PrinterSetup;
+ testBooleanOptionalProperty(xSettings, "IsKernAsianPunctuation");
+ //testShortOptionalProperty(xSettings, "CharacterCompressionType");
+ testBooleanOptionalProperty(xSettings, "ApplyUserData");
+ testBooleanOptionalProperty(xSettings, "SaveVersionOnClose");
+ testBooleanOptionalProperty(xSettings, "UpdateFromTemplate");
+ testBooleanOptionalProperty(xSettings, "FieldAutoUpdate");
+ testStringOptionalProperty(xSettings, "CurrentDatabaseDataSource");
+ testStringOptionalProperty(xSettings, "CurrentDatabaseCommand");
+ testLongOptionalProperty(xSettings, "CurrentDatabaseCommandType");
+ testLongOptionalProperty(xSettings, "DefaultTabStop");
+ testBooleanOptionalProperty(xSettings, "IsPrintBooklet");
+ testBooleanOptionalProperty(xSettings, "IsPrintBookletFront");
+ testBooleanOptionalProperty(xSettings, "IsPrintBookletBack");
+ testLongOptionalProperty(xSettings, "PrintQuality");
+ testStringOptionalProperty(xSettings, "ColorTableURL");
+ testStringOptionalProperty(xSettings, "DashTableURL");
+ testStringOptionalProperty(xSettings, "LineEndTableURL");
+ testStringOptionalProperty(xSettings, "HatchTableURL");
+ testStringOptionalProperty(xSettings, "GradientTableURL");
+ testStringOptionalProperty(xSettings, "BitmapTableURL");
+ testBooleanOptionalProperty(xSettings, "AutoCalculate");
+ testPrinterIndependentLayout(xSettings);
+ testBooleanOptionalProperty(xSettings, "AddExternalLeading");
+ testBooleanOptionalProperty(xSettings, "EmbedFonts");
+ testBooleanOptionalProperty(xSettings, "EmbedSystemFonts");
+ testBooleanOptionalProperty(xSettings, "EmbedOnlyUsedFonts");
+ testBooleanOptionalProperty(xSettings, "EmbedLatinScriptFonts");
+ testBooleanOptionalProperty(xSettings, "EmbedAsianScriptFonts");
+ testBooleanOptionalProperty(xSettings, "EmbedComplexScriptFonts");
+ }
+};
+} // end namespace apitest
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */