summaryrefslogtreecommitdiff
path: root/basic/qa
diff options
context:
space:
mode:
authorZdeněk Crhonek <zcrhonek@gmail.com>2017-04-12 18:29:59 +0200
committerZdenek Crhonek <zcrhonek@gmail.com>2017-04-13 09:54:18 +0200
commited4473abc1700cbd5c407d09f769fb1c7cdc0bfd (patch)
tree89e4c852eea624c9d81b2c758c926caee98f9ceb /basic/qa
parent3b9b4ca5d3aa15d51d6b54a5f5f23967f1666889 (diff)
VBA tests - INSTRREV, INT test case
Change-Id: I220b8dd57927486b697b46777e20db7d2f53e487 Reviewed-on: https://gerrit.libreoffice.org/36486 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Zdenek Crhonek <zcrhonek@gmail.com>
Diffstat (limited to 'basic/qa')
-rw-r--r--basic/qa/cppunit/test_vba.cxx2
-rw-r--r--basic/qa/vba_tests/instrrev.vb88
-rw-r--r--basic/qa/vba_tests/int.vb78
3 files changed, 168 insertions, 0 deletions
diff --git a/basic/qa/cppunit/test_vba.cxx b/basic/qa/cppunit/test_vba.cxx
index 6638bab883c9..a7f74ba91bd3 100644
--- a/basic/qa/cppunit/test_vba.cxx
+++ b/basic/qa/cppunit/test_vba.cxx
@@ -83,6 +83,8 @@ void VBATest::testMiscVBAFunctions()
"formatnumber.vb",
"iif.vb",
"instr.vb",
+ "instrrev.vb",
+ "int.vb",
#ifndef WIN32 // missing 64bit Currency marshalling.
"win32compat.vb", // windows compatibility hooks.
#endif
diff --git a/basic/qa/vba_tests/instrrev.vb b/basic/qa/vba_tests/instrrev.vb
new file mode 100644
index 000000000000..5d524f5c2b1a
--- /dev/null
+++ b/basic/qa/vba_tests/instrrev.vb
@@ -0,0 +1,88 @@
+Option VBASupport 1
+Option Explicit
+Dim passCount As Integer
+Dim failCount As Integer
+Dim result As String
+
+Function doUnitTest() As String
+result = verify_testInStrRev()
+If failCount <> 0 And passCount > 0 Then
+ doUnitTest = result
+Else
+ doUnitTest = "OK"
+End If
+End Function
+
+
+
+Function verify_testInStrRev() As String
+
+ passCount = 0
+ failCount = 0
+
+ result = "Test Results" & Chr$(10) & "============" & Chr$(10)
+
+ Dim testName As String
+ Dim TestDateTime As Date
+ Dim TestStr As String
+ Dim date1, date2, SearchString, SearchChar
+ testName = "Test InStrRev function"
+ On Error GoTo errorHandler
+
+ date2 = 5
+ date1 = InStrRev("somemoretext", "more", -1)
+ TestLog_ASSERT date1 = date2, "the return InStrRev is: " & date1
+
+ date2 = 5
+ date1 = InStrRev("somemoretext", "more")
+ TestLog_ASSERT date1 = date2, "the return InStrRev is: " & date1
+
+ date2 = 1
+ date1 = InStrRev("somemoretext", "somemoretext")
+ TestLog_ASSERT date1 = date2, "the return InStrRev is: " & date1
+
+ date2 = 0
+ date1 = InStrRev("somemoretext", "nothing")
+ TestLog_ASSERT date1 = date2, "the return InStrRev is: " & date1
+
+ SearchString = "XXpXXpXXPXXP" ' String to search in.
+ SearchChar = "P" ' Search for "P".
+ date2 = 3
+ date1 = InStrRev(SearchString, SearchChar, 4, 1)
+ TestLog_ASSERT date1 = date2, "the return InStrRev is: " & date1
+
+ date2 = 12
+ date1 = InStrRev(SearchString, SearchChar, -1, 0)
+ TestLog_ASSERT date1 = date2, "the return InStrRev is: " & date1
+
+ date2 = 0
+ date1 = InStrRev(SearchString, "W", 1)
+ TestLog_ASSERT date1 = date2, "the return InStrRev is: " & date1
+
+ result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
+ verify_testInStrRev = result
+
+ Exit Function
+errorHandler:
+ TestLog_ASSERT (False), testName & ": hit error handler"
+End Function
+
+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 & Chr$(10) & " Failed: " & testMsg
+ failCount = failCount + 1
+ End If
+
+End Sub
+
diff --git a/basic/qa/vba_tests/int.vb b/basic/qa/vba_tests/int.vb
new file mode 100644
index 000000000000..84b4fb707d9a
--- /dev/null
+++ b/basic/qa/vba_tests/int.vb
@@ -0,0 +1,78 @@
+Option VBASupport 1
+Option Explicit
+Dim passCount As Integer
+Dim failCount As Integer
+Dim result As String
+
+Function doUnitTest() As String
+result = verify_testInt()
+If failCount <> 0 And passCount > 0 Then
+ doUnitTest = result
+Else
+ doUnitTest = "OK"
+End If
+End Function
+
+
+
+Function verify_testInt() As String
+
+ passCount = 0
+ failCount = 0
+
+ result = "Test Results" & Chr$(10) & "============" & Chr$(10)
+
+ Dim testName As String
+ Dim TestDateTime As Date
+ Dim TestStr As String
+ Dim date1, date2
+ testName = "Test Int function"
+ On Error GoTo errorHandler
+
+ date2 = 99
+ date1 = Int(99.8)
+ TestLog_ASSERT date1 = date2, "the return Int is: " & date1
+
+ date2 = -100
+ date1 = Int(-99.8)
+ TestLog_ASSERT date1 = date2, "the return Int is: " & date1
+
+ date2 = -100
+ date1 = Int(-99.2)
+ TestLog_ASSERT date1 = date2, "the return Int is: " & date1
+
+ date2 = 0
+ date1 = Int(0.2)
+ TestLog_ASSERT date1 = date2, "the return Int is: " & date1
+
+ date2 = 0
+ date1 = Int(0)
+ TestLog_ASSERT date1 = date2, "the return Int is: " & date1
+
+ result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
+ verify_testInt = result
+
+ Exit Function
+errorHandler:
+ TestLog_ASSERT (False), testName & ": hit error handler"
+End Function
+
+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 & Chr$(10) & " Failed: " & testMsg
+ failCount = failCount + 1
+ End If
+
+End Sub
+