VBA tests-functions RIGHT,RTRIM,SECOND,SGN,SIN,SLN,SPACE,SQR

Change-Id: I0db9233f20fccbc4b2c4f4b3e36cf0aaa8583c99
Reviewed-on: https://gerrit.libreoffice.org/40339
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Zdenek Crhonek <zcrhonek@gmail.com>
This commit is contained in:
Zdeněk Crhonek
2017-07-23 21:39:33 +02:00
committed by Zdenek Crhonek
parent 8c7c72c8f8
commit fae4b84882
9 changed files with 532 additions and 0 deletions

View File

@@ -117,6 +117,14 @@ void VBATest::testMiscVBAFunctions()
"qbcolor.vb",
"rate.vb",
"rgb.vb",
"rtrim.vb",
"right.vb",
"second.vb",
"sgn.vb",
"sin.vb",
"sln.vb",
"space.vb",
"sqr.vb",
#ifndef WIN32 // missing 64bit Currency marshalling.
"win32compat.vb", // windows compatibility hooks.
#endif

View File

@@ -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_testRight()
If failCount <> 0 And passCount > 0 Then
doUnitTest = result
Else
doUnitTest = "OK"
End If
End Function
Function verify_testRight() 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 Right function"
On Error GoTo errorHandler
date2 = "text"
date1 = Right("sometext", 4)
TestLog_ASSERT date1 = date2, "the return Right is: " & date1
date2 = "sometext"
date1 = Right("sometext", 48)
TestLog_ASSERT date1 = date2, "the return Right is: " & date1
date2 = ""
date1 = Right("", 4)
TestLog_ASSERT date1 = date2, "the return Right is: " & date1
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
verify_testRight = 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

View File

@@ -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_testRTrim()
If failCount <> 0 And passCount > 0 Then
doUnitTest = result
Else
doUnitTest = "OK"
End If
End Function
Function verify_testRTrim() 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 RTrim function"
On Error GoTo errorHandler
date2 = " some text"
date1 = RTrim(" some text ")
TestLog_ASSERT date1 = date2, "the return RTrim is: " & date1
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
verify_testRTrim = 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

View File

@@ -0,0 +1,66 @@
Option VBASupport 1
Option Explicit
Dim passCount As Integer
Dim failCount As Integer
Dim result As String
Function doUnitTest() As String
result = verify_testSecond()
If failCount <> 0 And passCount > 0 Then
doUnitTest = result
Else
doUnitTest = "OK"
End If
End Function
Function verify_testSecond() 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 Second function"
On Error GoTo errorHandler
date2 = 0
date1 = Second(37566.3)
TestLog_ASSERT date1 = date2, "the return Second is: " & date1
date2 = 17
date1 = Second("4:35:17")
TestLog_ASSERT date1 = date2, "the return Second is: " & date1
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
verify_testSecond = 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

78
basic/qa/vba_tests/sgn.vb Normal file
View File

@@ -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_SGN()
If failCount <> 0 And passCount > 0 Then
doUnitTest = result
Else
doUnitTest = "OK"
End If
End Function
Function verify_SGN() 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 SGN function"
On Error GoTo errorHandler
date2 = 0
date1 = DateValue(0)
TestLog_ASSERT date1 = date2, "the return SGN is: " & date1
date2 = -1
date1 = DateValue(-1)
TestLog_ASSERT date1 = date2, "the return SGN is: " & date1
date2 = 1
date1 = DateValue(1)
TestLog_ASSERT date1 = date2, "the return SGN is: " & date1
date2 = 1
date1 = DateValue(50)
TestLog_ASSERT date1 = date2, "the return SGN is: " & date1
date2 = -1
date1 = DateValue(-50)
TestLog_ASSERT date1 = date2, "the return SGN is: " & date1
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
verify_SGN = 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

62
basic/qa/vba_tests/sin.vb Normal file
View File

@@ -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_testSIN()
If failCount <> 0 And passCount > 0 Then
doUnitTest = result
Else
doUnitTest = "OK"
End If
End Function
Function verify_testSIN() 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 SIN function"
On Error GoTo errorHandler
date2 = 0.43
date1 = Sin(0.45)
TestLog_ASSERT Round(date1, 2) = Round(date2, 2), "the return SIN is: " & date1
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
verify_testSIN = 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

62
basic/qa/vba_tests/sln.vb Normal file
View File

@@ -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_testSLN()
If failCount <> 0 And passCount > 0 Then
doUnitTest = result
Else
doUnitTest = "OK"
End If
End Function
Function verify_testSLN() 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 SLN function"
On Error GoTo errorHandler
date2 = 395.83
date1 = SLN(10000, 500, 24)
TestLog_ASSERT Round(date1, 2) = Round(date2, 2), "the return SLN is: " & date1
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
verify_testSLN = 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

View File

@@ -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_testSpace()
If failCount <> 0 And passCount > 0 Then
doUnitTest = result
Else
doUnitTest = "OK"
End If
End Function
Function verify_testSpace() 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 Space function"
On Error GoTo errorHandler
date2 = " "
date1 = Space(2)
TestLog_ASSERT date1 = date2, "the return Space is: " & date1
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
verify_testSpace = 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

62
basic/qa/vba_tests/sqr.vb Normal file
View File

@@ -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_testSQR()
If failCount <> 0 And passCount > 0 Then
doUnitTest = result
Else
doUnitTest = "OK"
End If
End Function
Function verify_testSQR() 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 SQR function"
On Error GoTo errorHandler
date2 = 3
date1 = Sqr(9)
TestLog_ASSERT date1 = date2, "the return SQR is: " & date1
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
verify_testSQR = 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