LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / basic / qa / vba_tests / ismissing.vb
blobfebe0339f68a1c5f5f27444c0331dbe9a4b049c6
2 ' This file is part of the LibreOffice project.
4 ' This Source Code Form is subject to the terms of the Mozilla Public
5 ' License, v. 2.0. If a copy of the MPL was not distributed with this
6 ' file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 Option VBASupport 1
11 Const IsMissingNone = -1
12 Const IsMissingA = 0
13 Const IsMissingB = 1
14 Const IsMissingAB = 2
16 Function doUnitTest() As String
17 TestUtil.TestInit
18 verify_testIsMissingVba
19 doUnitTest = TestUtil.GetResult()
20 End Function
22 ' tdf#36737 - Test isMissing function with different datatypes. In LO Basic
23 ' with option VBASupport, optional parameters are allowed including additional
24 ' default values. Missing optional parameters having types other than variant,
25 ' which don't have explicit default values, will be initialized to their
26 ' respective default value of its datatype.
27 Sub verify_testIsMissingVba()
29 testName = "Test missing (VBA)"
30 On Error GoTo errorHandler
32 ' optionals with variant datatypes
33 TestUtil.AssertEqual(TestOptVariant(), IsMissingA, "TestOptVariant()")
34 TestUtil.AssertEqual(TestOptVariant(123), IsMissingNone, "TestOptVariant(123)")
35 TestUtil.AssertEqual(TestOptVariant(, 456), IsMissingA, "TestOptVariant(, 456)")
36 TestUtil.AssertEqual(TestOptVariant(123, 456), IsMissingNone, "TestOptVariant(123, 456)")
38 ' optionals with variant datatypes (ByRef and ByVal)
39 TestUtil.AssertEqual(TestOptVariantByRefByVal(), IsMissingA, "TestOptVariantByRefByVal()")
40 TestUtil.AssertEqual(TestOptVariantByRefByVal(123),IsMissingNone, "TestOptVariantByRefByVal(123)")
41 TestUtil.AssertEqual(TestOptVariantByRefByVal(, 456), IsMissingA, "TestOptVariantByRefByVal(, 456)")
42 TestUtil.AssertEqual(TestOptVariantByRefByVal(123, 456), IsMissingNone, "TestOptVariantByRefByVal(123, 456)")
44 ' optionals with double datatypes
45 TestUtil.AssertEqual(TestOptDouble(), IsMissingNone, "TestOptDouble()")
46 TestUtil.AssertEqual(TestOptDouble(123.4), IsMissingNone, "TestOptDouble(123.4)")
47 TestUtil.AssertEqual(TestOptDouble(, 567.8), IsMissingNone, "TestOptDouble(, 567.8)")
48 TestUtil.AssertEqual(TestOptDouble(123.4, 567.8), IsMissingNone, "TestOptDouble(123.4, 567.8)")
50 ' optionals with double datatypes (ByRef and ByVal)
51 TestUtil.AssertEqual(TestOptDoubleByRefByVal(), IsMissingNone, "TestOptDouble()")
52 TestUtil.AssertEqual(TestOptDoubleByRefByVal(123.4), IsMissingNone, "TestOptDouble(123.4)")
53 TestUtil.AssertEqual(TestOptDoubleByRefByVal(, 567.8), IsMissingNone, "TestOptDoubleByRefByVal(, 567.8)")
54 TestUtil.AssertEqual(TestOptDoubleByRefByVal(123.4, 567.8), IsMissingNone, "TestOptDoubleByRefByVal(123.4, 567.8)")
56 ' optionals with integer datatypes
57 TestUtil.AssertEqual(TestOptInteger(), IsMissingNone, "TestOptInteger()")
58 TestUtil.AssertEqual(TestOptInteger(123), IsMissingNone, "TestOptInteger(123)")
59 TestUtil.AssertEqual(TestOptInteger(, 456), IsMissingNone, "TestOptInteger(, 456)")
60 TestUtil.AssertEqual(TestOptInteger(123, 456), IsMissingNone, "TestOptInteger(123, 456)")
62 ' optionals with integer datatypes (ByRef and ByVal)
63 TestUtil.AssertEqual(TestOptIntegerByRefByVal(), IsMissingNone, "TestOptIntegerByRefByVal()")
64 TestUtil.AssertEqual(TestOptIntegerByRefByVal(123), IsMissingNone, "TestOptIntegerByRefByVal(123)")
65 TestUtil.AssertEqual(TestOptIntegerByRefByVal(, 456), IsMissingNone, "TestOptIntegerByRefByVal(, 456)")
66 TestUtil.AssertEqual(TestOptIntegerByRefByVal(123, 456), IsMissingNone, "TestOptIntegerByRefByVal(123, 456)")
68 ' optionals with string datatypes
69 TestUtil.AssertEqual(TestOptString(), IsMissingNone, "TestOptString()")
70 TestUtil.AssertEqual(TestOptString("123"), IsMissingNone, "TestOptString(""123"")")
71 TestUtil.AssertEqual(TestOptString(, "456"), IsMissingNone, "TestOptString(, ""456"")")
72 TestUtil.AssertEqual(TestOptString("123", "456"), IsMissingNone, "TestOptString(""123"", ""456"")")
74 ' optionals with string datatypes (ByRef and ByVal)
75 TestUtil.AssertEqual(TestOptStringByRefByVal(), IsMissingNone, "TestOptStringByRefByVal()")
76 TestUtil.AssertEqual(TestOptStringByRefByVal("123"), IsMissingNone, "TestOptStringByRefByVal(""123"")")
77 TestUtil.AssertEqual(TestOptStringByRefByVal(, "456"), IsMissingNone, "TestOptStringByRefByVal(, ""456"")")
78 TestUtil.AssertEqual(TestOptStringByRefByVal("123", "456"), IsMissingNone, "TestOptStringByRefByVal(""123"", ""456"")")
80 ' optionals with object datatypes
81 Dim cA As New Collection
82 cA.Add (123)
83 cA.Add (456)
84 Dim cB As New Collection
85 cB.Add (123.4)
86 cB.Add (567.8)
87 TestUtil.AssertEqual(TestOptObject(), IsMissingAB, "TestOptObject()")
88 TestUtil.AssertEqual(TestOptObject(cA), IsMissingB, "TestOptObject(A)")
89 TestUtil.AssertEqual(TestOptObject(, cB), IsMissingA, "TestOptObject(, B)")
90 TestUtil.AssertEqual(TestOptObject(cA, cB), IsMissingNone, "TestOptObject(A, B)")
92 ' optionals with object datatypes (ByRef and ByVal)
93 TestUtil.AssertEqual(TestOptObjectByRefByVal(), IsMissingAB, "TestOptObjectByRefByVal()")
94 TestUtil.AssertEqual(TestOptObjectByRefByVal(cA), IsMissingB, "TestOptObjectByRefByVal(A)")
95 TestUtil.AssertEqual(TestOptObjectByRefByVal(, cB), IsMissingA, "TestOptObjectByRefByVal(, B)")
96 TestUtil.AssertEqual(TestOptObjectByRefByVal(cA, cB), IsMissingNone, "TestOptObjectByRefByVal(A, B)")
98 ' optionals with array datatypes
99 Dim aA(0 To 1) As Integer
100 aA(0) = 123
101 aA(1) = 456
102 Dim aB(0 To 1) As Variant
103 aB(0) = 123.4
104 aB(1) = 567.8
105 ' TODO - New bug report? Scanner initializes variable not as an array
106 ' TestUtil.AssertEqual(TestOptArray(), IsMissingAB, "TestOptArray()")
107 ' TestUtil.AssertEqual(TestOptArray(aA), IsMissingB, "TestOptArray(A)")
108 ' TestUtil.AssertEqual(TestOptArray(, aB), IsMissingA, "TestOptArray(, B)")
109 TestUtil.AssertEqual(TestOptArray(aA, aB), IsMissingNone, "TestOptArray(A, B)")
111 ' optionals with array datatypes (ByRef and ByVal)
112 ' TODO - New bug report? Scanner initializes variable not as an array
113 ' TestUtil.AssertEqual(TestOptArrayByRefByVal(), IsMissingAB, "TestOptArrayByRefByVal()")
114 ' TestUtil.AssertEqual(TestOptArrayByRefByVal(aA), IsMissingB, "TestOptArrayByRefByVal(A)")
115 ' TestUtil.AssertEqual(TestOptArrayByRefByVal(, aB), IsMissingA, "TestOptArrayByRefByVal(, B)")
116 TestUtil.AssertEqual(TestOptArrayByRefByVal(aA, aB), IsMissingNone, "TestOptArrayByRefByVal(A, B)")
118 Exit Sub
119 errorHandler:
120 TestUtil.ReportErrorHandler("verify_testIsMissingVba", Err, Error$, Erl)
121 End Sub
123 Function TestOptVariant(Optional A, Optional B As Variant = 123)
124 TestOptVariant = WhatIsMissing(IsMissing(A), IsMissing(B))
125 End Function
127 Function TestOptVariantByRefByVal(Optional ByRef A, Optional ByVal B As Variant = 123)
128 TestOptVariantByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B))
129 End Function
131 Function TestOptDouble(Optional A As Double, Optional B As Double = 123.4)
132 TestOptDouble = WhatIsMissing(IsMissing(A), IsMissing(B))
133 End Function
135 Function TestOptDoubleByRefByVal(Optional ByRef A As Double, Optional ByVal B As Double = 123.4)
136 TestOptDoubleByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B))
137 End Function
139 Function TestOptInteger(Optional A As Integer, Optional B As Integer = 123)
140 TestOptInteger = WhatIsMissing(IsMissing(A), IsMissing(B))
141 End Function
143 Function TestOptIntegerByRefByVal(Optional ByRef A As Integer, Optional ByVal B As Integer = 123)
144 TestOptIntegerByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B))
145 End Function
147 Function TestOptString(Optional A As String, Optional B As String = "123")
148 TestOptString = WhatIsMissing(IsMissing(A), IsMissing(B))
149 End Function
151 Function TestOptStringByRefByVal(Optional ByRef A As String, Optional ByVal B As String = "123")
152 TestOptStringByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B))
153 End Function
155 Function TestOptObject(Optional A As Collection, Optional B As Collection)
156 TestOptObject = WhatIsMissing(IsNull(A), IsNull(B))
157 End Function
159 Function TestOptObjectByRefByVal(Optional ByRef A As Collection, Optional ByVal B As Collection)
160 TestOptObjectByRefByVal = WhatIsMissing(IsNull(A), IsNull(B))
161 End Function
163 Function TestOptArray(Optional A() As Integer, Optional B() As Variant)
164 TestOptArray = WhatIsMissing(IsEmpty(A), IsEmpty(B))
165 End Function
167 Function TestOptArrayByRefByVal(Optional ByRef A() As Integer, Optional ByVal B() As Variant)
168 TestOptArrayByRefByVal = WhatIsMissing(IsEmpty(A), IsEmpty(B))
169 End Function
171 Function WhatIsMissing(is_missingA, is_missingB)
172 If is_missingA And is_missingB Then
173 WhatIsMissing = IsMissingAB
174 ElseIf is_missingA Then
175 WhatIsMissing = IsMissingA
176 ElseIf is_missingB Then
177 WhatIsMissing = IsMissingB
178 Else
179 WhatIsMissing = IsMissingNone
180 End If
181 End Function