1 Const IsMissingNone
= -1
8 Function doUnitTest() As String
10 verify_testIsMissingBasic
11 doUnitTest
= TestUtil
.GetResult()
14 ' tdf#36737 - Test optionals with different datatypes. In LO Basic, optional
15 ' parameters are allowed, but without any default values. Missing optional parameters
16 ' will not be initialized to their respective default values of its datatype, either.
17 Sub verify_testIsMissingBasic()
19 On Error GoTo errorHandler
21 ' optionals with variant datatypes
22 TestUtil
.AssertEqual(TestOptVariant(), IsMissingAB
, "TestOptVariant()")
23 TestUtil
.AssertEqual(TestOptVariant(123), IsMissingB
, "TestOptVariant(123)")
24 TestUtil
.AssertEqual(TestOptVariant(, 456), IsMissingA
, "TestOptVariant(, 456)")
25 TestUtil
.AssertEqual(TestOptVariant(123, 456), IsMissingNone
, "TestOptVariant(123, 456)")
27 ' optionals with variant datatypes (ByRef and ByVal)
28 TestUtil
.AssertEqual(TestOptVariantByRefByVal(), IsMissingAB
, "TestOptVariantByRefByVal()")
29 TestUtil
.AssertEqual(TestOptVariantByRefByVal(123), IsMissingB
, "TestOptVariantByRefByVal(123)")
30 TestUtil
.AssertEqual(TestOptVariantByRefByVal(, 456), IsMissingA
, "TestOptVariantByRefByVal(, 456)")
31 TestUtil
.AssertEqual(TestOptVariantByRefByVal(123, 456), IsMissingNone
, "TestOptVariantByRefByVal(123, 456)")
33 ' optionals with double datatypes
34 TestUtil
.AssertEqual(TestOptDouble(), IsMissingAB
, "TestOptDouble()")
35 TestUtil
.AssertEqual(TestOptDouble(123.4), IsMissingB
, "TestOptDouble(123.4)")
36 TestUtil
.AssertEqual(TestOptDouble(, 567.8), IsMissingA
, "TestOptDouble(, 567.8)")
37 TestUtil
.AssertEqual(TestOptDouble(123.4, 567.8), IsMissingNone
, "TestOptDouble(123.4, 567.8)")
39 ' optionals with double datatypes (ByRef and ByVal)
40 TestUtil
.AssertEqual(TestOptDoubleByRefByVal(), IsMissingAB
, "TestOptDouble()")
41 TestUtil
.AssertEqual(TestOptDoubleByRefByVal(123.4), IsMissingB
, "TestOptDouble(123.4)")
42 TestUtil
.AssertEqual(TestOptDoubleByRefByVal(, 567.8), IsMissingA
, "TestOptDoubleByRefByVal(, 567.8)")
43 TestUtil
.AssertEqual(TestOptDoubleByRefByVal(123.4, 567.8), IsMissingNone
, "TestOptDoubleByRefByVal(123.4, 567.8)")
45 ' optionals with integer datatypes
46 TestUtil
.AssertEqual(TestOptInteger(), IsMissingAB
, "TestOptInteger()")
47 TestUtil
.AssertEqual(TestOptInteger(123), IsMissingB
, "TestOptInteger(123)")
48 TestUtil
.AssertEqual(TestOptInteger(, 456), IsMissingA
, "TestOptInteger(, 456)")
49 TestUtil
.AssertEqual(TestOptInteger(123, 456), IsMissingNone
, "TestOptInteger(123, 456)")
51 ' optionals with integer datatypes (ByRef and ByVal)
52 TestUtil
.AssertEqual(TestOptIntegerByRefByVal(), IsMissingAB
, "TestOptIntegerByRefByVal()")
53 TestUtil
.AssertEqual(TestOptIntegerByRefByVal(123), IsMissingB
, "TestOptIntegerByRefByVal(123)")
54 TestUtil
.AssertEqual(TestOptIntegerByRefByVal(, 456), IsMissingA
, "TestOptIntegerByRefByVal(, 456)")
55 TestUtil
.AssertEqual(TestOptIntegerByRefByVal(123, 456), IsMissingNone
, "TestOptIntegerByRefByVal(123, 456)")
57 ' optionals with string datatypes
58 TestUtil
.AssertEqual(TestOptString(), IsMissingAB
, "TestOptString()")
59 TestUtil
.AssertEqual(TestOptString("123"), IsMissingB
, "TestOptString(""123"")")
60 TestUtil
.AssertEqual(TestOptString(, "456"), IsMissingA
, "TestOptString(, ""456"")")
61 TestUtil
.AssertEqual(TestOptString("123", "456"), IsMissingNone
, "TestOptString(""123"", ""456"")")
63 ' optionals with string datatypes (ByRef and ByVal)
64 TestUtil
.AssertEqual(TestOptStringByRefByVal(), IsMissingAB
, "TestOptStringByRefByVal()")
65 TestUtil
.AssertEqual(TestOptStringByRefByVal("123"), IsMissingB
, "TestOptStringByRefByVal(""123"")")
66 TestUtil
.AssertEqual(TestOptStringByRefByVal(, "456"), IsMissingA
, "TestOptStringByRefByVal(, ""456"")")
67 TestUtil
.AssertEqual(TestOptStringByRefByVal("123", "456"), IsMissingNone
, "TestOptStringByRefByVal(""123"", ""456"")")
69 ' optionals with object datatypes
70 Dim cA
As New Collection
73 Dim cB
As New Collection
76 TestUtil
.AssertEqual(TestOptObject(), IsMissingAB
, "TestOptObject()")
77 TestUtil
.AssertEqual(TestOptObject(cA
), IsMissingB
, "TestOptObject(A)")
78 TestUtil
.AssertEqual(TestOptObject(, cB
), IsMissingA
, "TestOptObject(, B)")
79 TestUtil
.AssertEqual(TestOptObject(cA
, cB
), IsMissingNone
, "TestOptObject(A, B)")
81 ' optionals with object datatypes (ByRef and ByVal)
82 TestUtil
.AssertEqual(TestOptObjectByRefByVal(), IsMissingAB
, "TestOptObjectByRefByVal()")
83 TestUtil
.AssertEqual(TestOptObjectByRefByVal(cA
), IsMissingB
, "TestOptObjectByRefByVal(A)")
84 TestUtil
.AssertEqual(TestOptObjectByRefByVal(, cB
), IsMissingA
, "TestOptObjectByRefByVal(, B)")
85 TestUtil
.AssertEqual(TestOptObjectByRefByVal(cA
, cB
), IsMissingNone
, "TestOptObjectByRefByVal(A, B)")
87 ' optionals with array datatypes
88 Dim aA(0 To 1) As Integer
91 Dim aB(0 To 1) As Variant
94 TestUtil
.AssertEqual(TestOptArray(), IsMissingAB
, "TestOptArray()")
95 TestUtil
.AssertEqual(TestOptArray(aA
), IsMissingB
, "TestOptArray(A)")
96 TestUtil
.AssertEqual(TestOptArray(, aB
), IsMissingA
, "TestOptArray(, B)")
97 TestUtil
.AssertEqual(TestOptArray(aA
, aB
), IsMissingNone
, "TestOptArray(A, B)")
99 ' optionals with array datatypes (ByRef and ByVal)
100 TestUtil
.AssertEqual(TestOptArrayByRefByVal(), IsMissingAB
, "TestOptArrayByRefByVal()")
101 TestUtil
.AssertEqual(TestOptArrayByRefByVal(aA
), IsMissingB
, "TestOptArrayByRefByVal(A)")
102 TestUtil
.AssertEqual(TestOptArrayByRefByVal(, aB
), IsMissingA
, "TestOptArrayByRefByVal(, B)")
103 TestUtil
.AssertEqual(TestOptArrayByRefByVal(aA
, aB
), IsMissingNone
, "TestOptArrayByRefByVal(A, B)")
107 TestUtil
.ReportErrorHandler("verify_testIsMissingBasic", Err
, Error$, Erl
)
110 Function TestOptVariant(Optional A
, Optional B
As Variant)
111 TestOptVariant
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
114 Function TestOptVariantByRefByVal(Optional ByRef A
, Optional ByVal B
As Variant)
115 TestOptVariantByRefByVal
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
118 Function TestOptDouble(Optional A
As Double, Optional B
As Double)
119 TestOptDouble
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
122 Function TestOptDoubleByRefByVal(Optional ByRef A
As Double, Optional ByVal B
As Double)
123 TestOptDoubleByRefByVal
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
126 Function TestOptInteger(Optional A
As Integer, Optional B
As Integer)
127 TestOptInteger
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
130 Function TestOptIntegerByRefByVal(Optional ByRef A
As Integer, Optional ByVal B
As Integer)
131 TestOptIntegerByRefByVal
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
134 Function TestOptString(Optional A
As String, Optional B
As String)
135 TestOptString
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
138 Function TestOptStringByRefByVal(Optional ByRef A
As String, Optional ByVal B
As String)
139 TestOptStringByRefByVal
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
142 Function TestOptObject(Optional A
As Collection
, Optional B
As Collection
)
143 TestOptObject
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
146 Function TestOptObjectByRefByVal(Optional ByRef A
As Collection
, Optional ByVal B
As Collection
)
147 TestOptObjectByRefByVal
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
150 Function TestOptArray(Optional A() As Integer, Optional B() As Variant)
151 TestOptArray
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
154 Function TestOptArrayByRefByVal(Optional ByRef A() As Integer, Optional ByVal B() As Variant)
155 TestOptArrayByRefByVal
= WhatIsMissing(IsMissing(A
), IsMissing(B
))
158 Function WhatIsMissing(is_missingA
, is_missingB
)
159 If is_missingA
And is_missingB
Then
160 WhatIsMissing
= IsMissingAB
161 ElseIf is_missingA
Then
162 WhatIsMissing
= IsMissingA
163 ElseIf is_missingB
Then
164 WhatIsMissing
= IsMissingB
166 WhatIsMissing
= IsMissingNone