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/.
11 Function doUnitTest() As String
14 doUnitTest
= TestUtil
.GetResult()
17 Sub verify_stringFixedLen()
18 On Error GoTo errorHandler
19 ' tdf#163680 - fixed-length strings support
22 TestUtil
.AssertEqual(Len(s
), 10, "Len(s) - default")
23 ' The default value is 10 null characters
24 TestUtil
.AssertEqual(s
, String(10, 0), "s - default")
26 TestUtil
.AssertEqual(Len(s
), 10, "Len(s) - abc")
27 TestUtil
.AssertEqual("""" & s
& """", """abc """, """s"" - abc")
29 TestUtil
.AssertEqual(Len(s
), 10, "Len(s) - defghijklmno")
30 TestUtil
.AssertEqual("""" & s
& """", """defghijklm""", """s"" - defghijklmno")
31 Let s
= "xyz" ' Test also Let keyword - uses a different code path
32 TestUtil
.AssertEqual(Len(s
), 10, "Len(s) - xyz")
33 TestUtil
.AssertEqual("""" & s
& """", """xyz """, """s"" - xyz")
34 Let s
= "opqrstuvwxyz"
35 TestUtil
.AssertEqual(Len(s
), 10, "Len(s) - opqrstuvwxyz")
36 TestUtil
.AssertEqual("""" & s
& """", """opqrstuvwx""", """s"" - opqrstuvwxyz")
38 Dim s1
As String * 0 ' Unlike VBA, LibreOffice Basic allows this for unrestricted strings
39 TestUtil
.AssertEqual(Len(s1
), 0, "Len(s1) - default")
40 TestUtil
.AssertEqual("""" & s1
& """", """""", """s1"" - default")
42 TestUtil
.AssertEqual(Len(s1
), 3, "Len(s1) - klm")
43 TestUtil
.AssertEqual("""" & s1
& """", """klm""", """s1"" - klm")
45 TestUtil
.AssertEqual(Len(s
), 10, "Len(s) - klm")
46 TestUtil
.AssertEqual("""" & s
& """", """klm """, """s"" - klm")
47 ' Also test s1 - it must not be affected
48 TestUtil
.AssertEqual(Len(s1
), 3, "Len(s1) - klm")
49 TestUtil
.AssertEqual("""" & s1
& """", """klm""", """s1"" - klm")
53 TestUtil
.ReportErrorHandler("verify_stringFixedLen", Err
, Error$, Erl
)