1Option Base 1
2
3Dim passCount As Integer
4Dim failCount As Integer
5Dim result As String
6
7Function doUnitTest() As String
8    result = verify_optionBase()
9    If failCount <> 0 Or passCount = 0 Then
10        doUnitTest = 0
11    Else
12        doUnitTest = 1
13    End If
14End Function
15
16Function verify_optionBase() As String
17    passCount = 0
18    failCount = 0
19
20    result = "Test Results" & Chr$(10) & "============" & Chr$(10)
21
22    ' tdf#54912 - with option base arrays should start at index 1.
23    ' Without option compatible the upper bound is changed as well (#109275).
24    Dim strArray(2) As String
25    TestLog_ASSERT LBound(strArray), 1, "Lower bound of a string array (before assignment): " & LBound(strArray)
26    TestLog_ASSERT UBound(strArray), 3, "Upper bound of a string array (before assignment): " & UBound(strArray)
27    strArray = Array("a", "b")
28    TestLog_ASSERT LBound(strArray), 1, "Lower bound of a string array (after assignment): " & LBound(strArray)
29    TestLog_ASSERT UBound(strArray), 2, "Upper bound of a string array (after assignment): " & UBound(strArray)
30
31    Dim intArray(2) As Integer
32    TestLog_ASSERT LBound(intArray), 1, "Lower bound of an integer array (before assignment): " & LBound(intArray)
33    TestLog_ASSERT UBound(intArray), 3, "Upper bound of an integer array (before assignment): " & UBound(intArray)
34    intArray = Array(1, 2)
35    TestLog_ASSERT LBound(intArray), 1, "Lower bound of an integer array (after assignment): " & LBound(intArray)
36    TestLog_ASSERT UBound(intArray), 2, "Upper bound of an integer array (after assignment): " & UBound(intArray)
37
38    Dim byteArray(2) As Byte
39    TestLog_ASSERT LBound(byteArray), 1, "Lower bound of a byte array (before assignment): " & LBound(byteArray)
40    TestLog_ASSERT UBound(byteArray), 3, "Upper bound of a byte array (before assignment): " & UBound(byteArray)
41    byteArray = StrConv("ab", 128)
42    TestLog_ASSERT LBound(byteArray), 1, "Lower bound of a byte array (StrConv): " & LBound(byteArray)
43    TestLog_ASSERT UBound(byteArray), 2, "Upper bound of a byte array (StrConv): " & UBound(byteArray)
44
45    ReDim byteArray(3)
46    TestLog_ASSERT LBound(byteArray), 1, "Lower bound of a byte array (ReDim): " & LBound(byteArray)
47    TestLog_ASSERT UBound(byteArray), 4, "Upper bound of a byte array (ReDim): " & UBound(byteArray)
48
49    result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
50    verify_optionBase = result
51End Function
52
53Sub TestLog_ASSERT(actual As Variant, expected As Variant, testName As String)
54    If expected = actual Then
55        passCount = passCount + 1
56    Else
57        result = result & Chr$(10) & "Failed: " & testName & " returned " & actual & ", expected " & expected
58        failCount = failCount + 1
59    End If
60End Sub
61