diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
commit | 940b4d1848e8c70ab7642901a68594e8016caffc (patch) | |
tree | eb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /xmlscript/test | |
parent | Initial commit. (diff) | |
download | libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip |
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xmlscript/test')
-rw-r--r-- | xmlscript/test/imexp.cxx | 209 | ||||
-rw-r--r-- | xmlscript/test/makefile.mk | 56 | ||||
-rw-r--r-- | xmlscript/test/test.xml | 123 | ||||
-rw-r--r-- | xmlscript/test/w3c.jpg | bin | 0 -> 2028 bytes |
4 files changed, 388 insertions, 0 deletions
diff --git a/xmlscript/test/imexp.cxx b/xmlscript/test/imexp.cxx new file mode 100644 index 000000000..d4dfd1679 --- /dev/null +++ b/xmlscript/test/imexp.cxx @@ -0,0 +1,209 @@ +/* -*- 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/. + * + * 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 . + */ + +#include <config_folders.h> + +#include <stdio.h> +#include <osl/file.h> + +#include <rtl/ustrbuf.hxx> +#include <sal/log.hxx> + +#include <xmlscript/xmldlg_imexp.hxx> +#include <xmlscript/xml_helper.hxx> + +#include <cppuhelper/servicefactory.hxx> +#include <cppuhelper/bootstrap.hxx> + +#include <comphelper/processfactory.hxx> + +#include <vcl/svapp.hxx> + +#include <com/sun/star/awt/UnoControlDialog.hpp> +#include <com/sun/star/awt/Toolkit.hpp> +#include <com/sun/star/awt/XToolkit.hpp> +#include <com/sun/star/awt/XControlModel.hpp> +#include <com/sun/star/awt/XControl.hpp> +#include <com/sun/star/awt/XDialog.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/io/XActiveDataSource.hpp> +#include <com/sun/star/registry/XSimpleRegistry.hpp> +#include <com/sun/star/registry/XImplementationRegistration.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> + +using namespace ::cppu; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +Reference< XComponentContext > createInitialComponentContext( + OUString const & inst_dir ) +{ + Reference< XComponentContext > xContext; + + try + { + OUString file_url; + oslFileError rc = osl_getFileURLFromSystemPath( + inst_dir.pData, &file_url.pData ); + OSL_ASSERT( osl_File_E_None == rc ); + + OUString unorc = file_url + ("/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("louno") ); + + return defaultBootstrap_InitialComponentContext( unorc ); + } + + catch( const Exception& rExc ) + { + SAL_WARN( "xmlscript", rExc ); + } + + return xContext; +} + +Reference< container::XNameContainer > importFile( + char const * fname, + Reference< XComponentContext > const & xContext ) +{ + // create the input stream + FILE *f = ::fopen( fname, "rb" ); + if (f) + { + ::fseek( f, 0 ,SEEK_END ); + int nLength = ::ftell( f ); + ::fseek( f, 0, SEEK_SET ); + + ByteSequence bytes( nLength ); + ::fread( bytes.getArray(), nLength, 1, f ); + ::fclose( f ); + + Reference< container::XNameContainer > xModel( xContext->getServiceManager()->createInstanceWithContext( + "com.sun.star.awt.UnoControlDialogModel", xContext ), UNO_QUERY ); + ::xmlscript::importDialogModel( ::xmlscript::createInputStream( bytes ), xModel, xContext ); + + return xModel; + } + else + { + throw Exception( "### Cannot read file!" ); + } +} + +void exportToFile( + char const * fname, + Reference< container::XNameContainer > const & xModel, + Reference< XComponentContext > const & xContext ) +{ + Reference< io::XInputStreamProvider > xProvider( ::xmlscript::exportDialogModel( xModel, xContext ) ); + 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; + OSL_ASSERT( readBytes.getLength() >= nRead ); + + sal_Int32 nPos = bytes.getLength(); + bytes.realloc( nPos + nRead ); + memcpy( bytes.getArray() + nPos, readBytes.getConstArray(), (sal_uInt32)nRead ); + } + + FILE * f = ::fopen( fname, "w" ); + ::fwrite( bytes.getConstArray(), 1, bytes.getLength(), f ); + ::fclose( f ); +} + +class MyApp : public Application +{ +public: + void Main(); +}; + +MyApp aMyApp; + +void MyApp::Main() +{ + if (GetCommandLineParamCount() < 2) + { + OSL_FAIL( "usage: imexp inst_dir inputfile [outputfile]" ); + return; + } + + Reference< XComponentContext > xContext( + createInitialComponentContext( OUString( GetCommandLineParam( 0 ) ) ) ); + Reference< lang::XMultiServiceFactory > xMSF( + xContext->getServiceManager(), UNO_QUERY ); + + try + { + ::comphelper::setProcessServiceFactory( xMSF ); + + Reference< awt::XToolkit> xToolkit = awt::Toolkit::create( xContext ); + + // import dialogs + OString aParam1( OUStringToOString( + OUString( GetCommandLineParam( 1 ) ), + RTL_TEXTENCODING_ASCII_US ) ); + Reference< container::XNameContainer > xModel( + importFile( aParam1.getStr(), xContext ) ); + OSL_ASSERT( xModel.is() ); + + Reference< awt::XUnoControlDialog > xDlg = UnoControlDialog::create( xContext ); + xDlg->setModel( xModel ); + xDlg->createPeer( xToolkit, 0 ); + xDlg->execute(); + + if (GetCommandLineParamCount() == 3) + { + // write modified dialogs + OString aParam2( OUStringToOString( + OUString( GetCommandLineParam( 2 ) ), RTL_TEXTENCODING_ASCII_US ) ); + exportToFile( aParam2.getStr(), xModel, xContext ); + } + } + catch (const xml::sax::SAXException & rExc) + { + OUString aStr( rExc ); + uno::Exception exc; + if (rExc.WrappedException >>= exc) + { + aStr += " >>> "; + aStr += exc; + } + SAL_WARN( "xmlscript", aStr ); + } + catch (const uno::Exception & rExc) + { + SAL_WARN( "xmlscript", rExc ); + } + + Reference< lang::XComponent > xComp( xContext, UNO_QUERY ); + if (xComp.is()) + { + xComp->dispose(); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmlscript/test/makefile.mk b/xmlscript/test/makefile.mk new file mode 100644 index 000000000..6a08433f1 --- /dev/null +++ b/xmlscript/test/makefile.mk @@ -0,0 +1,56 @@ +# +# 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 . +# +PRJ=.. + +PRJNAME=xmlscript +TARGET=imexp +TARGETTYPE=GUI +LIBTARGET=NO +ENABLE_EXCEPTIONS=TRUE + + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# --- Files -------------------------------------------------------- + +CXXFILES= \ + imexp.cxx + +OBJFILES= \ + $(OBJ)$/imexp.obj + +APP1TARGET=$(TARGET) +APP1OBJS=$(OBJFILES) +APP1STDLIBS= \ + $(TOOLSLIB) \ + $(SOTLIB) \ + $(SVTOOLLIB) \ + $(COMPHELPERLIB) \ + $(VCLLIB) \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(SALLIB) \ + $(XMLSCRIPTLIB) + +APP1DEF= $(MISC)$/imexp.def + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk diff --git a/xmlscript/test/test.xml b/xmlscript/test/test.xml new file mode 100644 index 000000000..06e44309b --- /dev/null +++ b/xmlscript/test/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/test/w3c.jpg b/xmlscript/test/w3c.jpg Binary files differnew file mode 100644 index 000000000..c541c20dc --- /dev/null +++ b/xmlscript/test/w3c.jpg |