Update git submodules
[LibreOffice.git] / basic / qa / basic_coverage / test_string_fixed_len.bas
blobd0bc1f30ea6addea54d2a73c79e0a0787abbe996
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 VBASupport 0
9 Option Explicit
11 Function doUnitTest() As String
12 TestUtil.TestInit
13 verify_stringFixedLen
14 doUnitTest = TestUtil.GetResult()
15 End Function
17 Sub verify_stringFixedLen()
18 On Error GoTo errorHandler
19 ' tdf#163680 - fixed-length strings support
21 Dim s As String * 10
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")
25 s = "abc"
26 TestUtil.AssertEqual(Len(s), 10, "Len(s) - abc")
27 TestUtil.AssertEqual("""" & s & """", """abc """, """s"" - abc")
28 s = "defghijklmno"
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")
41 s1 = "klm"
42 TestUtil.AssertEqual(Len(s1), 3, "Len(s1) - klm")
43 TestUtil.AssertEqual("""" & s1 & """", """klm""", """s1"" - klm")
44 s = s1
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")
51 Exit Sub
52 errorHandler:
53 TestUtil.ReportErrorHandler("verify_stringFixedLen", Err, Error$, Erl)
54 End Sub