1 ' This file is part of the LibreOffice project.
3 ' This Source Code Form is subject to the terms of the Mozilla Public
4 ' License, v. 2.0. If a copy of the MPL was not distributed with this
5 ' file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 Const IsMissingNone
= -1
15 Function doUnitTest() As String
17 verify_testIsMissingBasic
18 doUnitTest
= TestUtil
.GetResult()
21 ' tdf#36737 - Test optionals with different datatypes. In LO Basic, optional
22 ' parameters are allowed, but without any default values. Missing optional parameters
23 ' will not be initialized to their respective default values of its datatype, either.
24 Sub verify_testIsMissingBasic()
26 On Error GoTo errorHandler
28 ' optionals with variant datatypes
29 TestUtil
.AssertEqual(TestOptVariant(), IsMissingAB
, "TestOptVariant()")
30 TestUtil
.AssertEqual(TestOptVariant(123), IsMissingB
, "TestOptVariant(123)")
31 TestUtil
.AssertEqual(TestOptVariant(, 456), IsMissingA
, "TestOptVariant(, 456)")
32 TestUtil
.AssertEqual(TestOptVariant(123, 456), IsMissingNone
, "TestOptVariant(123, 456)")
34 ' optionals with variant datatypes (ByRef and ByVal)
35 TestUtil
.AssertEqual(TestOptVariantByRefByVal(), IsMissingAB
, "TestOptVariantByRefByVal()")
36 TestUtil
.AssertEqual(TestOptVariantByRefByVal(123), IsMissingB
, "TestOptVariantByRefByVal(123)")
37 TestUtil
.AssertEqual(TestOptVariantByRefByVal(, 456), IsMissingA
, "TestOptVariantByRefByVal(, 456)")
38 TestUtil
.AssertEqual(TestOptVariantByRefByVal(123, 456), IsMissingNone
, "TestOptVariantByRefByVal(123, 456)")
40 ' optionals with double datatypes
41 TestUtil
.AssertEqual(TestOptDouble(), IsMissingAB
, "TestOptDouble()")
42 TestUtil
.AssertEqual(TestOptDouble(123.4), IsMissingB
, "TestOptDouble(123.4)")
43 TestUtil
.AssertEqual(TestOptDouble(, 567.8), IsMissingA
, "TestOptDouble(, 567.8)")
44 TestUtil
.AssertEqual(TestOptDouble(123.4, 567.8), IsMissingNone
, "TestOptDouble(123.4, 567.8)")
46 ' optionals with double datatypes (ByRef and ByVal)
47 TestUtil
.AssertEqual(TestOptDoubleByRefByVal(), IsMissingAB
, "TestOptDouble()")
48 TestUtil
.AssertEqual(TestOptDoubleByRefByVal(123.4), IsMissingB
, "TestOptDouble(123.4)")
49 TestUtil
.AssertEqual(TestOptDoubleByRefByVal(, 567.8), IsMissingA
, "TestOptDoubleByRefByVal(, 567.8)")
50 TestUtil
.AssertEqual(TestOptDoubleByRefByVal(123.4, 567.8), IsMissingNone
, "TestOptDoubleByRefByVal(123.4, 567.8)")
52 ' optionals with integer datatypes
53 TestUtil
.AssertEqual(TestOptInteger(), IsMissingAB
, "TestOptInteger()")
54 TestUtil
.AssertEqual(TestOptInteger(123), IsMissingB
, "TestOptInteger(123)")
55 TestUtil
.AssertEqual(TestOptInteger(, 456), IsMissingA
, "TestOptInteger(, 456)")
56 TestUtil
.AssertEqual(TestOptInteger(123, 456), IsMissingNone
, "TestOptInteger(123, 456)")
58 ' optionals with integer datatypes (ByRef and ByVal)
59 TestUtil
.AssertEqual(TestOptIntegerByRefByVal(), IsMissingAB
, "TestOptIntegerByRefByVal()")
60 TestUtil
.AssertEqual(TestOptIntegerByRefByVal(123), IsMissingB
, "TestOptIntegerByRefByVal(123)")
61 TestUtil
.AssertEqual(TestOptIntegerByRefByVal(, 456), IsMissingA
, "TestOptIntegerByRefByVal(, 456)")
62 TestUtil
.AssertEqual(TestOptIntegerByRefByVal(123, 456), IsMissingNone
, "TestOptIntegerByRefByVal(123, 456)")
64 ' optionals with string datatypes
65 TestUtil
.AssertEqual(TestOptString(), IsMissingAB
, "TestOptString()")
66 TestUtil
.AssertEqual(TestOptString("123"), IsMissingB
, "TestOptString(""123"")")
67 TestUtil
.AssertEqual(TestOptString(, "456"), IsMissingA
, "TestOptString(, ""456"")")
68 TestUtil
.AssertEqual(TestOptString("123", "456"), IsMissingNone
, "TestOptString(""123"", ""456"")")
70 ' optionals with string datatypes (ByRef and ByVal)
71 TestUtil
.AssertEqual(TestOptStringByRefByVal(), IsMissingAB
, "TestOptStringByRefByVal()")
72 TestUtil
.AssertEqual(TestOptStringByRefByVal("123"), IsMissingB
, "TestOptStringByRefByVal(""123"")")
73 TestUtil
.AssertEqual(TestOptStringByRefByVal(, "456"), IsMissingA
, "TestOptStringByRefByVal(, ""456"")")
74 TestUtil
.AssertEqual(TestOptStringByRefByVal("123", "456"), IsMissingNone
, "TestOptStringByRefByVal(""123"", ""456"")")
76 ' optionals with object datatypes
77 Dim cA
As New Collection
80 Dim cB
As New Collection
83 TestUtil
.AssertEqual(TestOptObject(), IsMissingAB
, "TestOptObject()")
84 TestUtil
.AssertEqual(TestOptObject(cA
), IsMissingB
, "TestOptObject(A)")
85 TestUtil
.AssertEqual(TestOptObject(, cB
), IsMissingA
, "TestOptObject(, B)")
86 TestUtil
.AssertEqual(TestOptObject(cA
, cB
), IsMissingNone
, "TestOptObject(A, B)")
88 ' optionals with object datatypes (ByRef and ByVal)
89 TestUtil
.AssertEqual(TestOptObjectByRefByVal(), IsMissingAB
, "TestOptObjectByRefByVal()")
90 TestUtil
.AssertEqual(TestOptObjectByRefByVal(cA
), IsMissingB
, "TestOptObjectByRefByVal(A)")
91 TestUtil
.AssertEqual(TestOptObjectByRefByVal(, cB
), IsMissingA
, "TestOptObjectByRefByVal(, B)")
92 TestUtil
.AssertEqual(TestOptObjectByRefByVal(cA
, cB
), IsMissingNone
, "TestOptObjectByRefByVal(A, B)")
94 ' optionals with array datatypes
95 Dim aA(0 To 1) As Integer
98 Dim aB(0 To 1) As Variant
101 TestUtil
.AssertEqual(TestOptArray(), IsMissingAB
, "TestOptArray()")
102 TestUtil
.AssertEqual(TestOptArray(aA
), IsMissingB
, "TestOptArray(A)")
103 TestUtil
.AssertEqual(TestOptArray(, aB
), IsMissingA
, "TestOptArray(, B)")
104 TestUtil
.AssertEqual(TestOptArray(aA
, aB
), IsMissingNone
, "TestOptArray(A, B)")
106 ' optionals with array datatypes (ByRef and ByVal)
107 TestUtil
.AssertEqual(TestOptArrayByRefByVal(), IsMissingAB
, "TestOptArrayByRefByVal()")
108 TestUtil
.AssertEqual(TestOptArrayByRefByVal(aA
), IsMissingB
, "TestOptArrayByRefByVal(A)")
109 TestUtil
.AssertEqual(TestOptArrayByRefByVal(, aB
), IsMissingA
, "TestOptArrayByRefByVal(, B)")
110 TestUtil
.AssertEqual(TestOptArrayByRefByVal(aA
, aB
), IsMissingNone
, "TestOptArrayByRefByVal(A, B)")
114 TestUtil
.ReportErrorHandler("verify_testIsMissingBasic", Err
, Error$, Erl
)
117 Function TestOptVariant(Optional A
, Optional B
As Variant)
118 TestOptVariant
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
121 Function TestOptVariantByRefByVal(Optional ByRef A
, Optional ByVal B
As Variant)
122 TestOptVariantByRefByVal
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
125 Function TestOptDouble(Optional A
As Double, Optional B
As Double)
126 TestOptDouble
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
129 Function TestOptDoubleByRefByVal(Optional ByRef A
As Double, Optional ByVal B
As Double)
130 TestOptDoubleByRefByVal
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
133 Function TestOptInteger(Optional A
As Integer, Optional B
As Integer)
134 TestOptInteger
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
137 Function TestOptIntegerByRefByVal(Optional ByRef A
As Integer, Optional ByVal B
As Integer)
138 TestOptIntegerByRefByVal
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
141 Function TestOptString(Optional A
As String, Optional B
As String)
142 TestOptString
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
145 Function TestOptStringByRefByVal(Optional ByRef A
As String, Optional ByVal B
As String)
146 TestOptStringByRefByVal
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
149 Function TestOptObject(Optional A
As Collection
, Optional B
As Collection
)
150 TestOptObject
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
153 Function TestOptObjectByRefByVal(Optional ByRef A
As Collection
, Optional ByVal B
As Collection
)
154 TestOptObjectByRefByVal
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
157 Function TestOptArray(Optional A() As Integer, Optional B() As Variant)
158 TestOptArray
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
161 Function TestOptArrayByRefByVal(Optional ByRef A() As Integer, Optional ByVal B() As Variant)
162 TestOptArrayByRefByVal
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
165 Function WhatIsMissing(is_missingA
, is_missingB
)
166 If is_missingA
And is_missingB
Then
167 WhatIsMissing
= IsMissingAB
168 ElseIf is_missingA
Then
169 WhatIsMissing
= IsMissingA
170 ElseIf is_missingB
Then
171 WhatIsMissing
= IsMissingB
173 WhatIsMissing
= IsMissingNone