diff options
author | Zdeněk Crhonek <zcrhonek@gmail.com> | 2017-08-24 11:02:01 +0200 |
---|---|---|
committer | Zdenek Crhonek <zcrhonek@gmail.com> | 2017-08-24 12:55:26 +0200 |
commit | 74da6d5f9f875cc355776f8fa8fbff15f0316d0c (patch) | |
tree | 1935a4f0a8ed47bd8afe71c5fb02d683d7f077a3 /basic | |
parent | fd736c4f7910f5b876c3ab8b8e0e804aa83347a0 (diff) |
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>
Diffstat (limited to 'basic')
-rw-r--r-- | basic/qa/cppunit/test_vba.cxx | 5 | ||||
-rw-r--r-- | basic/qa/vba_tests/val.vb | 94 | ||||
-rw-r--r-- | basic/qa/vba_tests/vartype.vb | 86 | ||||
-rw-r--r-- | basic/qa/vba_tests/weekday.vb | 83 | ||||
-rw-r--r-- | basic/qa/vba_tests/weekdayname.vb | 86 | ||||
-rw-r--r-- | basic/qa/vba_tests/year.vb | 66 |
6 files changed, 420 insertions, 0 deletions
diff --git a/basic/qa/cppunit/test_vba.cxx b/basic/qa/cppunit/test_vba.cxx index 9ba9521036a5..a8d5c7c9410c 100644 --- a/basic/qa/cppunit/test_vba.cxx +++ b/basic/qa/cppunit/test_vba.cxx @@ -137,6 +137,11 @@ void VBATest::testMiscVBAFunctions() "typename.vb", "ubound.vb", "ucase.vb", + "val.vb", + "vartype.vb", + "weekday.vb", + "weekdayname.vb", + "year.vb", #ifndef WIN32 // missing 64bit Currency marshalling. "win32compat.vb", // windows compatibility hooks. #endif diff --git a/basic/qa/vba_tests/val.vb b/basic/qa/vba_tests/val.vb new file mode 100644 index 000000000000..08f2722c3c8d --- /dev/null +++ b/basic/qa/vba_tests/val.vb @@ -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 + diff --git a/basic/qa/vba_tests/vartype.vb b/basic/qa/vba_tests/vartype.vb new file mode 100644 index 000000000000..05cfa308fe28 --- /dev/null +++ b/basic/qa/vba_tests/vartype.vb @@ -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 + diff --git a/basic/qa/vba_tests/weekday.vb b/basic/qa/vba_tests/weekday.vb new file mode 100644 index 000000000000..95212eb58ceb --- /dev/null +++ b/basic/qa/vba_tests/weekday.vb @@ -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 + diff --git a/basic/qa/vba_tests/weekdayname.vb b/basic/qa/vba_tests/weekdayname.vb new file mode 100644 index 000000000000..a4cdbc5be9b9 --- /dev/null +++ b/basic/qa/vba_tests/weekdayname.vb @@ -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 + diff --git a/basic/qa/vba_tests/year.vb b/basic/qa/vba_tests/year.vb new file mode 100644 index 000000000000..879e3097f7b1 --- /dev/null +++ b/basic/qa/vba_tests/year.vb @@ -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 + |