Rename LibreOffice Basic test files from .vb to .bas: they are not VBA
[LibreOffice.git] / basic / qa / basic_coverage / test_ismissing_basic.bas
blob85efb401274b2249831709404aa0d0a3f9ee30ec
1 Const IsMissingNone = -1
2 Const IsMissingA = 0
3 Const IsMissingB = 1
4 Const IsMissingAB = 2
6 Function doUnitTest() As String
7 TestUtil.TestInit
8 verify_testIsMissingBasic
9 doUnitTest = TestUtil.GetResult()
10 End Function
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
69 cA.Add (123)
70 cA.Add (456)
71 Dim cB As New Collection
72 cB.Add (123.4)
73 cB.Add (567.8)
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
87 aA(0) = 123
88 aA(1) = 456
89 Dim aB(0 To 1) As Variant
90 aB(0) = 123.4
91 aB(1) = 567.8
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)")
103 Exit Sub
104 errorHandler:
105 TestUtil.ReportErrorHandler("verify_testIsMissingBasic", Err, Error$, Erl)
106 End Sub
108 Function TestOptVariant(Optional A, Optional B As Variant)
109 TestOptVariant = WhatIsMissing(IsMissing(A), IsMissing(B))
110 End Function
112 Function TestOptVariantByRefByVal(Optional ByRef A, Optional ByVal B As Variant)
113 TestOptVariantByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B))
114 End Function
116 Function TestOptDouble(Optional A As Double, Optional B As Double)
117 TestOptDouble = WhatIsMissing(IsMissing(A), IsMissing(B))
118 End Function
120 Function TestOptDoubleByRefByVal(Optional ByRef A As Double, Optional ByVal B As Double)
121 TestOptDoubleByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B))
122 End Function
124 Function TestOptInteger(Optional A As Integer, Optional B As Integer)
125 TestOptInteger = WhatIsMissing(IsMissing(A), IsMissing(B))
126 End Function
128 Function TestOptIntegerByRefByVal(Optional ByRef A As Integer, Optional ByVal B As Integer)
129 TestOptIntegerByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B))
130 End Function
132 Function TestOptString(Optional A As String, Optional B As String)
133 TestOptString = WhatIsMissing(IsMissing(A), IsMissing(B))
134 End Function
136 Function TestOptStringByRefByVal(Optional ByRef A As String, Optional ByVal B As String)
137 TestOptStringByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B))
138 End Function
140 Function TestOptObject(Optional A As Collection, Optional B As Collection)
141 TestOptObject = WhatIsMissing(IsMissing(A), IsMissing(B))
142 End Function
144 Function TestOptObjectByRefByVal(Optional ByRef A As Collection, Optional ByVal B As Collection)
145 TestOptObjectByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B))
146 End Function
148 Function TestOptArray(Optional A() As Integer, Optional B() As Variant)
149 TestOptArray = WhatIsMissing(IsMissing(A), IsMissing(B))
150 End Function
152 Function TestOptArrayByRefByVal(Optional ByRef A() As Integer, Optional ByVal B() As Variant)
153 TestOptArrayByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B))
154 End Function
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
163 Else
164 WhatIsMissing = IsMissingNone
165 End If
166 End Function