[Libreoffice-commits] core.git: basic/qa

Zdeněk Crhonek zcrhonek at gmail.com
Sun Apr 9 13:43:11 UTC 2017


 basic/qa/cppunit/test_vba.cxx |    4 +
 basic/qa/vba_tests/hex.vb     |   87 +++++++++++++++++++++++++++++++++++++++++
 basic/qa/vba_tests/hour.vb    |   73 ++++++++++++++++++++++++++++++++++
 basic/qa/vba_tests/iif.vb     |   71 +++++++++++++++++++++++++++++++++
 basic/qa/vba_tests/instr.vb   |   88 ++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 323 insertions(+)

New commits:
commit d89a4213520996b73fdb74685f24647a37536f4d
Author: Zdeněk Crhonek <zcrhonek at gmail.com>
Date:   Sun Apr 9 13:44:25 2017 +0200

    VBA tests - HEX, HOUR, IIF, INSTR test cases
    
    Change-Id: Ib9e05dcfbd72f56cb3b5fb4e4760f868c008c7ac
    Reviewed-on: https://gerrit.libreoffice.org/36315
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Zdenek Crhonek <zcrhonek at gmail.com>

diff --git a/basic/qa/cppunit/test_vba.cxx b/basic/qa/cppunit/test_vba.cxx
index 5ea598a3b50a..db6267fb9f2f 100644
--- a/basic/qa/cppunit/test_vba.cxx
+++ b/basic/qa/cppunit/test_vba.cxx
@@ -78,7 +78,11 @@ void VBATest::testMiscVBAFunctions()
         "error.vb",
         "exp.vb",
         "fix.vb",
+        "hex.vb",
+        "hour.vb",
         "formatnumber.vb",
+        "iif.vb",
+        "instr.vb",
 #ifndef WIN32 // missing 64bit Currency marshalling.
         "win32compat.vb", // windows compatibility hooks.
 #endif
