1 Const IsMissingNone
= -1
6 Function doUnitTest() As String
8 verify_testIsMissingBasic
9 doUnitTest
= TestUtil
.GetResult()
12 ' tdf#36737 - Test optionals with different datatypes. In LO Basic, optional
13 ' parameters are allowed, but without any default values. Missing optional parameters
14 ' will not be initialized to their respective default values of its datatype, either.
15 Sub verify_testIsMissingBasic()
17 On Error GoTo errorHandler
19 ' optionals with variant datatypes
20 TestUtil
.AssertEqual(TestOptVariant(), IsMissingAB
, "TestOptVariant()")
21 TestUtil
.AssertEqual(TestOptVariant(123), IsMissingB
, "TestOptVariant(123)")
22 TestUtil
.AssertEqual(TestOptVariant(, 456), IsMissingA
, "TestOptVariant(, 456)")
23 TestUtil
.AssertEqual(TestOptVariant(123, 456), IsMissingNone
, "TestOptVariant(123, 456)")
25 ' optionals with variant datatypes (ByRef and ByVal)
26 TestUtil
.AssertEqual(TestOptVariantByRefByVal(), IsMissingAB
, "TestOptVariantByRefByVal()")
27 TestUtil
.AssertEqual(TestOptVariantByRefByVal(123), IsMissingB
, "TestOptVariantByRefByVal(123)")
28 TestUtil
.AssertEqual(TestOptVariantByRefByVal(, 456), IsMissingA
, "TestOptVariantByRefByVal(, 456)")
29 TestUtil
.AssertEqual(TestOptVariantByRefByVal(123, 456), IsMissingNone
, "TestOptVariantByRefByVal(123, 456)")
31 ' optionals with double datatypes
32 TestUtil
.AssertEqual(TestOptDouble(), IsMissingAB
, "TestOptDouble()")
33 TestUtil
.AssertEqual(TestOptDouble(123.4), IsMissingB
, "TestOptDouble(123.4)")
34 TestUtil
.AssertEqual(TestOptDouble(, 567.8), IsMissingA
, "TestOptDouble(, 567.8)")
35 TestUtil
.AssertEqual(TestOptDouble(123.4, 567.8), IsMissingNone
, "TestOptDouble(123.4, 567.8)")
37 ' optionals with double datatypes (ByRef and ByVal)
38 TestUtil
.AssertEqual(TestOptDoubleByRefByVal(), IsMissingAB
, "TestOptDouble()")
39 TestUtil
.AssertEqual(TestOptDoubleByRefByVal(123.4), IsMissingB
, "TestOptDouble(123.4)")
40 TestUtil
.AssertEqual(TestOptDoubleByRefByVal(, 567.8), IsMissingA
, "TestOptDoubleByRefByVal(, 567.8)")
41 TestUtil
.AssertEqual(TestOptDoubleByRefByVal(123.4, 567.8), IsMissingNone
, "TestOptDoubleByRefByVal(123.4, 567.8)")
43 ' optionals with integer datatypes
44 TestUtil
.AssertEqual(TestOptInteger(), IsMissingAB
, "TestOptInteger()")
45 TestUtil
.AssertEqual(TestOptInteger(123), IsMissingB
, "TestOptInteger(123)")
46 TestUtil
.AssertEqual(TestOptInteger(, 456), IsMissingA
, "TestOptInteger(, 456)")
47 TestUtil
.AssertEqual(TestOptInteger(123, 456), IsMissingNone
, "TestOptInteger(123, 456)")
49 ' optionals with integer datatypes (ByRef and ByVal)
50 TestUtil
.AssertEqual(TestOptIntegerByRefByVal(), IsMissingAB
, "TestOptIntegerByRefByVal()")
51 TestUtil
.AssertEqual(TestOptIntegerByRefByVal(123), IsMissingB
, "TestOptIntegerByRefByVal(123)")
52 TestUtil
.AssertEqual(TestOptIntegerByRefByVal(, 456), IsMissingA
, "TestOptIntegerByRefByVal(, 456)")
53 TestUtil
.AssertEqual(TestOptIntegerByRefByVal(123, 456), IsMissingNone
, "TestOptIntegerByRefByVal(123, 456)")
55 ' optionals with string datatypes
56 TestUtil
.AssertEqual(TestOptString(), IsMissingAB
, "TestOptString()")
57 TestUtil
.AssertEqual(TestOptString("123"), IsMissingB
, "TestOptString(""123"")")
58 TestUtil
.AssertEqual(TestOptString(, "456"), IsMissingA
, "TestOptString(, ""456"")")
59 TestUtil
.AssertEqual(TestOptString("123", "456"), IsMissingNone
, "TestOptString(""123"", ""456"")")
61 ' optionals with string datatypes (ByRef and ByVal)
62 TestUtil
.AssertEqual(TestOptStringByRefByVal(), IsMissingAB
, "TestOptStringByRefByVal()")
63 TestUtil
.AssertEqual(TestOptStringByRefByVal("123"), IsMissingB
, "TestOptStringByRefByVal(""123"")")
64 TestUtil
.AssertEqual(TestOptStringByRefByVal(, "456"), IsMissingA
, "TestOptStringByRefByVal(, ""456"")")
65 TestUtil
.AssertEqual(TestOptStringByRefByVal("123", "456"), IsMissingNone
, "TestOptStringByRefByVal(""123"", ""456"")")
67 ' optionals with object datatypes
68 Dim cA
As New Collection
71 Dim cB
As New Collection
74 TestUtil
.AssertEqual(TestOptObject(), IsMissingAB
, "TestOptObject()")
75 TestUtil
.AssertEqual(TestOptObject(cA
), IsMissingB
, "TestOptObject(A)")
76 TestUtil
.AssertEqual(TestOptObject(, cB
), IsMissingA
, "TestOptObject(, B)")
77 TestUtil
.AssertEqual(TestOptObject(cA
, cB
), IsMissingNone
, "TestOptObject(A, B)")
79 ' optionals with object datatypes (ByRef and ByVal)
80 TestUtil
.AssertEqual(TestOptObjectByRefByVal(), IsMissingAB
, "TestOptObjectByRefByVal()")
81 TestUtil
.AssertEqual(TestOptObjectByRefByVal(cA
), IsMissingB
, "TestOptObjectByRefByVal(A)")
82 TestUtil
.AssertEqual(TestOptObjectByRefByVal(, cB
), IsMissingA
, "TestOptObjectByRefByVal(, B)")
83 TestUtil
.AssertEqual(TestOptObjectByRefByVal(cA
, cB
), IsMissingNone
, "TestOptObjectByRefByVal(A, B)")
85 ' optionals with array datatypes
86 Dim aA(0 To 1) As Integer
89 Dim aB(0 To 1) As Variant
92 TestUtil
.AssertEqual(TestOptArray(), IsMissingAB
, "TestOptArray()")
93 TestUtil
.AssertEqual(TestOptArray(aA
), IsMissingB
, "TestOptArray(A)")
94 TestUtil
.AssertEqual(TestOptArray(, aB
), IsMissingA
, "TestOptArray(, B)")
95 TestUtil
.AssertEqual(TestOptArray(aA
, aB
), IsMissingNone
, "TestOptArray(A, B)")
97 ' optionals with array datatypes (ByRef and ByVal)
98 TestUtil
.AssertEqual(TestOptArrayByRefByVal(), IsMissingAB
, "TestOptArrayByRefByVal()")
99 TestUtil
.AssertEqual(TestOptArrayByRefByVal(aA
), IsMissingB
, "TestOptArrayByRefByVal(A)")
100 TestUtil
.AssertEqual(TestOptArrayByRefByVal(, aB
), IsMissingA
, "TestOptArrayByRefByVal(, B)")
101 TestUtil
.AssertEqual(TestOptArrayByRefByVal(aA
, aB
), IsMissingNone
, "TestOptArrayByRefByVal(A, B)")
105 TestUtil
.ReportErrorHandler("verify_testIsMissingBasic", Err
, Error$, Erl
)
108 Function TestOptVariant(Optional A
, Optional B
As Variant)
109 TestOptVariant
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
112 Function TestOptVariantByRefByVal(Optional ByRef A
, Optional ByVal B
As Variant)
113 TestOptVariantByRefByVal
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
116 Function TestOptDouble(Optional A
As Double, Optional B
As Double)
117 TestOptDouble
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
120 Function TestOptDoubleByRefByVal(Optional ByRef A
As Double, Optional ByVal B
As Double)
121 TestOptDoubleByRefByVal
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
124 Function TestOptInteger(Optional A
As Integer, Optional B
As Integer)
125 TestOptInteger
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
128 Function TestOptIntegerByRefByVal(Optional ByRef A
As Integer, Optional ByVal B
As Integer)
129 TestOptIntegerByRefByVal
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
132 Function TestOptString(Optional A
As String, Optional B
As String)
133 TestOptString
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
136 Function TestOptStringByRefByVal(Optional ByRef A
As String, Optional ByVal B
As String)
137 TestOptStringByRefByVal
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
140 Function TestOptObject(Optional A
As Collection
, Optional B
As Collection
)
141 TestOptObject
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
144 Function TestOptObjectByRefByVal(Optional ByRef A
As Collection
, Optional ByVal B
As Collection
)
145 TestOptObjectByRefByVal
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
148 Function TestOptArray(Optional A() As Integer, Optional B() As Variant)
149 TestOptArray
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
152 Function TestOptArrayByRefByVal(Optional ByRef A() As Integer, Optional ByVal B() As Variant)
153 TestOptArrayByRefByVal
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
156 Function WhatIsMissing(is_missingA
, is_missingB
)
157 If is_missingA
And is_missingB
Then
158 WhatIsMissing
= IsMissingAB
159 ElseIf is_missingA
Then
160 WhatIsMissing
= IsMissingA
161 ElseIf is_missingB
Then
162 WhatIsMissing
= IsMissingB
164 WhatIsMissing
= IsMissingNone