1 <?xml version="1.0" encoding="UTF-8"?>
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
20 <script:module xmlns:script="http://openoffice.org/2000/script" script:name="Test_10er" script:language="StarBasic">REM 10er Test
22 const sSWLogFileName = "swlog.dat", sSCLogFileName = "sclog.dat"
23 const sSDLogFileName = "sdlog.dat", sSMathLogFileName = "smalog.dat"
24 const sSChartLogFileName = "schlog.dat"
25 const sSHptLogFileName = "shptlog.dat"
26 const sSDrawLogFileName = "sdrwlog.dat", sJavaLogFileName = "javalog.dat"
27 const sSDBLogFileName = "dblog.dat", sExtLogFileName = "extlog.dat"
28 const sTestGlueLogFileName = "testclosure.log"
29 const sLogFileName = "smoketest.log"
30 const cTempFileName = "smoketest_file"
32 const cMessageSaveOpen8Doc = "Save/Open open Documents (8.0)"
33 const cMessageNewDoc = "New Document"
34 const cMessageCloseDoc = "Close Document"
35 const cMessageRunMacros = "Run Macros"
46 Sub DeleteAllSavedFiles()
47 Dim sFileName as String
48 sFileName = sWorkPath+cTempFileName+"."+GetDocEndings(frmWriter)
49 If FileExists (sFileName) then
52 sFileName = sWorkPath+cTempFileName+"."+GetDocEndings(frmCalc)
53 If FileExists (sFileName) then
56 sFileName = sWorkPath+cTempFileName+"."+GetDocEndings(frmImpress)
57 If FileExists (sFileName) then
60 sFileName = sWorkPath+cTempFileName+"."+GetDocEndings(frmDraw)
61 If FileExists (sFileName) then
64 sFileName = sWorkPath+cTempFileName+"."+GetDocEndings(frmHyperText)
65 If FileExists (sFileName) then
70 Sub DeleteAllLogFiles()
71 If FileExists (sWorkPath+sLogFileName) then
72 Kill (sWorkPath+sLogFileName)
74 If FileExists (sWorkPath+sSWLogFileName) then
75 Kill (sWorkPath+sSWLogFileName)
77 If FileExists (sWorkPath+sSCLogFileName) then
78 Kill (sWorkPath+sSCLogFileName)
80 If FileExists (sWorkPath+sSDLogFileName) then
81 Kill (sWorkPath+sSDLogFileName)
83 If FileExists (sWorkPath+sSMathLogFileName) then
84 Kill (sWorkPath+sSMathLogFileName)
86 If FileExists (sWorkPath+sSChartLogFileName) then
87 Kill (sWorkPath+sSChartLogFileName)
89 If FileExists (sWorkPath+sSHptLogFileName) then
90 Kill (sWorkPath+sSHptLogFileName)
92 If FileExists (sWorkPath+sSDrawLogFileName) then
93 Kill (sWorkPath+sSDrawLogFileName)
95 If FileExists (sWorkPath+sJavaLogFileName) then
96 Kill (sWorkPath+sJavaLogFileName)
98 If FileExists (sWorkPath+sTestGlueLogFileName) then
99 Kill (sWorkPath+sTestGlueLogFileName)
101 If FileExists (sWorkPath+sSDBLogFileName) then
102 Kill (sWorkPath+sSDBLogFileName)
104 If FileExists (sWorkPath+sExtLogFileName) then
105 Kill (sWorkPath+sExtLogFileName)
109 Function OpenLogDat (sFileName as String) as Integer
110 Dim LocaleFileChannel%
111 If FileExists (sWorkPath+sFileName) then
112 Kill (sWorkPath+sFileName)
114 LocaleFileChannel% = Freefile
115 Open sWorkPath+sFileName For Output As LocaleFileChannel%
116 OpenLogDat = LocaleFileChannel%
120 Dim configManager as Object
121 configManager = CreateUnoService( "com.sun.star.config.SpecialConfigManager" )
123 sWorkPath = configManager.SubstituteVariables( "$(userpath)/temp/" )
124 sWorkPathURL = configManager.SubstituteVariables( "$(userurl)/temp/" )
127 Function GetSystem (sTmpWorkPath as string) as string
128 GetSystem = ""
129 if InStr (sTmpWorkPath, ":") then
130 GetSystem = "windows"
132 GetSystem = "unix"
136 Function ConvertPathToWin (sTmpWorkPath as string) as string
137 for i%=1 to Len(sTmpWorkPath)
138 sTemp = Mid (sTmpWorkPath, i%, 1)
139 if sTemp = "/" then
140 sTmpWorkPath = Left (sTmpWorkPath, i%-1) + "\" + Right (sTmpWorkPath, Len(sTmpWorkPath)-i%)
142 if sTemp = "|" then
143 sTmpWorkPath = Left (sTmpWorkPath, i%-1) + ":" + Right (sTmpWorkPath, Len(sTmpWorkPath)-i%)
147 ConvertPathToWin = sTmpWorkPath
151 DIM sDocURL as String, sDocPath as String
154 'search ExtensionURL
155 sDocURL = gOutputDoc.URL
156 CompatibilityMode(true)
157 nStrPos = InStrRev (sDocURL, "/" )
158 CompatibilityMode(false)
159 sExtensionURL = Left (sDocURL, nStrPos) + "../Extension/" + cExtensionFileName
161 GlobalTestLog = OpenLogDat (sLogFileName)
162 call WriteTestSequence
164 ' Do extension test first to avoid OOM with ASAN
165 if bMakeExtensionTest then
166 gCurrentDocTest = frmExtension
167 call Test_Ext.TestExtensions
170 if bMakeWriterTest then
171 gCurrentDocTest = frmWriter
174 if bMakeCalcTest then
175 gCurrentDocTest = frmCalc
178 if bMakeImpressTest then
179 gCurrentDocTest = frmImpress
182 if bMakeDrawTest then
183 gCurrentDocTest = frmDraw
186 if bMakeHTMLTest then
187 gCurrentDocTest = frmHyperText
190 if bMakeChartTest then
191 gCurrentDocTest = frmChart
194 if bMakeMathTest then
195 gCurrentDocTest = frmMath
198 if bMakeJavaTest then
199 gCurrentDocTest = frmJava
203 gCurrentDocTest = frmDataBase
211 Sub WriteTestSequence
212 Print #GlobalTestLog, "Sequence of testing"
214 if bMakeExtensionTest then
215 WriteExtensionTests ("Extension : ", GlobalTestLog)
216 if bMakeWriterTest then
217 WriteTests ("writer : ", true, GlobalTestLog)
219 if bMakeCalcTest then
220 WriteTests ("calc : ", true, GlobalTestLog)
222 if bMakeImpressTest then
223 WriteTests ("impress : ", true, GlobalTestLog)
225 if bMakeDrawTest then
226 WriteTests ("draw : ", true, GlobalTestLog)
228 if bMakeHTMLTest then
229 WriteTests ("HTML : ", true, GlobalTestLog)
231 if bMakeChartTest then
232 WriteTests ("chart : ", false, GlobalTestLog)
234 if bMakeMathTest then
235 WriteTests ("math : ", false, GlobalTestLog)
237 if bMakeJavaTest then
238 WriteTests ("Java : ", false, GlobalTestLog)
241 WriteDBTests ("Database : ", GlobalTestLog)
245 Print #GlobalTestLog, "testclosure : setup, write_status"
250 Sub WriteTests (sText as string, bTestAll as boolean)
251 Dim sWriteStr as string
254 sWriteStr = sWriteStr + "new"
256 if bMakeSaveOpen8Test then
257 sWriteStr = sWriteStr + ", save 8.0"
259 if bMakeSaveOpen8Test then
260 sWriteStr = sWriteStr + ", open 8.0"
262 if bMakeMacrosTest then
263 sWriteStr = sWriteStr + ", run macros"
267 sWriteStr = sWriteStr + ", close"
269 Print #GlobalTestLog, sWriteStr
272 Sub WriteDBTests (sText as string, nFileChannel as integer)
273 Dim sWriteStr as string
276 sWriteStr = sWriteStr + "open / services"
277 sWriteStr = sWriteStr + ", insert"
278 sWriteStr = sWriteStr + ", delete"
279 sWriteStr = sWriteStr + ", seek"
280 sWriteStr = sWriteStr + ", close"
282 Print #nFileChannel, sWriteStr
285 Sub WriteExtensionTests (sText as string, nFileChannel as integer)
286 Dim sWriteStr as string
289 sWriteStr = sWriteStr + "services"
290 sWriteStr = sWriteStr + ", install"
291 sWriteStr = sWriteStr + ", uninstall"
293 Print #nFileChannel, sWriteStr
298 Dim sFileNameXML$, sFileName8$
299 Dim bSuccess as Boolean
301 On Local Error GoTo DOCTESTERROR
302 gCurrentTestCase = cLogfileFailed
303 LocalTestLog% = OpenLogDat (GetLogFileName(gCurrentDocTest))
304 gCurrentTestCase = cDocNew
305 oDoc = LoadDoc ("private:factory/" + GetDocFilter(gCurrentDocTest or cFltNewDoc))
306 LogTestResult( GetDocFilter(gCurrentDocTest or cFltNewDoc)+" "+ cMessageNewDoc, not IsNull (oDoc) )
307 if not IsNull (oDoc) then
308 gCurrentTestCase = cDocSaveOpen8
309 if bMakeSaveOpen8Test and IsFilterAvailable (gCurrentDocTest or cFlt8) then
310 sFileName8 = sWorkPathURL+cTempFileName+"."+GetDocEndings(gCurrentDocTest or cFlt8)
311 SaveDoc (sFileName8, oDoc, GetDocFilter(gCurrentDocTest or cFlt8))
313 gCurrentTestCase = cDocClose
314 bSuccess = CloseDoc( oDoc )
315 LogTestResult( GetDocFilter(gCurrentDocTest)+" "+ cMessageCloseDoc, bSuccess )
316 gCurrentTestCase = cDocSaveOpen8
317 if bMakeSaveOpen8Test and IsFilterAvailable (gCurrentDocTest or cFlt8) then
318 oDoc = LoadDoc (sFileName8)
320 ' oDoc = Documents.open(sFileName)
321 LogTestResult( GetDocFilter(gCurrentDocTest or cFltNewDoc)+" "+ cMessageSaveOpen8Doc, not IsNull (oDoc) )
323 if not IsNull (oDoc) then
324 gCurrentTestCase = cDocClose
329 gCurrentTestCase = cDocMacros
330 ' Just one calc macro test for now
331 ' To-Do split this into its own per-module/test .xml and add more
332 if bMakeMacrosTest and gCurrentDocTest = frmCalc then
333 oDoc = LoadDoc ("private:factory/" + GetDocFilter(gCurrentDocTest or cFltNewDoc))
334 oDocCtrl = oDoc.getCurrentController()
335 oDocFrame = oDocCtrl.getFrame()
336 oDispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
338 dim args(0) as new com.sun.star.beans.PropertyValue
340 args(0).Name = "ToPoint"
341 args(0).Value = "$A$1"
342 oDispatcher.executeDispatch(oDocFrame, ".uno:GoToCell", "", 0, args())
343 args(0).Name = "By"
345 oDispatcher.executeDispatch(oDocFrame, ".uno:GoRightSel", "", 0, args())
346 args(0).Name = "By"
348 oDispatcher.executeDispatch(oDocFrame, ".uno:GoDownSel", "", 0, args())
350 oRangeAddr = oDoc.getCurrentSelection().getRangeAddress()
352 bResult = oRangeAddr.StartColumn = 0 and oRangeAddr.EndColumn = 5 and oRangeAddr.StartRow = 0 and oRangeAddr.EndRow = 5
354 LogTestResult( GetDocFilter(gCurrentDocTest or cFltNewDoc)+" "+ cMessageRunMacros, bResult )
356 if not IsNull (oDoc) then
357 gCurrentTestCase = cDocClose
363 Print #LocalTestLog, "---"
366 Exit Sub ' Without error
369 If ( gCurrentTestCase = cLogfileFailed ) then
370 LogTestResult( " ", False )
373 LogTestResult( GetDocFilter(gCurrentDocTest or cFltNewDoc)+" "+ GetErrorMessage(gCurrentTestCase), False )
377 Exit Sub ' With error
382 Dim bSuccess as Boolean
383 On Local Error GoTo DOCTESTERROR2
384 gCurrentTestCase = cLogfileFailed
385 LocalTestLog% = OpenLogDat (GetLogFileName(gCurrentDocTest))
386 gCurrentTestCase = cDocNew
387 ' oDoc = Documents.Add(GetDocFilter(gCurrentDocTest))
388 oDoc = LoadDoc ("private:factory/" + GetDocFilter(gCurrentDocTest or cFltNewDoc))
389 LogTestResult( GetDocFilter(gCurrentDocTest or cFltNewDoc)+" "+ cMessageNewDoc, not IsNull (oDoc) )
390 if not IsNull (oDoc) then
391 gCurrentTestCase = cDocClose
392 bSuccess = CloseDoc( oDoc )
393 LogTestResult( GetDocFilter(gCurrentDocTest)+" "+ cMessageCloseDoc, bSuccess )
395 Print #LocalTestLog, "---"
398 Exit Sub ' Without error
401 If ( gCurrentTestCase = cLogfileFailed ) then
402 LogTestResult( " ", False )
405 LogTestResult( GetDocFilter(gCurrentDocTest or cFltNewDoc)+" "+ GetErrorMessage(gCurrentTestCase), False )
409 Exit Sub ' With error
413 Dim oCharts as Object
415 Dim oRange(0) as New com.sun.star.table.CellRangeAddress
416 Dim oRect as New com.sun.star.awt.Rectangle
417 const cChartName="TestChart"
418 Dim bSuccess as Boolean
419 On Local Error GoTo CHARTTESTERROR
420 gCurrentTestCase = cLogfileFailed
421 LocalTestLog% = OpenLogDat (GetLogFileName(gCurrentDocTest))
422 gCurrentTestCase = cDocNew
423 oDoc = LoadDoc ("private:factory/" + GetDocFilter(frmCalc or cFltNewDoc))
424 if not IsNull (oDoc) then
425 oCharts = oDoc.sheets(0).Charts
426 oCharts.AddNewByName (cChartName, oRect, oRange(), true, true)
427 bSuccess=oCharts.HasByName(cChartName)
428 LogTestResult( GetDocFilter(gCurrentDocTest or cFltNewDoc)+" "+ cMessageNewDoc, bSuccess )
429 gCurrentTestCase = cDocClose
432 LogTestResult( GetDocFilter(frmCalc or cFltNewDoc)+" "+ cMessageNewDoc, FALSE )
434 Print #LocalTestLog, "---"
437 Exit Sub ' Without error
440 If ( gCurrentTestCase = cLogfileFailed ) then
441 LogTestResult( " ", False )
444 LogTestResult( GetDocFilter(gCurrentDocTest or cFltNewDoc)+" "+ GetErrorMessage(gCurrentTestCase), FALSE )
448 Exit Sub ' With error
451 Sub LogState (bState as Boolean, sText as String, nLocaleFileChannel as integer)
453 Print #nLocaleFileChannel, sText+" -> ok"
455 Print #nLocaleFileChannel, sText+" -> error"
459 Function GetDocEndings (DocType as Integer) as String
460 Select Case ( DocType )
461 case frmWriter or cFlt8
462 GetDocEndings = "odt" ' Textdokument
463 case frmCalc or cFlt8
464 GetDocEndings = "ods" 'Tabellendokument
465 case frmImpress or cFlt8
466 GetDocEndings = "odp" 'PrÕsentation
467 case frmDraw or cFlt8
468 GetDocEndings = "odg" 'Zeichen
469 case frmHyperText, frmHyperText or cFltXML
470 GetDocEndings = "html" 'Hypertext-Dokument
471 case frmWriter or cFltXML
472 GetDocEndings = "sxw" ' Textdokument
473 case frmCalc or cFltXML
474 GetDocEndings = "sxc" 'Tabellendokument
475 case frmImpress or cFltXML
476 GetDocEndings = "sxi" 'PrÕsentation
477 case frmDraw or cFltXML
478 GetDocEndings = "sxd" 'Zeichen
480 GetDocEndings = ""
484 Function GetDocFilter (DocType as Integer) as String
485 Select Case ( DocType )
486 case frmWriter or cFlt8
487 GetDocFilter = "writer8" ' text document
488 case frmCalc or cFlt8
489 GetDocFilter = "calc8" ' spreadsheet document
490 case frmImpress or cFlt8
491 GetDocFilter = "impress8" ' presentation
492 case frmDraw or cFlt8
493 GetDocFilter = "draw8" ' drawing
494 case frmMath or cFlt8
495 GetDocFilter = "math8" ' formula
497 case frmWriter or cFltXML
498 GetDocFilter = "StarOffice XML (Writer)" ' text document
499 case frmCalc or cFltXML
500 GetDocFilter = "StarOffice XML (Calc)" ' spreadsheet document
501 case frmImpress or cFltXML
502 GetDocFilter = "StarOffice XML (Impress)" ' presentation
503 case frmDraw or cFltXML
504 GetDocFilter = "StarOffice XML (Draw)" ' drawing
505 case frmMath or cFltXML
506 GetDocFilter = "StarOffice XML (Math)" ' formula
508 case frmHyperText, frmHyperText or cFltXML
509 GetDocFilter = "HTML" ' HTML document
511 case frmWriter or cFltNewDoc
512 GetDocFilter = "swriter" ' text document
513 case frmCalc or cFltNewDoc
514 GetDocFilter = "scalc" ' spreadsheet document
515 case frmImpress or cFltNewDoc
516 GetDocFilter = "simpress" ' presentation
517 case frmDraw or cFltNewDoc
518 GetDocFilter = "sdraw" ' drawing
519 case frmMath or cFltNewDoc
520 GetDocFilter = "smath" ' formula
521 case frmHyperText or cFltNewDoc
522 GetDocFilter = "swriter/web" ' HTML document
523 case frmChart or cFltNewDoc
524 GetDocFilter = "schart" ' chart
526 GetDocFilter = ""
530 Function GetLogFileName (DocType as Integer) as String
531 Select Case ( DocType )
533 GetLogFileName = sSWLogFileName ' text document
535 GetLogFileName = sSCLogFileName ' spreadsheet document
537 GetLogFileName = sSDLogFileName ' presentation
539 GetLogFileName = sSDrawLogFileName ' drawing
541 GetLogFileName = sSMathLogFileName ' formula
543 GetLogFileName = sSHptLogFileName ' HTML document
545 GetLogFileName = sSChartLogFileName ' chart
547 GetLogFileName = sJavaLogFileName 'Java
549 GetLogFileName = sTestGlueLogFileName ' test framework
551 GetLogFileName = sSDBLogFileName 'Database
553 GetLogFileName = sExtLogFileName 'Extension
555 GetLogFileName = ""
559 Function GetErrorMessageOnAction (nAction as Integer) as String
560 Select Case ( nAction )
562 GetErrorMessageOnAction = cMessageNewDoc
564 GetErrorMessageOnAction = cMessageSaveOpen8Doc
566 GetErrorMessageOnAction = cMessageRunMacros
568 GetErrorMessageOnAction = cMessageCloseDoc
570 GetErrorMessageOnAction = ""
574 Function IsFilterAvailable (FilterType as Integer) as boolean
575 IsFilterAvailable = true
576 if (FilterType = (frmHyperText or cFltXML)) then
577 IsFilterAvailable = false
583 gCurrentTestCase = cLogfileFailed
584 LocalTestLog% = OpenLogDat (GetLogFileName(gCurrentDocTest))
585 gCurrentTestCase = cDocNew
586 oObj = createUnoService( cUnoJavaLoader )
587 LogTestResult( "Java "+ cMessageNewDoc, not IsNull (oObj) )
589 Print #LocalTestLog, "---"
593 TestJava = not IsNull (oObj)
596 Sub LoadLibrary( LibName as String )
599 dim arg as new com.sun.star.beans.PropertyValue
600 arg.Name = "LibraryName"
604 dim url as new com.sun.star.util.URL
606 trans = createUnoService("com.sun.star.util.URLTransformer" )
607 url.Complete = "slot:6517"
608 trans.parsestrict( url )
611 disp = StarDesktop.currentFrame.queryDispatch( url, "", 0 )
612 disp.dispatch( url, args() )
616 Sub LoadDoc (DocName as String) as Object
618 trans = createUnoService("com.sun.star.util.URLTransformer" )
619 url = createUnoStruct("com.sun.star.util.URL" )
620 url.Complete = DocName
621 if Left(DocName, 5 ) <> "file:" then
622 trans.parsestrict( url )
625 Dim aPropArray(0) as Object
626 aPropArray(0) = CreateUnoStruct("com.sun.star.beans.PropertyValue")
627 aPropArray(0).Name = "OpenFlags"
628 aPropArray(0).Value = "S"
632 doc = StarDesktop.loadComponentFromURL( url.Complete, "_blank", 0, aPropArray() ) ' XModel
636 Sub SaveDoc (DocName as String, oDoc as Object, sFilterName as string )
638 trans = createUnoService("com.sun.star.util.URLTransformer" )
639 url = createUnoStruct("com.sun.star.util.URL" )
640 url.Complete = DocName
641 if Left(DocName, 5 ) <> "file:" then
642 trans.parsestrict( url )
645 if not (sFilterName = "") then
646 Dim aPropArray(0) as Object
647 aPropArray(0) = CreateUnoStruct("com.sun.star.beans.PropertyValue")
648 aPropArray(0).Name = "FilterName"
649 aPropArray(0).Value = sFilterName
651 oDoc.storeAsURL( url.Complete, aPropArray() )
653 MessageBox "Filtername is unknown!"
657 Function CloseDoc( oDoc as Object )
658 Dim oListener as Object
659 oListener = CreateUnoListener( "Events.closeListener_", "com.sun.star.util.XCloseListener" )
660 oDoc.addCloseListener( oListener )
662 Events.ResetCloseListenerFlag()
664 closeDoc = Events.HasCloseListenerBeenCalled()
666 if ( Not Events.HasCloseListenerBeenCalled() ) Then
667 ' do this only if closing was not successful - otherwise, we'd get a DisposedException
668 oDoc.removeCloseListener( oListener )