4 Dim passCount
As Integer
5 Dim failCount
As Integer
6 Dim displayMessage
As Boolean
9 Function doUnitTest() As String
11 result
= verify_ByteArrayString()
12 If failCount
<> 0 Then
20 MsgBox
verify_ByteArrayString()
23 Function verify_ByteArrayString() As String
28 Dim testName
As String
29 Dim MyString
As String
32 testName
= "Test the conversion between bytearray and string"
35 On Error GoTo errorHandler
38 x
= MyString
' string -> byte array
40 result
= "Test Results" & Chr
$(10) & "============" & Chr
$(10)
42 count
= UBound(x
) ' 6 byte
44 ' test bytes in string
45 result
= result
+ updateResultString("test1 numbytes ", (count
), 5)
48 MyString
= x
'byte array -> string
49 result
= result
+ updateResultString("test assign byte array to string", MyString
, "abc")
51 result
= result
& Chr
$(10) & "Tests passed: " & passCount
& Chr
$(10) & "Tests failed: " & failCount
& Chr
$(10)
52 verify_ByteArrayString
= result
55 failCount
= failCount
+ 1
56 verify_ByteArrayString
= "Error Handler hit"
59 Function updateResultString(testDesc
As String, actual
As String, expected
As String) As String
61 If actual
<> expected
Then
62 result
= result
& Chr
$(10) & testDesc
& " Failed: expected " & expected
& " got " & actual
63 failCount
= failCount
+ 1
65 passCount
= passCount
+ 1
67 updateResultString
= result