VBA tests-add VAL,VARTYPE,WEEKDAY,WEEKDAYNAME,YEAR tests
Change-Id: I3f1803617a2bdeaab9922ebb375ec4fd67318d20 Reviewed-on: https://gerrit.libreoffice.org/41499 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Zdenek Crhonek <zcrhonek@gmail.com>
This commit is contained in:
committed by
Zdenek Crhonek
parent
fd736c4f79
commit
74da6d5f9f
@@ -137,6 +137,11 @@ void VBATest::testMiscVBAFunctions()
|
|||||||
"typename.vb",
|
"typename.vb",
|
||||||
"ubound.vb",
|
"ubound.vb",
|
||||||
"ucase.vb",
|
"ucase.vb",
|
||||||
|
"val.vb",
|
||||||
|
"vartype.vb",
|
||||||
|
"weekday.vb",
|
||||||
|
"weekdayname.vb",
|
||||||
|
"year.vb",
|
||||||
#ifndef WIN32 // missing 64bit Currency marshalling.
|
#ifndef WIN32 // missing 64bit Currency marshalling.
|
||||||
"win32compat.vb", // windows compatibility hooks.
|
"win32compat.vb", // windows compatibility hooks.
|
||||||
#endif
|
#endif
|
||||||
|
94
basic/qa/vba_tests/val.vb
Normal file
94
basic/qa/vba_tests/val.vb
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
Option VBASupport 1
|
||||||
|
Option Explicit
|
||||||
|
Dim passCount As Integer
|
||||||
|
Dim failCount As Integer
|
||||||
|
Dim result As String
|
||||||
|
|
||||||
|
Function doUnitTest() As String
|
||||||
|
result = verify_testVal()
|
||||||
|
If failCount <> 0 And passCount > 0 Then
|
||||||
|
doUnitTest = result
|
||||||
|
Else
|
||||||
|
doUnitTest = "OK"
|
||||||
|
End If
|
||||||
|
End Function
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Function verify_testVal() 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 Val function"
|
||||||
|
On Error GoTo errorHandler
|
||||||
|
|
||||||
|
date2 = 2
|
||||||
|
date1 = Val("02/04/2010")
|
||||||
|
TestLog_ASSERT date1 = date2, "the return Val is: " & date1
|
||||||
|
|
||||||
|
date2 = 1050
|
||||||
|
date1 = Val("1050")
|
||||||
|
TestLog_ASSERT date1 = date2, "the return Val is: " & date1
|
||||||
|
|
||||||
|
date2 = 130.75
|
||||||
|
date1 = Val("130.75")
|
||||||
|
TestLog_ASSERT date1 = date2, "the return Val is: " & date1
|
||||||
|
|
||||||
|
date2 = 50
|
||||||
|
date1 = Val("50 Park Lane")
|
||||||
|
TestLog_ASSERT date1 = date2, "the return Val is: " & date1
|
||||||
|
|
||||||
|
date2 = 1320
|
||||||
|
date1 = Val("1320 then some text")
|
||||||
|
TestLog_ASSERT date1 = date2, "the return Val is: " & date1
|
||||||
|
|
||||||
|
date2 = 0
|
||||||
|
date1 = Val("L13.5")
|
||||||
|
TestLog_ASSERT date1 = date2, "the return Val is: " & date1
|
||||||
|
|
||||||
|
date2 = 0
|
||||||
|
date1 = Val("sometext")
|
||||||
|
TestLog_ASSERT date1 = date2, "the return Val is: " & date1
|
||||||
|
|
||||||
|
REM date2 = 1
|
||||||
|
REM date1 = Val("1, 2")
|
||||||
|
REM TestLog_ASSERT date1 = date2, "the return Val is: " & date1
|
||||||
|
REM tdf#111999
|
||||||
|
|
||||||
|
date2 = -1
|
||||||
|
date1 = Val("&HFFFF")
|
||||||
|
TestLog_ASSERT date1 = date2, "the return Val is: " & date1
|
||||||
|
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
|
||||||
|
verify_testVal = 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
|
||||||
|
|
86
basic/qa/vba_tests/vartype.vb
Normal file
86
basic/qa/vba_tests/vartype.vb
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
Option VBASupport 1
|
||||||
|
Option Explicit
|
||||||
|
Dim passCount As Integer
|
||||||
|
Dim failCount As Integer
|
||||||
|
Dim result As String
|
||||||
|
|
||||||
|
Function doUnitTest() As String
|
||||||
|
result = verify_testVarType()
|
||||||
|
If failCount <> 0 And passCount > 0 Then
|
||||||
|
doUnitTest = result
|
||||||
|
Else
|
||||||
|
doUnitTest = "OK"
|
||||||
|
End If
|
||||||
|
End Function
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Function verify_testVarType() 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 TestInt As Integer
|
||||||
|
Dim TestLong As Long
|
||||||
|
Dim TestDouble As Double
|
||||||
|
Dim TestBoo As Boolean
|
||||||
|
Dim date1, date2
|
||||||
|
testName = "Test VarType function"
|
||||||
|
On Error GoTo errorHandler
|
||||||
|
|
||||||
|
date2 = 8
|
||||||
|
date1 = VarType(testName)
|
||||||
|
TestLog_ASSERT date1 = date2, "the return VarType is: " & date1
|
||||||
|
|
||||||
|
date2 = 11
|
||||||
|
date1 = VarType(TestBoo)
|
||||||
|
TestLog_ASSERT date1 = date2, "the return VarType is: " & date1
|
||||||
|
|
||||||
|
date2 = 5
|
||||||
|
date1 = VarType(TestDouble)
|
||||||
|
TestLog_ASSERT date1 = date2, "the return VarType is: " & date1
|
||||||
|
|
||||||
|
date2 = 3
|
||||||
|
date1 = VarType(TestLong)
|
||||||
|
TestLog_ASSERT date1 = date2, "the return VarType is: " & date1
|
||||||
|
|
||||||
|
date2 = 2
|
||||||
|
date1 = VarType(TestInt)
|
||||||
|
TestLog_ASSERT date1 = date2, "the return VarType is: " & date1
|
||||||
|
|
||||||
|
date2 = 7
|
||||||
|
date1 = VarType(TestDateTime)
|
||||||
|
TestLog_ASSERT date1 = date2, "the return VarType is: " & date1
|
||||||
|
|
||||||
|
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
|
||||||
|
verify_testVarType = 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
|
||||||
|
|
83
basic/qa/vba_tests/weekday.vb
Normal file
83
basic/qa/vba_tests/weekday.vb
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
Option VBASupport 1
|
||||||
|
Option Explicit
|
||||||
|
Dim passCount As Integer
|
||||||
|
Dim failCount As Integer
|
||||||
|
Dim result As String
|
||||||
|
|
||||||
|
Function doUnitTest() As String
|
||||||
|
result = verify_testWeekDay()
|
||||||
|
If failCount <> 0 And passCount > 0 Then
|
||||||
|
doUnitTest = result
|
||||||
|
Else
|
||||||
|
doUnitTest = "OK"
|
||||||
|
End If
|
||||||
|
End Function
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Function verify_testWeekDay() 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 WeekDay function"
|
||||||
|
On Error GoTo errorHandler
|
||||||
|
|
||||||
|
date2 = 7
|
||||||
|
date1 = Weekday(#6/7/2009#, vbMonday)
|
||||||
|
TestLog_ASSERT date1 = date2, "the return WeekDay is: " & date1
|
||||||
|
|
||||||
|
date2 = 2
|
||||||
|
date1 = Weekday(#7/7/2009#, vbMonday)
|
||||||
|
TestLog_ASSERT date1 = date2, "the return WeekDay is: " & date1
|
||||||
|
|
||||||
|
date2 = 5
|
||||||
|
date1 = Weekday(#8/7/2009#, vbMonday)
|
||||||
|
TestLog_ASSERT date1 = date2, "the return WeekDay is: " & date1
|
||||||
|
|
||||||
|
date2 = 1
|
||||||
|
date1 = Weekday(#12/7/2009#, vbMonday)
|
||||||
|
TestLog_ASSERT date1 = date2, "the return WeekDay is: " & date1
|
||||||
|
|
||||||
|
date2 = 1
|
||||||
|
date1 = Weekday(#6/7/2009#, vbSunday)
|
||||||
|
TestLog_ASSERT date1 = date2, "the return WeekDay is: " & date1
|
||||||
|
|
||||||
|
date2 = 5
|
||||||
|
date1 = Weekday(#6/7/2009#, 4)
|
||||||
|
TestLog_ASSERT date1 = date2, "the return WeekDay is: " & date1
|
||||||
|
|
||||||
|
|
||||||
|
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
|
||||||
|
verify_testWeekDay = 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
|
||||||
|
|
86
basic/qa/vba_tests/weekdayname.vb
Normal file
86
basic/qa/vba_tests/weekdayname.vb
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
Option VBASupport 1
|
||||||
|
Option Explicit
|
||||||
|
Dim passCount As Integer
|
||||||
|
Dim failCount As Integer
|
||||||
|
Dim result As String
|
||||||
|
|
||||||
|
Function doUnitTest() As String
|
||||||
|
result = verify_testWeekDayName()
|
||||||
|
If failCount <> 0 And passCount > 0 Then
|
||||||
|
doUnitTest = result
|
||||||
|
Else
|
||||||
|
doUnitTest = "OK"
|
||||||
|
End If
|
||||||
|
End Function
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Function verify_testWeekDayName() 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 WeekDayName function"
|
||||||
|
On Error GoTo errorHandler
|
||||||
|
|
||||||
|
date2 = "Sunday"
|
||||||
|
date1 = WeekdayName(1)
|
||||||
|
TestLog_ASSERT date1 = date2, "the return WeekDayName is: " & date1
|
||||||
|
|
||||||
|
date2 = "Sunday"
|
||||||
|
date1 = WeekdayName(1, , vbSunday)
|
||||||
|
TestLog_ASSERT date1 = date2, "the return WeekDayName is: " & date1
|
||||||
|
|
||||||
|
date2 = "Monday"
|
||||||
|
date1 = WeekdayName(1, , vbMonday)
|
||||||
|
TestLog_ASSERT date1 = date2, "the return WeekDayName is: " & date1
|
||||||
|
|
||||||
|
date2 = "Monday"
|
||||||
|
date1 = WeekdayName(2)
|
||||||
|
TestLog_ASSERT date1 = date2, "the return WeekDayName is: " & date1
|
||||||
|
|
||||||
|
date2 = "Tue"
|
||||||
|
date1 = WeekdayName(2, True, vbMonday)
|
||||||
|
TestLog_ASSERT date1 = date2, "the return WeekDayName is: " & date1
|
||||||
|
|
||||||
|
date2 = "Wed"
|
||||||
|
date1 = WeekdayName(2, True, vbTuesday)
|
||||||
|
TestLog_ASSERT date1 = date2, "the return WeekDayName is: " & date1
|
||||||
|
|
||||||
|
date2 = "Thu"
|
||||||
|
date1 = WeekdayName(2, True, vbWednesday)
|
||||||
|
TestLog_ASSERT date1 = date2, "the return WeekDayName is: " & date1
|
||||||
|
|
||||||
|
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
|
||||||
|
verify_testWeekDayName = 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/year.vb
Normal file
66
basic/qa/vba_tests/year.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_testYear()
|
||||||
|
If failCount <> 0 And passCount > 0 Then
|
||||||
|
doUnitTest = result
|
||||||
|
Else
|
||||||
|
doUnitTest = "OK"
|
||||||
|
End If
|
||||||
|
End Function
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Function verify_testYear() 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 Year function"
|
||||||
|
On Error GoTo errorHandler
|
||||||
|
|
||||||
|
date2 = 1969
|
||||||
|
date1 = Year("12.2.1969")
|
||||||
|
TestLog_ASSERT date1 = date2, "the return Year is: " & date1
|
||||||
|
|
||||||
|
date2 = 1900
|
||||||
|
date1 = Year(256)
|
||||||
|
TestLog_ASSERT date1 = date2, "the return Year is: " & date1
|
||||||
|
|
||||||
|
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
|
||||||
|
verify_testYear = 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