tdf#161412 - UI: fix warning in PDF password dialog didn't disappear
[LibreOffice.git] / basic / qa / cppunit / _test_asserts.vb
blob2130ce02f45440a263f8feac3b149e6ffc5eeba0
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/.
9 Option VBASupport 1
10 Option Explicit
12 Dim passCount As Integer
13 Dim failCount As Integer
14 Dim result As String
16 Function GetResult()
17 If passCount <> 0 and failCount = 0 Then
18 GetResult = "OK"
19 Else
20 GetResult = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
21 End If
22 End Function
24 Sub TestInit()
25 passCount = 0
26 failCount = 0
27 result = result & "Test Results" & Chr$(10) & "============" & Chr$(10)
28 End Sub
30 Sub Assert(Assertion As Boolean, Optional testId As String, Optional testComment As String)
31 If Assertion = True Then
32 passCount = passCount + 1
33 Else
34 Dim testMsg As String
35 If Not IsMissing(testId) Then
36 testMsg = " " + testId
37 End If
38 If Not IsMissing(testComment) Then
39 If Not (testComment = "") Then testMsg = testMsg + " (" + testComment + ")"
40 End If
42 result = result & Chr$(10) & " Failed:" & testMsg
43 failCount = failCount + 1
44 End If
45 End Sub
47 Sub AssertEqual(actual As Variant, expected As Variant, testName As String)
48 If expected = actual Then
49 passCount = passCount + 1
50 Else
51 result = result & Chr$(10) & " Failed: " & testName & " returned " & actual & ", expected " & expected
52 failCount = failCount + 1
53 End If
54 End Sub
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:"
60 End Sub
62 Sub AssertEqualApprox(actual, expected, epsilon, testName As String)
63 If Abs(expected - actual) <= epsilon Then
64 passCount = passCount + 1
65 Else
66 result = result & Chr$(10) & " Failed: " & testName & " returned " & actual & ", expected " & expected & ", epsilon " & epsilon
67 failCount = failCount + 1
68 End If
69 End Sub
71 Sub ReportErrorHandler(testName As String, aErr, sError, nErl)
72 Assert False, testName, "hit error handler - " & aErr & ": " & sError & " line : " & nErl
73 End Sub