cid#1636693 COPY_INSTEAD_OF_MOVE
[LibreOffice.git] / basic / qa / vba_tests / strconv.vb
blob9b7dfaf218660a7223bcffd808e8e1f47f505d43
2 ' This file is part of the LibreOffice project.
4 ' This Source Code Form is subject to the terms of the Mozilla Public
5 ' License, v. 2.0. If a copy of the MPL was not distributed with this
6 ' file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 Option VBASupport 1
10 Option Explicit
12 Function doUnitTest() As String
13 TestUtil.TestInit
14 verify_testStrConv
15 doUnitTest = TestUtil.GetResult()
16 End Function
18 Sub verify_testStrConv()
19 On Error GoTo errorHandler
21 TestUtil.AssertEqual(StrConv("abc EFG hij αβγ ΔΕΖ ηθι", vbUpperCase), "ABC EFG HIJ ΑΒΓ ΔΕΖ ΗΘΙ", "StrConv(""abc EFG hij αβγ ΔΕΖ ηθι"", vbUpperCase)")
22 TestUtil.AssertEqual(StrConv("abc EFG hij αβγ ΔΕΖ ηθι", vbLowerCase), "abc efg hij αβγ δεζ ηθι", "StrConv(""abc EFG hij αβγ ΔΕΖ ηθι"", vbLowerCase)")
23 TestUtil.AssertEqual(StrConv("abc EFG hij αβγ ΔΕΖ ηθι", vbProperCase), "Abc Efg Hij Αβγ Δεζ Ηθι", "StrConv(""abc EFG hij αβγ ΔΕΖ ηθι"", vbProperCase)")
25 ' Converts narrow (single-byte) characters in string to wide
26 TestUtil.AssertEqual(StrConv("ABCDEVB¥ì¥¹¥­¥å©", vbWide), "ABCDEVB¥ì¥¹¥­¥å©", "StrConv(""ABCDEVB¥ì¥¹¥­¥å©"", vbWide)")
27 TestUtil.AssertEqual(StrConv("ABCDEVB¥ì¥¹¥­¥å©", vbWide + vbLowerCase), "abcdevb¥ì¥¹¥­¥å©", "StrConv(""ABCDEVB¥ì¥¹¥­¥å©"", vbWide + vbLowerCase)")
29 ' Converts wide (double-byte) characters in string to narrow (single-byte) characters
30 TestUtil.AssertEqual(StrConv("ABCD@$%23'?EG", vbNarrow), "ABCD@$%23'?EG", "StrConv(""ABCD@$%23'?EG"", vbNarrow)")
31 TestUtil.AssertEqual(StrConv("ABCD@$%23'?EG", vbNarrow + vbLowerCase), "abcd@$%23'?eg", "StrConv(""ABCD@$%23'?EG"", vbNarrow + vbLowerCase)")
33 ' Converts Hiragana characters in string to Katakana characters
34 TestUtil.AssertEqual(StrConv("かたかな", vbKatakana), "カタカナ", "StrConv(""かたかな"", vbKatakana)")
35 TestUtil.AssertEqual(StrConv("かたかな abc", vbKatakana + vbUpperCase + vbWide), "カタカナ ABC", "StrConv(""かたかな abc"", vbKatakana + vbUpperCase + vbWide)")
37 ' Converts Katakana characters in string to Hiragana characters
38 TestUtil.AssertEqual(StrConv("カタカナ", vbHiragana), "かたかな", "StrConv(""カタカナ"", vbHiragana)")
39 TestUtil.AssertEqual(StrConv("カタカナ ABC", vbLowerCase + vbNarrow), "カタカナ abc", "StrConv(""カタカナ ABC"", vbLowerCase + vbNarrow)")
41 Dim x() As Byte
42 Const Cp1252TestString = "ÉϺ£ÊÐABC"
44 x = StrConv(Cp1252TestString, vbFromUnicode, &h0409)' CP-1252 encoding associated with en-US locale
45 TestUtil.AssertEqual(UBound(x), 8, "UBound(x)")
46 TestUtil.AssertEqual(x(0), 201, "x(0)")
47 TestUtil.AssertEqual(x(1), 207, "x(1)")
48 TestUtil.AssertEqual(x(2), 186, "x(2)")
49 TestUtil.AssertEqual(x(3), 163, "x(3)")
50 TestUtil.AssertEqual(x(4), 202, "x(4)")
51 TestUtil.AssertEqual(x(5), 208, "x(5)")
52 TestUtil.AssertEqual(x(6), 65, "x(6)")
53 TestUtil.AssertEqual(x(7), 66, "x(7)")
54 TestUtil.AssertEqual(x(8), 67, "x(8)")
55 TestUtil.AssertEqual(StrConv(x, vbUnicode, &h0409), Cp1252TestString, "StrConv(x, vbUnicode, &h0409)")
57 x = StrConv(Cp1252TestString, vbUnicode, &h0409)
58 TestUtil.AssertEqual(UBound(x), 35, "UBound(x)")
59 TestUtil.AssertEqual(StrConv(x, vbFromUnicode, &h0409), Cp1252TestString, "StrConv(x, vbFromUnicode, &h0409)")
61 Exit Sub
62 errorHandler:
63 TestUtil.ReportErrorHandler("verify_testStrConv", Err, Error$, Erl)
64 End Sub