summaryrefslogtreecommitdiff
path: root/basic/qa
diff options
context:
space:
mode:
authorZdeněk Crhonek <zcrhonek@gmail.com>2017-04-14 18:30:13 +0200
committerZdenek Crhonek <zcrhonek@gmail.com>2017-04-16 18:01:59 +0200
commit377d2d4bed5a085d0112482d01ce9b4215fb83a6 (patch)
tree6f31742148c737e5920ca3352665f39a2d9f06b8 /basic/qa
parentd1a594686a704a7b0d255fd90f9c017b2318e560 (diff)
add VBA test cases
functions - LEFT, LEN, LOG, LTRIM, MID, MINUTE, MIRR, MONTH Change-Id: Ifa4c6c1b715772644afc4280379b2a9e8429842f Reviewed-on: https://gerrit.libreoffice.org/36551 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.cxx8
-rw-r--r--basic/qa/vba_tests/left.vb70
-rw-r--r--basic/qa/vba_tests/len.vb71
-rw-r--r--basic/qa/vba_tests/log.vb70
-rw-r--r--basic/qa/vba_tests/ltrim.vb62
-rw-r--r--basic/qa/vba_tests/mid.vb71
-rw-r--r--basic/qa/vba_tests/minute.vb62
-rw-r--r--basic/qa/vba_tests/mirr.vb68
-rw-r--r--basic/qa/vba_tests/month.vb81
9 files changed, 563 insertions, 0 deletions
diff --git a/basic/qa/cppunit/test_vba.cxx b/basic/qa/cppunit/test_vba.cxx
index 5875a535be19..4ae819c06ab3 100644
--- a/basic/qa/cppunit/test_vba.cxx
+++ b/basic/qa/cppunit/test_vba.cxx
@@ -96,6 +96,14 @@ void VBATest::testMiscVBAFunctions()
"isempty.vb",
"isnumeric.vb",
"lcase.vb",
+ "left.vb",
+ "len.vb",
+ "log.vb",
+ "ltrim.vb",
+ "mid.vb",
+ "minute.vb",
+ "mirr.vb",
+ "month.vb",
#ifndef WIN32 // missing 64bit Currency marshalling.
"win32compat.vb", // windows compatibility hooks.
#endif
diff --git a/basic/qa/vba_tests/left.vb b/basic/qa/vba_tests/left.vb
new file mode 100644
index 000000000000..72c25018a86a
--- /dev/null
+++ b/basic/qa/vba_tests/left.vb
@@ -0,0 +1,70 @@
+Option VBASupport 1
+Option Explicit
+Dim passCount As Integer
+Dim failCount As Integer
+Dim result As String
+
+Function doUnitTest() As String
+result = verify_testLeft()
+If failCount <> 0 And passCount > 0 Then
+ doUnitTest = result
+Else
+ doUnitTest = "OK"
+End If
+End Function
+
+
+
+Function verify_testLeft() 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 Left function"
+ On Error GoTo errorHandler
+
+ date2 = "some"
+ date1 = Left("sometext", 4)
+ TestLog_ASSERT date1 = date2, "the return Left is: " & date1
+
+ date2 = "sometext"
+ date1 = Left("sometext", 48)
+ TestLog_ASSERT date1 = date2, "the return Left is: " & date1
+
+ date2 = ""
+ date1 = Left("", 4)
+ TestLog_ASSERT date1 = date2, "the return Left is: " & date1
+
+ result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
+ verify_testLeft = 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/len.vb b/basic/qa/vba_tests/len.vb
new file mode 100644
index 000000000000..424547a28d0c
--- /dev/null
+++ b/basic/qa/vba_tests/len.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_testLen()
+If failCount <> 0 And passCount > 0 Then
+ doUnitTest = result
+Else
+ doUnitTest = "OK"
+End If
+End Function
+
+
+
+Function verify_testLen() 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 Len function"
+ On Error GoTo errorHandler
+
+ date2 = 8
+ date1 = Len("sometext")
+ TestLog_ASSERT date1 = date2, "the return Len is: " & date1
+
+ date2 = 9
+ date1 = Len("some text")
+ TestLog_ASSERT date1 = date2, "the return Len is: " & date1
+
+ date2 = 0
+ date1 = Len("")
+ TestLog_ASSERT date1 = date2, "the return Len is: " & date1
+
+
+ result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
+ verify_testLen = 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/log.vb b/basic/qa/vba_tests/log.vb
new file mode 100644
index 000000000000..1312717b8590
--- /dev/null
+++ b/basic/qa/vba_tests/log.vb
@@ -0,0 +1,70 @@
+Option VBASupport 1
+Option Explicit
+Dim passCount As Integer
+Dim failCount As Integer
+Dim result As String
+
+Function doUnitTest() As String
+result = verify_testLog()
+If failCount <> 0 And passCount > 0 Then
+ doUnitTest = result
+Else
+ doUnitTest = "OK"
+End If
+End Function
+
+
+
+Function verify_testLog() 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 Log function"
+ On Error GoTo errorHandler
+
+ date2 = 4.454
+ date1 = Log(86)
+ TestLog_ASSERT Round(date1, 3) = Round(date2, 3), "the return Log is: " & date1
+
+ date2 = 4
+ date1 = Exp(Log(4))
+ TestLog_ASSERT date1 = date2, "the return Log is: " & date1
+
+ date2 = 1
+ date1 = Log(2.7182818)
+ TestLog_ASSERT Round(date1, 3) = Round(date2, 3), "the return Log is: " & date1
+
+ result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
+ verify_testLog = 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/ltrim.vb b/basic/qa/vba_tests/ltrim.vb
new file mode 100644
index 000000000000..901020e0d467
--- /dev/null
+++ b/basic/qa/vba_tests/ltrim.vb
@@ -0,0 +1,62 @@
+Option VBASupport 1
+Option Explicit
+Dim passCount As Integer
+Dim failCount As Integer
+Dim result As String
+
+Function doUnitTest() As String
+result = verify_testLTrim()
+If failCount <> 0 And passCount > 0 Then
+ doUnitTest = result
+Else
+ doUnitTest = "OK"
+End If
+End Function
+
+
+
+Function verify_testLTrim() 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 LTrim function"
+ On Error GoTo errorHandler
+
+ date2 = "some text "
+ date1 = LTrim(" some text ")
+ TestLog_ASSERT date1 = date2, "the return LTrim is: " & date1
+
+ result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
+ verify_testLTrim = 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/mid.vb b/basic/qa/vba_tests/mid.vb
new file mode 100644
index 000000000000..65e486d32745
--- /dev/null
+++ b/basic/qa/vba_tests/mid.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_testMid()
+If failCount <> 0 And passCount > 0 Then
+ doUnitTest = result
+Else
+ doUnitTest = "OK"
+End If
+End Function
+
+
+
+Function verify_testMid() 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 Mid function"
+ On Error GoTo errorHandler
+
+ date2 = "Mid"
+ date1 = Mid("Mid Function Demo", 1, 3)
+ TestLog_ASSERT date1 = date2, "the return Mid is: " & date1
+
+ date2 = "Demo"
+ date1 = Mid("Mid Function Demo", 14, 4)
+ TestLog_ASSERT date1 = date2, "the return Mid is: " & date1
+
+ date2 = "Function Demo"
+ date1 = Mid("Mid Function Demo", 5)
+ TestLog_ASSERT date1 = date2, "the return Mid is: " & date1
+
+
+ result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
+ verify_testMid = 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/minute.vb b/basic/qa/vba_tests/minute.vb
new file mode 100644
index 000000000000..ab19a63342c0
--- /dev/null
+++ b/basic/qa/vba_tests/minute.vb
@@ -0,0 +1,62 @@
+Option VBASupport 1
+Option Explicit
+Dim passCount As Integer
+Dim failCount As Integer
+Dim result As String
+
+Function doUnitTest() As String
+result = verify_testMinute()
+If failCount <> 0 And passCount > 0 Then
+ doUnitTest = result
+Else
+ doUnitTest = "OK"
+End If
+End Function
+
+
+
+Function verify_testMinute() 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 Minute function"
+ On Error GoTo errorHandler
+
+ date2 = 34
+ date1 = Minute("09:34:20")
+ TestLog_ASSERT date1 = date2, "the return Minute is: " & date1
+
+ result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
+ verify_testMinute = 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/mirr.vb b/basic/qa/vba_tests/mirr.vb
new file mode 100644
index 000000000000..36efb0a25065
--- /dev/null
+++ b/basic/qa/vba_tests/mirr.vb
@@ -0,0 +1,68 @@
+Option VBASupport 1
+Option Explicit
+Dim passCount As Integer
+Dim failCount As Integer
+Dim result As String
+
+Function doUnitTest() As String
+result = verify_testMIRR()
+If failCount <> 0 And passCount > 0 Then
+ doUnitTest = result
+Else
+ doUnitTest = "OK"
+End If
+End Function
+
+
+
+Function verify_testMIRR() 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, LoanAPR, InvAPR, Fmt, RetRate, Msg
+ testName = "Test MIRR function"
+ On Error GoTo errorHandler
+
+ Static Values(5) As Double ' Set up array.
+ LoanAPR = 0.1 ' Loan rate.
+ InvAPR = 0.12 ' Reinvestment rate.
+ Values(0) = -70000 ' Business start-up costs.
+ Values(1) = 22000: Values(2) = 25000
+ Values(3) = 28000: Values(4) = 31000
+ date2 = 0.148
+ date1 = MIRR(Values(), LoanAPR, InvAPR)
+ TestLog_ASSERT Round(date1, 3) = Round(date2, 3), "the return MIRR is: " & date1
+
+ result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
+ verify_testMIRR = 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/month.vb b/basic/qa/vba_tests/month.vb
new file mode 100644
index 000000000000..36343736b980
--- /dev/null
+++ b/basic/qa/vba_tests/month.vb
@@ -0,0 +1,81 @@
+Option VBASupport 1
+Option Explicit
+Dim passCount As Integer
+Dim failCount As Integer
+Dim result As String
+
+Function doUnitTest() As String
+result = verify_testMonth()
+If failCount <> 0 And passCount > 0 Then
+ doUnitTest = result
+Else
+ doUnitTest = "OK"
+End If
+End Function
+
+
+
+Function verify_testMonth() 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
+ Dim ldate As Date
+ testName = "Test Month function"
+ On Error GoTo errorHandler
+ ldate = 32616
+
+ date2 = 4
+ date1 = Month(ldate)
+ TestLog_ASSERT date1 = date2, "the return Month is: " & date1
+
+ date2 = 2
+ date1 = Month("01/02/2007")
+ TestLog_ASSERT date1 = date2, "the return Month is: " & date1
+
+ date2 = 12
+ date1 = Month(1)
+ TestLog_ASSERT date1 = date2, "the return Month is: " & date1
+
+ date2 = 2
+ date1 = Month(60)
+ TestLog_ASSERT date1 = date2, "the return Month is: " & date1
+
+ date2 = 6
+ date1 = Month(2000)
+ TestLog_ASSERT date1 = date2, "the return Month is: " & date1
+
+
+ result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
+ verify_testMonth = 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
+