Bump version to 6.4.7.2.M8
[LibreOffice.git] / basic / qa / vba_tests / instrrev.vb
blob7fe02cd606177666af564b277345dc4611494540
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_testInStrRev()
9 If failCount <> 0 or passCount = 0 Then
10 doUnitTest = result
11 Else
12 doUnitTest = "OK"
13 End If
14 End Function
18 Function verify_testInStrRev() As String
20 passCount = 0
21 failCount = 0
23 result = "Test Results" & Chr$(10) & "============" & Chr$(10)
25 Dim testName As String
26 Dim date1, date2, SearchString, SearchChar
27 testName = "Test InStrRev function"
28 On Error GoTo errorHandler
30 date2 = 5
31 date1 = InStrRev("somemoretext", "more", -1)
32 TestLog_ASSERT date1 = date2, "the return InStrRev is: " & date1
34 date2 = 5
35 date1 = InStrRev("somemoretext", "more")
36 TestLog_ASSERT date1 = date2, "the return InStrRev is: " & date1
38 date2 = 1
39 date1 = InStrRev("somemoretext", "somemoretext")
40 TestLog_ASSERT date1 = date2, "the return InStrRev is: " & date1
42 date2 = 0
43 date1 = InStrRev("somemoretext", "nothing")
44 TestLog_ASSERT date1 = date2, "the return InStrRev is: " & date1
46 SearchString = "XXpXXpXXPXXP" ' String to search in.
47 SearchChar = "P" ' Search for "P".
48 date2 = 3
49 date1 = InStrRev(SearchString, SearchChar, 4, 1)
50 TestLog_ASSERT date1 = date2, "the return InStrRev is: " & date1
52 date2 = 12
53 date1 = InStrRev(SearchString, SearchChar, -1, 0)
54 TestLog_ASSERT date1 = date2, "the return InStrRev is: " & date1
56 date2 = 0
57 date1 = InStrRev(SearchString, "W", 1)
58 TestLog_ASSERT date1 = date2, "the return InStrRev is: " & date1
60 result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
61 verify_testInStrRev = result
63 Exit Function
64 errorHandler:
65 TestLog_ASSERT (False), testName & ": hit error handler"
66 End Function
68 Sub TestLog_ASSERT(assertion As Boolean, Optional testId As String, Optional testComment As String)
70 If assertion = True Then
71 passCount = passCount + 1
72 Else
73 Dim testMsg As String
74 If Not IsMissing(testId) Then
75 testMsg = testMsg + " : " + testId
76 End If
77 If Not IsMissing(testComment) And Not (testComment = "") Then
78 testMsg = testMsg + " (" + testComment + ")"
79 End If
81 result = result & Chr$(10) & " Failed: " & testMsg
82 failCount = failCount + 1
83 End If
85 End Sub