LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / basic / qa / basic_coverage / test_ismissing_compatible.bas
blobfb7e6981d74c94384f40d9499dbd8932e43f28c6
1 Option Compatible
2 Option Explicit
3 Const IsMissingNone = -1
4 Const IsMissingA = 0
5 Const IsMissingB = 1
6 Const IsMissingAB = 2
8 Function doUnitTest() As String
9 TestUtil.TestInit
10 verify_testIsMissingCompatible
11 doUnitTest = TestUtil.GetResult()
12 End Function
14 ' tdf#36737 - Test isMissing function with different datatypes. In LO Basic
15 ' with option Compatible, optional parameters are allowed with default values.
16 ' Missing optional parameters that don't have explicit default values will
17 ' not be initialized to their default values of its datatype.
18 Sub verify_testIsMissingCompatible()
19 On Error GoTo errorHandler
21 ' optionals with variant datatypes
22 TestUtil.AssertEqual(TestOptVariant(), IsMissingA, "TestOptVariant()")
23 TestUtil.AssertEqual(TestOptVariant(123), IsMissingNone, "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(), IsMissingA, "TestOptVariantByRefByVal()")
29 TestUtil.AssertEqual(TestOptVariantByRefByVal(123), IsMissingNone, "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(), IsMissingA, "TestOptDouble()")
35 TestUtil.AssertEqual(TestOptDouble(123.4), IsMissingNone, "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(), IsMissingA, "TestOptDouble()")
41 TestUtil.AssertEqual(TestOptDoubleByRefByVal(123.4), IsMissingNone, "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(), IsMissingA, "TestOptInteger()")
47 TestUtil.AssertEqual(TestOptInteger(123), IsMissingNone, "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(), IsMissingA, "TestOptIntegerByRefByVal()")
53 TestUtil.AssertEqual(TestOptIntegerByRefByVal(123), IsMissingNone, "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(), IsMissingA, "TestOptString()")
59 TestUtil.AssertEqual(TestOptString("123"), IsMissingNone, "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(), IsMissingA, "TestOptStringByRefByVal()")
65 TestUtil.AssertEqual(TestOptStringByRefByVal("123"), IsMissingNone, "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
71 cA.Add (123)
72 cA.Add (456)
73 Dim cB As New Collection
74 cB.Add (123.4)
75 cB.Add (567.8)
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
89 aA(0) = 123
90 aA(1) = 456
91 Dim aB(0 To 1) As Variant
92 aB(0) = 123.4
93 aB(1) = 567.8
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)")
105 Exit Sub
106 errorHandler:
107 TestUtil.ReportErrorHandler("verify_testIsMissingCompatible", Err, Error$, Erl)
108 End Sub
110 Function TestOptVariant(Optional A, Optional B As Variant = 123)
111 TestOptVariant = WhatIsMissing(IsMissing(A), IsMissing(B))
112 End Function
114 Function TestOptVariantByRefByVal(Optional ByRef A, Optional ByVal B As Variant = 123)
115 TestOptVariantByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B))
116 End Function
118 Function TestOptDouble(Optional A As Double, Optional B As Double = 123.4)
119 TestOptDouble = WhatIsMissing(IsMissing(A), IsMissing(B))
120 End Function
122 Function TestOptDoubleByRefByVal(Optional ByRef A As Double, Optional ByVal B As Double = 123.4)
123 TestOptDoubleByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B))
124 End Function
126 Function TestOptInteger(Optional A As Integer, Optional B As Integer = 123)
127 TestOptInteger = WhatIsMissing(IsMissing(A), IsMissing(B))
128 End Function
130 Function TestOptIntegerByRefByVal(Optional ByRef A As Integer, Optional ByVal B As Integer = 123)
131 TestOptIntegerByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B))
132 End Function
134 Function TestOptString(Optional A As String, Optional B As String = "123")
135 TestOptString = WhatIsMissing(IsMissing(A), IsMissing(B))
136 End Function
138 Function TestOptStringByRefByVal(Optional ByRef A As String, Optional ByVal B As String = "123")
139 TestOptStringByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B))
140 End Function
142 Function TestOptObject(Optional A As Collection, Optional B As Collection)
143 TestOptObject = WhatIsMissing(IsMissing(A), IsMissing(B))
144 End Function
146 Function TestOptObjectByRefByVal(Optional ByRef A As Collection, Optional ByVal B As Collection)
147 TestOptObjectByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B))
148 End Function
150 Function TestOptArray(Optional A() As Integer, Optional B() As Variant)
151 TestOptArray = WhatIsMissing(IsMissing(A), IsMissing(B))
152 End Function
154 Function TestOptArrayByRefByVal(Optional ByRef A() As Integer, Optional ByVal B() As Variant)
155 TestOptArrayByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B))
156 End Function
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
165 Else
166 WhatIsMissing = IsMissingNone
167 End If
168 End Function