diff --git a/basic/qa/vba_tests/hex.vb b/basic/qa/vba_tests/hex.vb
new file mode 100644
index 000000000000..7958eef7b9ba
--- /dev/null
+++ b/basic/qa/vba_tests/hex.vb
@@ -0,0 +1,87 @@
+Option VBASupport 1
+Option Explicit
+Dim passCount As Integer
+Dim failCount As Integer
+Dim result As String
+
+Function doUnitTest() As String
+result = verify_testHex()
+If failCount <> 0 And passCount > 0 Then
+    doUnitTest = result
+Else
+    doUnitTest = "OK"
+End If
+End Function
+
+
+
+Function verify_testHex() 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 Hex function"
+    On Error GoTo errorHandler
+
+    date2 = "9"
+    date1 = Hex(9)
+    TestLog_ASSERT date1 = date2, "the return Hex is: " & date1
+
+    date2 = "9"
+    date1 = Hex(9)
+    TestLog_ASSERT date1 = date2, "the return Hex is: " & date1
+
+    date2 = "A"
+    date1 = Hex(10)
+    TestLog_ASSERT date1 = date2, "the return Hex is: " & date1
+
+    date2 = "10"
+    date1 = Hex(16)
+    TestLog_ASSERT date1 = date2, "the return Hex is: " & date1
+
+    date2 = "FF"
+    date1 = Hex(255)
+    TestLog_ASSERT date1 = date2, "the return Hex is: " & date1
+
+    date2 = "100"
+    date1 = Hex(256)
+    TestLog_ASSERT date1 = date2, "the return Hex is: " & date1
+
+    date2 = "1CB"
+    date1 = Hex(459)
+    TestLog_ASSERT date1 = date2, "the return Hex is: " & date1
+
+
+    result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
+    verify_testHex = 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/hour.vb b/basic/qa/vba_tests/hour.vb
new file mode 100644
index 000000000000..587b36a825b0
--- /dev/null
+++ b/basic/qa/vba_tests/hour.vb
@@ -0,0 +1,73 @@
+Option VBASupport 1
+Option Explicit
+Dim passCount As Integer
+Dim failCount As Integer
+Dim result As String
+
+Function doUnitTest() As String
+result = verify_testHour()
+If failCount <> 0 And passCount > 0 Then
+    doUnitTest = result
+Else
+    doUnitTest = "OK"
+End If
+End Function
+
+
+
+Function verify_testHour() 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, myTime
+    testName = "Test Hour function"
+    On Error GoTo errorHandler
+    
+    myTime = "6:25:39 AM"
+    date2 = 6
+    date1 = Hour(myTime)
+    TestLog_ASSERT date1 = date2, "the return Hour is: " & date1
+
+    myTime = "6:25:39 PM"
+    date2 = 18
+    date1 = Hour(myTime)
+    TestLog_ASSERT date1 = date2, "the return Hour is: " & date1
+
+    myTime = "06:25:39 AM"
+    date2 = 6
+    date1 = Hour(myTime)
+    TestLog_ASSERT date1 = date2, "the return Hour is: " & date1
+
+    result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
+    verify_testHour = 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/iif.vb b/basic/qa/vba_tests/iif.vb
new file mode 100644
index 000000000000..4ddbef29e679
--- /dev/null
+++ b/basic/qa/vba_tests/iif.vb
@@ -0,0 +1,71 @@
+Option VBASupport 1
+Option Explicit
+Dim passCount As Integer
+Dim failCount As Integer
+Dim result As String
+
+Function doUnitTest() As String
+result = verify_testIIf()
+If failCount <> 0 And passCount > 0 Then
+    doUnitTest = result
+Else
+    doUnitTest = "OK"
+End If
+End Function
+
+
+
+Function verify_testIIf() 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, testnr
+    testName = "Test IIf function"
+    On Error GoTo errorHandler
+
+    date2 = "it is true"
+    date1 = IIf(True, "it is true", "it is false")
+    TestLog_ASSERT date1 = date2, "the return IIf is: " & date1
+
+    date2 = "it is false"
+    date1 = IIf(False, "It is true", "it is false")
+    TestLog_ASSERT date1 = date2, "the return IIf is: " & date1
+
+    testnr = 1001
+    date2 = "Large"
+    date1 = IIf(testnr > 1000, "Large", "Small")
+    TestLog_ASSERT date1 = date2, "the return IIf is: " & date1
+
+    result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
+    verify_testIIf = 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/instr.vb b/basic/qa/vba_tests/instr.vb
new file mode 100644
index 000000000000..29f35249e919
--- /dev/null
+++ b/basic/qa/vba_tests/instr.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_testInStr()
+If failCount <> 0 And passCount > 0 Then
+    doUnitTest = result
+Else
+    doUnitTest = "OK"
+End If
+End Function
+
+
+
+Function verify_testInStr() 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 InStr function"
+    On Error GoTo errorHandler
+
+    date2 = 5
+    date1 = InStr(1, "somemoretext", "more")
+    TestLog_ASSERT date1 = date2, "the return InStr is: " & date1
+
+    date2 = 5
+    date1 = InStr("somemoretext", "more")
+    TestLog_ASSERT date1 = date2, "the return InStr is: " & date1
+
+    date2 = 1
+    date1 = InStr("somemoretext", "somemoretext")
+    TestLog_ASSERT date1 = date2, "the return InStr is: " & date1
+
+    date2 = 0
+    date1 = InStr("somemoretext", "nothing")
+    TestLog_ASSERT date1 = date2, "the return InStr is: " & date1
+
+    SearchString = "XXpXXpXXPXXP"   ' String to search in.
+    SearchChar = "P"    ' Search for "P".
+    date2 = 6
+    date1 = InStr(4, SearchString, SearchChar, 1)
+    TestLog_ASSERT date1 = date2, "the return InStr is: " & date1
+
+    date2 = 9
+    date1 = InStr(1, SearchString, SearchChar, 0)
+    TestLog_ASSERT date1 = date2, "the return InStr is: " & date1
+    
+    date2 = 0
+    date1 = InStr(1, SearchString, "W")
+    TestLog_ASSERT date1 = date2, "the return InStr is: " & date1
+    
+    result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
+    verify_testInStr = 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
+


More information about the Libreoffice-commits mailing list