diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:54:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:54:39 +0000 |
commit | 267c6f2ac71f92999e969232431ba04678e7437e (patch) | |
tree | 358c9467650e1d0a1d7227a21dac2e3d08b622b2 /xmlscript/qa | |
parent | Initial commit. (diff) | |
download | libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.tar.xz libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.zip |
Adding upstream version 4:24.2.0.upstream/4%24.2.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xmlscript/qa')
-rw-r--r-- | xmlscript/qa/cppunit/data/EmptyPopupItems.xdl | 13 | ||||
-rw-r--r-- | xmlscript/qa/cppunit/data/test.xml | 123 | ||||
-rw-r--r-- | xmlscript/qa/cppunit/data/w3c.jpg | bin | 0 -> 2028 bytes | |||
-rw-r--r-- | xmlscript/qa/cppunit/test.cxx | 236 |
4 files changed, 372 insertions, 0 deletions
diff --git a/xmlscript/qa/cppunit/data/EmptyPopupItems.xdl b/xmlscript/qa/cppunit/data/EmptyPopupItems.xdl new file mode 100644 index 0000000000..827469e95a --- /dev/null +++ b/xmlscript/qa/cppunit/data/EmptyPopupItems.xdl @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE dlg:window PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "dialog.dtd"> +<dlg:window xmlns:dlg="http://openoffice.org/2000/dialog" xmlns:script="http://openoffice.org/2000/script" dlg:id="TestDialog" dlg:left="116" dlg:top="56" dlg:width="175" dlg:height="123" dlg:closeable="true" dlg:moveable="true"> + <dlg:bulletinboard> + <dlg:combobox dlg:id="ComboBox1" dlg:tab-index="0" dlg:left="9" dlg:top="15" dlg:width="92" dlg:height="15" dlg:spin="true"> + <dlg:menupopup> + <dlg:menuitem dlg:value="Eintrag1"/> + <dlg:menuitem dlg:value=""/> + <dlg:menuitem dlg:value="Eintrag2"/> + </dlg:menupopup> + </dlg:combobox> + </dlg:bulletinboard> +</dlg:window>
\ No newline at end of file diff --git a/xmlscript/qa/cppunit/data/test.xml b/xmlscript/qa/cppunit/data/test.xml new file mode 100644 index 0000000000..06e44309b1 --- /dev/null +++ b/xmlscript/qa/cppunit/data/test.xml @@ -0,0 +1,123 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE dialog:dialogs SYSTEM "../dtd/dialog.dtd"> +<!-- + * 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . +--> + +<window xmlns="http://openoffice.org/2000/dialog" + xmlns:dlg="http://openoffice.org/2000/dialog" + xmlns:script="http://openoffice.org/2000/script" + style-id="dialog" + id="window1" title="Test-Dialog" left="50" top="50" height="690" width="400" + closeable="true" moveable="true" resizeable="true" disabled="false" +> + + <script:event script:event-name="on-rowchange" script:macro-name="ExecutingMacro" script:location="application" script:language="StarBasic"/> + + <dlg:styles xmlns:dlg="http://openoffice.org/2000/dialog"> + <dlg:style style-id="bla" background-color="0xffffff" dlg:text-color="255" dlg:textline-color="0xff0000" dlg:font-underline="single"/> + <dlg:style style-id="bla3" background-color="888888" dlg:text-color="0xffffff" font-name="Arial" font-height="24" font-relief="embossed" font-emphasismark="dot"/> + <dlg:style style-id="no_border" border="none" fill-color="0xff"/> + <dlg:style style-id="dialog" border="3d" dlg:text-color="255" dlg:textline-color="0xff0000"/> + </dlg:styles> + + <dlg:bulletinboard xmlns:ns="http://www.fake" xmlns:dlg="http://openoffice.org/2000/dialog"> + + <button dlg:id="button1" ns:value="hallo" dlg:left="50" ns:top="50" ns:checked="true" width="50" height="50" style-id="bla3" xmlns:ns="http://openoffice.org/2000/dialog"> + <dlg:event listener-type="com.sun.star.awt.XKeyListener" event-method="keyReleased" script-type="StarBasic" script-code="application:ExecutingMacro"/> + <script:event script:event-name="on-rowchange" script:macro-name="ExecutingMacro" script:location="application" script:language="StarBasic"/> + <script:listener-event script:macro-name="ExecutingMacro" script:location="application" script:language="StarBasic" script:listener-type="com.sun.star.awt.XMouseListener" script:listener-method="mouseEntered"/> + <script:listener-event script:macro-name="ExecutingMacro" script:location="application" script:language="StarBasic" script:listener-type="com.sun.star.awt.XMouseListener" script:listener-method="mousePressed" script:listener-param="parameter0, so this will never ever be a script:event, but always a script:listener-event element!"/> + </button> + + <button dlg:id="button3" dlg:image-src="file:///f|src641/xmlscript/test/w3c.jpg" dlg:image-align="right" ns:value="help button" dlg:left="250" ns:top="50" width="50" height="50" style-id="bla" button-type="help" xmlns:ns="http://openoffice.org/2000/dialog"/> + + <checkbox id="check1" help-text="helphelphelp!!!" help-url="http://www.xml.org" value="checked" left="50" top="150" width="100" height="20" checked="true"/> + <checkbox id="check2" value="dontknow" left="50" top="170" width="100" height="20" tristate="true"/> + <checkbox id="check3" value="tristate_checked" left="50" top="190" width="100" height="20" checked="true" tristate="true"/> + + <menulist id="list1" multiselection="true" left="50" top="400" width="100" height="100"> + <menupopup> + <menuitem value="item1"/> + <menuitem value="item2 sel" selected="true"/> + <menuitem value="item3 sel" selected="true"/> + </menupopup> + </menulist> + + <dlg:menulist id="list2" left="250" top="400" width="100" height="100"> + <menupopup> + <menuitem value="item4" selected="false"/> + <menuitem value="item5 sel" selected="true"/> + <menuitem value="item6"/> + </menupopup> + </dlg:menulist> + + <combobox id="combo1" value="combotext1" left="250" top="150" width="50" height="50"> + <menupopup> + <menuitem value="Citem1"/> + <menuitem value="Citem2"/> + </menupopup> + </combobox> + + <combobox id="combo2" value="combotext2" left="310" top="150" width="50" height="50" spin="true"> + <menupopup> + <menuitem value="Citem3"/> + <menuitem value="Citem4"/> + </menupopup> + </combobox> + + <radiogroup> + <radio id="radio1" value="default radio" left="50" top="250" width="100" height="20"/> + <radio id="radio2" value="checked" left="50" top="270" width="100" height="20" checked="true"/> + <radio id="radio3" value="unchecked" left="50" top="290" width="100" height="20" checked="false"/> + </radiogroup> + + <titledbox id="groupbox1" left="250" top="250" width="120" height="100"> + <script:listener-event script:macro-name="ExecutingMacro" script:location="application" script:language="StarBasic" script:listener-type="com.sun.star.awt.XMouseListener" script:listener-method="mouseEntered"/> + <title value="grouped"/> + <radio id="radio5" value="default radio" left="5" top="15" width="100" height="20"/> + <radio id="radio7" value="unchecked" left="5" top="35" width="100" height="20" checked="false"/> + <radio id="radio8" value="checked" left="5" top="55" width="100" height="20" checked="true"/> + </titledbox> + + <text id="fixed1" left="50" top="520" width="180" height="20" value="fixed text is here..." multiline="true" align="center"> + <script:listener-event script:macro-name="ExecutingMacro" script:location="application" script:language="StarBasic" script:listener-type="com.sun.star.awt.XMouseListener" script:listener-method="mouseEntered"/> + </text> + <textfield id="field1" left="250" top="520" width="50" height="40" value="edit no text here..." readonly="true" vscroll="true" multiline="true" align="right" style-id="no_border"/> + <textfield id="field2" left="320" top="520" width="50" height="40" value="hidden text" hscroll="true" echochar="*" align="left"/> + <img id="image1" scale-image="true" left="50" top="585" width="80" height="20" src="file:///f|src641/xmlscript/test/w3c.jpg"> + <script:listener-event script:macro-name="ExecutingMacro" script:location="application" script:language="StarBasic" script:listener-type="com.sun.star.awt.XMouseListener" script:listener-method="mouseEntered"/> + </img> + <filecontrol id="file1" left="150" top="585" width="100" height="20" value="../../test/w3c.jpg"/> + + <datefield id="datefield1" left="20" top="610" width="100" height="20" show-century="false" date-format="short_DDMMYY" spin="true" value="20010301"/> + <timefield id="time1" left="20" top="635" width="100" height="20" time-format="24h_long" value-min="0" value-max="24000000" strict-format="true" value="12000000" spin="true"/> + <patternfield id="pattern1" maxlength="4" left="20" top="0" width="100" height="20" value="pattern" strict-format="true" readonly="true"/> + <currencyfield id="currency1" left="200" top="610" width="100" height="20" value="5.6075" value-min="0.5" value-max="10.0" value-step="0.1" spin="true" thousands-separator="true" currency-symbol="$" prepend-symbol="true"/> + <numericfield id="numeric1" left="200" top="635" width="100" height="20" value="5.6075" value-min="0.5" value-max="10.0" value-step="0.1" thousands-separator="true"/> + <fixedline style-id="bla3" id="fixedline1" left="20" top="660" width="150" height="20" value="FixedLineLabel" align="horizontal"/> + <progressmeter style-id="no_border" id="progress1" left="200" top="660" width="80" height="20" align="horizontal" value="50" value-min="0" value-max="80"/> + <scrollbar style-id="dialog" id="scrollbar1" left="300" top="660" width="80" height="20" align="horizontal" curpos="50" maxpos="200" increment="1" pageincrement="10"/> + + <formattedfield style-id="dialog" treat-as-number="true" id="ffield0" left="20" top="110" width="80" height="20" align="center" text="first ffield" + dlg:value-max="750" dlg:value-min="0" dlg:value="2" spin="true"/> + <formattedfield style-id="dialog" id="ffield1" left="250" top="110" width="80" height="20" align="center" text="second ffield" + dlg:format-code="[$$-409]#.##0,00;[ROT]-[$$-409]#.##0,00" dlg:format-locale="de;DE;WIN" dlg:value-max="750" dlg:value-min="0" dlg:value="4" spin="true"/> + + </dlg:bulletinboard> + +</window> diff --git a/xmlscript/qa/cppunit/data/w3c.jpg b/xmlscript/qa/cppunit/data/w3c.jpg Binary files differnew file mode 100644 index 0000000000..c541c20dcd --- /dev/null +++ b/xmlscript/qa/cppunit/data/w3c.jpg diff --git a/xmlscript/qa/cppunit/test.cxx b/xmlscript/qa/cppunit/test.cxx new file mode 100644 index 0000000000..f29c9bb7ba --- /dev/null +++ b/xmlscript/qa/cppunit/test.cxx @@ -0,0 +1,236 @@ +/* -*- 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 <test/xmltesttools.hxx> +#include <unotest/macros_test.hxx> +#include <unotools/tempfile.hxx> + +#include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/frame/DispatchHelper.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XInputStreamProvider.hpp> +#include <com/sun/star/io/XOutputStream.hpp> + +#include <comphelper/processfactory.hxx> +#include <comphelper/propertysequence.hxx> + +#include <config_folders.h> +#include <osl/file.hxx> +#include <rtl/ustrbuf.hxx> +#include <rtl/byteseq.hxx> +#include <sal/log.hxx> + +#include <xmlscript/xmldlg_imexp.hxx> +#include <xmlscript/xml_helper.hxx> +#include <cppuhelper/bootstrap.hxx> + +using namespace ::cppu; +using namespace ::com::sun::star::uno; + +using namespace ::com::sun::star; + +/// Sample tests for import +class XmlScriptTest : public test::BootstrapFixture, public unotest::MacrosTest, public XmlTestTools +{ + OUString maDataPath; + + void testBasicElements(); + void testEmptyPopupItems(); + + Reference<container::XNameContainer> importFile(std::u16string_view sFileName); + void exportToFile(std::u16string_view sFileName, + Reference<container::XNameContainer> const& xDialogModel); + +public: + virtual void setUp() override; + + virtual void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) override + { + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("dlg"), + BAD_CAST("http://openoffice.org/2000/dialog")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("script"), + BAD_CAST("http://openoffice.org/2000/script")); + } + CPPUNIT_TEST_SUITE(XmlScriptTest); + CPPUNIT_TEST(testBasicElements); + CPPUNIT_TEST(testEmptyPopupItems); + CPPUNIT_TEST_SUITE_END(); +}; + +void XmlScriptTest::setUp() +{ + test::BootstrapFixture::setUp(); + maDataPath = "/xmlscript/qa/cppunit/data/"; + + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +Reference<container::XNameContainer> XmlScriptTest::importFile(std::u16string_view sFileName) +{ + OUString sFullName = m_directories.getURLFromSrc(maDataPath) + sFileName; + osl::File aFile(sFullName); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, aFile.open(osl_File_OpenFlag_Read)); + sal_uInt64 nBytes; + aFile.getSize(nBytes); + std::vector<sal_Int8> bytes(nBytes); + sal_uInt64 nBytesRead; + aFile.read(bytes.data(), nBytes, nBytesRead); + CPPUNIT_ASSERT_EQUAL_MESSAGE("File not read correctly", nBytes, nBytesRead); + aFile.close(); + + Reference<container::XNameContainer> xDialogModel( + mxComponentContext->getServiceManager()->createInstanceWithContext( + "com.sun.star.awt.UnoControlDialogModel", mxComponentContext), + UNO_QUERY); + + ::xmlscript::importDialogModel(::xmlscript::createInputStream(std::move(bytes)), xDialogModel, + mxComponentContext, nullptr); + + Reference<lang::XComponent> xDialogModelComp(xDialogModel, UNO_QUERY); + if (xDialogModelComp) + xDialogModelComp->dispose(); + + return xDialogModel; +} + +void XmlScriptTest::exportToFile(std::u16string_view sURL, + Reference<container::XNameContainer> const& xDialogModel) +{ + Reference<io::XInputStreamProvider> xProvider( + ::xmlscript::exportDialogModel(xDialogModel, mxComponentContext, nullptr)); + Reference<io::XInputStream> xStream(xProvider->createInputStream()); + + Sequence<sal_Int8> bytes; + sal_Int32 nRead = xStream->readBytes(bytes, xStream->available()); + for (;;) + { + Sequence<sal_Int8> readBytes; + nRead = xStream->readBytes(readBytes, 1024); + if (!nRead) + break; + + sal_Int32 nPos = bytes.getLength(); + bytes.realloc(nPos + nRead); + memcpy(bytes.getArray() + nPos, readBytes.getConstArray(), static_cast<sal_uInt32>(nRead)); + } + + osl::File aFile(OUString{ sURL }); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, aFile.open(osl_File_OpenFlag_Write)); + sal_uInt64 nBytesWritten; + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, + aFile.write(bytes.getConstArray(), bytes.getLength(), nBytesWritten)); + aFile.close(); +} + +void XmlScriptTest::testBasicElements() +{ + // Import + Reference<container::XNameContainer> xModel(importFile(u"test.xml")); + CPPUNIT_ASSERT(xModel.is()); + + // Export + utl::TempFileNamed aTempFile; + aTempFile.EnableKillingFile(); + exportToFile(aTempFile.GetURL(), xModel); + + // Parse & check + xmlDocUniquePtr pXmlDoc = parseXml(aTempFile); + CPPUNIT_ASSERT(pXmlDoc); + + // Ensure we have all elements + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:button[1]"_ostr, "id"_ostr, "button1"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:button[2]"_ostr, "id"_ostr, "button3"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:checkbox[1]"_ostr, "id"_ostr, "check1"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:checkbox[2]"_ostr, "id"_ostr, "check2"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:checkbox[3]"_ostr, "id"_ostr, "check3"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:menulist[1]"_ostr, "id"_ostr, "list1"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:menulist[2]"_ostr, "id"_ostr, "list2"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:combobox[1]"_ostr, "id"_ostr, "combo1"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:radiogroup[1]/dlg:radio[1]"_ostr, + "id"_ostr, "radio1"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:radiogroup[1]/dlg:radio[2]"_ostr, + "id"_ostr, "radio2"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:radiogroup[1]/dlg:radio[3]"_ostr, + "id"_ostr, "radio3"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:titledbox[1]"_ostr, "id"_ostr, + "groupbox1"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:radiogroup[2]/dlg:radio[1]"_ostr, + "id"_ostr, "radio5"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:radiogroup[2]/dlg:radio[2]"_ostr, + "id"_ostr, "radio7"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:radiogroup[2]/dlg:radio[3]"_ostr, + "id"_ostr, "radio8"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:text[1]"_ostr, "id"_ostr, "fixed1"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:textfield[1]"_ostr, "id"_ostr, + "field1"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:textfield[2]"_ostr, "id"_ostr, + "field2"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:img[1]"_ostr, "id"_ostr, "image1"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:filecontrol[1]"_ostr, "id"_ostr, + "file1"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:datefield[1]"_ostr, "id"_ostr, + "datefield1"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:timefield[1]"_ostr, "id"_ostr, "time1"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:patternfield[1]"_ostr, "id"_ostr, + "pattern1"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:currencyfield[1]"_ostr, "id"_ostr, + "currency1"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:numericfield[1]"_ostr, "id"_ostr, + "numeric1"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:fixedline[1]"_ostr, "id"_ostr, + "fixedline1"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:progressmeter[1]"_ostr, "id"_ostr, + "progress1"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:scrollbar[1]"_ostr, "id"_ostr, + "scrollbar1"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:formattedfield[1]"_ostr, "id"_ostr, + "ffield0"); + assertXPath(pXmlDoc, "/dlg:window/dlg:bulletinboard/dlg:formattedfield[2]"_ostr, "id"_ostr, + "ffield1"); + + Reference<lang::XComponent> xDialogModelComp(xModel, UNO_QUERY); + if (xDialogModelComp) + xDialogModelComp->dispose(); +} + +void XmlScriptTest::testEmptyPopupItems() +{ + // Import + Reference<container::XNameContainer> xModel(importFile(u"EmptyPopupItems.xdl")); + CPPUNIT_ASSERT(xModel.is()); + + // Export + utl::TempFileNamed aTempFile; + aTempFile.EnableKillingFile(); + exportToFile(aTempFile.GetURL(), xModel); + + // Parse & check + xmlDocUniquePtr pXmlDoc = parseXml(aTempFile); + CPPUNIT_ASSERT(pXmlDoc); + + // Ensure we have 3 items in combobox after import/export and second one is empty + assertXPath(pXmlDoc, + "/dlg:window/dlg:bulletinboard/dlg:combobox/dlg:menupopup/dlg:menuitem[1]"_ostr, + "value"_ostr, "Eintrag1"); + assertXPath(pXmlDoc, + "/dlg:window/dlg:bulletinboard/dlg:combobox/dlg:menupopup/dlg:menuitem[2]"_ostr, + "value"_ostr, ""); + assertXPath(pXmlDoc, + "/dlg:window/dlg:bulletinboard/dlg:combobox/dlg:menupopup/dlg:menuitem[3]"_ostr, + "value"_ostr, "Eintrag2"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(XmlScriptTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |