fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sc / qa / extras / macros-test.cxx
blob68bed145ec51693ea99c502d5d641e2916db06b2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <sal/config.h>
11 #include <test/unoapi_test.hxx>
12 #include <unotest/macros_test.hxx>
13 #include <rtl/strbuf.hxx>
14 #include <osl/file.hxx>
16 #include <sfx2/app.hxx>
17 #include <sfx2/docfilt.hxx>
18 #include <sfx2/docfile.hxx>
19 #include <sfx2/sfxmodelfactory.hxx>
20 #include <svl/intitem.hxx>
21 #include <com/sun/star/frame/Desktop.hpp>
23 #include <basic/sbxdef.hxx>
25 #include "docsh.hxx"
26 #include "patattr.hxx"
27 #include "scitems.hxx"
28 #include "document.hxx"
30 using namespace ::com::sun::star;
31 using namespace ::com::sun::star::uno;
33 /* Implementation of Macros test */
35 class ScMacrosTest : public UnoApiTest
37 public:
38 ScMacrosTest();
40 void testStarBasic();
41 void testVba();
42 CPPUNIT_TEST_SUITE(ScMacrosTest);
43 #if !defined(MACOSX)
44 //enable this test if you want to play with star basic macros in unit tests
45 //works but does nothing useful yet
46 CPPUNIT_TEST(testStarBasic);
47 CPPUNIT_TEST(testVba);
48 #endif
50 CPPUNIT_TEST_SUITE_END();
52 private:
53 uno::Reference<uno::XInterface> m_xCalcComponent;
56 void ScMacrosTest::testStarBasic()
58 const OUString aFileNameBase("StarBasic.ods");
59 OUString aFileName;
60 createFileURL(aFileNameBase, aFileName);
61 std::cout << "StarBasic test" << std::endl;
62 uno::Reference< com::sun::star::lang::XComponent > xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument");
64 CPPUNIT_ASSERT_MESSAGE("Failed to load StarBasic.ods", xComponent.is());
66 OUString aURL("vnd.sun.Star.script:Standard.Module1.Macro1?language=Basic&location=document");
67 String sUrl = aURL;
68 Any aRet;
69 Sequence< sal_Int16 > aOutParamIndex;
70 Sequence< Any > aOutParam;
71 Sequence< uno::Any > aParams;
73 SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent);
75 CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell);
76 ScDocShell* xDocSh = static_cast<ScDocShell*>(pFoundShell);
77 ScDocument* pDoc = xDocSh->GetDocument();
79 pFoundShell->CallXScript(xComponent, sUrl, aParams, aRet, aOutParamIndex,aOutParam);
80 double aValue;
81 pDoc->GetValue(0,0,0,aValue);
82 std::cout << "returned value = " << aValue << std::endl;
83 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("script did not change the value of Sheet1.A1",2.0, aValue, 0.00001);
84 xDocSh->DoClose();
87 void ScMacrosTest::testVba()
89 TestMacroInfo testInfo[] = {
91 OUString("TestAddress."),
92 OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document")
95 OUString("vba."),
96 OUString("vnd.sun.Star.script:VBAProject.Modul1.Modul1?language=Basic&location=document"),
99 OUString("MiscRangeTests."),
100 OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document")
103 OUString("bytearraystring."),
104 OUString("vnd.sun.Star.script:VBAProject.testMacro.test?language=Basic&location=document")
107 OUString("AutoFilter."),
108 OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document")
111 OUString("CalcFont."),
112 OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document")
115 OUString("TestIntersection."),
116 OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document")
119 OUString("TestUnion."),
120 OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document")
123 OUString("range-4."),
124 OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document")
127 OUString("Ranges-3."),
128 OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document")
131 OUString("TestCalc_Rangetest."),
132 OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document")
135 OUString("TestCalc_Rangetest2."),
136 OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document")
139 OUString("Ranges-2."),
140 OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document")
143 OUString("pagesetup."),
144 OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document")
147 OUString("Window."),
148 OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document")
151 OUString("window2."),
152 OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document")
155 OUString("PageBreaks."),
156 OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document")
159 OUString("Shapes."),
160 OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document")
163 OUString("Ranges."),
164 OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document")
167 OUString("CheckOptionToggleValue."),
168 OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document")
171 OUString("GeneratedEventTest."),
172 OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document")
175 OUString("MiscControlTests."),
176 OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document")
179 OUString("Workbooks."),
180 OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document")
183 OUString("Names."),
184 OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document")
187 OUString sTempDir;
188 OUString sTempDirURL;
189 osl::FileBase:: getTempDirURL( sTempDirURL );
190 osl::FileBase::getSystemPathFromFileURL( sTempDirURL, sTempDir );
191 sTempDir += OUString( SAL_PATHDELIMITER );
192 OUString sTestFileName("My Test WorkBook.xls");
193 Sequence< uno::Any > aParams;
194 for ( sal_uInt32 i=0; i<SAL_N_ELEMENTS( testInfo ); ++i )
196 OUString aFileName;
197 createFileURL(testInfo[i].sFileBaseName + "xls", aFileName);
198 uno::Reference< com::sun::star::lang::XComponent > xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument");
199 OUString sMsg( "Failed to load " + aFileName );
200 CPPUNIT_ASSERT_MESSAGE( OUStringToOString( sMsg, RTL_TEXTENCODING_UTF8 ).getStr(), xComponent.is() );
202 String sUrl = testInfo[i].sMacroUrl;
203 Any aRet;
204 Sequence< sal_Int16 > aOutParamIndex;
205 Sequence< Any > aOutParam;
206 bool bWorkbooksHandling = OUString( testInfo[i].sFileBaseName ).equalsAscii("Workbooks.") && !sTempDir.isEmpty() ;
208 if ( bWorkbooksHandling )
210 aParams.realloc(2);
211 aParams[ 0 ] <<= sTempDir;
212 aParams[ 1 ] <<= sTestFileName;
215 SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent);
217 CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell);
218 std::cout << "about to invoke vba test in " << OUStringToOString( aFileName, RTL_TEXTENCODING_UTF8 ).getStr() << std::endl;
220 pFoundShell->CallXScript(xComponent, sUrl, aParams, aRet, aOutParamIndex,aOutParam);
221 OUString aStringRes;
222 aRet >>= aStringRes;
223 std::cout << "value of Ret " << OUStringToOString( aStringRes, RTL_TEXTENCODING_UTF8 ).getStr() << std::endl;
224 CPPUNIT_ASSERT_MESSAGE( "script reported failure",aStringRes == "OK" );
225 pFoundShell->DoClose();
226 if ( bWorkbooksHandling )
228 OUString sFileUrl;
229 OUString sFilePath = sTempDir + sTestFileName;
230 osl::FileBase::getFileURLFromSystemPath( sFilePath, sFileUrl );
231 if ( !sFileUrl.isEmpty() )
232 osl::File::remove( sFileUrl );
237 ScMacrosTest::ScMacrosTest()
238 : UnoApiTest("/sc/qa/extras/testdocuments")
242 CPPUNIT_TEST_SUITE_REGISTRATION(ScMacrosTest);
244 CPPUNIT_PLUGIN_IMPLEMENT();
246 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */