diff options
author | Andreas Heinisch <andreas.heinisch@yahoo.de> | 2020-01-27 20:09:05 +0100 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2020-03-02 10:08:58 +0100 |
commit | 8e323fcacebad1afe9d867b846722a6b9bf20f78 (patch) | |
tree | 6a180434e7e08dd6e02af2d6730896bf6ce1e1fe /basic/qa | |
parent | 6c12de3ed36083f35105dddab6943e5d3693edd8 (diff) |
tdf#36737 - Initialize default values of optionals
Initialize default values of optionals in function headers.
In LO Basic, optional parameters are allowed, but without
any default values. Missing parameters will not be initialized
to their respective default values of its datatype, either.
With option Compatible, optional parameters are allowed
with default values. Missing optional parameters that
don't have explicit default values will not be initialized
to their default values of its datatype.
With option VBASupport, optional parameters are allowed with
default values. Missing optional parameters that don't have
explicit default values will be initialized to their default
values of its datatype.
Change-Id: I57aabae5f70d1cf6c4e8feb95ce0db6af753383c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87550
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'basic/qa')
-rw-r--r-- | basic/qa/basic_coverage/test_ismissing_basic.vb | 202 | ||||
-rw-r--r-- | basic/qa/basic_coverage/test_ismissing_compatible.vb | 205 | ||||
-rw-r--r-- | basic/qa/basic_coverage/test_optional_paramters_basic.vb | 220 | ||||
-rw-r--r-- | basic/qa/basic_coverage/test_optional_paramters_compatible.vb | 224 | ||||
-rw-r--r-- | basic/qa/cppunit/test_vba.cxx | 1 | ||||
-rw-r--r-- | basic/qa/vba_tests/ismissing.vb | 224 | ||||
-rw-r--r-- | basic/qa/vba_tests/optional_paramters.vb | 231 |
7 files changed, 1264 insertions, 43 deletions
diff --git a/basic/qa/basic_coverage/test_ismissing_basic.vb b/basic/qa/basic_coverage/test_ismissing_basic.vb new file mode 100644 index 000000000000..8705220e26d4 --- /dev/null +++ b/basic/qa/basic_coverage/test_ismissing_basic.vb @@ -0,0 +1,202 @@ +Dim passCount As Integer +Dim failCount As Integer +Dim result As String + +Const IsMissingNone = -1 +Const IsMissingA = 0 +Const IsMissingB = 1 +Const IsMissingAB = 2 + +Function doUnitTest() As String + result = verify_testIsMissingBasic() + If failCount <> 0 Or passCount = 0 Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function + +' tdf#36737 - Test optionals with different datatypes. In LO Basic, optional +' parameters are allowed, but without any default values. Missing optional parameters +' will not be initialized to their respective default values of its datatype, either. +Function verify_testIsMissingBasic() As String + + passCount = 0 + failCount = 0 + + result = "Test Results" & Chr$(10) & "============" & Chr$(10) + testName = "Test optionals (Basic)" + On Error GoTo errorHandler + + ' optionals with variant datatypes + TestLog_ASSERT TestOptVariant(), IsMissingAB, "TestOptVariant()" + TestLog_ASSERT TestOptVariant(123), IsMissingB, "TestOptVariant(123)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptVariant(, 456), IsMissingA, "TestOptVariant(, 456)" + TestLog_ASSERT TestOptVariant(123, 456), IsMissingNone, "TestOptVariant(123, 456)" + + ' optionals with variant datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptVariantByRefByVal(), IsMissingAB, "TestOptVariantByRefByVal()" + TestLog_ASSERT TestOptVariantByRefByVal(123), IsMissingB, "TestOptVariantByRefByVal(123)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptVariantByRefByVal(, 456), IsMissingA, "TestOptVariantByRefByVal(, 456)" + TestLog_ASSERT TestOptVariantByRefByVal(123, 456), IsMissingNone, "TestOptVariantByRefByVal(123, 456)" + + ' optionals with double datatypes + TestLog_ASSERT TestOptDouble(), IsMissingAB, "TestOptDouble()" + TestLog_ASSERT TestOptDouble(123.4), IsMissingB, "TestOptDouble(123.4)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptDouble(, 567.8), IsMissingA, "TestOptDouble(, 567.8)" + TestLog_ASSERT TestOptDouble(123.4, 567.8), IsMissingNone, "TestOptDouble(123.4, 567.8)" + + ' optionals with double datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptDoubleByRefByVal(), IsMissingAB, "TestOptDouble()" + TestLog_ASSERT TestOptDoubleByRefByVal(123.4), IsMissingB, "TestOptDouble(123.4)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptDoubleByRefByVal(, 567.8), IsMissingA, "TestOptDoubleByRefByVal(, 567.8)" + TestLog_ASSERT TestOptDoubleByRefByVal(123.4, 567.8), IsMissingNone, "TestOptDoubleByRefByVal(123.4, 567.8)" + + ' optionals with integer datatypes + TestLog_ASSERT TestOptInteger(), IsMissingAB, "TestOptInteger()" + TestLog_ASSERT TestOptInteger(123), IsMissingB, "TestOptInteger(123)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptInteger(, 456), IsMissingA, "TestOptInteger(, 456)" + TestLog_ASSERT TestOptInteger(123, 456), IsMissingNone, "TestOptInteger(123, 456)" + + ' optionals with integer datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptIntegerByRefByVal(), IsMissingAB, "TestOptIntegerByRefByVal()" + TestLog_ASSERT TestOptIntegerByRefByVal(123), IsMissingB, "TestOptIntegerByRefByVal(123)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptIntegerByRefByVal(, 456), IsMissingA, "TestOptIntegerByRefByVal(, 456)" + TestLog_ASSERT TestOptIntegerByRefByVal(123, 456), IsMissingNone, "TestOptIntegerByRefByVal(123, 456)" + + ' optionals with string datatypes + TestLog_ASSERT TestOptString(), IsMissingAB, "TestOptString()" + TestLog_ASSERT TestOptString("123"), IsMissingB, "TestOptString(""123"")" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptString(, "456"), IsMissingA, "TestOptString(, ""456"")" + TestLog_ASSERT TestOptString("123", "456"), IsMissingNone, "TestOptString(""123"", ""456"")" + + ' optionals with string datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptStringByRefByVal(), IsMissingAB, "TestOptStringByRefByVal()" + TestLog_ASSERT TestOptStringByRefByVal("123"), IsMissingB, "TestOptStringByRefByVal(""123"")" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptStringByRefByVal(, "456"), IsMissingA, "TestOptStringByRefByVal(, ""456"")" + TestLog_ASSERT TestOptStringByRefByVal("123", "456"), IsMissingNone, "TestOptStringByRefByVal(""123"", ""456"")" + + ' optionals with object datatypes + Dim cA As New Collection + cA.Add (123) + cA.Add (456) + Dim cB As New Collection + cB.Add (123.4) + cB.Add (567.8) + TestLog_ASSERT TestOptObject(), IsMissingAB, "TestOptObject()" + TestLog_ASSERT TestOptObject(cA), IsMissingB, "TestOptObject(A)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptObject(, cB), IsMissingA, "TestOptObject(, B)" + TestLog_ASSERT TestOptObject(cA, cB), IsMissingNone, "TestOptObject(A, B)" + + ' optionals with object datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptObjectByRefByVal(), IsMissingAB, "TestOptObjectByRefByVal()" + TestLog_ASSERT TestOptObjectByRefByVal(cA), IsMissingB, "TestOptObjectByRefByVal(A)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptObjectByRefByVal(, cB), IsMissingA, "TestOptObjectByRefByVal(, B)" + TestLog_ASSERT TestOptObjectByRefByVal(cA, cB), IsMissingNone, "TestOptObjectByRefByVal(A, B)" + + ' optionals with array datatypes + Dim aA(0 To 1) As Integer + aA(0) = 123 + aA(1) = 456 + Dim aB(0 To 1) As Variant + aB(0) = 123.4 + aB(1) = 567.8 + TestLog_ASSERT TestOptArray(), IsMissingAB, "TestOptArray()" + TestLog_ASSERT TestOptArray(aA), IsMissingB, "TestOptArray(A)" + ' TODO - tdf#125180 for more details + 'TestLog_ASSERT TestOptArray(, aB), IsMissingA, "TestOptArray(, B)" + TestLog_ASSERT TestOptArray(aA, aB), IsMissingNone, "TestOptArray(A, B)" + + ' optionals with array datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptArrayByRefByVal(), IsMissingAB, "TestOptArrayByRefByVal()" + TestLog_ASSERT TestOptArrayByRefByVal(aA), IsMissingB, "TestOptArrayByRefByVal(A)" + ' TODO - tdf#125180 for more details + 'TestLog_ASSERT TestOptArrayByRefByVal(, aB), IsMissingA, "TestOptArrayByRefByVal(, B)" + TestLog_ASSERT TestOptArrayByRefByVal(aA, aB), IsMissingNone, "TestOptArrayByRefByVal(A, B)" + + result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10) + verify_testIsMissingBasic = result + + Exit Function +errorHandler: + TestLog_ASSERT False, True, Err.Description +End Function + +Function TestOptVariant(Optional A, Optional B As Variant) + TestOptVariant = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptVariantByRefByVal(Optional ByRef A, Optional ByVal B As Variant) + TestOptVariantByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptDouble(Optional A As Double, Optional B As Double) + TestOptDouble = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptDoubleByRefByVal(Optional ByRef A As Double, Optional ByVal B As Double) + TestOptDoubleByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptInteger(Optional A As Integer, Optional B As Integer) + TestOptInteger = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptIntegerByRefByVal(Optional ByRef A As Integer, Optional ByVal B As Integer) + TestOptIntegerByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptString(Optional A As String, Optional B As String) + TestOptString = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptStringByRefByVal(Optional ByRef A As String, Optional ByVal B As String) + TestOptStringByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptObject(Optional A As Collection, Optional B As Collection) + TestOptObject = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptObjectByRefByVal(Optional ByRef A As Collection, Optional ByVal B As Collection) + TestOptObjectByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptArray(Optional A() As Integer, Optional B() As Variant) + TestOptArray = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptArrayByRefByVal(Optional ByRef A() As Integer, Optional ByVal B() As Variant) + TestOptArrayByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function WhatIsMissing(is_missingA, is_missingB) + If is_missingA And is_missingB Then + WhatIsMissing = IsMissingAB + ElseIf is_missingA Then + WhatIsMissing = IsMissingA + ElseIf is_missingB Then + WhatIsMissing = IsMissingB + Else + WhatIsMissing = IsMissingNone + End If +End Function + +Sub TestLog_ASSERT(actual As Variant, expected As Integer, testName As String) + If expected = actual Then + passCount = passCount + 1 + Else + result = result & Chr$(10) & " Failed: " & testName & " returned " & actual & ", expected " & expected + failCount = failCount + 1 + End If +End Sub
\ No newline at end of file diff --git a/basic/qa/basic_coverage/test_ismissing_compatible.vb b/basic/qa/basic_coverage/test_ismissing_compatible.vb new file mode 100644 index 000000000000..13f076d5bc30 --- /dev/null +++ b/basic/qa/basic_coverage/test_ismissing_compatible.vb @@ -0,0 +1,205 @@ +Option Compatible + +Dim passCount As Integer +Dim failCount As Integer +Dim result As String + +Const IsMissingNone = -1 +Const IsMissingA = 0 +Const IsMissingB = 1 +Const IsMissingAB = 2 + +Function doUnitTest() As String + result = verify_testIsMissingCompatible() + If failCount <> 0 Or passCount = 0 Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function + +' tdf#36737 - Test isMissing function with different datatypes. In LO Basic +' with option Compatible, optional parameters are allowed with default values. +' Missing optional parameters that don't have explicit default values will +' not be initialized to their default values of its datatype. +Function verify_testIsMissingCompatible() As String + + passCount = 0 + failCount = 0 + + result = "Test Results" & Chr$(10) & "============" & Chr$(10) + testName = "Test optionals (Basic)" + On Error GoTo errorHandler + + ' optionals with variant datatypes + TestLog_ASSERT TestOptVariant(), IsMissingA, "TestOptVariant()" + TestLog_ASSERT TestOptVariant(123), IsMissingNone, "TestOptVariant(123)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptVariant(, 456), IsMissingA, "TestOptVariant(, 456)" + TestLog_ASSERT TestOptVariant(123, 456), IsMissingNone, "TestOptVariant(123, 456)" + + ' optionals with variant datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptVariantByRefByVal(), IsMissingA, "TestOptVariantByRefByVal()" + TestLog_ASSERT TestOptVariantByRefByVal(123), IsMissingNone, "TestOptVariantByRefByVal(123)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptVariantByRefByVal(, 456), IsMissingA, "TestOptVariantByRefByVal(, 456)" + TestLog_ASSERT TestOptVariantByRefByVal(123, 456), IsMissingNone, "TestOptVariantByRefByVal(123, 456)" + + ' optionals with double datatypes + TestLog_ASSERT TestOptDouble(), IsMissingA, "TestOptDouble()" + TestLog_ASSERT TestOptDouble(123.4), IsMissingNone, "TestOptDouble(123.4)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptDouble(, 567.8), IsMissingA, "TestOptDouble(, 567.8)" + TestLog_ASSERT TestOptDouble(123.4, 567.8), IsMissingNone, "TestOptDouble(123.4, 567.8)" + + ' optionals with double datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptDoubleByRefByVal(), IsMissingA, "TestOptDouble()" + TestLog_ASSERT TestOptDoubleByRefByVal(123.4), IsMissingNone, "TestOptDouble(123.4)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptDoubleByRefByVal(, 567.8), IsMissingA, "TestOptDoubleByRefByVal(, 567.8)" + TestLog_ASSERT TestOptDoubleByRefByVal(123.4, 567.8), IsMissingNone, "TestOptDoubleByRefByVal(123.4, 567.8)" + + ' optionals with integer datatypes + TestLog_ASSERT TestOptInteger(), IsMissingA, "TestOptInteger()" + TestLog_ASSERT TestOptInteger(123), IsMissingNone, "TestOptInteger(123)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptInteger(, 456), IsMissingA, "TestOptInteger(, 456)" + TestLog_ASSERT TestOptInteger(123, 456), IsMissingNone, "TestOptInteger(123, 456)" + + ' optionals with integer datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptIntegerByRefByVal(), IsMissingA, "TestOptIntegerByRefByVal()" + TestLog_ASSERT TestOptIntegerByRefByVal(123), IsMissingNone, "TestOptIntegerByRefByVal(123)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptIntegerByRefByVal(, 456), IsMissingA, "TestOptIntegerByRefByVal(, 456)" + TestLog_ASSERT TestOptIntegerByRefByVal(123, 456), IsMissingNone, "TestOptIntegerByRefByVal(123, 456)" + + ' optionals with string datatypes + TestLog_ASSERT TestOptString(), IsMissingA, "TestOptString()" + TestLog_ASSERT TestOptString("123"), IsMissingNone, "TestOptString(""123"")" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptString(, "456"), IsMissingA, "TestOptString(, ""456"")" + TestLog_ASSERT TestOptString("123", "456"), IsMissingNone, "TestOptString(""123"", ""456"")" + + ' optionals with string datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptStringByRefByVal(), IsMissingA, "TestOptStringByRefByVal()" + TestLog_ASSERT TestOptStringByRefByVal("123"), IsMissingNone, "TestOptStringByRefByVal(""123"")" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptStringByRefByVal(, "456"), IsMissingA, "TestOptStringByRefByVal(, ""456"")" + TestLog_ASSERT TestOptStringByRefByVal("123", "456"), IsMissingNone, "TestOptStringByRefByVal(""123"", ""456"")" + + ' optionals with object datatypes + Dim cA As New Collection + cA.Add (123) + cA.Add (456) + Dim cB As New Collection + cB.Add (123.4) + cB.Add (567.8) + TestLog_ASSERT TestOptObject(), IsMissingAB, "TestOptObject()" + TestLog_ASSERT TestOptObject(cA), IsMissingB, "TestOptObject(A)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptObject(, cB), IsMissingA, "TestOptObject(, B)" + TestLog_ASSERT TestOptObject(cA, cB), IsMissingNone, "TestOptObject(A, B)" + + ' optionals with object datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptObjectByRefByVal(), IsMissingAB, "TestOptObjectByRefByVal()" + TestLog_ASSERT TestOptObjectByRefByVal(cA), IsMissingB, "TestOptObjectByRefByVal(A)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptObjectByRefByVal(, cB), IsMissingA, "TestOptObjectByRefByVal(, B)" + TestLog_ASSERT TestOptObjectByRefByVal(cA, cB), IsMissingNone, "TestOptObjectByRefByVal(A, B)" + + ' optionals with array datatypes + Dim aA(0 To 1) As Integer + aA(0) = 123 + aA(1) = 456 + Dim aB(0 To 1) As Variant + aB(0) = 123.4 + aB(1) = 567.8 + TestLog_ASSERT TestOptArray(), IsMissingAB, "TestOptArray()" + TestLog_ASSERT TestOptArray(aA), IsMissingB, "TestOptArray(A)" + ' TODO - tdf#125180 for more details + 'TestLog_ASSERT TestOptArray(, aB), IsMissingA, "TestOptArray(, B)" + TestLog_ASSERT TestOptArray(aA, aB), IsMissingNone, "TestOptArray(A, B)" + + ' optionals with array datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptArrayByRefByVal(), IsMissingAB, "TestOptArrayByRefByVal()" + TestLog_ASSERT TestOptArrayByRefByVal(aA), IsMissingB, "TestOptArrayByRefByVal(A)" + ' TODO - tdf#125180 for more details + 'TestLog_ASSERT TestOptArrayByRefByVal(, aB), IsMissingA, "TestOptArrayByRefByVal(, B)" + TestLog_ASSERT TestOptArrayByRefByVal(aA, aB), IsMissingNone, "TestOptArrayByRefByVal(A, B)" + + result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10) + verify_testIsMissingCompatible = result + + Exit Function +errorHandler: + TestLog_ASSERT False, True, Err.Description +End Function + +Function TestOptVariant(Optional A, Optional B As Variant = 123) + TestOptVariant = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptVariantByRefByVal(Optional ByRef A, Optional ByVal B As Variant = 123) + TestOptVariantByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptDouble(Optional A As Double, Optional B As Double = 123.4) + TestOptDouble = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptDoubleByRefByVal(Optional ByRef A As Double, Optional ByVal B As Double = 123.4) + TestOptDoubleByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptInteger(Optional A As Integer, Optional B As Integer = 123) + TestOptInteger = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptIntegerByRefByVal(Optional ByRef A As Integer, Optional ByVal B As Integer = 123) + TestOptIntegerByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptString(Optional A As String, Optional B As String = "123") + TestOptString = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptStringByRefByVal(Optional ByRef A As String, Optional ByVal B As String = "123") + TestOptStringByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptObject(Optional A As Collection, Optional B As Collection) + TestOptObject = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptObjectByRefByVal(Optional ByRef A As Collection, Optional ByVal B As Collection) + TestOptObjectByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptArray(Optional A() As Integer, Optional B() As Variant) + TestOptArray = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptArrayByRefByVal(Optional ByRef A() As Integer, Optional ByVal B() As Variant) + TestOptArrayByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function WhatIsMissing(is_missingA, is_missingB) + If is_missingA And is_missingB Then + WhatIsMissing = IsMissingAB + ElseIf is_missingA Then + WhatIsMissing = IsMissingA + ElseIf is_missingB Then + WhatIsMissing = IsMissingB + Else + WhatIsMissing = IsMissingNone + End If +End Function + +Sub TestLog_ASSERT(actual As Variant, expected As Variant, testName As String) + If expected = actual Then + passCount = passCount + 1 + Else + result = result & Chr$(10) & " Failed: " & testName & " returned " & actual & ", expected " & expected + failCount = failCount + 1 + End If +End Sub
\ No newline at end of file diff --git a/basic/qa/basic_coverage/test_optional_paramters_basic.vb b/basic/qa/basic_coverage/test_optional_paramters_basic.vb new file mode 100644 index 000000000000..d260246508de --- /dev/null +++ b/basic/qa/basic_coverage/test_optional_paramters_basic.vb @@ -0,0 +1,220 @@ +Dim passCount As Integer +Dim failCount As Integer +Dim result As String + +Function doUnitTest() As String + result = verify_testOptionalsBasic() + If failCount <> 0 Or passCount = 0 Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function + +' tdf#36737 - Test optionals with different datatypes. In LO Basic, optional +' parameters are allowed, but without any default values. Missing optional +' parameters will not be initialized to their respective default values of +' its datatype, either. +Function verify_testOptionalsBasic() As String + + passCount = 0 + failCount = 0 + + result = "Test Results" & Chr$(10) & "============" & Chr$(10) + testName = "Test optionals (Basic)" + On Error GoTo errorHandler + + ' optionals with variant datatypes + TestLog_ASSERT TestOptVariant(), 0, "TestOptVariant()" + TestLog_ASSERT TestOptVariant(123), 123, "TestOptVariant(123)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptVariant(, 456), 456, "TestOptVariant(, 456)" + TestLog_ASSERT TestOptVariant(123, 456), 579, "TestOptVariant(123, 456)" + + ' optionals with variant datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptVariantByRefByVal(), 0, "TestOptVariantByRefByVal()" + TestLog_ASSERT TestOptVariantByRefByVal(123), 123, "TestOptVariantByRefByVal(123)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptVariantByRefByVal(, 456), 456, "TestOptVariantByRefByVal(, 456)" + TestLog_ASSERT TestOptVariantByRefByVal(123, 456), 579, "TestOptVariantByRefByVal(123, 456)" + + ' optionals with double datatypes + TestLog_ASSERT TestOptDouble(), 0, "TestOptDouble()" + TestLog_ASSERT TestOptDouble(123.4), 123.4, "TestOptDouble(123.4)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptDouble(, 567.8), 567.8, "TestOptDouble(, 567.8)" + TestLog_ASSERT Format(TestOptDouble(123.4, 567.8), "0.0"), 691.2, "TestOptDouble(123.4, 567.8)" + + ' optionals with double datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptDoubleByRefByVal(), 0, "TestOptDouble()" + TestLog_ASSERT TestOptDoubleByRefByVal(123.4), 123.4, "TestOptDouble(123.4)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptDoubleByRefByVal(, 567.8), 567.8, "TestOptDoubleByRefByVal(, 567.8)" + TestLog_ASSERT Format(TestOptDoubleByRefByVal(123.4, 567.8), "0.0"), 691.2, "TestOptDoubleByRefByVal(123.4, 567.8)" + + ' optionals with integer datatypes + TestLog_ASSERT TestOptInteger(), 0, "TestOptInteger()" + TestLog_ASSERT TestOptInteger(123), 123, "TestOptInteger(123)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptInteger(, 456), 456, "TestOptInteger(, 456)" + TestLog_ASSERT TestOptInteger(123, 456), 579, "TestOptInteger(123, 456)" + + ' optionals with integer datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptIntegerByRefByVal(), 0, "TestOptIntegerByRefByVal()" + TestLog_ASSERT TestOptIntegerByRefByVal(123), 123, "TestOptIntegerByRefByVal(123)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptIntegerByRefByVal(, 456), 456, "TestOptIntegerByRefByVal(, 456)" + TestLog_ASSERT TestOptIntegerByRefByVal(123, 456), 579, "TestOptIntegerByRefByVal(123, 456)" + + ' optionals with string datatypes + TestLog_ASSERT TestOptString(), "", "TestOptString()" + TestLog_ASSERT TestOptString("123"), "123", "TestOptString(""123"")" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptString(, "456"), "456", "TestOptString(, ""456"")" + TestLog_ASSERT TestOptString("123", "456"), "123456", "TestOptString(""123"", ""456"")" + + ' optionals with string datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptStringByRefByVal(), "", "TestOptStringByRefByVal()" + TestLog_ASSERT TestOptStringByRefByVal("123"), "123", "TestOptStringByRefByVal(""123"")" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptStringByRefByVal(, "456"), "456", "TestOptStringByRefByVal(, ""456"")" + TestLog_ASSERT TestOptStringByRefByVal("123", "456"), "123456", "TestOptStringByRefByVal(""123"", ""456"")" + + ' optionals with object datatypes + Dim cA As New Collection + cA.Add (123) + cA.Add (456) + Dim cB As New Collection + cB.Add (123.4) + cB.Add (567.8) + TestLog_ASSERT TestOptObject(), 0, "TestOptObject()" + TestLog_ASSERT TestOptObject(cA), 579, "TestOptObject(A)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT Format(TestOptObject(, cB), "0.0"), 691.2, "TestOptObject(, B)" + TestLog_ASSERT Format(TestOptObject(cA, cB), "0.0"), 1270.2, "TestOptObject(A, B)" + + ' optionals with object datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptObjectByRefByVal(), 0, "TestOptObjectByRefByVal()" + TestLog_ASSERT TestOptObjectByRefByVal(cA), 579, "TestOptObjectByRefByVal(A)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT Format(TestOptObjectByRefByVal(, cB), "0.0"), 691.2, "TestOptObjectByRefByVal(, B)" + TestLog_ASSERT Format(TestOptObjectByRefByVal(cA, cB), "0.0"), 1270.2, "TestOptObjectByRefByVal(A, B)" + + ' optionals with array datatypes + Dim aA(0 To 1) As Integer + aA(0) = 123 + aA(1) = 456 + Dim aB(0 To 1) As Variant + aB(0) = 123.4 + aB(1) = 567.8 + TestLog_ASSERT TestOptArray(), 0, "TestOptArray()" + TestLog_ASSERT TestOptArray(aA), 579, "TestOptArray(A)" + ' TODO - tdf#125180 for more details + 'TestLog_ASSERT Format(TestOptArray(, aB), "0.0"), 691.2, "TestOptArray(, B)" + TestLog_ASSERT Format(TestOptArray(aA, aB), "0.0"), 1270.2, "TestOptArray(A, B)" + + ' optionals with array datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptArrayByRefByVal(), 0, "TestOptArrayByRefByVal()" + TestLog_ASSERT TestOptArrayByRefByVal(aA), 579, "TestOptArrayByRefByVal(A)" + ' TODO - tdf#125180 for more details + 'TestLog_ASSERT Format(TestOptArrayByRefByVal(, aB), "0.0"), 691.2, "TestOptArrayByRefByVal(, B)" + TestLog_ASSERT Format(TestOptArrayByRefByVal(aA, aB), "0.0"), 1270.2, "TestOptArrayByRefByVal(A, B)" + + result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10) + verify_testOptionalsBasic = result + + Exit Function +errorHandler: + TestLog_ASSERT False, True, Err.Description +End Function + +Function TestOptVariant(Optional A, Optional B As Variant) + TestOptVariant = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptVariantByRefByVal(Optional ByRef A, Optional ByVal B As Variant) + TestOptVariantByRefByVal = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptDouble(Optional A As Double, Optional B As Double) + TestOptDouble = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptDoubleByRefByVal(Optional ByRef A As Double, Optional ByVal B As Double) + TestOptDoubleByRefByVal = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptInteger(Optional A As Integer, Optional B As Integer) + TestOptInteger = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptIntegerByRefByVal(Optional ByRef A As Integer, Optional ByVal B As Integer) + TestOptIntegerByRefByVal = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptString(Optional A As String, Optional B As String) + TestOptString = OptStringConcat(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptStringByRefByVal(Optional ByRef A As String, Optional ByVal B As String) + TestOptStringByRefByVal = OptStringConcat(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptObject(Optional A As Collection, Optional B As Collection) + TestOptObject = 0 + If Not IsMissing(A) Then TestOptObject = CollectionSum(A) + If Not IsMissing(B) Then TestOptObject = TestOptObject + CollectionSum(B) +End Function + +Function TestOptObjectByRefByVal(Optional ByRef A As Collection, Optional ByVal B As Collection) + TestOptObjectByRefByVal = 0 + If Not IsMissing(A) Then TestOptObjectByRefByVal = CollectionSum(A) + If Not IsMissing(B) Then TestOptObjectByRefByVal = TestOptObjectByRefByVal + CollectionSum(B) +End Function + +Function TestOptArray(Optional A() As Integer, Optional B() As Variant) + TestOptArray = ArraySum(IsMissing(A), A) + ArraySum(IsMissing(B), B) +End Function + +Function TestOptArrayByRefByVal(Optional ByRef A() As Integer, Optional ByVal B() As Variant) + TestOptArrayByRefByVal = ArraySum(IsMissing(A), A) + ArraySum(IsMissing(B), B) +End Function + +Function OptNumberSum(is_missingA As Boolean, A, is_missingB As Boolean, B) + OptNumberSum = 0 + If Not is_missingA Then OptNumberSum = A + If Not is_missingB Then OptNumberSum = OptNumberSum + B +End Function + +Function OptStringConcat(is_missingA As Boolean, A, is_missingB As Boolean, B) + OptStringConcat = "" + If Not is_missingA Then OptStringConcat = A + If Not is_missingB Then OptStringConcat = OptStringConcat & B +End Function + +Function CollectionSum(C) + Dim idx As Integer + CollectionSum = 0 + For idx = 1 To C.Count + CollectionSum = CollectionSum + C.Item(idx) + Next idx +End Function + +Function ArraySum(is_missingC As Boolean, C) + Dim idx As Integer + ArraySum = 0 + If Not is_missingC Then + For idx = LBound(C) To UBound(C) + ArraySum = ArraySum + C(idx) + Next idx + End If +End Function + +Sub TestLog_ASSERT(actual As Variant, expected As Variant, testName As String) + If expected = actual Then + passCount = passCount + 1 + Else + result = result & Chr$(10) & " Failed: " & testName & " returned " & actual & ", expected " & expected + failCount = failCount + 1 + End If +End Sub
\ No newline at end of file diff --git a/basic/qa/basic_coverage/test_optional_paramters_compatible.vb b/basic/qa/basic_coverage/test_optional_paramters_compatible.vb new file mode 100644 index 000000000000..5cbaeab258ad --- /dev/null +++ b/basic/qa/basic_coverage/test_optional_paramters_compatible.vb @@ -0,0 +1,224 @@ +Option Compatible + +Dim passCount As Integer +Dim failCount As Integer +Dim result As String + +Function doUnitTest() As String + result = verify_testOptionalsCompatible() + If failCount <> 0 Or passCount = 0 Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function + +' tdf#36737 - Test optionals with different datatypes. In LO Basic +' with option Compatible, optional parameters are allowed with default values. +' Missing optional parameters that don't have explicit default values will +' not be initialized to their default values of its datatype. +Function verify_testOptionalsCompatible() As String + + passCount = 0 + failCount = 0 + + result = "Test Results" & Chr$(10) & "============" & Chr$(10) + testName = "Test optionals (Basic)" + On Error GoTo errorHandler + + ' optionals with variant datatypes + ' TODO - New bug report? Scanner initializes variable as String. Function returns "123" + ' TestLog_ASSERT TestOptVariant(), 123, "TestOptVariant()" + TestLog_ASSERT TestOptVariant(123), 246, "TestOptVariant(123)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptVariant(, 456), 456, "TestOptVariant(, 456)" + TestLog_ASSERT TestOptVariant(123, 456), 579, "TestOptVariant(123, 456)" + + ' optionals with variant datatypes (ByRef and ByVal) + ' TODO - New bug report? Scanner initializes variable as String. Function returns "123" + ' TestLog_ASSERT TestOptVariantByRefByVal(), 123, "TestOptVariantByRefByVal()" + TestLog_ASSERT TestOptVariantByRefByVal(123), 246, "TestOptVariantByRefByVal(123)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptVariantByRefByVal(, 456), 456, "TestOptVariantByRefByVal(, 456)" + TestLog_ASSERT TestOptVariantByRefByVal(123, 456), 579, "TestOptVariantByRefByVal(123, 456)" + + ' optionals with double datatypes + TestLog_ASSERT TestOptDouble(), 123.4, "TestOptDouble()" + TestLog_ASSERT TestOptDouble(123.4), 246.8, "TestOptDouble(123.4)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptDouble(, 567.8), 567.8, "TestOptDouble(, 567.8)" + TestLog_ASSERT Format(TestOptDouble(123.4, 567.8), "0.0"), 691.2, "TestOptDouble(123.4, 567.8)" + + ' optionals with double datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptDoubleByRefByVal(), 123.4, "TestOptDouble()" + TestLog_ASSERT TestOptDoubleByRefByVal(123.4), 246.8, "TestOptDouble(123.4)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptDoubleByRefByVal(, 567.8), 567.8, "TestOptDoubleByRefByVal(, 567.8)" + TestLog_ASSERT Format(TestOptDoubleByRefByVal(123.4, 567.8), "0.0"), 691.2, "TestOptDoubleByRefByVal(123.4, 567.8)" + + ' optionals with integer datatypes + TestLog_ASSERT TestOptInteger(), 123, "TestOptInteger()" + TestLog_ASSERT TestOptInteger(123), 246, "TestOptInteger(123)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptInteger(, 456), 456, "TestOptInteger(, 456)" + TestLog_ASSERT TestOptInteger(123, 456), 579, "TestOptInteger(123, 456)" + + ' optionals with integer datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptIntegerByRefByVal(), 123, "TestOptIntegerByRefByVal()" + TestLog_ASSERT TestOptIntegerByRefByVal(123), 246, "TestOptIntegerByRefByVal(123)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptIntegerByRefByVal(, 456), 456, "TestOptIntegerByRefByVal(, 456)" + TestLog_ASSERT TestOptIntegerByRefByVal(123, 456), 579, "TestOptIntegerByRefByVal(123, 456)" + + ' optionals with string datatypes + TestLog_ASSERT TestOptString(), "123", "TestOptString()" + TestLog_ASSERT TestOptString("123"), "123123", "TestOptString(""123"")" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptString(, "456"), "456", "TestOptString(, ""456"")" + TestLog_ASSERT TestOptString("123", "456"), "123456", "TestOptString(""123"", ""456"")" + + ' optionals with string datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptStringByRefByVal(), "123", "TestOptStringByRefByVal()" + TestLog_ASSERT TestOptStringByRefByVal("123"), "123123", "TestOptStringByRefByVal(""123"")" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptStringByRefByVal(, "456"), "456", "TestOptStringByRefByVal(, ""456"")" + TestLog_ASSERT TestOptStringByRefByVal("123", "456"), "123456", "TestOptStringByRefByVal(""123"", ""456"")" + + ' optionals with object datatypes + Dim cA As New Collection + cA.Add (123) + cA.Add (456) + Dim cB As New Collection + cB.Add (123.4) + cB.Add (567.8) + TestLog_ASSERT TestOptObject(), 0, "TestOptObject()" + TestLog_ASSERT TestOptObject(cA), 579, "TestOptObject(A)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT Format(TestOptObject(, cB), "0.0"), 691.2, "TestOptObject(, B)" + TestLog_ASSERT Format(TestOptObject(cA, cB), "0.0"), 1270.2, "TestOptObject(A, B)" + + ' optionals with object datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptObjectByRefByVal(), 0, "TestOptObjectByRefByVal()" + TestLog_ASSERT TestOptObjectByRefByVal(cA), 579, "TestOptObjectByRefByVal(A)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT Format(TestOptObjectByRefByVal(, cB), "0.0"), 691.2, "TestOptObjectByRefByVal(, B)" + TestLog_ASSERT Format(TestOptObjectByRefByVal(cA, cB), "0.0"), 1270.2, "TestOptObjectByRefByVal(A, B)" + + ' optionals with array datatypes + Dim aA(0 To 1) As Integer + aA(0) = 123 + aA(1) = 456 + Dim aB(0 To 1) As Variant + aB(0) = 123.4 + aB(1) = 567.8 + TestLog_ASSERT TestOptArray(), 0, "TestOptArray()" + TestLog_ASSERT TestOptArray(aA), 579, "TestOptArray(A)" + ' TODO - tdf#125180 for more details + 'TestLog_ASSERT Format(TestOptArray(, aB), "0.0"), 691.2, "TestOptArray(, B)" + TestLog_ASSERT Format(TestOptArray(aA, aB), "0.0"), 1270.2, "TestOptArray(A, B)" + + ' optionals with array datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptArrayByRefByVal(), 0, "TestOptArrayByRefByVal()" + TestLog_ASSERT TestOptArrayByRefByVal(aA), 579, "TestOptArrayByRefByVal(A)" + ' TODO - tdf#125180 for more details + 'TestLog_ASSERT Format(TestOptArrayByRefByVal(, aB), "0.0"), 691.2, "TestOptArrayByRefByVal(, B)" + TestLog_ASSERT Format(TestOptArrayByRefByVal(aA, aB), "0.0"), 1270.2, "TestOptArrayByRefByVal(A, B)" + + result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10) + verify_testOptionalsCompatible = result + + Exit Function +errorHandler: + TestLog_ASSERT False, True, Err.Description +End Function + +Function TestOptVariant(Optional A, Optional B As Variant = 123) + TestOptVariant = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptVariantByRefByVal(Optional ByRef A, Optional ByVal B As Variant = 123) + TestOptVariantByRefByVal = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptDouble(Optional A As Double, Optional B As Double = 123.4) + TestOptDouble = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptDoubleByRefByVal(Optional ByRef A As Double, Optional ByVal B As Double = 123.4) + TestOptDoubleByRefByVal = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptInteger(Optional A As Integer, Optional B As Integer = 123) + TestOptInteger = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptIntegerByRefByVal(Optional ByRef A As Integer, Optional ByVal B As Integer = 123) + TestOptIntegerByRefByVal = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptString(Optional A As String, Optional B As String = "123") + TestOptString = OptStringConcat(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptStringByRefByVal(Optional ByRef A As String, Optional ByVal B As String = "123") + TestOptStringByRefByVal = OptStringConcat(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptObject(Optional A As Collection, Optional B As Collection) + TestOptObject = 0 + If Not IsMissing(A) Then TestOptObject = CollectionSum(A) + If Not IsMissing(B) Then TestOptObject = TestOptObject + CollectionSum(B) +End Function + +Function TestOptObjectByRefByVal(Optional ByRef A As Collection, Optional ByVal B As Collection) + TestOptObjectByRefByVal = 0 + If Not IsMissing(A) Then TestOptObjectByRefByVal = CollectionSum(A) + If Not IsMissing(B) Then TestOptObjectByRefByVal = TestOptObjectByRefByVal + CollectionSum(B) +End Function + +Function TestOptArray(Optional A() As Integer, Optional B() As Variant) + TestOptArray = ArraySum(IsMissing(A), A) + ArraySum(IsMissing(B), B) +End Function + +Function TestOptArrayByRefByVal(Optional ByRef A() As Integer, Optional ByVal B() As Variant) + TestOptArrayByRefByVal = ArraySum(IsMissing(A), A) + ArraySum(IsMissing(B), B) +End Function + +Function OptNumberSum(is_missingA As Boolean, A, is_missingB As Boolean, B) + OptNumberSum = 0 + If Not is_missingA Then OptNumberSum = A + If Not is_missingB Then OptNumberSum = OptNumberSum + B +End Function + +Function OptStringConcat(is_missingA As Boolean, A, is_missingB As Boolean, B) + OptStringConcat = "" + If Not is_missingA Then OptStringConcat = A + If Not is_missingB Then OptStringConcat = OptStringConcat & B +End Function + +Function CollectionSum(C) + Dim idx As Integer + CollectionSum = 0 + For idx = 1 To C.Count + CollectionSum = CollectionSum + C.Item(idx) + Next idx +End Function + +Function ArraySum(is_missingC As Boolean, C) + Dim idx As Integer + ArraySum = 0 + If Not is_missingC Then + For idx = LBound(C) To UBound(C) + ArraySum = ArraySum + C(idx) + Next idx + End If +End Function + +Sub TestLog_ASSERT(actual As Variant, expected As Variant, testName As String) + If expected = actual Then + passCount = passCount + 1 + Else + result = result & Chr$(10) & " Failed: " & testName & " returned " & actual & ", expected " & expected + failCount = failCount + 1 + End If +End Sub
\ No newline at end of file diff --git a/basic/qa/cppunit/test_vba.cxx b/basic/qa/cppunit/test_vba.cxx index 74c9752cf1c5..fd0bdb1c2c2c 100644 --- a/basic/qa/cppunit/test_vba.cxx +++ b/basic/qa/cppunit/test_vba.cxx @@ -113,6 +113,7 @@ void VBATest::testMiscVBAFunctions() "month.vb", "monthname.vb", "oct.vb", + "optional_paramters.vb", "qbcolor.vb", "rgb.vb", "rtrim.vb", diff --git a/basic/qa/vba_tests/ismissing.vb b/basic/qa/vba_tests/ismissing.vb index 496a57a533e7..1adc73441c22 100644 --- a/basic/qa/vba_tests/ismissing.vb +++ b/basic/qa/vba_tests/ismissing.vb @@ -1,72 +1,210 @@ Option VBASupport 1 -Option Explicit + Dim passCount As Integer Dim failCount As Integer Dim result As String +Const IsMissingNone = -1 +Const IsMissingA = 0 +Const IsMissingB = 1 +Const IsMissingAB = 2 + Function doUnitTest() As String -result = verify_testIsMissing() -If failCount <> 0 Or passCount = 0 Then - doUnitTest = result -Else - doUnitTest = "OK" -End If + result = verify_testIsMissingVba() + If failCount <> 0 Or passCount = 0 Then + doUnitTest = result + Else + doUnitTest = "OK" + End If End Function - - -Function verify_testIsMissing() As String +' tdf#36737 - Test isMissing function with different datatypes. In LO Basic +' with option VBASupport, optional parameters are allowed including additional +' default values. Missing optional parameters having types other than variant, +' which don't have explicit default values, will be initialized to their +' respective default value of its datatype. +Function verify_testIsMissingVba() As String passCount = 0 failCount = 0 result = "Test Results" & Chr$(10) & "============" & Chr$(10) - - Dim testName As String - Dim num1, num2 As Integer - testName = "Test IsMissing function" + testName = "Test optionals (Basic)" On Error GoTo errorHandler - num1 = ReturnTwice() - TestLog_ASSERT IsNull(num1) + ' optionals with variant datatypes + TestLog_ASSERT TestOptVariant(), IsMissingA, "TestOptVariant()" + TestLog_ASSERT TestOptVariant(123), IsMissingNone, "TestOptVariant(123)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptVariant(, 456), IsMissingNone, "TestOptVariant(, 456)" + TestLog_ASSERT TestOptVariant(123, 456), IsMissingNone, "TestOptVariant(123, 456)" + + ' optionals with variant datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptVariantByRefByVal(), IsMissingA, "TestOptVariantByRefByVal()" + TestLog_ASSERT TestOptVariantByRefByVal(123),IsMissingNone, "TestOptVariantByRefByVal(123)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptVariantByRefByVal(, 456), IsMissingNone, "TestOptVariantByRefByVal(, 456)" + TestLog_ASSERT TestOptVariantByRefByVal(123, 456), IsMissingNone, "TestOptVariantByRefByVal(123, 456)" + + ' optionals with double datatypes + TestLog_ASSERT TestOptDouble(), IsMissingNone, "TestOptDouble()" + TestLog_ASSERT TestOptDouble(123.4), IsMissingNone, "TestOptDouble(123.4)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptDouble(, 567.8), IsMissingNone, "TestOptDouble(, 567.8)" + TestLog_ASSERT TestOptDouble(123.4, 567.8), IsMissingNone, "TestOptDouble(123.4, 567.8)" + + ' optionals with double datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptDoubleByRefByVal(), IsMissingNone, "TestOptDouble()" + TestLog_ASSERT TestOptDoubleByRefByVal(123.4), IsMissingNone, "TestOptDouble(123.4)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptDoubleByRefByVal(, 567.8), IsMissingNone, "TestOptDoubleByRefByVal(, 567.8)" + TestLog_ASSERT TestOptDoubleByRefByVal(123.4, 567.8), IsMissingNone, "TestOptDoubleByRefByVal(123.4, 567.8)" + + ' optionals with integer datatypes + TestLog_ASSERT TestOptInteger(), IsMissingNone, "TestOptInteger()" + TestLog_ASSERT TestOptInteger(123), IsMissingNone, "TestOptInteger(123)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptInteger(, 456), IsMissingNone, "TestOptInteger(, 456)" + TestLog_ASSERT TestOptInteger(123, 456), IsMissingNone, "TestOptInteger(123, 456)" + + ' optionals with integer datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptIntegerByRefByVal(), IsMissingNone, "TestOptIntegerByRefByVal()" + TestLog_ASSERT TestOptIntegerByRefByVal(123), IsMissingNone, "TestOptIntegerByRefByVal(123)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptIntegerByRefByVal(, 456), IsMissingNone, "TestOptIntegerByRefByVal(, 456)" + TestLog_ASSERT TestOptIntegerByRefByVal(123, 456), IsMissingNone, "TestOptIntegerByRefByVal(123, 456)" - num2 = 4 - num1 = ReturnTwice(2) - TestLog_ASSERT num1 = num2, "the return IsMissing is: " & num1 + ' optionals with string datatypes + TestLog_ASSERT TestOptString(), IsMissingNone, "TestOptString()" + TestLog_ASSERT TestOptString("123"), IsMissingNone, "TestOptString(""123"")" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptString(, "456"), IsMissingNone, "TestOptString(, ""456"")" + TestLog_ASSERT TestOptString("123", "456"), IsMissingNone, "TestOptString(""123"", ""456"")" + + ' optionals with string datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptStringByRefByVal(), IsMissingNone, "TestOptStringByRefByVal()" + TestLog_ASSERT TestOptStringByRefByVal("123"), IsMissingNone, "TestOptStringByRefByVal(""123"")" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptStringByRefByVal(, "456"), IsMissingNone, "TestOptStringByRefByVal(, ""456"")" + TestLog_ASSERT TestOptStringByRefByVal("123", "456"), IsMissingNone, "TestOptStringByRefByVal(""123"", ""456"")" + + ' optionals with object datatypes + Dim cA As New Collection + cA.Add (123) + cA.Add (456) + Dim cB As New Collection + cB.Add (123.4) + cB.Add (567.8) + TestLog_ASSERT TestOptObject(), IsMissingAB, "TestOptObject()" + TestLog_ASSERT TestOptObject(cA), IsMissingB, "TestOptObject(A)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptObject(, cB), IsMissingA, "TestOptObject(, B)" + TestLog_ASSERT TestOptObject(cA, cB), IsMissingNone, "TestOptObject(A, B)" + + ' optionals with object datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptObjectByRefByVal(), IsMissingAB, "TestOptObjectByRefByVal()" + TestLog_ASSERT TestOptObjectByRefByVal(cA), IsMissingB, "TestOptObjectByRefByVal(A)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptObjectByRefByVal(, cB), IsMissingA, "TestOptObjectByRefByVal(, B)" + TestLog_ASSERT TestOptObjectByRefByVal(cA, cB), IsMissingNone, "TestOptObjectByRefByVal(A, B)" + + ' optionals with array datatypes + Dim aA(0 To 1) As Integer + aA(0) = 123 + aA(1) = 456 + Dim aB(0 To 1) As Variant + aB(0) = 123.4 + aB(1) = 567.8 + ' TODO - New bug report? Scanner initializes variable not as an array + ' TestLog_ASSERT TestOptArray(), IsMissingAB, "TestOptArray()" + ' TestLog_ASSERT TestOptArray(aA), IsMissingB, "TestOptArray(A)" + + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptArray(, aB), IsMissingA, "TestOptArray(, B)" + TestLog_ASSERT TestOptArray(aA, aB), IsMissingNone, "TestOptArray(A, B)" + + ' optionals with array datatypes (ByRef and ByVal) + ' TODO - New bug report? Scanner initializes variable not as an array + ' TestLog_ASSERT TestOptArrayByRefByVal(), IsMissingAB, "TestOptArrayByRefByVal()" + ' TestLog_ASSERT TestOptArrayByRefByVal(aA), IsMissingB, "TestOptArrayByRefByVal(A)" + + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptArrayByRefByVal(, aB), IsMissingA, "TestOptArrayByRefByVal(, B)" + TestLog_ASSERT TestOptArrayByRefByVal(aA, aB), IsMissingNone, "TestOptArrayByRefByVal(A, B)" result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10) - verify_testIsMissing = result + verify_testIsMissingVba = result Exit Function errorHandler: - TestLog_ASSERT (False), testName & ": hit error handler" + TestLog_ASSERT False, True, Err.Description End Function -Sub TestLog_ASSERT(assertion As Boolean, Optional testId As String, Optional testComment As String) +Function TestOptVariant(Optional A, Optional B As Variant = 123) + TestOptVariant = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function - If assertion = True Then - passCount = passCount + 1 +Function TestOptVariantByRefByVal(Optional ByRef A, Optional ByVal B As Variant = 123) + TestOptVariantByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptDouble(Optional A As Double, Optional B As Double = 123.4) + TestOptDouble = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptDoubleByRefByVal(Optional ByRef A As Double, Optional ByVal B As Double = 123.4) + TestOptDoubleByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptInteger(Optional A As Integer, Optional B As Integer = 123) + TestOptInteger = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptIntegerByRefByVal(Optional ByRef A As Integer, Optional ByVal B As Integer = 123) + TestOptIntegerByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptString(Optional A As String, Optional B As String = "123") + TestOptString = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptStringByRefByVal(Optional ByRef A As String, Optional ByVal B As String = "123") + TestOptStringByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptObject(Optional A As Collection, Optional B As Collection) + TestOptObject = WhatIsMissing(IsNull(A), IsNull(B)) +End Function + +Function TestOptObjectByRefByVal(Optional ByRef A As Collection, Optional ByVal B As Collection) + TestOptObjectByRefByVal = WhatIsMissing(IsNull(A), IsNull(B)) +End Function + +Function TestOptArray(Optional A() As Integer, Optional B() As Variant) + TestOptArray = WhatIsMissing(IsEmpty(A), IsEmpty(B)) +End Function + +Function TestOptArrayByRefByVal(Optional ByRef A() As Integer, Optional ByVal B() As Variant) + TestOptArrayByRefByVal = WhatIsMissing(IsEmpty(A), IsEmpty(B)) +End Function + +Function WhatIsMissing(is_missingA, is_missingB) + If is_missingA And is_missingB Then + WhatIsMissing = IsMissingAB + ElseIf is_missingA Then + WhatIsMissing = IsMissingA + ElseIf is_missingB Then + WhatIsMissing = IsMissingB Else - Dim testMsg As String - If Not IsMissing(testId) Then - testMsg = testMsg + " : " + testId - End If - If Not IsMissing(testComment) And Not (testComment = "") Then - testMsg = testMsg + " (" + testComment + ")" - End If - - result = result & Chr$(10) & " Failed: " & testMsg - failCount = failCount + 1 + WhatIsMissing = IsMissingNone End If +End Function -End Sub -' Function procedure definition. -Function ReturnTwice(Optional A) - If IsMissing(A) Then - ' If argument is missing, return a Null. - ReturnTwice = Null +Sub TestLog_ASSERT(actual As Variant, expected As Integer, testName As String) + If expected = actual Then + passCount = passCount + 1 Else - ' If argument is present, return twice the value. - ReturnTwice = A * 2 + result = result & Chr$(10) & " Failed: " & testName & " returned " & actual & ", expected " & expected + failCount = failCount + 1 End If -End Function +End Sub
\ No newline at end of file diff --git a/basic/qa/vba_tests/optional_paramters.vb b/basic/qa/vba_tests/optional_paramters.vb new file mode 100644 index 000000000000..eff8275d0e63 --- /dev/null +++ b/basic/qa/vba_tests/optional_paramters.vb @@ -0,0 +1,231 @@ +Option VBASupport 1 + +Dim passCount As Integer +Dim failCount As Integer +Dim result As String + +Function doUnitTest() As String + result = verify_testOptionalsVba() + If failCount <> 0 Or passCount = 0 Then + doUnitTest = result + Else + doUnitTest = "OK" + End If +End Function + +' tdf#36737 - Test optionals with different datatypes. In LO Basic +' with option VBASupport, optional parameters are allowed including additional +' default values. Missing optional parameters having types other than variant, +' which don't have explicit default values, will be initialized to their +' respective default value of its datatype +Function verify_testOptionalsVba() As String + + passCount = 0 + failCount = 0 + + result = "Test Results" & Chr$(10) & "============" & Chr$(10) + testName = "Test optionals (Basic)" + On Error GoTo errorHandler + + ' optionals with variant datatypes + ' TODO - New bug report? Scanner initializes variable as String. Function returns "123" + ' TestLog_ASSERT TestOptVariant(), 123, "TestOptVariant()" + TestLog_ASSERT TestOptVariant(123), 246, "TestOptVariant(123)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptVariant(, 456), 456, "TestOptVariant(, 456)" + TestLog_ASSERT TestOptVariant(123, 456), 579, "TestOptVariant(123, 456)" + + ' optionals with variant datatypes (ByRef and ByVal) + ' TODO - New bug report? Scanner initializes variable as String. Function returns "123" + ' TestLog_ASSERT TestOptVariantByRefByVal(), 123, "TestOptVariantByRefByVal()" + TestLog_ASSERT TestOptVariantByRefByVal(123), 246, "TestOptVariantByRefByVal(123)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptVariantByRefByVal(, 456), 456, "TestOptVariantByRefByVal(, 456)" + TestLog_ASSERT TestOptVariantByRefByVal(123, 456), 579, "TestOptVariantByRefByVal(123, 456)" + + ' optionals with double datatypes + TestLog_ASSERT TestOptDouble(), 123.4, "TestOptDouble()" + TestLog_ASSERT TestOptDouble(123.4), 246.8, "TestOptDouble(123.4)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptDouble(, 567.8), 567.8, "TestOptDouble(, 567.8)" + TestLog_ASSERT Format(TestOptDouble(123.4, 567.8), "0.0"), 691.2, "TestOptDouble(123.4, 567.8)" + + ' optionals with double datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptDoubleByRefByVal(), 123.4, "TestOptDouble()" + TestLog_ASSERT TestOptDoubleByRefByVal(123.4), 246.8, "TestOptDouble(123.4)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptDoubleByRefByVal(, 567.8), 567.8, "TestOptDoubleByRefByVal(, 567.8)" + TestLog_ASSERT Format(TestOptDoubleByRefByVal(123.4, 567.8), "0.0"), 691.2, "TestOptDoubleByRefByVal(123.4, 567.8)" + + ' optionals with integer datatypes + TestLog_ASSERT TestOptInteger(), 123, "TestOptInteger()" + TestLog_ASSERT TestOptInteger(123), 246, "TestOptInteger(123)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptInteger(, 456), 456, "TestOptInteger(, 456)" + TestLog_ASSERT TestOptInteger(123, 456), 579, "TestOptInteger(123, 456)" + + ' optionals with integer datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptIntegerByRefByVal(), 123, "TestOptIntegerByRefByVal()" + TestLog_ASSERT TestOptIntegerByRefByVal(123), 246, "TestOptIntegerByRefByVal(123)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptIntegerByRefByVal(, 456), 456, "TestOptIntegerByRefByVal(, 456)" + TestLog_ASSERT TestOptIntegerByRefByVal(123, 456), 579, "TestOptIntegerByRefByVal(123, 456)" + + ' optionals with string datatypes + TestLog_ASSERT TestOptString(), "123", "TestOptString()" + TestLog_ASSERT TestOptString("123"), "123123", "TestOptString(""123"")" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptString(, "456"), "456", "TestOptString(, ""456"")" + TestLog_ASSERT TestOptString("123", "456"), "123456", "TestOptString(""123"", ""456"")" + + ' optionals with string datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptStringByRefByVal(), "123", "TestOptStringByRefByVal()" + TestLog_ASSERT TestOptStringByRefByVal("123"), "123123", "TestOptStringByRefByVal(""123"")" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT TestOptStringByRefByVal(, "456"), "456", "TestOptStringByRefByVal(, ""456"")" + TestLog_ASSERT TestOptStringByRefByVal("123", "456"), "123456", "TestOptStringByRefByVal(""123"", ""456"")" + + ' optionals with object datatypes + Dim cA As New Collection + cA.Add (123) + cA.Add (456) + Dim cB As New Collection + cB.Add (123.4) + cB.Add (567.8) + TestLog_ASSERT TestOptObject(), 0, "TestOptObject()" + TestLog_ASSERT TestOptObject(cA), 579, "TestOptObject(A)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT Format(TestOptObject(, cB), "0.0"), 691.2, "TestOptObject(, B)" + TestLog_ASSERT Format(TestOptObject(cA, cB), "0.0"), 1270.2, "TestOptObject(A, B)" + + ' optionals with object datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptObjectByRefByVal(), 0, "TestOptObjectByRefByVal()" + TestLog_ASSERT TestOptObjectByRefByVal(cA), 579, "TestOptObjectByRefByVal(A)" + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT Format(TestOptObjectByRefByVal(, cB), "0.0"), 691.2, "TestOptObjectByRefByVal(, B)" + TestLog_ASSERT Format(TestOptObjectByRefByVal(cA, cB), "0.0"), 1270.2, "TestOptObjectByRefByVal(A, B)" + + ' optionals with array datatypes + Dim aA(0 To 1) As Integer + aA(0) = 123 + aA(1) = 456 + Dim aB(0 To 1) As Variant + aB(0) = 123.4 + aB(1) = 567.8 + ' TODO - New bug report? Scanner initializes variable not as an array + ' TestLog_ASSERT TestOptArray(), 0, "TestOptArray()" + ' TestLog_ASSERT TestOptArray(aA), 579, "TestOptArray(A)" + + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT Format(TestOptArray(, aB), "0.0"), 691.2, "TestOptArray(, B)" + TestLog_ASSERT Format(TestOptArray(aA, aB), "0.0"), 1270.2, "TestOptArray(A, B)" + + ' optionals with array datatypes (ByRef and ByVal) + ' TODO - New bug report? Scanner initializes variable not as an array + ' TestLog_ASSERT TestOptArrayByRefByVal(), 0, "TestOptArrayByRefByVal()" + ' TestLog_ASSERT TestOptArrayByRefByVal(aA), 579, "TestOptArrayByRefByVal(A)" + + ' TODO - tdf#125180 for more details + ' TestLog_ASSERT Format(TestOptArrayByRefByVal(, aB), "0.0"), 691.2, "TestOptArrayByRefByVal(, B)" + TestLog_ASSERT Format(TestOptArrayByRefByVal(aA, aB), "0.0"), 1270.2, "TestOptArrayByRefByVal(A, B)" + + result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10) + verify_testOptionalsVba = result + + Exit Function +errorHandler: + TestLog_ASSERT False, True, Err.Description +End Function + +Function TestOptVariant(Optional A, Optional B As Variant = 123) + TestOptVariant = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptVariantByRefByVal(Optional ByRef A, Optional ByVal B As Variant = 123) + TestOptVariantByRefByVal = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptDouble(Optional A As Double, Optional B As Double = 123.4) + TestOptDouble = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptDoubleByRefByVal(Optional ByRef A As Double, Optional ByVal B As Double = 123.4) + TestOptDoubleByRefByVal = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptInteger(Optional A As Integer, Optional B As Integer = 123) + TestOptInteger = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptIntegerByRefByVal(Optional ByRef A As Integer, Optional ByVal B As Integer = 123) + TestOptIntegerByRefByVal = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptString(Optional A As String, Optional B As String = "123") + TestOptString = OptStringConcat(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptStringByRefByVal(Optional ByRef A As String, Optional ByVal B As String = "123") + TestOptStringByRefByVal = OptStringConcat(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptObject(Optional A As Collection, Optional B As Collection) + ' TODO - isMissing returns false even though the collection is null and is missing? + TestOptObject = 0 + If Not IsNull(A) Then TestOptObject = CollectionSum(A) + If Not IsNull(B) Then TestOptObject = TestOptObject + CollectionSum(B) +End Function + +Function TestOptObjectByRefByVal(Optional ByRef A As Collection, Optional ByVal B As Collection) + ' TODO - isMissing returns false even though the collection is null and is missing? + TestOptObjectByRefByVal = 0 + If Not IsNull(A) Then TestOptObjectByRefByVal = CollectionSum(A) + If Not IsNull(B) Then TestOptObjectByRefByVal = TestOptObjectByRefByVal + CollectionSum(B) +End Function + +Function TestOptArray(Optional A() As Integer, Optional B() As Variant) + TestOptArray = ArraySum(IsMissing(A), A) + ArraySum(IsMissing(B), B) +End Function + +Function TestOptArrayByRefByVal(Optional ByRef A() As Integer, Optional ByVal B() As Variant) + TestOptArrayByRefByVal = ArraySum(IsMissing(A), A) + ArraySum(IsMissing(B), B) +End Function + +Function OptNumberSum(is_missingA As Boolean, A, is_missingB As Boolean, B) + OptNumberSum = 0 + If Not is_missingA Then OptNumberSum = A + If Not is_missingB Then OptNumberSum = OptNumberSum + B +End Function + +Function OptStringConcat(is_missingA As Boolean, A, is_missingB As Boolean, B) + OptStringConcat = "" + If Not is_missingA Then OptStringConcat = A + If Not is_missingB Then OptStringConcat = OptStringConcat & B +End Function + +Function CollectionSum(C) + Dim idx As Integer + CollectionSum = 0 + For idx = 1 To C.Count + CollectionSum = CollectionSum + C.Item(idx) + Next idx +End Function + +Function ArraySum(is_missingC As Boolean, C) + Dim idx As Integer + ArraySum = 0 + If Not is_missingC Then + For idx = LBound(C) To UBound(C) + ArraySum = ArraySum + C(idx) + Next idx + End If +End Function + +Sub TestLog_ASSERT(actual As Variant, expected As Variant, testName As String) + If expected = actual Then + passCount = passCount + 1 + Else + result = result & Chr$(10) & " Failed: " & testName & " returned " & actual & ", expected " & expected + failCount = failCount + 1 + End If +End Sub
\ No newline at end of file |