summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibreOfficiant <LibreOfficiant@sfr.fr>2019-12-12 09:54:34 +0100
committerMike Kaganski <mike.kaganski@collabora.com>2020-03-24 11:16:21 +0100
commit45435e2ac007aed2aabd175ad944d6c779d99167 (patch)
tree0a08369b5c42e86dc5f112941b95fd20a9db0537
parent5a2c0ab29719ac914d30d8789c0e386541702cbf (diff)
VBA Err object raise method TestCases
Err.Raise(#) enables 'User-Defined Exceptions' Std Basic alternative is: Error # 'without parentheses which throws pre-defined error codes. Change-Id: I76229b237066e33229d4d13e6742c660887fda2e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/85017 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r--basic/qa/cppunit/test_vba.cxx1
-rw-r--r--basic/qa/vba_tests/Err.Raise.vb86
2 files changed, 87 insertions, 0 deletions
diff --git a/basic/qa/cppunit/test_vba.cxx b/basic/qa/cppunit/test_vba.cxx
index fd0bdb1c2c2c..235bcc2cf7b6 100644
--- a/basic/qa/cppunit/test_vba.cxx
+++ b/basic/qa/cppunit/test_vba.cxx
@@ -84,6 +84,7 @@ void VBATest::testMiscVBAFunctions()
"day.vb",
"enum.vb",
"error.vb",
+ "Err.Raise.vb",
"exp.vb",
"fix.vb",
"hex.vb",
diff --git a/basic/qa/vba_tests/Err.Raise.vb b/basic/qa/vba_tests/Err.Raise.vb
new file mode 100644
index 000000000000..fa04856cc5b5
--- /dev/null
+++ b/basic/qa/vba_tests/Err.Raise.vb
@@ -0,0 +1,86 @@
+'
+' This file is part of the LibreOffice project.
+'
+' This Source Code Form is subject to the terms of the Mozilla Public
+' License, v. 2.0. If a copy of the MPL was not distributed with this
+' file, You can obtain one at http://mozilla.org/MPL/2.0/.
+'
+
+Option VBASupport 1
+Option Explicit
+Dim passCount As Integer
+Dim failCount As Integer
+Dim result As String
+
+Function doUnitTest()
+ ''' This routine is QA/…/test_vba.cxx main entry point '''
+ passCount = 0 : failCount = 0
+ Const MIN_ERR = &hFFFFFFFF : Const MAX_ERR = 2^31-1
+
+ ''' Raise one-to-many User-Defined Errors as signed Int32 '''
+ result = "Test Results" & vbNewLine & "============" & vbNewLine
+ ' test_Description | Err # | Err_Source | Err_Description
+ Call TestErrRaise("MAXimum error value", MAX_ERR, "doUnitTest.vb", "Custom Error Maximum value")
+ Call TestErrRaise("Positive custom error", 1789, "" , "User-Defined Error Number")
+ Call TestErrRaise("Negative custom error", -1793, "doUnitTest.vb", "Negative User-Defined Error Number")
+ Call TestErrRaise("MINimum error value", MIN_ERR, "" , "Custom Error Minimum value")
+
+ If failCount <> 0 Or passCount = 0 Then
+ doUnitTest = result
+ Else
+ doUnitTest = "OK"
+ End If
+End Function
+
+Sub TestErrRaise(TestName As String, CurErrNo As Long, CurErrSource As String, CurErrDescription As String)
+ result = result & vbNewLine & TestName
+ Dim origPassCount As Integer, origFailCount As Integer
+ origPassCount = passCount
+ origFailCount = failCount
+
+try: On Error Goto catch
+ Err.Raise(CurErrNo, CurErrSource, CurErrDescription, "", "")
+
+ 'result = result & vbNewLine & "Testing after error handler"
+ TestLog_ASSERT (passCount + failCount) > (origPassCount + origFailCount), TestName, "error handler did not execute!"
+ TestLog_ASSERT Erl = 0, TestName, "Erl = " & Erl
+ TestLog_ASSERT Err = 0, TestName, "Err = " & Err
+ TestLog_ASSERT Error = "", TestName, "Error = " & Error
+ TestLog_ASSERT Err.Description = "", "Err.Description reset", "Err.Description = "& Err.Description
+ TestLog_ASSERT Err.Number = 0, "Err.Number reset", "Err.Number = " & Err.Number
+ TestLog_ASSERT Err.Source = "", "Err.Source reset", "Err.Source = " & Err.Source
+ Exit Sub
+
+catch:
+ 'result = result & vbNewLine & "Testing in error handler"
+ TestLog_ASSERT Err.Number = CurErrNo, "Err.Number failure", "Err.Number = " & Err.Number
+ TestLog_ASSERT Err.Source = CurErrSource, "Err.Source failure", "Err.Source = " & Err.Source
+ TestLog_ASSERT Err.Description = CurErrDescription, "Err.Description failure", "Err.Description = " & Err.Description
+
+ TestLog_ASSERT Erl = 42, "line# failure", "Erl = " & Erl ' WATCH OUT for HARDCODED LINE # HERE !
+ TestLog_ASSERT Err = CurErrNo, "Err# failure", "Err = " & Err
+ TestLog_ASSERT Error = CurErrDescription, "Error description failure", "Error$ = " & Error$
+
+ Resume Next ' Err object properties reset from here …
+End Sub
+
+Sub DEV_TEST : doUnitTest : MsgBox result : End Sub
+
+Sub TestLog_ASSERT(assertion As Boolean, Optional testId As String, Optional testComment As String)
+
+ If assertion = True Then
+ passCount = passCount + 1
+ Else
+ Dim testMsg As String
+ If Not IsMissing(testId) Then
+ testMsg = testMsg + testId + ":"
+ End If
+ If Not IsMissing(testComment) And Not (testComment = "") Then
+ testMsg = testMsg + " (" + testComment + ")"
+ End If
+
+ result = result & vbNewLine & "Failed: " & testMsg
+ failCount = failCount + 1
+ End If
+
+End Sub