1Option VBASupport 1 2Option Explicit 3Dim passCount As Integer 4Dim failCount As Integer 5Dim result As String 6 7Function doUnitTest() As String 8result = verify_testStrConv() 9If failCount <> 0 Or passCount = 0 Then 10 doUnitTest = result 11Else 12 doUnitTest = "OK" 13End If 14End Function 15 16Function verify_testStrConv() as String 17 passCount = 0 18 failCount = 0 19 20 result = "Test Results" & Chr$(10) & "============" & Chr$(10) 21 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 28 29 retStr = StrConv(srcStr, vbUpperCase) 30 'MsgBox retStr 31 TestLog_ASSERT retStr = "ABC EFG HIJ", "Converts the string to uppercase characters:" & retStr 32 33 retStr = StrConv(srcStr, vbLowerCase) 34 'MsgBox retStr 35 TestLog_ASSERT retStr = "abc efg hij", "Converts the string to lowercase characters:" & retStr 36 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 40 41 'retStr = StrConv("ABCDEVB¥ì¥¹¥¥å©`", vbWide) 42 'MsgBox retStr 43 'TestLog_ASSERT retStr = "£Á£Â£Ã£Ä£ÅVB¥ì¥¹¥¥å©`", "Converts narrow (single-byte) characters in string to wide" 44 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 48 49 'retStr = StrConv("¤Ï¤Ê¤Á¤ã¤ó", vbKatakana) 50 'MsgBox retStr 51 'TestLog_ASSERT retStr = "¥Ï¥Ê¥Á¥ã¥ó", "Converts Hiragana characters in string to Katakana characters.." & retStr 52 53 ' retStr = StrConv("¥Ï¥Ê¥Á¥ã¥ó", vbHiragana) 54 'MsgBox retStr 55 ' TestLog_ASSERT retStr = "¤Ï¤Ê¤Á¤ã¤ó", "Converts Katakana characters in string to Hiragana characters.." & retStr 56 57 'x = StrConv("ÉϺ£ÊÐABC", vbFromUnicode) 58 'MsgBox retStr 59 'TestLog_ASSERT UBound(x) = 8, "Converts the string from Unicode, the length is : " & UBound(x) + 1 60 61 ' retStr = StrConv(x, vbUnicode) 62 'MsgBox retStr 63 ' TestLog_ASSERT retStr = "ÉϺ£ÊÐABC", "Converts the string to Unicode: " & retStr 64 65 result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10) 66 verify_testStrConv = result 67 68 Exit Function 69errorHandler: 70 TestLog_ASSERT (False), testName & ": hit error handler" 71End Function 72 73Sub TestLog_ASSERT(assertion As Boolean, Optional testId As String, Optional testComment As String) 74 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 85 86 result = result & Chr$(10) & " Failed: " & testMsg 87 failCount = failCount + 1 88 End If 89 90End Sub 91
