Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / extensions / qa / ole / automationtest.vbs
blob9b5dff05e9576ed1cccc8329eb4ac313fb97d324
1 ' -*- tab-width: 4; indent-tabs-mode: nil -*-
3 If WScript.Arguments.Count <> 1 Then
4 WScript.Echo "Pass $(SRCDIR) as parameter"
5 WScript.Quit(1)
6 End If
8 srcdir = WScript.Arguments.Item(0)
10 exitStatus = 0
12 testCounter = 0
13 okCounter = 0
15 Sub ExitWithReport
16 If okCounter <> testCounter Then
17 exitStatus = 1
18 End If
19 WScript.Echo "OK (" + CStr(okCounter) + ")"
20 WScript.Quit(exitstatus)
21 End Sub
23 Sub CheckFatal(expr)
24 testCounter = testCounter + 1
25 If Not Eval(expr) Then
26 WScript.Echo "FAIL: " & expr
27 ExitWithReport
28 Else
29 WScript.Echo "PASS: " & expr
30 okCounter = okCounter + 1
31 End If
32 End Sub
34 Sub Check(expr)
35 testCounter = testCounter + 1
36 If Not Eval(expr) Then
37 WScript.Echo "FAIL: " & expr
38 Else
39 WScript.Echo "PASS: " & expr
40 okCounter = okCounter + 1
41 End If
42 End Sub
44 Sub CheckIfExpected(expr, expected)
45 testCounter = testCounter + 1
46 actual = Eval(expr)
47 If actual <> expected Then
48 WScript.Echo "FAIL: Value of '" & expr & "' was expected to be '" & CStr(expected) & "', but was " & CStr(actual)
49 Else
50 WScript.Echo "PASS: " & expr & " == " & CStr(expected)
51 okCounter = okCounter + 1
52 End If
53 End Sub
55 Sub CheckErrorFatal(test)
56 testCounter = testCounter + 1
57 Execute(test)
58 If Err.Number <> 0 Then
59 WScript.Echo "FAIL: " & test
60 WScript.Echo "ERROR: " & Err.Description
61 ExitWithReport
62 Else
63 WScript.Echo "PASS: " & test
64 okCounter = okCounter + 1
65 End If
66 End Sub
68 Sub CheckError(test)
69 testCounter = testCounter + 1
70 Execute(test)
71 If Err.Number <> 0 Then
72 WScript.Echo "FAIL: " & test
73 WScript.Echo "ERROR: " & Err.Description
74 Else
75 WScript.Echo "PASS: " & test
76 okCounter = okCounter + 1
77 End If
78 End Sub
80 WScript.Echo "Running Automation client tests"
82 On Error Resume Next
84 ' FIXME: How can we ever make this work specifically with the
85 ' LibreOffice in instdir, when WScript.CreateObject() wants the
86 ' symbolic name that it then looks up from the Registry to find the
87 ' CLSID of the class?
89 CheckErrorFatal "Set writer = WScript.CreateObject(""Writer.Application"")"
90 CheckErrorFatal "writer.Visible = True"
91 CheckErrorFatal "writer.Caption = ""=== This is Writer ==="""
92 CheckErrorFatal "writer.ShowMe"
94 CheckErrorFatal "Set documents = writer.Documents"
96 ' Open two randomly chosen documents
97 CheckErrorFatal "Set d1 = documents.Open(""" & srcdir & "/sw/qa/extras/ww8export/data/n325936.doc"")"
98 CheckErrorFatal "Set d2 = documents.Open(""" & srcdir & "/sw/qa/extras/ww8export/data/bnc636128.doc"")"
100 CheckErrorFatal "n1 = d1.FullName"
101 CheckErrorFatal "n2 = d2.FullName"
103 CheckIfExpected "n1", "n325936.doc"
104 CheckIfExpected "n2", "bnc636128.doc"
106 CheckErrorFatal "Set c1 = d1.Content"
107 CheckErrorFatal "Set c2 = d2.Content"
109 ' The range of characters in these documents
110 CheckIfExpected "c1.Start", 0
111 CheckIfExpected "c1.End", 4
112 CheckIfExpected "c2.Start", 0
113 CheckIfExpected "c2.End", 42
115 ' Check number of paragraphs in each document
116 CheckErrorFatal "Set p1 = d1.Paragraphs"
117 nparas = 0
118 For Each i in p1
119 nparas = nparas + 1
120 Next
121 CheckIfExpected "nparas", 1
123 CheckErrorFatal "Set p2 = d2.Paragraphs"
124 nparas = 0
125 For Each i in p2
126 nparas = nparas + 1
127 Next
128 CheckIfExpected "nparas", 1
130 CheckErrorFatal "writer.Quit"
132 ExitWithReport