3 Dim passCount
As Integer
4 Dim failCount
As Integer
7 Function doUnitTest() As String
8 result
= verify_testCDec()
9 If failCount
<> 0 And passCount
> 0 Then
16 Function verify_testCDec() as String
20 result
= "Test Results" & Chr
$(10) & "============" & Chr
$(10)
22 Dim testName
As String
24 testName
= "Test CDec function"
25 On Error GoTo errorHandler
28 TestLog_ASSERT ret
= 0, "Empty string test:" & ret
31 TestLog_ASSERT ret
= 1234, "Simple number:" & ret
34 TestLog_ASSERT ret
= 1234, "Simple number with whitespaces:" & ret
37 TestLog_ASSERT ret
= -1234, "Simple negative number:" & ret
39 ret
= CDec(" - 1234 ")
40 TestLog_ASSERT ret
= -1234, "Simple negative number with whitespaces:" & ret
43 ' Those are erroneous, see i#64348
45 TestLog_ASSERT ret
= -1234, "Wrong negative number1:" & ret
48 TestLog_ASSERT ret
= -1234, "Wrong negative number2:" & ret
50 'ret = CDec("79228162514264300000000000001")
51 'TestLog_ASSERT ret = 79228162514264300000000000001, "Very long number1:" & ret
53 'TestLog_ASSERT ret = 79228162514264300000000000002, "Very long number2:" & ret
55 ret
= CDec("79228162514264400000000000000")
56 TestLog_ASSERT ret
= 62406456049664, "Very long number3:" & ret
58 ret
= CDec("79228162514264340000000000000") ' gives zero
59 TestLog_ASSERT ret
= 0, "Very long number4:" & ret
61 result
= result
& Chr
$(10) & "Tests passed: " & passCount
& Chr
$(10) & "Tests failed: " & failCount
& Chr
$(10)
62 verify_testCDec
= result
66 TestLog_ASSERT (False), testName
& ": hit error handler"
69 Sub TestLog_ASSERT(assertion
As Boolean, Optional testId
As String, Optional testComment
As String)
71 If assertion
= True Then
72 passCount
= passCount
+ 1
75 If Not IsMissing(testId
) Then
76 testMsg
= testMsg
+ " : " + testId
78 If Not IsMissing(testComment
) And Not (testComment
= "") Then
79 testMsg
= testMsg
+ " (" + testComment
+ ")"
82 result
= result
& Chr
$(10) & " Failed: " & testMsg
83 failCount
= failCount
+ 1