Bump version to 4.1-6
[LibreOffice.git] / basic / qa / vba_tests / strconv.vb
bloba98fbaa5b09245eeb54a9db8759297b41b5c5792
1 Option VBASupport 1
2 Option Explicit
3 Dim passCount As Integer
4 Dim failCount As Integer
5 Dim result As String
7 Function doUnitTest() As String
8 result = verify_testStrConv()
9 If failCount <> 0 And passCount > 0 Then
10 doUnitTest = result
11 Else
12 doUnitTest = "OK"
13 End If
14 End Function
16 Function verify_testStrConv() as String
17 passCount = 0
18 failCount = 0
20 result = "Test Results" & Chr$(10) & "============" & Chr$(10)
22 Dim testName As String
23 Dim srcStr, retStr As String
24 Dim x() As Byte
25 srcStr = "abc EFG hij"
26 testName = "Test StrConv function"
27 On Error GoTo errorHandler
29 retStr = StrConv(srcStr, vbUpperCase)
30 'MsgBox retStr
31 TestLog_ASSERT retStr = "ABC EFG HIJ", "Converts the string to uppercase characters:" & retStr
33 retStr = StrConv(srcStr, vbLowerCase)
34 'MsgBox retStr
35 TestLog_ASSERT retStr = "abc efg hij", "Converts the string to lowercase characters:" & retStr
37 retStr = StrConv(srcStr, vbProperCase)
38 'MsgBox retStr
39 TestLog_ASSERT retStr = "Abc Efg Hij", "Converts the first letter of every word in string to uppercase:" & retStr
41 'retStr = StrConv("ABCDEVB¥ì¥¹¥­¥å©`", vbWide)
42 'MsgBox retStr
43 'TestLog_ASSERT retStr = "£Á£Â£Ã£Ä£ÅVB¥ì¥¹¥­¥å©`", "Converts narrow (single-byte) characters in string to wide"
45 'retStr = StrConv("£Á£Â£Ã£Ä£ÅVB¥ì¥¹¥­¥å©`", vbNarrow)
46 'MsgBox retStr
47 'TestLog_ASSERT retStr = "ABCDEVB¥ì¥¹¥­¥å©`", "Converts wide (double-byte) characters in string to narrow (single-byte) characters." & retStr
49 'retStr = StrConv("¤Ï¤Ê¤Á¤ã¤ó", vbKatakana)
50 'MsgBox retStr
51 'TestLog_ASSERT retStr = "¥Ï¥Ê¥Á¥ã¥ó", "Converts Hiragana characters in string to Katakana characters.." & retStr
53 ' retStr = StrConv("¥Ï¥Ê¥Á¥ã¥ó", vbHiragana)
54 'MsgBox retStr
55 ' TestLog_ASSERT retStr = "¤Ï¤Ê¤Á¤ã¤ó", "Converts Katakana characters in string to Hiragana characters.." & retStr
57 'x = StrConv("ÉϺ£ÊÐABC", vbFromUnicode)
58 'MsgBox retStr
59 'TestLog_ASSERT UBound(x) = 8, "Converts the string from Unicode, the lenght is : " & UBound(x) + 1
61 ' retStr = StrConv(x, vbUnicode)
62 'MsgBox retStr
63 ' TestLog_ASSERT retStr = "ÉϺ£ÊÐABC", "Converts the string to Unicode: " & retStr
65 result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
66 verify_testStrConv = result
68 Exit Function
69 errorHandler:
70 TestLog_ASSERT (False), testName & ": hit error handler"
71 End Function
73 Sub TestLog_ASSERT(assertion As Boolean, Optional testId As String, Optional testComment As String)
75 If assertion = True Then
76 passCount = passCount + 1
77 Else
78 Dim testMsg As String
79 If Not IsMissing(testId) Then
80 testMsg = testMsg + " : " + testId
81 End If
82 If Not IsMissing(testComment) And Not (testComment = "") Then
83 testMsg = testMsg + " (" + testComment + ")"
84 End If
86 result = result & Chr$(10) & " Failed: " & testMsg
87 failCount = failCount + 1
88 End If
90 End Sub