bump product version to 5.0.4.1
[LibreOffice.git] / basic / qa / vba_tests / replace.vb
blobd7b48d8a7d2742fb7774a867e7ae4e77cbf8ca6c
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_testReplace()
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_testReplace() as String
17 passCount = 0
18 failCount = 0
20 result = "Test Results" & Chr$(10) & "============" & Chr$(10)
22 Dim testName As String
23 Dim srcStr, destStr, repStr, start, count, retStr
24 testName = "Test Replace function"
25 On Error GoTo errorHandler
26 srcStr = "abcbcdBc"
27 destStr = "bc"
28 repStr = "ef"
29 retStr = Replace(srcStr, destStr, repStr)
30 TestLog_ASSERT retStr = "aefefdBc", "common string:" & retStr
31 retStr = Replace("abcbcdbc", destStr, repStr)
32 TestLog_ASSERT retStr = "aefefdef", "expression string:" & retStr
33 retStr = Replace(srcStr, destStr, repStr, 1, -1, vbBinaryCompare)
34 TestLog_ASSERT retStr = "aefefdBc", "binanary compare:" & retStr
35 retStr = Replace(srcStr, destStr, repStr, 1, -1, vbTextCompare)
36 TestLog_ASSERT retStr = "aefefdef", "text compare:" & retStr
37 retStr = Replace(srcStr, destStr, repStr, compare:=vbTextCompare)
38 TestLog_ASSERT retStr = "aefefdef", "text compare:" & retStr
39 retStr = Replace(srcStr, destStr, repStr, 3, -1, vbBinaryCompare)
40 TestLog_ASSERT retStr = "cefdBc", "start = 3:" & retStr
41 retStr = Replace(srcStr, destStr, repStr, 1, 2, vbBinaryCompare)
42 TestLog_ASSERT retStr = "aefefdBc", "count = 2: " & retStr
43 retStr = Replace(srcStr, destStr, repStr, 1, 0, vbBinaryCompare)
44 TestLog_ASSERT retStr = "abcbcdBc", "start = 1, count = 0, not support in Unix: " & retStr
45 result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
46 verify_testReplace = result
48 Exit Function
49 errorHandler:
50 TestLog_ASSERT (False), testName & ": hit error handler"
51 End Function
53 Sub TestLog_ASSERT(assertion As Boolean, Optional testId As String, Optional testComment As String)
55 If assertion = True Then
56 passCount = passCount + 1
57 Else
58 Dim testMsg As String
59 If Not IsMissing(testId) Then
60 testMsg = testMsg + " : " + testId
61 End If
62 If Not IsMissing(testComment) And Not (testComment = "") Then
63 testMsg = testMsg + " (" + testComment + ")"
64 End If
66 result = result & Chr$(10) & " Failed: " & testMsg
67 failCount = failCount + 1
68 End If
70 End Sub