tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / basic / qa / basic_coverage / test_ismissing_compatible.bas
blob6d11ab0902bec3772f3d42bed6c2f2ce4c1fac81
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 Option Compatible
9 Option Explicit
10 Const IsMissingNone = -1
11 Const IsMissingA = 0
12 Const IsMissingB = 1
13 Const IsMissingAB = 2
15 Function doUnitTest() As String
16 TestUtil.TestInit
17 verify_testIsMissingCompatible
18 doUnitTest = TestUtil.GetResult()
19 End Function
21 ' tdf#36737 - Test isMissing function with different datatypes. In LO Basic
22 ' with option Compatible, optional parameters are allowed with default values.
23 ' Missing optional parameters that don't have explicit default values will
24 ' not be initialized to their default values of its datatype.
25 Sub verify_testIsMissingCompatible()
26 On Error GoTo errorHandler
28 ' optionals with variant datatypes
29 TestUtil.AssertEqual(TestOptVariant(), IsMissingA, "TestOptVariant()")
30 TestUtil.AssertEqual(TestOptVariant(123), IsMissingNone, "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(), IsMissingA, "TestOptVariantByRefByVal()")
36 TestUtil.AssertEqual(TestOptVariantByRefByVal(123), IsMissingNone, "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(), IsMissingA, "TestOptDouble()")
42 TestUtil.AssertEqual(TestOptDouble(123.4), IsMissingNone, "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(), IsMissingA, "TestOptDouble()")
48 TestUtil.AssertEqual(TestOptDoubleByRefByVal(123.4), IsMissingNone, "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(), IsMissingA, "TestOptInteger()")
54 TestUtil.AssertEqual(TestOptInteger(123), IsMissingNone, "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(), IsMissingA, "TestOptIntegerByRefByVal()")
60 TestUtil.AssertEqual(TestOptIntegerByRefByVal(123), IsMissingNone, "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(), IsMissingA, "TestOptString()")
66 TestUtil.AssertEqual(TestOptString("123"), IsMissingNone, "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(), IsMissingA, "TestOptStringByRefByVal()")
72 TestUtil.AssertEqual(TestOptStringByRefByVal("123"), IsMissingNone, "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
78 cA.Add (123)
79 cA.Add (456)
80 Dim cB As New Collection
81 cB.Add (123.4)
82 cB.Add (567.8)
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
96 aA(0) = 123
97 aA(1) = 456
98 Dim aB(0 To 1) As Variant
99 aB(0) = 123.4
100 aB(1) = 567.8
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)")
112 Exit Sub
113 errorHandler:
114 TestUtil.ReportErrorHandler("verify_testIsMissingCompatible", Err, Error$, Erl)
115 End Sub
117 Function TestOptVariant(Optional A, Optional B As Variant = 123)
118 TestOptVariant = WhatIsMissing(IsMissing(A), IsMissing(B))
119 End Function
121 Function TestOptVariantByRefByVal(Optional ByRef A, Optional ByVal B As Variant = 123)
122 TestOptVariantByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B))
123 End Function
125 Function TestOptDouble(Optional A As Double, Optional B As Double = 123.4)
126 TestOptDouble = WhatIsMissing(IsMissing(A), IsMissing(B))
127 End Function
129 Function TestOptDoubleByRefByVal(Optional ByRef A As Double, Optional ByVal B As Double = 123.4)
130 TestOptDoubleByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B))
131 End Function
133 Function TestOptInteger(Optional A As Integer, Optional B As Integer = 123)
134 TestOptInteger = WhatIsMissing(IsMissing(A), IsMissing(B))
135 End Function
137 Function TestOptIntegerByRefByVal(Optional ByRef A As Integer, Optional ByVal B As Integer = 123)
138 TestOptIntegerByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B))
139 End Function
141 Function TestOptString(Optional A As String, Optional B As String = "123")
142 TestOptString = WhatIsMissing(IsMissing(A), IsMissing(B))
143 End Function
145 Function TestOptStringByRefByVal(Optional ByRef A As String, Optional ByVal B As String = "123")
146 TestOptStringByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B))
147 End Function
149 Function TestOptObject(Optional A As Collection, Optional B As Collection)
150 TestOptObject = WhatIsMissing(IsMissing(A), IsMissing(B))
151 End Function
153 Function TestOptObjectByRefByVal(Optional ByRef A As Collection, Optional ByVal B As Collection)
154 TestOptObjectByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B))
155 End Function
157 Function TestOptArray(Optional A() As Integer, Optional B() As Variant)
158 TestOptArray = WhatIsMissing(IsMissing(A), IsMissing(B))
159 End Function
161 Function TestOptArrayByRefByVal(Optional ByRef A() As Integer, Optional ByVal B() As Variant)
162 TestOptArrayByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B))
163 End Function
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
172 Else
173 WhatIsMissing = IsMissingNone
174 End If
175 End Function