forked from amazingfate/loongoffice
add VBA test cases
tests: ISARRAY, ISDATE, ISEMPTY, ISERROR, ISMISSING, ISNULL, ISNUMERIC, ISOBJECT, JOIN, LBOUND, LCASE Change-Id: I0b0dacd0d62bf00680f33866ce7ec0152eec27e0 Reviewed-on: https://gerrit.libreoffice.org/36509 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Zdenek Crhonek <zcrhonek@gmail.com>
This commit is contained in:
committed by
Zdenek Crhonek
parent
e72f3ce68e
commit
31dc11e7e3
@ -85,6 +85,17 @@ void VBATest::testMiscVBAFunctions()
|
||||
"instr.vb",
|
||||
"instrrev.vb",
|
||||
"int.vb",
|
||||
"iserror.vb",
|
||||
"ismissing.vb",
|
||||
"isnull.vb",
|
||||
"isobject.vb",
|
||||
"join.vb",
|
||||
"lbound.vb",
|
||||
"isarray.vb",
|
||||
"isdate.vb",
|
||||
"isempty.vb",
|
||||
"isnumeric.vb",
|
||||
"lcase.vb",
|
||||
#ifndef WIN32 // missing 64bit Currency marshalling.
|
||||
"win32compat.vb", // windows compatibility hooks.
|
||||
#endif
|
||||
|
||||
72
basic/qa/vba_tests/isarray.vb
Normal file
72
basic/qa/vba_tests/isarray.vb
Normal file
@ -0,0 +1,72 @@
|
||||
Option VBASupport 1
|
||||
Option Explicit
|
||||
Dim passCount As Integer
|
||||
Dim failCount As Integer
|
||||
Dim result As String
|
||||
|
||||
Function doUnitTest() As String
|
||||
result = verify_testIsArray()
|
||||
If failCount <> 0 And passCount > 0 Then
|
||||
doUnitTest = result
|
||||
Else
|
||||
doUnitTest = "OK"
|
||||
End If
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
Function verify_testIsArray() 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 MyArray(1 To 5) As Integer, YourArray ' Declare array variables.
|
||||
testName = "Test IsArray function"
|
||||
On Error GoTo errorHandler
|
||||
YourArray = Array(1, 2, 3) ' Use Array function.
|
||||
|
||||
date2 = True
|
||||
date1 = IsArray(MyArray)
|
||||
TestLog_ASSERT date1 = date2, "the return IsArray is: " & date1
|
||||
|
||||
date2 = True
|
||||
date1 = IsArray(YourArray)
|
||||
TestLog_ASSERT date1 = date2, "the return IsArray is: " & date1
|
||||
|
||||
date2 = False
|
||||
date1 = IsArray(date2)
|
||||
TestLog_ASSERT date1 = date2, "the return IsArray is: " & date1
|
||||
|
||||
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
|
||||
verify_testIsArray = 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
|
||||
|
||||
70
basic/qa/vba_tests/isdate.vb
Normal file
70
basic/qa/vba_tests/isdate.vb
Normal 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_testIsDate()
|
||||
If failCount <> 0 And passCount > 0 Then
|
||||
doUnitTest = result
|
||||
Else
|
||||
doUnitTest = "OK"
|
||||
End If
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
Function verify_testIsDate() 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 IsDate function"
|
||||
On Error GoTo errorHandler
|
||||
|
||||
date2 = True
|
||||
date1 = IsDate(cdate("12/2/1969"))
|
||||
TestLog_ASSERT date1 = date2, "the return IsDate is: " & date1
|
||||
|
||||
date2 = True
|
||||
date1 = IsDate("12:22:12")
|
||||
TestLog_ASSERT date1 = date2, "the return IsDate is: " & date1
|
||||
|
||||
date2 = False
|
||||
date1 = IsDate("a12.2.1969")
|
||||
TestLog_ASSERT date1 = date2, "the return IsDate is: " & date1
|
||||
|
||||
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
|
||||
verify_testIsDate = 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
|
||||
|
||||
72
basic/qa/vba_tests/isempty.vb
Normal file
72
basic/qa/vba_tests/isempty.vb
Normal file
@ -0,0 +1,72 @@
|
||||
Option VBASupport 1
|
||||
Option Explicit
|
||||
Dim passCount As Integer
|
||||
Dim failCount As Integer
|
||||
Dim result As String
|
||||
|
||||
Function doUnitTest() As String
|
||||
result = verify_testIsEmpty()
|
||||
If failCount <> 0 And passCount > 0 Then
|
||||
doUnitTest = result
|
||||
Else
|
||||
doUnitTest = "OK"
|
||||
End If
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
Function verify_testIsEmpty() 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, MyVar
|
||||
testName = "Test IsEmpty function"
|
||||
On Error GoTo errorHandler
|
||||
|
||||
date2 = True
|
||||
date1 = IsEmpty(MyVar)
|
||||
TestLog_ASSERT date1 = date2, "the return IsEmpty is: " & date1
|
||||
|
||||
MyVar = Null ' Assign Null.
|
||||
date2 = False
|
||||
date1 = IsEmpty(MyVar)
|
||||
TestLog_ASSERT date1 = date2, "the return IsEmpty is: " & date1
|
||||
|
||||
MyVar = Empty ' Assign Empty.
|
||||
date2 = True
|
||||
date1 = IsEmpty(MyVar)
|
||||
TestLog_ASSERT date1 = date2, "the return IsEmpty is: " & date1
|
||||
|
||||
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
|
||||
verify_testIsEmpty = 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
|
||||
|
||||
66
basic/qa/vba_tests/iserror.vb
Normal file
66
basic/qa/vba_tests/iserror.vb
Normal 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_testIsError()
|
||||
If failCount <> 0 And passCount > 0 Then
|
||||
doUnitTest = result
|
||||
Else
|
||||
doUnitTest = "OK"
|
||||
End If
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
Function verify_testIsError() 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 IsError function"
|
||||
On Error GoTo errorHandler
|
||||
|
||||
date2 = False
|
||||
date1 = IsError("12.2.1969")
|
||||
TestLog_ASSERT date1 = date2, "the return IsError is: " & date1
|
||||
|
||||
date2 = True
|
||||
date1 = IsError(CVErr(64))
|
||||
TestLog_ASSERT date1 = date2, "the return IsError is: " & date1
|
||||
|
||||
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
|
||||
verify_testIsError = 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
|
||||
|
||||
75
basic/qa/vba_tests/ismissing.vb
Normal file
75
basic/qa/vba_tests/ismissing.vb
Normal file
@ -0,0 +1,75 @@
|
||||
Option VBASupport 1
|
||||
Option Explicit
|
||||
Dim passCount As Integer
|
||||
Dim failCount As Integer
|
||||
Dim result As String
|
||||
|
||||
Function doUnitTest() As String
|
||||
result = verify_testIsMissing()
|
||||
If failCount <> 0 And passCount > 0 Then
|
||||
doUnitTest = result
|
||||
Else
|
||||
doUnitTest = "OK"
|
||||
End If
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
Function verify_testIsMissing() 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 IsMissing function"
|
||||
On Error GoTo errorHandler
|
||||
|
||||
date2 = Null
|
||||
date1 = ReturnTwice()
|
||||
TestLog_ASSERT IsNull(date1), "the return IsMissing is: " & date1
|
||||
|
||||
date2 = 4
|
||||
date1 = ReturnTwice(2)
|
||||
TestLog_ASSERT date1 = date2, "the return IsMissing is: " & date1
|
||||
|
||||
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
|
||||
verify_testIsMissing = 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
|
||||
' Function procedure definition.
|
||||
Function ReturnTwice(Optional A)
|
||||
If IsMissing(A) Then
|
||||
' If argument is missing, return a Null.
|
||||
ReturnTwice = Null
|
||||
Else
|
||||
' If argument is present, return twice the value.
|
||||
ReturnTwice = A * 2
|
||||
End If
|
||||
End Function
|
||||
66
basic/qa/vba_tests/isnull.vb
Normal file
66
basic/qa/vba_tests/isnull.vb
Normal 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_testIsNull()
|
||||
If failCount <> 0 And passCount > 0 Then
|
||||
doUnitTest = result
|
||||
Else
|
||||
doUnitTest = "OK"
|
||||
End If
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
Function verify_testIsNull() 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 IsNull function"
|
||||
On Error GoTo errorHandler
|
||||
|
||||
date2 = True
|
||||
date1 = IsNull(Null)
|
||||
TestLog_ASSERT date1 = date2, "the return IsNull is: " & date1
|
||||
|
||||
date2 = False
|
||||
date1 = IsNull("")
|
||||
TestLog_ASSERT date1 = date2, "the return IsNull is: " & date1
|
||||
|
||||
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
|
||||
verify_testIsNull = 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
|
||||
|
||||
82
basic/qa/vba_tests/isnumeric.vb
Normal file
82
basic/qa/vba_tests/isnumeric.vb
Normal file
@ -0,0 +1,82 @@
|
||||
Option VBASupport 1
|
||||
Option Explicit
|
||||
Dim passCount As Integer
|
||||
Dim failCount As Integer
|
||||
Dim result As String
|
||||
|
||||
Function doUnitTest() As String
|
||||
result = verify_testIsNumeric()
|
||||
If failCount <> 0 And passCount > 0 Then
|
||||
doUnitTest = result
|
||||
Else
|
||||
doUnitTest = "OK"
|
||||
End If
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
Function verify_testIsNumeric() 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 IsNumeric function"
|
||||
On Error GoTo errorHandler
|
||||
|
||||
date2 = True
|
||||
date1 = IsNumeric(123)
|
||||
TestLog_ASSERT date1 = date2, "the return IsNumeric is: " & date1
|
||||
|
||||
date2 = True
|
||||
date1 = IsNumeric(-123)
|
||||
TestLog_ASSERT date1 = date2, "the return IsNumeric is: " & date1
|
||||
|
||||
date2 = True
|
||||
date1 = IsNumeric(123.8)
|
||||
TestLog_ASSERT date1 = date2, "the return IsNumeric is: " & date1
|
||||
|
||||
date2 = False
|
||||
date1 = IsNumeric("a")
|
||||
TestLog_ASSERT date1 = date2, "the return IsNumeric is: " & date1
|
||||
|
||||
rem date2 = True
|
||||
rem date1 = IsNumeric(True)
|
||||
rem TestLog_ASSERT date1 = date2, "the return IsNumeric is: " & date1
|
||||
|
||||
date2 = True
|
||||
date1 = IsNumeric("123")
|
||||
TestLog_ASSERT date1 = date2, "the return IsNumeric is: " & date1
|
||||
|
||||
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
|
||||
verify_testIsNumeric = 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
|
||||
|
||||
68
basic/qa/vba_tests/isobject.vb
Normal file
68
basic/qa/vba_tests/isobject.vb
Normal file
@ -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_testIsObject()
|
||||
If failCount <> 0 And passCount > 0 Then
|
||||
doUnitTest = result
|
||||
Else
|
||||
doUnitTest = "OK"
|
||||
End If
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
Function verify_testIsObject() 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 MyObject As Object
|
||||
Dim date1, date2, YourObject
|
||||
testName = "Test IsObject function"
|
||||
On Error GoTo errorHandler
|
||||
|
||||
Set YourObject = MyObject ' Assign an object reference.
|
||||
date2 = True
|
||||
date1 = IsObject(YourObject)
|
||||
TestLog_ASSERT date1 = date2, "the return IsObject is: " & date1
|
||||
|
||||
date2 = False
|
||||
date1 = IsObject(TestStr)
|
||||
TestLog_ASSERT date1 = date2, "the return IsObject is: " & date1
|
||||
|
||||
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
|
||||
verify_testIsObject = 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/join.vb
Normal file
78
basic/qa/vba_tests/join.vb
Normal 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_testJoin()
|
||||
If failCount <> 0 And passCount > 0 Then
|
||||
doUnitTest = result
|
||||
Else
|
||||
doUnitTest = "OK"
|
||||
End If
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
Function verify_testJoin() 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 vaArray() As String
|
||||
testName = "Test Join function"
|
||||
On Error GoTo errorHandler
|
||||
vaArray(0) = "string1"
|
||||
vaArray(1) = "string2"
|
||||
vaArray(2) = "string3"
|
||||
|
||||
date2 = "string1 string2 string3"
|
||||
date1 = Join(vaArray)
|
||||
TestLog_ASSERT date1 = date2, "the return Join is: " & date1
|
||||
|
||||
date2 = "string1 string2 string3"
|
||||
date1 = Join(vaArray, " ")
|
||||
TestLog_ASSERT date1 = date2, "the return Join is: " & date1
|
||||
|
||||
date2 = "string1<>string2<>string3"
|
||||
date1 = Join(vaArray, "<>")
|
||||
TestLog_ASSERT date1 = date2, "the return Join is: " & date1
|
||||
|
||||
date2 = "string1string2string3"
|
||||
date1 = Join(vaArray, "")
|
||||
TestLog_ASSERT date1 = date2, "the return Join is: " & date1
|
||||
|
||||
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
|
||||
verify_testJoin = 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
|
||||
|
||||
68
basic/qa/vba_tests/lbound.vb
Normal file
68
basic/qa/vba_tests/lbound.vb
Normal file
@ -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_testLBound()
|
||||
If failCount <> 0 And passCount > 0 Then
|
||||
doUnitTest = result
|
||||
Else
|
||||
doUnitTest = "OK"
|
||||
End If
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
Function verify_testLBound() 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 MyArray(1 To 10, 5 To 15, 10 To 20) ' Declare array variables.
|
||||
testName = "Test LBound function"
|
||||
On Error GoTo errorHandler
|
||||
|
||||
date2 = 1
|
||||
date1 = LBound(MyArray, 1)
|
||||
TestLog_ASSERT date1 = date2, "the return LBound is: " & date1
|
||||
|
||||
date2 = 10
|
||||
date1 = LBound(MyArray, 3)
|
||||
TestLog_ASSERT date1 = date2, "the return LBound is: " & date1
|
||||
|
||||
|
||||
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
|
||||
verify_testLBound = 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
|
||||
|
||||
75
basic/qa/vba_tests/lcase.vb
Normal file
75
basic/qa/vba_tests/lcase.vb
Normal file
@ -0,0 +1,75 @@
|
||||
Option VBASupport 1
|
||||
Option Explicit
|
||||
Dim passCount As Integer
|
||||
Dim failCount As Integer
|
||||
Dim result As String
|
||||
|
||||
Function doUnitTest() As String
|
||||
result = verify_testLCase()
|
||||
If failCount <> 0 And passCount > 0 Then
|
||||
doUnitTest = result
|
||||
Else
|
||||
doUnitTest = "OK"
|
||||
End If
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
Function verify_testLCase() 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 As Date 'variables for test
|
||||
testName = "Test LCase function"
|
||||
On Error GoTo errorHandler
|
||||
|
||||
date2 = "lowercase"
|
||||
date1 = LCase("LOWERCASE")
|
||||
TestLog_ASSERT date1 = date2, "the return LCase is: " & date1
|
||||
|
||||
date2 = "lowercase"
|
||||
date1 = LCase("LowerCase")
|
||||
TestLog_ASSERT date1 = date2, "the return LCase is: " & date1
|
||||
|
||||
date2 = "lowercase"
|
||||
date1 = LCase("lowercase")
|
||||
TestLog_ASSERT date1 = date2, "the return LCase is: " & date1
|
||||
|
||||
date2 = "lowercase"
|
||||
date1 = LCase("LOWER CASE")
|
||||
TestLog_ASSERT date1 = date2, "the return LCase is: " & date1
|
||||
|
||||
|
||||
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
|
||||
verify_testLCase = 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
|
||||
|
||||
Reference in New Issue
Block a user