Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / basic / qa / cppunit / _test_asserts.bas
blob68865755bdcd950e1ac38ffc50ea789fe37eedd0
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 Explicit
11 Dim passCount As Integer
12 Dim failCount As Integer
13 Dim result As String
15 Function GetResult()
16 If passCount <> 0 and failCount = 0 Then
17 GetResult = "OK"
18 Else
19 GetResult = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
20 End If
21 End Function
23 Sub TestInit()
24 passCount = 0
25 failCount = 0
26 result = result & "Test Results" & Chr$(10) & "============" & Chr$(10)
27 End Sub
29 Sub Assert(Assertion As Boolean, Optional testId As String, Optional testComment As String)
30 If Assertion = True Then
31 passCount = passCount + 1
32 Else
33 Dim testMsg As String
34 If Not IsMissing(testId) Then
35 testMsg = " " + testId
36 End If
37 If Not IsMissing(testComment) Then
38 If Not (testComment = "") Then testMsg = testMsg + " (" + testComment + ")"
39 End If
41 result = result & Chr$(10) & " Failed:" & testMsg
42 failCount = failCount + 1
43 End If
44 End Sub
46 Sub AssertEqual(actual As Variant, expected As Variant, testName As String)
47 If expected = actual Then
48 passCount = passCount + 1
49 Else
50 result = result & Chr$(10) & " Failed: " & testName & " returned " & actual & ", expected " & expected
51 failCount = failCount + 1
52 End If
53 End Sub
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:")
59 End Sub
61 Sub AssertEqualApprox(actual, expected, epsilon, testName As String)
62 If Abs(expected - actual) <= epsilon Then
63 passCount = passCount + 1
64 Else
65 result = result & Chr$(10) & " Failed: " & testName & " returned " & actual & ", expected " & expected & ", epsilon " & epsilon
66 failCount = failCount + 1
67 End If
68 End Sub
70 Sub ReportErrorHandler(testName As String, aErr, sError, nErl)
71 Assert False, testName, "hit error handler - " & aErr & ": " & sError & " line : " & nErl
72 End Sub