bump product version to 5.0.4.1
[LibreOffice.git] / basic / qa / vba_tests / bytearraystring.vb
blobc404b6e9a9a9d1b7472bd22cd66ada6d1f8ee088
1 Option VBASupport 1
2 Option Explicit
4 Dim passCount As Integer
5 Dim failCount As Integer
6 Dim displayMessage As Boolean
7 Dim thisTest As String
9 Function doUnitTest() As String
10 Dim result As String
11 result = verify_ByteArrayString()
12 If failCount <> 0 Then
13 doUnitTest = result
14 Else
15 doUnitTest = "OK"
16 End If
17 End Function
19 Sub Main()
20 MsgBox verify_ByteArrayString()
21 End Sub
23 Function verify_ByteArrayString() As String
24 passCount = 0
25 failCount = 0
26 Dim result As String
28 Dim testName As String
29 Dim MyString As String
30 Dim x() As Byte
31 Dim count As Integer
32 testName = "Test the conversion between bytearray and string"
35 On Error GoTo errorHandler
37 MyString = "abc"
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
53 Exit Function
54 errorHandler:
55 failCount = failCount + 1
56 verify_ByteArrayString = "Error Handler hit"
57 End Function
59 Function updateResultString(testDesc As String, actual As String, expected As String) As String
60 Dim result As String
61 If actual <> expected Then
62 result = result & Chr$(10) & testDesc & " Failed: expected " & expected & " got " & actual
63 failCount = failCount + 1
64 Else
65 passCount = passCount + 1
66 End If
67 updateResultString = result
68 End Function