2 ' This file is part of the LibreOffice project.
4 ' This Source Code Form is subject to the terms of the Mozilla Public
5 ' License, v. 2.0. If a copy of the MPL was not distributed with this
6 ' file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 Dim passCount
As Integer
12 Dim failCount
As Integer
16 If passCount
<> 0 and failCount
= 0 Then
19 GetResult
= result
& Chr
$(10) & "Tests passed: " & passCount
& Chr
$(10) & "Tests failed: " & failCount
& Chr
$(10)
26 result
= result
& "Test Results" & Chr
$(10) & "============" & Chr
$(10)
29 Sub Assert(Assertion
As Boolean, Optional testId
As String, Optional testComment
As String)
30 If Assertion
= True Then
31 passCount
= passCount
+ 1
34 If Not IsMissing(testId
) Then
35 testMsg
= " " + testId
37 If Not IsMissing(testComment
) Then
38 If Not (testComment
= "") Then testMsg
= testMsg
+ " (" + testComment
+ ")"
41 result
= result
& Chr
$(10) & " Failed:" & testMsg
42 failCount
= failCount
+ 1
46 Sub AssertEqual(actual
As Variant, expected
As Variant, testName
As String)
47 If expected
= actual
Then
48 passCount
= passCount
+ 1
50 result
= result
& Chr
$(10) & " Failed: " & testName
& " returned " & actual
& ", expected " & expected
51 failCount
= failCount
+ 1
55 ' Same as AssertEqual, but also checks actual and expected types
56 Sub AssertEqualStrict(actual
As Variant, expected
As Variant, testName
As String)
57 AssertEqual(actual
, expected
, testName
)
58 AssertEqual(TypeName(actual
), TypeName(expected
), testName
& " type mismatch:")
61 Sub AssertEqualApprox(actual
, expected
, epsilon
, testName
As String)
62 If Abs(expected
- actual
) <= epsilon
Then
63 passCount
= passCount
+ 1
65 result
= result
& Chr
$(10) & " Failed: " & testName
& " returned " & actual
& ", expected " & expected
& ", epsilon " & epsilon
66 failCount
= failCount
+ 1
70 Sub ReportErrorHandler(testName
As String, aErr
, sError
, nErl
)
71 Assert
False, testName
, "hit error handler - " & aErr
& ": " & sError
& " line : " & nErl