3 Dim passCount
As Integer
4 Dim failCount
As Integer
7 Function doUnitTest() As String
8 result
= verify_testSTRcomp()
9 If failCount
<> 0 or passCount
= 0 Then
18 Function verify_testSTRcomp() As String
23 result
= "Test Results" & Chr
$(10) & "============" & Chr
$(10)
25 Dim testName
As String
26 Dim TestStr
, TestStr1
, TestStr2
As String
28 testName
= "Test STRcomp function"
29 On Error GoTo errorHandler
34 date1
= StrComp(TestStr1
, TestStr2
, vbTextCompare
)
35 TestLog_ASSERT date1
= date2
, "the return STRcomp is: " & date1
38 date1
= StrComp(TestStr1
, TestStr2
, vbBinaryCompare
)
39 TestLog_ASSERT date1
= date2
, "the return STRcomp is: " & date1
42 date1
= StrComp(TestStr1
, TestStr2
)
43 TestLog_ASSERT date1
= date2
, "the return STRcomp is: " & date1
46 date1
= StrComp("text", "text", vbBinaryCompare
)
47 TestLog_ASSERT date1
= date2
, "the return STRcomp is: " & date1
50 date1
= StrComp("text ", "text", vbBinaryCompare
)
51 TestLog_ASSERT date1
= date2
, "the return STRcomp is: " & date1
54 date1
= StrComp("Text", "text", vbBinaryCompare
)
55 TestLog_ASSERT date1
= date2
, "the return STRcomp is: " & date1
58 date1
= StrComp("text", "text", vbTextCompare
)
59 TestLog_ASSERT date1
= date2
, "the return STRcomp is: " & date1
62 date1
= StrComp("text ", "text", vbTextCompare
)
63 TestLog_ASSERT date1
= date2
, "the return STRcomp is: " & date1
66 date1
= StrComp("Text", "text", vbTextCompare
)
67 TestLog_ASSERT date1
= date2
, "the return STRcomp is: " & date1
69 result
= result
& Chr
$(10) & "Tests passed: " & passCount
& Chr
$(10) & "Tests failed: " & failCount
& Chr
$(10)
70 verify_testSTRcomp
= result
74 TestLog_ASSERT (False), testName
& ": hit error handler"
77 Sub TestLog_ASSERT(assertion
As Boolean, Optional testId
As String, Optional testComment
As String)
79 If assertion
= True Then
80 passCount
= passCount
+ 1
83 If Not IsMissing(testId
) Then
84 testMsg
= testMsg
+ " : " + testId
86 If Not IsMissing(testComment
) And Not (testComment
= "") Then
87 testMsg
= testMsg
+ " (" + testComment
+ ")"
90 result
= result
& Chr
$(10) & " Failed: " & testMsg
91 failCount
= failCount
+ 1