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/.
12 Dim passCount
As Integer
13 Dim failCount
As Integer
17 If passCount
<> 0 and failCount
= 0 Then
20 GetResult
= result
& Chr
$(10) & "Tests passed: " & passCount
& Chr
$(10) & "Tests failed: " & failCount
& Chr
$(10)
27 result
= result
& "Test Results" & Chr
$(10) & "============" & Chr
$(10)
30 Sub Assert(Assertion
As Boolean, Optional testId
As String, Optional testComment
As String)
31 If Assertion
= True Then
32 passCount
= passCount
+ 1
35 If Not IsMissing(testId
) Then
36 testMsg
= " " + testId
38 If Not IsMissing(testComment
) Then
39 If Not (testComment
= "") Then testMsg
= testMsg
+ " (" + testComment
+ ")"
42 result
= result
& Chr
$(10) & " Failed:" & testMsg
43 failCount
= failCount
+ 1
47 Sub AssertEqual(actual
As Variant, expected
As Variant, testName
As String)
48 If expected
= actual
Then
49 passCount
= passCount
+ 1
51 result
= result
& Chr
$(10) & " Failed: " & testName
& " returned " & actual
& ", expected " & expected
52 failCount
= failCount
+ 1
56 ' Same as AssertEqual, but also checks actual and expected types
57 Sub AssertEqualStrict(actual
As Variant, expected
As Variant, testName
As String)
58 AssertEqual actual
, expected
, testName
59 AssertEqual
TypeName(actual
), TypeName(expected
), testName
& " type mismatch:"
62 Sub AssertEqualApprox(actual
, expected
, epsilon
, testName
As String)
63 If Abs(expected
- actual
) <= epsilon
Then
64 passCount
= passCount
+ 1
66 result
= result
& Chr
$(10) & " Failed: " & testName
& " returned " & actual
& ", expected " & expected
& ", epsilon " & epsilon
67 failCount
= failCount
+ 1
71 Sub ReportErrorHandler(testName
As String, aErr
, sError
, nErl
)
72 Assert
False, testName
, "hit error handler - " & aErr
& ": " & sError
& " line : " & nErl