| 1 |
' This file is part of the LibreOffice project. |
| 2 |
' |
| 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/. |
| 6 |
' |
| 7 |
|
| 8 |
Option Base 1 |
| 9 |
Option Explicit |
| 10 |
|
| 11 |
Function doUnitTest() As String |
| 12 |
TestUtil.TestInit |
| 13 |
verify_optionBase |
| 14 |
doUnitTest = TestUtil.GetResult() |
| 15 |
End Function |
| 16 |
|
| 17 |
Sub verify_optionBase() As String |
| 18 |
On Error GoTo errorHandler |
| 19 |
|
| 20 |
' tdf#54912 - with option base arrays should start at index 1. |
| 21 |
' Without option compatible the upper bound is changed as well (#109275). |
| 22 |
Dim strArray(2) As String |
| 23 |
TestUtil.AssertEqual(LBound(strArray), 1, "Lower bound of a string array (before assignment): " & LBound(strArray)) |
| 24 |
TestUtil.AssertEqual(UBound(strArray), 3, "Upper bound of a string array (before assignment): " & UBound(strArray)) |
| 25 |
strArray = Array("a", "b") |
| 26 |
TestUtil.AssertEqual(LBound(strArray), 1, "Lower bound of a string array (after assignment): " & LBound(strArray)) |
| 27 |
TestUtil.AssertEqual(UBound(strArray), 2, "Upper bound of a string array (after assignment): " & UBound(strArray)) |
| 28 |
|
| 29 |
Dim intArray(2) As Integer |
| 30 |
TestUtil.AssertEqual(LBound(intArray), 1, "Lower bound of an integer array (before assignment): " & LBound(intArray)) |
| 31 |
TestUtil.AssertEqual(UBound(intArray), 3, "Upper bound of an integer array (before assignment): " & UBound(intArray)) |
| 32 |
intArray = Array(1, 2) |
| 33 |
TestUtil.AssertEqual(LBound(intArray), 1, "Lower bound of an integer array (after assignment): " & LBound(intArray)) |
| 34 |
TestUtil.AssertEqual(UBound(intArray), 2, "Upper bound of an integer array (after assignment): " & UBound(intArray)) |
| 35 |
|
| 36 |
Dim byteArray(2) As Byte |
| 37 |
TestUtil.AssertEqual(LBound(byteArray), 1, "Lower bound of a byte array (before assignment): " & LBound(byteArray)) |
| 38 |
TestUtil.AssertEqual(UBound(byteArray), 3, "Upper bound of a byte array (before assignment): " & UBound(byteArray)) |
| 39 |
byteArray = StrConv("ab", 128) |
| 40 |
TestUtil.AssertEqual(LBound(byteArray), 1, "Lower bound of a byte array (StrConv): " & LBound(byteArray)) |
| 41 |
TestUtil.AssertEqual(UBound(byteArray), 2, "Upper bound of a byte array (StrConv): " & UBound(byteArray)) |
| 42 |
|
| 43 |
ReDim byteArray(3) |
| 44 |
TestUtil.AssertEqual(LBound(byteArray), 1, "Lower bound of a byte array (ReDim): " & LBound(byteArray)) |
| 45 |
TestUtil.AssertEqual(UBound(byteArray), 4, "Upper bound of a byte array (ReDim): " & UBound(byteArray)) |
| 46 |
|
| 47 |
Exit Sub |
| 48 |
errorHandler: |
| 49 |
TestUtil.ReportErrorHandler("verify_optionBase", Err, Error$, Erl) |
| 50 |
End Sub |