diff options
Diffstat (limited to 'basic/qa/basic_coverage')
136 files changed, 3258 insertions, 0 deletions
diff --git a/basic/qa/basic_coverage/da-DK/cdbl-2.vb b/basic/qa/basic_coverage/da-DK/cdbl-2.vb new file mode 100644 index 000000000..a219304d4 --- /dev/null +++ b/basic/qa/basic_coverage/da-DK/cdbl-2.vb @@ -0,0 +1,14 @@ +Function doUnitTest() as Integer + Dim A As String + Dim B As Double + Dim Expected As Double + A = "222,222" + ' in da-DK locale ',' is the decimal separator + Expected = 222.222 + B = Cdbl(A) + If B <> Expected Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/da-DK/cdbl.vb b/basic/qa/basic_coverage/da-DK/cdbl.vb new file mode 100644 index 000000000..128cfcc99 --- /dev/null +++ b/basic/qa/basic_coverage/da-DK/cdbl.vb @@ -0,0 +1,14 @@ +Function doUnitTest() as Integer + Dim A As String + Dim B As Double + Dim Expected As String + A = "222.222" + ' in da-DK locale ',' is the decimal separator + Expected = "222222" + B = Cdbl(A) + If B <> Expected Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/string_left_01.vb b/basic/qa/basic_coverage/string_left_01.vb new file mode 100644 index 000000000..ef896bef1 --- /dev/null +++ b/basic/qa/basic_coverage/string_left_01.vb @@ -0,0 +1,25 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + + +Function doUnitTest as Integer + +Dim s1 As String +Dim s2 As String + + s1 = "abc" + + s2 = Left(s1, 2) + + If s2 = "ab" Then + doUnitTest = 1 + Else + doUnitTest = 0 + End If + +End Function diff --git a/basic/qa/basic_coverage/string_right_01.vb b/basic/qa/basic_coverage/string_right_01.vb new file mode 100644 index 000000000..65b16c6a8 --- /dev/null +++ b/basic/qa/basic_coverage/string_right_01.vb @@ -0,0 +1,24 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + +Dim s1 As String +Dim s2 As String + + s1 = "abc" + + s2 = Right(s1, 2) + + If s2 = "bc" Then + doUnitTest = 1 + Else + doUnitTest = 0 + End If + +End Function diff --git a/basic/qa/basic_coverage/test_Property.GetLet.vb b/basic/qa/basic_coverage/test_Property.GetLet.vb new file mode 100644 index 000000000..992496a21 --- /dev/null +++ b/basic/qa/basic_coverage/test_Property.GetLet.vb @@ -0,0 +1,27 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Option Compatible + +Function doUnitTest as Integer + ' PROPERTY GET/LET + aString = "Office" + If ( aString <> "LibreOffice") Then + doUnitTest = 0 ' Ko + Else + doUnitTest = 1 ' Ok + End If +End Function + +Dim _pn As String +Property Get aString As String + aString = _pn +End Property +Property Let aString(value As String) + _pn = "Libre"& value +End Property diff --git a/basic/qa/basic_coverage/test_Property.GetSet.vb b/basic/qa/basic_coverage/test_Property.GetSet.vb new file mode 100644 index 000000000..4a23867c2 --- /dev/null +++ b/basic/qa/basic_coverage/test_Property.GetSet.vb @@ -0,0 +1,37 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Option Compatible + +Function doUnitTest as Integer + ' PROPERTY GET/SET for classes or UNO services + + Set objSetter = New Collection ' OR objLetter = New Collection + If ( objGetter.Count <> 3 ) Then + doUnitTest = 0 ' not Ok + Else + doUnitTest = 1 ' Ok + End If +End Function + +Sub DEV_TST : MsgBox doUnitTesT : End Sub + +Property Get objGetter As Object + _obj.add "roots" + Set objGetter = _obj +End Property + +Private _obj As Object + +Property Set objSetter(value As Object) + Set _obj = value + With _obj + .add "branches" + .add "leaves" + End With +End Property diff --git a/basic/qa/basic_coverage/test_abs_method.vb b/basic/qa/basic_coverage/test_abs_method.vb new file mode 100644 index 000000000..b79b9bcbb --- /dev/null +++ b/basic/qa/basic_coverage/test_abs_method.vb @@ -0,0 +1,17 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' ABS + If (Abs(-3.5) <> 3.5) Then + doUnitTest = 0 + ElseIf (Abs(3.5) <> 3.5) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_array_method.vb b/basic/qa/basic_coverage/test_array_method.vb new file mode 100644 index 000000000..42f10a25a --- /dev/null +++ b/basic/qa/basic_coverage/test_array_method.vb @@ -0,0 +1,20 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + dim aVector as Variant + ' ARRAY + aVector = Array( "Hello", -3.14) + If (aVector(0) <> "Hello") Then + doUnitTest = 0 + ElseIf ( aVector(1) <> -3.14 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_asc_method.vb b/basic/qa/basic_coverage/test_asc_method.vb new file mode 100644 index 000000000..48b88933f --- /dev/null +++ b/basic/qa/basic_coverage/test_asc_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' ASC + If (Asc("€a") <> 8364) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_atn_method.vb b/basic/qa/basic_coverage/test_atn_method.vb new file mode 100644 index 000000000..771714134 --- /dev/null +++ b/basic/qa/basic_coverage/test_atn_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' ATN (arc tan) + If (Atn(1) <> PI/4) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_beep_method.vb b/basic/qa/basic_coverage/test_beep_method.vb new file mode 100644 index 000000000..28eed61a6 --- /dev/null +++ b/basic/qa/basic_coverage/test_beep_method.vb @@ -0,0 +1,12 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' BEEP + Beep + doUnitTest = 1 +End Function diff --git a/basic/qa/basic_coverage/test_cbool_method.vb b/basic/qa/basic_coverage/test_cbool_method.vb new file mode 100644 index 000000000..d1d995f19 --- /dev/null +++ b/basic/qa/basic_coverage/test_cbool_method.vb @@ -0,0 +1,16 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' CBOOL + If (CBool(3) <> True) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_cbyte_method.vb b/basic/qa/basic_coverage/test_cbyte_method.vb new file mode 100644 index 000000000..35bb1654c --- /dev/null +++ b/basic/qa/basic_coverage/test_cbyte_method.vb @@ -0,0 +1,16 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' CBYTE + If (CByte("3") <> 3) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_ccur_method.vb b/basic/qa/basic_coverage/test_ccur_method.vb new file mode 100644 index 000000000..b84ddafd5 --- /dev/null +++ b/basic/qa/basic_coverage/test_ccur_method.vb @@ -0,0 +1,16 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' CCUR + If (CCur("100") <> 100) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_cdate_method.vb b/basic/qa/basic_coverage/test_cdate_method.vb new file mode 100644 index 000000000..c26287b1f --- /dev/null +++ b/basic/qa/basic_coverage/test_cdate_method.vb @@ -0,0 +1,16 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' CDATE + If (CDate(100) <> 100) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_cdatetofromiso_methods.vb b/basic/qa/basic_coverage/test_cdatetofromiso_methods.vb new file mode 100644 index 000000000..d2f4ce9c7 --- /dev/null +++ b/basic/qa/basic_coverage/test_cdatetofromiso_methods.vb @@ -0,0 +1,41 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' CDateFromIso CDateToIso + If ( CDateToIso( CDateFromIso("20161016") ) <> "20161016" ) Then + doUnitTest = 0 + ElseIf ( CDateToIso( CDateFromIso("2016-10-16") ) <> "20161016" ) Then + doUnitTest = 0 + ElseIf ( CDateToIso( CDateFromIso("-2016-10-16") ) <> "-20161016" ) Then + doUnitTest = 0 + ElseIf ( CDateToIso( CDateFromIso("-20161016") ) <> "-20161016" ) Then + doUnitTest = 0 + ElseIf ( CDateToIso( CDateFromIso("12016-10-16") ) <> "120161016" ) Then + doUnitTest = 0 + ElseIf ( CDateToIso( CDateFromIso("120161016") ) <> "120161016" ) Then + doUnitTest = 0 + ElseIf ( CDateToIso( CDateFromIso("-12016-10-16") ) <> "-120161016" ) Then + doUnitTest = 0 + ElseIf ( CDateToIso( CDateFromIso("-120161016") ) <> "-120161016" ) Then + doUnitTest = 0 + ElseIf ( CDateToIso( CDateFromIso("0001-01-01") ) <> "00010101" ) Then + doUnitTest = 0 + ElseIf ( CDateToIso( CDateFromIso("00010101") ) <> "00010101" ) Then + doUnitTest = 0 + ElseIf ( CDateToIso( CDateFromIso("-0001-12-31") ) <> "-00011231" ) Then + doUnitTest = 0 + ElseIf ( CDateToIso( CDateFromIso("-00011231") ) <> "-00011231" ) Then + doUnitTest = 0 + ElseIf ( CDateToIso( CDateFromIso("991231") ) <> "19991231" ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If + ' TODO: add some failure tests for misformed input, On Error whatever? +End Function diff --git a/basic/qa/basic_coverage/test_cdatetounodatecdatefromunodate_methods.vb b/basic/qa/basic_coverage/test_cdatetounodatecdatefromunodate_methods.vb new file mode 100644 index 000000000..2aa735c54 --- /dev/null +++ b/basic/qa/basic_coverage/test_cdatetounodatecdatefromunodate_methods.vb @@ -0,0 +1,18 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + dim aDate as Date + aDate = Date() + ' CDateToUnoDate CDateFromUnoDate + If ( CDateFromUnoDate( CDateToUnoDate( aDate ) ) <> aDate ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_cdatetounodatetimecdatefromunodatetime_methods.vb b/basic/qa/basic_coverage/test_cdatetounodatetimecdatefromunodatetime_methods.vb new file mode 100644 index 000000000..9aa5680b1 --- /dev/null +++ b/basic/qa/basic_coverage/test_cdatetounodatetimecdatefromunodatetime_methods.vb @@ -0,0 +1,18 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + dim aDate as Date + aDate = Now() + ' CDateToUnoDateTime CDateFromUnoDateTime + If ( CDateFromUnoDateTime( CDateToUnoDateTime( aDate ) ) <> aDate ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_cdatetounotimecdatefromunotime_methods.vb b/basic/qa/basic_coverage/test_cdatetounotimecdatefromunotime_methods.vb new file mode 100644 index 000000000..38fd9da45 --- /dev/null +++ b/basic/qa/basic_coverage/test_cdatetounotimecdatefromunotime_methods.vb @@ -0,0 +1,18 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + dim aDate as Date + aDate = Time() + ' CDateToUnoTime CDateFromUnoTime + If ( CDateFromUnoTime( CDateToUnoTime( aDate ) ) <> aDate ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_cdbl_method.vb b/basic/qa/basic_coverage/test_cdbl_method.vb new file mode 100644 index 000000000..a0ba8f029 --- /dev/null +++ b/basic/qa/basic_coverage/test_cdbl_method.vb @@ -0,0 +1,16 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' CDBL + If (CDbl("100") <> 100) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_chdircurdir_methods.vb b/basic/qa/basic_coverage/test_chdircurdir_methods.vb new file mode 100644 index 000000000..dadd65b10 --- /dev/null +++ b/basic/qa/basic_coverage/test_chdircurdir_methods.vb @@ -0,0 +1,12 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' CHDIR CURDIR + ChDir( CurDir ) + doUnitTest = 1 +End Function diff --git a/basic/qa/basic_coverage/test_choose_method.vb b/basic/qa/basic_coverage/test_choose_method.vb new file mode 100644 index 000000000..6ab2aea80 --- /dev/null +++ b/basic/qa/basic_coverage/test_choose_method.vb @@ -0,0 +1,16 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' CHOOSE + If (Choose(2, 1, 100, 3) <> 100) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_chr_method.vb b/basic/qa/basic_coverage/test_chr_method.vb new file mode 100644 index 000000000..8e8179463 --- /dev/null +++ b/basic/qa/basic_coverage/test_chr_method.vb @@ -0,0 +1,64 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. + +Function overflow1 as Integer + On Error GoTo handler + Chr(-32769) + overflow1 = 0 + Exit Function +handler: + if (Err <> 6) Then + overflow1 = 0 + Exit Function + Endif + overflow1 = 1 +End Function + +Function overflow2 as Integer + On Error GoTo handler + Chr(65536) + overflow2 = 0 + Exit Function +handler: + if (Err <> 6) Then + overflow2 = 0 + Exit Function + Endif + overflow2 = 1 +End Function + +Function overflow3 as Integer + On Error GoTo handler + Chr(&H10000) + overflow3 = 0 + Exit Function +handler: + if (Err <> 6) Then + overflow3 = 0 + Exit Function + Endif + overflow3 = 1 +End Function + +Function doUnitTest as Integer + Chr(-32768) + Chr(65535) + Chr(&H8000) + Chr(&HFFFF) + if (overflow1 = 0) Then + doUnitTest = 0 + Exit Function + Endif + if (overflow2 = 0) Then + doUnitTest = 0 + Exit Function + Endif + if (overflow3 = 0) Then + doUnitTest = 0 + Exit Function + Endif + doUnitTest = 1 +End Function diff --git a/basic/qa/basic_coverage/test_cint_method.vb b/basic/qa/basic_coverage/test_cint_method.vb new file mode 100644 index 000000000..b84af04d7 --- /dev/null +++ b/basic/qa/basic_coverage/test_cint_method.vb @@ -0,0 +1,16 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' CINT + If (CInt("100") <> 100) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_compatibilitymode_method.vb b/basic/qa/basic_coverage/test_compatibilitymode_method.vb new file mode 100644 index 000000000..599adb963 --- /dev/null +++ b/basic/qa/basic_coverage/test_compatibilitymode_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' CompatibilityMode + If (CompatibilityMode(True) <> True) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_converttofromurl_methods.vb b/basic/qa/basic_coverage/test_converttofromurl_methods.vb new file mode 100644 index 000000000..40c6494bd --- /dev/null +++ b/basic/qa/basic_coverage/test_converttofromurl_methods.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' ConvertFromUrl ConvertToUrl + If ( ConvertToUrl( ConvertFromUrl("") ) <> "") Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_cossin_methods.vb b/basic/qa/basic_coverage/test_cossin_methods.vb new file mode 100644 index 000000000..c4a5cc5e5 --- /dev/null +++ b/basic/qa/basic_coverage/test_cossin_methods.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' COS SIN + If ( Abs(Cos(PI/3) - Sin(PI/6)) > 1E-6 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_createobject_method.vb b/basic/qa/basic_coverage/test_createobject_method.vb new file mode 100644 index 000000000..6ae316b57 --- /dev/null +++ b/basic/qa/basic_coverage/test_createobject_method.vb @@ -0,0 +1,21 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Type address + Name1 As String + City As String +End Type + +Function doUnitTest as Integer + ' CREATEOBJECT + If ( IsObject( CreateObject("address") ) = False ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_createunolistener_method.vb b/basic/qa/basic_coverage/test_createunolistener_method.vb new file mode 100644 index 000000000..08c71fd8a --- /dev/null +++ b/basic/qa/basic_coverage/test_createunolistener_method.vb @@ -0,0 +1,13 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' CreateUnoListener + Dim oListener + oListener = CreateUnoListener( "ContListener_","com.sun.star.container.XContainerListener" ) + doUnitTest = 1 +End Function diff --git a/basic/qa/basic_coverage/test_createunoservice_method.vb b/basic/qa/basic_coverage/test_createunoservice_method.vb new file mode 100644 index 000000000..8fc043fd3 --- /dev/null +++ b/basic/qa/basic_coverage/test_createunoservice_method.vb @@ -0,0 +1,13 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' CreateUnoService + Dim filepicker + filepicker = CreateUnoService("com.sun.star.ui.dialogs.FilePicker") + doUnitTest = 1 +End Function diff --git a/basic/qa/basic_coverage/test_createunostruct_method.vb b/basic/qa/basic_coverage/test_createunostruct_method.vb new file mode 100644 index 000000000..f08368fed --- /dev/null +++ b/basic/qa/basic_coverage/test_createunostruct_method.vb @@ -0,0 +1,13 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' CreateUnoStruct + Dim oStruct + oStruct = CreateUnoStruct( "com.sun.star.beans.Property" ) + doUnitTest = 1 +End Function diff --git a/basic/qa/basic_coverage/test_createunovalue_method.vb b/basic/qa/basic_coverage/test_createunovalue_method.vb new file mode 100644 index 000000000..e640354ac --- /dev/null +++ b/basic/qa/basic_coverage/test_createunovalue_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' CreateUnoValue + Dim oUnoValue as Variant + Dim aValue as Variant + aValue = Array ( 1, 1 ) + oUnoValue = CreateUnoValue( "[]byte", aValue ) + doUnitTest = 1 +End Function diff --git a/basic/qa/basic_coverage/test_csng_method.vb b/basic/qa/basic_coverage/test_csng_method.vb new file mode 100644 index 000000000..87704ec1d --- /dev/null +++ b/basic/qa/basic_coverage/test_csng_method.vb @@ -0,0 +1,16 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' CSNG + If (CSng("100") <> 100) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_cstr_method.vb b/basic/qa/basic_coverage/test_cstr_method.vb new file mode 100644 index 000000000..53484b06f --- /dev/null +++ b/basic/qa/basic_coverage/test_cstr_method.vb @@ -0,0 +1,16 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' CSTR + If (CStr(100) <> "100") Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_cvar_method.vb b/basic/qa/basic_coverage/test_cvar_method.vb new file mode 100644 index 000000000..cc13bef6c --- /dev/null +++ b/basic/qa/basic_coverage/test_cvar_method.vb @@ -0,0 +1,16 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' CVAR + If (CVar(100) <> 100) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_cverr_method.vb b/basic/qa/basic_coverage/test_cverr_method.vb new file mode 100644 index 000000000..f74445c20 --- /dev/null +++ b/basic/qa/basic_coverage/test_cverr_method.vb @@ -0,0 +1,36 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' CVERR + If (CVerr(100) <> 100) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If + + ' tdf#79426 - passing an error object to a function + if ( TestCVErr( CVErr( 2 ) ) <> 2 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If + + ' tdf#79426 - test with Error-Code 448 ( ERRCODE_BASIC_NAMED_NOT_FOUND ) + if ( TestCVErr( CVErr( 448 ) ) <> 448 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function + +Function TestCVErr(vErr As Variant) + Dim nValue As Integer + nValue = vErr + TestCVErr = nValue +End Function
\ No newline at end of file diff --git a/basic/qa/basic_coverage/test_date_literal.vb b/basic/qa/basic_coverage/test_date_literal.vb new file mode 100644 index 000000000..a175368f3 --- /dev/null +++ b/basic/qa/basic_coverage/test_date_literal.vb @@ -0,0 +1,16 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + + +Function doUnitTest as Integer + If #07/28/1977# = 28334 And #1977-07-28# = 28334 Then + doUnitTest = 1 + Else + doUnitTest = 0 + End If +End Function diff --git a/basic/qa/basic_coverage/test_datedateadddatediff_methods.vb b/basic/qa/basic_coverage/test_datedateadddatediff_methods.vb new file mode 100644 index 000000000..4ba40f8eb --- /dev/null +++ b/basic/qa/basic_coverage/test_datedateadddatediff_methods.vb @@ -0,0 +1,18 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + dim aDate as Date + aDate = Date() + ' DATE DATEDIFF DATEADD + If ( DateDiff( "d", aDate, DateAdd("d", 1, aDate) ) <> 1 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_datedatepartday_methods.vb b/basic/qa/basic_coverage/test_datedatepartday_methods.vb new file mode 100644 index 000000000..04cc326f7 --- /dev/null +++ b/basic/qa/basic_coverage/test_datedatepartday_methods.vb @@ -0,0 +1,18 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + dim aDate as Date + aDate = Date() + ' DATEPART DAY + If ( DatePart( "d", aDate ) <> Day( aDate ) ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_dimarray_method.vb b/basic/qa/basic_coverage/test_dimarray_method.vb new file mode 100644 index 000000000..f92c7459d --- /dev/null +++ b/basic/qa/basic_coverage/test_dimarray_method.vb @@ -0,0 +1,18 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + Dim aValue as variant + aValue = DimArray( 1, 2, 4 ) + aValue( 1, 2, 4 ) = 3 + ' DIMARRAY + If ( aValue( 1, 2, 4 ) <> 3 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_empty_parameter.vb b/basic/qa/basic_coverage/test_empty_parameter.vb new file mode 100644 index 000000000..fe6e2651c --- /dev/null +++ b/basic/qa/basic_coverage/test_empty_parameter.vb @@ -0,0 +1,22 @@ +'
+' This file is part of the LibreOffice project.
+'
+' This Source Code Form is subject to the terms of the Mozilla Public
+' License, v. 2.0. If a copy of the MPL was not distributed with this
+' file, You can obtain one at http://mozilla.org/MPL/2.0/.
+'
+
+Sub assignVar(v As Variant)
+ v = 1
+End Sub
+
+Function doUnitTest() As Integer + ' tdf#132563 - check if empty parameters are converted to their respective types
+ anEmptyVar = Empty
+ assignVar(anEmptyVar)
+ If (anEmptyVar = 1 And TypeName(anEmptyVar) = "Integer") Then
+ doUnitTest = 1
+ Else
+ doUnitTest = 0
+ End If
+End Function diff --git a/basic/qa/basic_coverage/test_environ_method.vb b/basic/qa/basic_coverage/test_environ_method.vb new file mode 100644 index 000000000..63b6f360a --- /dev/null +++ b/basic/qa/basic_coverage/test_environ_method.vb @@ -0,0 +1,12 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' ENVIRON + Environ ("TMP") + doUnitTest = 1 +End Function diff --git a/basic/qa/basic_coverage/test_equalunoobjects_method.vb b/basic/qa/basic_coverage/test_equalunoobjects_method.vb new file mode 100644 index 000000000..b48111546 --- /dev/null +++ b/basic/qa/basic_coverage/test_equalunoobjects_method.vb @@ -0,0 +1,25 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' EqualUnoObjects + ' Copy of objects -> same instance + oIntrospection = CreateUnoService( "com.sun.star.beans.Introspection" ) + oIntro2 = oIntrospection + If ( EqualUnoObjects( oIntrospection, oIntro2 ) = False ) Then + doUnitTest = 0 + Else + ' Copy of structs as value -> new instance + Dim Struct1 as new com.sun.star.beans.Property + Struct2 = Struct1 + If ( EqualUnoObjects( Struct1, Struct2 ) ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If + End If +End Function diff --git a/basic/qa/basic_coverage/test_erl_method.vb b/basic/qa/basic_coverage/test_erl_method.vb new file mode 100644 index 000000000..b541b15fa --- /dev/null +++ b/basic/qa/basic_coverage/test_erl_method.vb @@ -0,0 +1,22 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' ERL + On Error GoTo ErrorHandler ' Set up error handler + Dim nVar As Integer + nVar = 0 + nVar = 1/nVar + doUnitTest = 0 + Exit Function +ErrorHandler: + If ( Erl <> 13 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + Endif +End Function diff --git a/basic/qa/basic_coverage/test_err_method.vb b/basic/qa/basic_coverage/test_err_method.vb new file mode 100644 index 000000000..c21b417b4 --- /dev/null +++ b/basic/qa/basic_coverage/test_err_method.vb @@ -0,0 +1,22 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' ERR + On Error GoTo ErrorHandler ' Set up error handler + Dim nVar As Integer + nVar = 0 + nVar = 1/nVar + doUnitTest = 0 + Exit Function +ErrorHandler: + If ( Err <> 11 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + Endif +End Function diff --git a/basic/qa/basic_coverage/test_falsetrue_method.vb b/basic/qa/basic_coverage/test_falsetrue_method.vb new file mode 100644 index 000000000..f99b8032b --- /dev/null +++ b/basic/qa/basic_coverage/test_falsetrue_method.vb @@ -0,0 +1,16 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' FALSE TRUE + If (False = True) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_filedatetime_nonexistent.vb b/basic/qa/basic_coverage/test_filedatetime_nonexistent.vb new file mode 100644 index 000000000..53a72549c --- /dev/null +++ b/basic/qa/basic_coverage/test_filedatetime_nonexistent.vb @@ -0,0 +1,20 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' +'Bug 121337 - FileDateTime("\\nonexistent\smb\path") returns bogus result rather than throwing error +Function doUnitTest as Integer + On Error GoTo ErrorHandler ' Set up error handler + Dim result + result = FileDateTime("/bogus/unix/path") + doUnitTest = 0 + Exit Function +ErrorHandler: + If ( Err <> 0 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + Endif +End Function diff --git a/basic/qa/basic_coverage/test_filedatetime_nonexistent2.vb b/basic/qa/basic_coverage/test_filedatetime_nonexistent2.vb new file mode 100644 index 000000000..2135b25d2 --- /dev/null +++ b/basic/qa/basic_coverage/test_filedatetime_nonexistent2.vb @@ -0,0 +1,20 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' +'Bug 121337 - FileDateTime("\\nonexistent\smb\path") returns bogus result rather than throwing error +Function doUnitTest as Integer + On Error GoTo ErrorHandler ' Set up error handler + Dim result + result = FileDateTime("\\bogus\smb\path") + doUnitTest = 0 + Exit Function +ErrorHandler: + If ( Err <> 0 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + Endif +End Function diff --git a/basic/qa/basic_coverage/test_fix_method.vb b/basic/qa/basic_coverage/test_fix_method.vb new file mode 100644 index 000000000..91d2f01fc --- /dev/null +++ b/basic/qa/basic_coverage/test_fix_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' FIX + If (Fix(PI) <> 3) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_for_each.vb b/basic/qa/basic_coverage/test_for_each.vb new file mode 100644 index 000000000..654513e88 --- /dev/null +++ b/basic/qa/basic_coverage/test_for_each.vb @@ -0,0 +1,43 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + Dim n As Integer, i + Dim a(3) + n = 0 + For Each i In a + n = n + 1 + Next i + If n <> 4 Then + doUnitTest = "For Each over array failed" + Exit Function + End If + + If TestInvalidForEachWithErrorHandler <> "13 91 14 " Then + doUnitTest = "For Each doesn't generate proper errors on bad arguments" + Exit Function + End If + + doUnitTest = 1 +End Function + +Function TestInvalidForEachWithErrorHandler + Dim s As String + On Error Goto ErrHandler +' This For Each is given a bad iterable; it must generate first error ("Data type mismatch") for b; + For Each a In b +' Then proceed here (Resume Next from ErrHandler), and generate "Object variable not set" for c; + c.d +' Then proceed here (Resume Next from ErrHandler), and generate "Invalid parameter" at Next. + Next + TestInvalidForEachWithErrorHandler = s + Exit Function +ErrHandler: + s = s & Err & " " + Resume Next +End Function diff --git a/basic/qa/basic_coverage/test_frac_method.vb b/basic/qa/basic_coverage/test_frac_method.vb new file mode 100644 index 000000000..14d6863db --- /dev/null +++ b/basic/qa/basic_coverage/test_frac_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' FRAC + If ( 3+Frac(PI) <> PI) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_freefile_method.vb b/basic/qa/basic_coverage/test_freefile_method.vb new file mode 100644 index 000000000..d2a5cb93b --- /dev/null +++ b/basic/qa/basic_coverage/test_freefile_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' FREEFILE + If ( FreeFile < 0 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_freelibrary_method.vb b/basic/qa/basic_coverage/test_freelibrary_method.vb new file mode 100644 index 000000000..4f6f9cd2d --- /dev/null +++ b/basic/qa/basic_coverage/test_freelibrary_method.vb @@ -0,0 +1,12 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' FREELIBRARY + FreeLibrary("") + doUnitTest = 1 +End Function diff --git a/basic/qa/basic_coverage/test_getdefaultcontext_method.vb b/basic/qa/basic_coverage/test_getdefaultcontext_method.vb new file mode 100644 index 000000000..8a90d6e96 --- /dev/null +++ b/basic/qa/basic_coverage/test_getdefaultcontext_method.vb @@ -0,0 +1,12 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' GetDefaultContext + GetDefaultContext() + doUnitTest = 1 +End Function diff --git a/basic/qa/basic_coverage/test_getdialogzoomfactorx_method.vb b/basic/qa/basic_coverage/test_getdialogzoomfactorx_method.vb new file mode 100644 index 000000000..279fc005d --- /dev/null +++ b/basic/qa/basic_coverage/test_getdialogzoomfactorx_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' GETDIALOGFACTORX + If ( GetDialogZoomFactorX(100) < 0 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_getdialogzoomfactory_method.vb b/basic/qa/basic_coverage/test_getdialogzoomfactory_method.vb new file mode 100644 index 000000000..f4139bed5 --- /dev/null +++ b/basic/qa/basic_coverage/test_getdialogzoomfactory_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' GETDIALOGFACTORY + If ( GetDialogZoomFactorY(100) < 0 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_getguitype_method.vb b/basic/qa/basic_coverage/test_getguitype_method.vb new file mode 100644 index 000000000..c1606da10 --- /dev/null +++ b/basic/qa/basic_coverage/test_getguitype_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' GETGUITYPE + If ( GetGuiType = 0 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_getguiversion_method.vb b/basic/qa/basic_coverage/test_getguiversion_method.vb new file mode 100644 index 000000000..a70ff07e6 --- /dev/null +++ b/basic/qa/basic_coverage/test_getguiversion_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' GETGUIVERSION + If ( GetGuiVersion = 0 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_getpathseparator_method.vb b/basic/qa/basic_coverage/test_getpathseparator_method.vb new file mode 100644 index 000000000..63a7b6737 --- /dev/null +++ b/basic/qa/basic_coverage/test_getpathseparator_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' GETPATHSEPARATOR + If ( GetPathSeparator = "" ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_getprocessservicemanager_method.vb b/basic/qa/basic_coverage/test_getprocessservicemanager_method.vb new file mode 100644 index 000000000..90e2012d6 --- /dev/null +++ b/basic/qa/basic_coverage/test_getprocessservicemanager_method.vb @@ -0,0 +1,12 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' GetProcessServiceManager + GetProcessServiceManager() + doUnitTest = 1 +End Function diff --git a/basic/qa/basic_coverage/test_getsolarversion_method.vb b/basic/qa/basic_coverage/test_getsolarversion_method.vb new file mode 100644 index 000000000..c2a75d11d --- /dev/null +++ b/basic/qa/basic_coverage/test_getsolarversion_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' GetSolarVersion + If ( GetSolarVersion() < 50000) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_getsystemtype_method.vb b/basic/qa/basic_coverage/test_getsystemtype_method.vb new file mode 100644 index 000000000..eced70204 --- /dev/null +++ b/basic/qa/basic_coverage/test_getsystemtype_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' GETSYSTEMTYPE + If ( GetSystemType <> -1 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_hasunointerfaces_method.vb b/basic/qa/basic_coverage/test_hasunointerfaces_method.vb new file mode 100644 index 000000000..06472d847 --- /dev/null +++ b/basic/qa/basic_coverage/test_hasunointerfaces_method.vb @@ -0,0 +1,16 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' HASUNOINTERFACES + dim aObject as Object + If ( HasUnoInterfaces( aObject, "com.sun.star.beans.XIntrospection" ) ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_hex_method.vb b/basic/qa/basic_coverage/test_hex_method.vb new file mode 100644 index 000000000..72edd9d8e --- /dev/null +++ b/basic/qa/basic_coverage/test_hex_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' HEX + If ( Hex(100) <> "64") Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_hour_method.vb b/basic/qa/basic_coverage/test_hour_method.vb new file mode 100644 index 000000000..e132775f8 --- /dev/null +++ b/basic/qa/basic_coverage/test_hour_method.vb @@ -0,0 +1,16 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' HOUR + If ( Hour(TimeSerial(12,30,41)) <> 12 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_iif_method.vb b/basic/qa/basic_coverage/test_iif_method.vb new file mode 100644 index 000000000..502cadcb3 --- /dev/null +++ b/basic/qa/basic_coverage/test_iif_method.vb @@ -0,0 +1,16 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' IIF + If ( IIF(True, 10, 12) <> 10 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_instr_method.vb b/basic/qa/basic_coverage/test_instr_method.vb new file mode 100644 index 000000000..716aa2158 --- /dev/null +++ b/basic/qa/basic_coverage/test_instr_method.vb @@ -0,0 +1,17 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + dim aString as Variant + aString = "Hello" + ' InStr + If ( InStr( 1, aString, "l", 1) <> 3 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_int_method.vb b/basic/qa/basic_coverage/test_int_method.vb new file mode 100644 index 000000000..69e811648 --- /dev/null +++ b/basic/qa/basic_coverage/test_int_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' INT + If ( Int(PI) <> 3 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_isarray_method.vb b/basic/qa/basic_coverage/test_isarray_method.vb new file mode 100644 index 000000000..9d73984b5 --- /dev/null +++ b/basic/qa/basic_coverage/test_isarray_method.vb @@ -0,0 +1,18 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + dim aVector as Variant + aVector = Array( 123, "Hello", -3.14) + ' ISARRAY + If ( IsArray( aVector ) = False ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_isdate_method.vb b/basic/qa/basic_coverage/test_isdate_method.vb new file mode 100644 index 000000000..5ce72f87b --- /dev/null +++ b/basic/qa/basic_coverage/test_isdate_method.vb @@ -0,0 +1,18 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + dim aDate as Date + aDate = Date( ) + ' ISDATE + If ( IsDate( aDate ) = False ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_isempty_method.vb b/basic/qa/basic_coverage/test_isempty_method.vb new file mode 100644 index 000000000..6ca2fae6d --- /dev/null +++ b/basic/qa/basic_coverage/test_isempty_method.vb @@ -0,0 +1,18 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + dim aVariant as Variant + aVariant = Date( ) + ' ISEMPTY + If ( IsEmpty( aVariant ) ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_iserror_method.vb b/basic/qa/basic_coverage/test_iserror_method.vb new file mode 100644 index 000000000..fb12abe6a --- /dev/null +++ b/basic/qa/basic_coverage/test_iserror_method.vb @@ -0,0 +1,22 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Type MyType + tName as String +End Type + +Function doUnitTest as Integer + dim aVariant as MyType + aVariant.tName = "A string" + ' ISERROR + If ( IsError( aVariant ) ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_ismissing_basic.vb b/basic/qa/basic_coverage/test_ismissing_basic.vb new file mode 100644 index 000000000..b838ce718 --- /dev/null +++ b/basic/qa/basic_coverage/test_ismissing_basic.vb @@ -0,0 +1,190 @@ +Dim passCount As Integer +Dim failCount As Integer +Dim result As String + +Const IsMissingNone = -1 +Const IsMissingA = 0 +Const IsMissingB = 1 +Const IsMissingAB = 2 + +Function doUnitTest() As String + result = verify_testIsMissingBasic() + If failCount <> 0 Or passCount = 0 Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function + +' tdf#36737 - Test optionals with different datatypes. In LO Basic, optional +' parameters are allowed, but without any default values. Missing optional parameters +' will not be initialized to their respective default values of its datatype, either. +Function verify_testIsMissingBasic() As String + + passCount = 0 + failCount = 0 + + result = "Test Results" & Chr$(10) & "============" & Chr$(10) + testName = "Test missing (Basic)" + On Error GoTo errorHandler + + ' optionals with variant datatypes + TestLog_ASSERT TestOptVariant(), IsMissingAB, "TestOptVariant()" + TestLog_ASSERT TestOptVariant(123), IsMissingB, "TestOptVariant(123)" + TestLog_ASSERT TestOptVariant(, 456), IsMissingA, "TestOptVariant(, 456)" + TestLog_ASSERT TestOptVariant(123, 456), IsMissingNone, "TestOptVariant(123, 456)" + + ' optionals with variant datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptVariantByRefByVal(), IsMissingAB, "TestOptVariantByRefByVal()" + TestLog_ASSERT TestOptVariantByRefByVal(123), IsMissingB, "TestOptVariantByRefByVal(123)" + TestLog_ASSERT TestOptVariantByRefByVal(, 456), IsMissingA, "TestOptVariantByRefByVal(, 456)" + TestLog_ASSERT TestOptVariantByRefByVal(123, 456), IsMissingNone, "TestOptVariantByRefByVal(123, 456)" + + ' optionals with double datatypes + TestLog_ASSERT TestOptDouble(), IsMissingAB, "TestOptDouble()" + TestLog_ASSERT TestOptDouble(123.4), IsMissingB, "TestOptDouble(123.4)" + TestLog_ASSERT TestOptDouble(, 567.8), IsMissingA, "TestOptDouble(, 567.8)" + TestLog_ASSERT TestOptDouble(123.4, 567.8), IsMissingNone, "TestOptDouble(123.4, 567.8)" + + ' optionals with double datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptDoubleByRefByVal(), IsMissingAB, "TestOptDouble()" + TestLog_ASSERT TestOptDoubleByRefByVal(123.4), IsMissingB, "TestOptDouble(123.4)" + TestLog_ASSERT TestOptDoubleByRefByVal(, 567.8), IsMissingA, "TestOptDoubleByRefByVal(, 567.8)" + TestLog_ASSERT TestOptDoubleByRefByVal(123.4, 567.8), IsMissingNone, "TestOptDoubleByRefByVal(123.4, 567.8)" + + ' optionals with integer datatypes + TestLog_ASSERT TestOptInteger(), IsMissingAB, "TestOptInteger()" + TestLog_ASSERT TestOptInteger(123), IsMissingB, "TestOptInteger(123)" + TestLog_ASSERT TestOptInteger(, 456), IsMissingA, "TestOptInteger(, 456)" + TestLog_ASSERT TestOptInteger(123, 456), IsMissingNone, "TestOptInteger(123, 456)" + + ' optionals with integer datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptIntegerByRefByVal(), IsMissingAB, "TestOptIntegerByRefByVal()" + TestLog_ASSERT TestOptIntegerByRefByVal(123), IsMissingB, "TestOptIntegerByRefByVal(123)" + TestLog_ASSERT TestOptIntegerByRefByVal(, 456), IsMissingA, "TestOptIntegerByRefByVal(, 456)" + TestLog_ASSERT TestOptIntegerByRefByVal(123, 456), IsMissingNone, "TestOptIntegerByRefByVal(123, 456)" + + ' optionals with string datatypes + TestLog_ASSERT TestOptString(), IsMissingAB, "TestOptString()" + TestLog_ASSERT TestOptString("123"), IsMissingB, "TestOptString(""123"")" + TestLog_ASSERT TestOptString(, "456"), IsMissingA, "TestOptString(, ""456"")" + TestLog_ASSERT TestOptString("123", "456"), IsMissingNone, "TestOptString(""123"", ""456"")" + + ' optionals with string datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptStringByRefByVal(), IsMissingAB, "TestOptStringByRefByVal()" + TestLog_ASSERT TestOptStringByRefByVal("123"), IsMissingB, "TestOptStringByRefByVal(""123"")" + TestLog_ASSERT TestOptStringByRefByVal(, "456"), IsMissingA, "TestOptStringByRefByVal(, ""456"")" + TestLog_ASSERT TestOptStringByRefByVal("123", "456"), IsMissingNone, "TestOptStringByRefByVal(""123"", ""456"")" + + ' optionals with object datatypes + Dim cA As New Collection + cA.Add (123) + cA.Add (456) + Dim cB As New Collection + cB.Add (123.4) + cB.Add (567.8) + TestLog_ASSERT TestOptObject(), IsMissingAB, "TestOptObject()" + TestLog_ASSERT TestOptObject(cA), IsMissingB, "TestOptObject(A)" + TestLog_ASSERT TestOptObject(, cB), IsMissingA, "TestOptObject(, B)" + TestLog_ASSERT TestOptObject(cA, cB), IsMissingNone, "TestOptObject(A, B)" + + ' optionals with object datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptObjectByRefByVal(), IsMissingAB, "TestOptObjectByRefByVal()" + TestLog_ASSERT TestOptObjectByRefByVal(cA), IsMissingB, "TestOptObjectByRefByVal(A)" + TestLog_ASSERT TestOptObjectByRefByVal(, cB), IsMissingA, "TestOptObjectByRefByVal(, B)" + TestLog_ASSERT TestOptObjectByRefByVal(cA, cB), IsMissingNone, "TestOptObjectByRefByVal(A, B)" + + ' optionals with array datatypes + Dim aA(0 To 1) As Integer + aA(0) = 123 + aA(1) = 456 + Dim aB(0 To 1) As Variant + aB(0) = 123.4 + aB(1) = 567.8 + TestLog_ASSERT TestOptArray(), IsMissingAB, "TestOptArray()" + TestLog_ASSERT TestOptArray(aA), IsMissingB, "TestOptArray(A)" + TestLog_ASSERT TestOptArray(, aB), IsMissingA, "TestOptArray(, B)" + TestLog_ASSERT TestOptArray(aA, aB), IsMissingNone, "TestOptArray(A, B)" + + ' optionals with array datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptArrayByRefByVal(), IsMissingAB, "TestOptArrayByRefByVal()" + TestLog_ASSERT TestOptArrayByRefByVal(aA), IsMissingB, "TestOptArrayByRefByVal(A)" + TestLog_ASSERT TestOptArrayByRefByVal(, aB), IsMissingA, "TestOptArrayByRefByVal(, B)" + TestLog_ASSERT TestOptArrayByRefByVal(aA, aB), IsMissingNone, "TestOptArrayByRefByVal(A, B)" + + result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10) + verify_testIsMissingBasic = result + + Exit Function +errorHandler: + TestLog_ASSERT False, True, Err.Description +End Function + +Function TestOptVariant(Optional A, Optional B As Variant) + TestOptVariant = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptVariantByRefByVal(Optional ByRef A, Optional ByVal B As Variant) + TestOptVariantByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptDouble(Optional A As Double, Optional B As Double) + TestOptDouble = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptDoubleByRefByVal(Optional ByRef A As Double, Optional ByVal B As Double) + TestOptDoubleByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptInteger(Optional A As Integer, Optional B As Integer) + TestOptInteger = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptIntegerByRefByVal(Optional ByRef A As Integer, Optional ByVal B As Integer) + TestOptIntegerByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptString(Optional A As String, Optional B As String) + TestOptString = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptStringByRefByVal(Optional ByRef A As String, Optional ByVal B As String) + TestOptStringByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptObject(Optional A As Collection, Optional B As Collection) + TestOptObject = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptObjectByRefByVal(Optional ByRef A As Collection, Optional ByVal B As Collection) + TestOptObjectByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptArray(Optional A() As Integer, Optional B() As Variant) + TestOptArray = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptArrayByRefByVal(Optional ByRef A() As Integer, Optional ByVal B() As Variant) + TestOptArrayByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function WhatIsMissing(is_missingA, is_missingB) + If is_missingA And is_missingB Then + WhatIsMissing = IsMissingAB + ElseIf is_missingA Then + WhatIsMissing = IsMissingA + ElseIf is_missingB Then + WhatIsMissing = IsMissingB + Else + WhatIsMissing = IsMissingNone + End If +End Function + +Sub TestLog_ASSERT(actual As Variant, expected As Integer, testName As String) + If expected = actual Then + passCount = passCount + 1 + Else + result = result & Chr$(10) & " Failed: " & testName & " returned " & actual & ", expected " & expected + failCount = failCount + 1 + End If +End Sub
\ No newline at end of file diff --git a/basic/qa/basic_coverage/test_ismissing_cascade.vb b/basic/qa/basic_coverage/test_ismissing_cascade.vb new file mode 100644 index 000000000..ad967c7bb --- /dev/null +++ b/basic/qa/basic_coverage/test_ismissing_cascade.vb @@ -0,0 +1,51 @@ +Dim passCount As Integer +Dim failCount As Integer +Dim result As String + +Function doUnitTest() As String + result = verify_testIsMissingCascade() + If failCount <> 0 Or passCount = 0 Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function + +Function verify_testIsMissingCascade() As String + + passCount = 0 + failCount = 0 + + result = "Test Results" & Chr$(10) & "============" & Chr$(10) + testName = "Test missing (IsMissing with cascading optionals)" + On Error GoTo errorHandler + + ' tdf#136143 - test cascading optionals in order to prevent type conversion errors, because + ' optional arguments are of type SbxERROR and set to not fixed. + TestLog_ASSERT TestOpt(), 2, "Cascading optionals" + + result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10) + verify_testIsMissingCascade = result + + Exit Function +errorHandler: + TestLog_ASSERT False, True, Err.Description +End Function + +Function TestOpt(Optional A) + TestOpt = TestOptCascade(A) +End Function + +Function TestOptCascade(Optional A) + If IsMissing(A) Then A = 2 + TestOptCascade = A +End Function + +Sub TestLog_ASSERT(actual As Variant, expected As Integer, testName As String) + If expected = actual Then + passCount = passCount + 1 + Else + result = result & Chr$(10) & " Failed: " & testName & " returned " & actual & ", expected " & expected + failCount = failCount + 1 + End If +End Sub
\ No newline at end of file diff --git a/basic/qa/basic_coverage/test_ismissing_compatible.vb b/basic/qa/basic_coverage/test_ismissing_compatible.vb new file mode 100644 index 000000000..dbe2a815d --- /dev/null +++ b/basic/qa/basic_coverage/test_ismissing_compatible.vb @@ -0,0 +1,193 @@ +Option Compatible + +Dim passCount As Integer +Dim failCount As Integer +Dim result As String + +Const IsMissingNone = -1 +Const IsMissingA = 0 +Const IsMissingB = 1 +Const IsMissingAB = 2 + +Function doUnitTest() As String + result = verify_testIsMissingCompatible() + If failCount <> 0 Or passCount = 0 Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function + +' tdf#36737 - Test isMissing function with different datatypes. In LO Basic +' with option Compatible, optional parameters are allowed with default values. +' Missing optional parameters that don't have explicit default values will +' not be initialized to their default values of its datatype. +Function verify_testIsMissingCompatible() As String + + passCount = 0 + failCount = 0 + + result = "Test Results" & Chr$(10) & "============" & Chr$(10) + testName = "Test missing (Compatible)" + On Error GoTo errorHandler + + ' optionals with variant datatypes + TestLog_ASSERT TestOptVariant(), IsMissingA, "TestOptVariant()" + TestLog_ASSERT TestOptVariant(123), IsMissingNone, "TestOptVariant(123)" + TestLog_ASSERT TestOptVariant(, 456), IsMissingA, "TestOptVariant(, 456)" + TestLog_ASSERT TestOptVariant(123, 456), IsMissingNone, "TestOptVariant(123, 456)" + + ' optionals with variant datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptVariantByRefByVal(), IsMissingA, "TestOptVariantByRefByVal()" + TestLog_ASSERT TestOptVariantByRefByVal(123), IsMissingNone, "TestOptVariantByRefByVal(123)" + TestLog_ASSERT TestOptVariantByRefByVal(, 456), IsMissingA, "TestOptVariantByRefByVal(, 456)" + TestLog_ASSERT TestOptVariantByRefByVal(123, 456), IsMissingNone, "TestOptVariantByRefByVal(123, 456)" + + ' optionals with double datatypes + TestLog_ASSERT TestOptDouble(), IsMissingA, "TestOptDouble()" + TestLog_ASSERT TestOptDouble(123.4), IsMissingNone, "TestOptDouble(123.4)" + TestLog_ASSERT TestOptDouble(, 567.8), IsMissingA, "TestOptDouble(, 567.8)" + TestLog_ASSERT TestOptDouble(123.4, 567.8), IsMissingNone, "TestOptDouble(123.4, 567.8)" + + ' optionals with double datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptDoubleByRefByVal(), IsMissingA, "TestOptDouble()" + TestLog_ASSERT TestOptDoubleByRefByVal(123.4), IsMissingNone, "TestOptDouble(123.4)" + TestLog_ASSERT TestOptDoubleByRefByVal(, 567.8), IsMissingA, "TestOptDoubleByRefByVal(, 567.8)" + TestLog_ASSERT TestOptDoubleByRefByVal(123.4, 567.8), IsMissingNone, "TestOptDoubleByRefByVal(123.4, 567.8)" + + ' optionals with integer datatypes + TestLog_ASSERT TestOptInteger(), IsMissingA, "TestOptInteger()" + TestLog_ASSERT TestOptInteger(123), IsMissingNone, "TestOptInteger(123)" + TestLog_ASSERT TestOptInteger(, 456), IsMissingA, "TestOptInteger(, 456)" + TestLog_ASSERT TestOptInteger(123, 456), IsMissingNone, "TestOptInteger(123, 456)" + + ' optionals with integer datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptIntegerByRefByVal(), IsMissingA, "TestOptIntegerByRefByVal()" + TestLog_ASSERT TestOptIntegerByRefByVal(123), IsMissingNone, "TestOptIntegerByRefByVal(123)" + TestLog_ASSERT TestOptIntegerByRefByVal(, 456), IsMissingA, "TestOptIntegerByRefByVal(, 456)" + TestLog_ASSERT TestOptIntegerByRefByVal(123, 456), IsMissingNone, "TestOptIntegerByRefByVal(123, 456)" + + ' optionals with string datatypes + TestLog_ASSERT TestOptString(), IsMissingA, "TestOptString()" + TestLog_ASSERT TestOptString("123"), IsMissingNone, "TestOptString(""123"")" + TestLog_ASSERT TestOptString(, "456"), IsMissingA, "TestOptString(, ""456"")" + TestLog_ASSERT TestOptString("123", "456"), IsMissingNone, "TestOptString(""123"", ""456"")" + + ' optionals with string datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptStringByRefByVal(), IsMissingA, "TestOptStringByRefByVal()" + TestLog_ASSERT TestOptStringByRefByVal("123"), IsMissingNone, "TestOptStringByRefByVal(""123"")" + TestLog_ASSERT TestOptStringByRefByVal(, "456"), IsMissingA, "TestOptStringByRefByVal(, ""456"")" + TestLog_ASSERT TestOptStringByRefByVal("123", "456"), IsMissingNone, "TestOptStringByRefByVal(""123"", ""456"")" + + ' optionals with object datatypes + Dim cA As New Collection + cA.Add (123) + cA.Add (456) + Dim cB As New Collection + cB.Add (123.4) + cB.Add (567.8) + TestLog_ASSERT TestOptObject(), IsMissingAB, "TestOptObject()" + TestLog_ASSERT TestOptObject(cA), IsMissingB, "TestOptObject(A)" + TestLog_ASSERT TestOptObject(, cB), IsMissingA, "TestOptObject(, B)" + TestLog_ASSERT TestOptObject(cA, cB), IsMissingNone, "TestOptObject(A, B)" + + ' optionals with object datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptObjectByRefByVal(), IsMissingAB, "TestOptObjectByRefByVal()" + TestLog_ASSERT TestOptObjectByRefByVal(cA), IsMissingB, "TestOptObjectByRefByVal(A)" + TestLog_ASSERT TestOptObjectByRefByVal(, cB), IsMissingA, "TestOptObjectByRefByVal(, B)" + TestLog_ASSERT TestOptObjectByRefByVal(cA, cB), IsMissingNone, "TestOptObjectByRefByVal(A, B)" + + ' optionals with array datatypes + Dim aA(0 To 1) As Integer + aA(0) = 123 + aA(1) = 456 + Dim aB(0 To 1) As Variant + aB(0) = 123.4 + aB(1) = 567.8 + TestLog_ASSERT TestOptArray(), IsMissingAB, "TestOptArray()" + TestLog_ASSERT TestOptArray(aA), IsMissingB, "TestOptArray(A)" + TestLog_ASSERT TestOptArray(, aB), IsMissingA, "TestOptArray(, B)" + TestLog_ASSERT TestOptArray(aA, aB), IsMissingNone, "TestOptArray(A, B)" + + ' optionals with array datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptArrayByRefByVal(), IsMissingAB, "TestOptArrayByRefByVal()" + TestLog_ASSERT TestOptArrayByRefByVal(aA), IsMissingB, "TestOptArrayByRefByVal(A)" + TestLog_ASSERT TestOptArrayByRefByVal(, aB), IsMissingA, "TestOptArrayByRefByVal(, B)" + TestLog_ASSERT TestOptArrayByRefByVal(aA, aB), IsMissingNone, "TestOptArrayByRefByVal(A, B)" + + result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10) + verify_testIsMissingCompatible = result + + Exit Function +errorHandler: + TestLog_ASSERT False, True, Err.Description +End Function + +Function TestOptVariant(Optional A, Optional B As Variant = 123) + TestOptVariant = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptVariantByRefByVal(Optional ByRef A, Optional ByVal B As Variant = 123) + TestOptVariantByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptDouble(Optional A As Double, Optional B As Double = 123.4) + TestOptDouble = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptDoubleByRefByVal(Optional ByRef A As Double, Optional ByVal B As Double = 123.4) + TestOptDoubleByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptInteger(Optional A As Integer, Optional B As Integer = 123) + TestOptInteger = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptIntegerByRefByVal(Optional ByRef A As Integer, Optional ByVal B As Integer = 123) + TestOptIntegerByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptString(Optional A As String, Optional B As String = "123") + TestOptString = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptStringByRefByVal(Optional ByRef A As String, Optional ByVal B As String = "123") + TestOptStringByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptObject(Optional A As Collection, Optional B As Collection) + TestOptObject = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptObjectByRefByVal(Optional ByRef A As Collection, Optional ByVal B As Collection) + TestOptObjectByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptArray(Optional A() As Integer, Optional B() As Variant) + TestOptArray = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function TestOptArrayByRefByVal(Optional ByRef A() As Integer, Optional ByVal B() As Variant) + TestOptArrayByRefByVal = WhatIsMissing(IsMissing(A), IsMissing(B)) +End Function + +Function WhatIsMissing(is_missingA, is_missingB) + If is_missingA And is_missingB Then + WhatIsMissing = IsMissingAB + ElseIf is_missingA Then + WhatIsMissing = IsMissingA + ElseIf is_missingB Then + WhatIsMissing = IsMissingB + Else + WhatIsMissing = IsMissingNone + End If +End Function + +Sub TestLog_ASSERT(actual As Variant, expected As Variant, testName As String) + If expected = actual Then + passCount = passCount + 1 + Else + result = result & Chr$(10) & " Failed: " & testName & " returned " & actual & ", expected " & expected + failCount = failCount + 1 + End If +End Sub
\ No newline at end of file diff --git a/basic/qa/basic_coverage/test_isnull_method.vb b/basic/qa/basic_coverage/test_isnull_method.vb new file mode 100644 index 000000000..0d9044d8f --- /dev/null +++ b/basic/qa/basic_coverage/test_isnull_method.vb @@ -0,0 +1,18 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + dim aVariant as Variant + aVariant = Null + ' ISNULL + If ( IsNull( aVariant ) = False ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_isnumeric_method.vb b/basic/qa/basic_coverage/test_isnumeric_method.vb new file mode 100644 index 000000000..d3b614f56 --- /dev/null +++ b/basic/qa/basic_coverage/test_isnumeric_method.vb @@ -0,0 +1,18 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + dim aVariant as Variant + aVariant = 3 + ' ISNUMERIC + If ( IsNumeric( aVariant ) = False ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_isobject_method.vb b/basic/qa/basic_coverage/test_isobject_method.vb new file mode 100644 index 000000000..bb5e270b3 --- /dev/null +++ b/basic/qa/basic_coverage/test_isobject_method.vb @@ -0,0 +1,17 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + dim aVariant as Object + ' ISOBJECT + If ( IsObject( aVariant ) = False ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_isunostruct_method.vb b/basic/qa/basic_coverage/test_isunostruct_method.vb new file mode 100644 index 000000000..ac45f1961 --- /dev/null +++ b/basic/qa/basic_coverage/test_isunostruct_method.vb @@ -0,0 +1,17 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + dim aVariant as Object + ' ISUNOSTRUCT + If ( IsUnoStruct( aVariant ) ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_join_method.vb b/basic/qa/basic_coverage/test_join_method.vb new file mode 100644 index 000000000..236062516 --- /dev/null +++ b/basic/qa/basic_coverage/test_join_method.vb @@ -0,0 +1,18 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' Join + Dim aStrings(2) as String + aStrings(0) = "Hello" + aStrings(1) = "world" + If ( Join( aStrings, " " ) <> "Hello world " ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_lbound_method.vb b/basic/qa/basic_coverage/test_lbound_method.vb new file mode 100644 index 000000000..b7a91fd3f --- /dev/null +++ b/basic/qa/basic_coverage/test_lbound_method.vb @@ -0,0 +1,19 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + dim aVector as Variant + ' ARRAY + aVector = Array( "Hello", -3.14) + ' LBOUND + If ( LBound( aVector() ) <> 0 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_lcase_method.vb b/basic/qa/basic_coverage/test_lcase_method.vb new file mode 100644 index 000000000..65df764ef --- /dev/null +++ b/basic/qa/basic_coverage/test_lcase_method.vb @@ -0,0 +1,17 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + dim aString as Variant + aString = "Hello" + ' LCASE + If ( LCase( aString ) <> "hello" ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_len_method.vb b/basic/qa/basic_coverage/test_len_method.vb new file mode 100644 index 000000000..0a7e1abf2 --- /dev/null +++ b/basic/qa/basic_coverage/test_len_method.vb @@ -0,0 +1,17 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + dim aString as Variant + aString = "Hello" + ' LEN + If ( Len( aString ) <> 5 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_lenb_method.vb b/basic/qa/basic_coverage/test_lenb_method.vb new file mode 100644 index 000000000..550b8313a --- /dev/null +++ b/basic/qa/basic_coverage/test_lenb_method.vb @@ -0,0 +1,17 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + dim aString as Variant + aString = "Hello" + ' LENB + If ( LenB( aString ) <> 5 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_logexp_methods.vb b/basic/qa/basic_coverage/test_logexp_methods.vb new file mode 100644 index 000000000..00db99837 --- /dev/null +++ b/basic/qa/basic_coverage/test_logexp_methods.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' EXP LOG + If ( Log( Exp(1) ) <> 1 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_ltrim_method.vb b/basic/qa/basic_coverage/test_ltrim_method.vb new file mode 100644 index 000000000..562193c8b --- /dev/null +++ b/basic/qa/basic_coverage/test_ltrim_method.vb @@ -0,0 +1,17 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + dim aString as Variant + aString = "Hello" + ' LTRIM + If ( LTrim( " Hello" ) <> aString ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_mid_CountNegative_3args.vb b/basic/qa/basic_coverage/test_mid_CountNegative_3args.vb new file mode 100644 index 000000000..d67370626 --- /dev/null +++ b/basic/qa/basic_coverage/test_mid_CountNegative_3args.vb @@ -0,0 +1,15 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + If (Mid("abc", 5, -3) = "") Then + doUnitTest = 1 + Else + doUnitTest = 0 + End If +End Function diff --git a/basic/qa/basic_coverage/test_mid_EndOutOfBounds_3args.vb b/basic/qa/basic_coverage/test_mid_EndOutOfBounds_3args.vb new file mode 100644 index 000000000..f54ee9444 --- /dev/null +++ b/basic/qa/basic_coverage/test_mid_EndOutOfBounds_3args.vb @@ -0,0 +1,15 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + If (Mid("abc", 1, 4) = "abc") Then + doUnitTest = 1 + Else + doUnitTest = 0 + End If +End Function diff --git a/basic/qa/basic_coverage/test_mid_StartOutOfBounds_2args.vb b/basic/qa/basic_coverage/test_mid_StartOutOfBounds_2args.vb new file mode 100644 index 000000000..5ab01f987 --- /dev/null +++ b/basic/qa/basic_coverage/test_mid_StartOutOfBounds_2args.vb @@ -0,0 +1,15 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + If (Mid("abc", 5) = "") Then + doUnitTest = 1 + Else + doUnitTest = 0 + End If +End Function diff --git a/basic/qa/basic_coverage/test_mid_StartOutOfBounds_3args.vb b/basic/qa/basic_coverage/test_mid_StartOutOfBounds_3args.vb new file mode 100644 index 000000000..9c623ce51 --- /dev/null +++ b/basic/qa/basic_coverage/test_mid_StartOutOfBounds_3args.vb @@ -0,0 +1,15 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + If (Mid("abc", 5, 1) = "") Then + doUnitTest = 1 + Else + doUnitTest = 0 + End If +End Function diff --git a/basic/qa/basic_coverage/test_mid_firstletter_3args.vb b/basic/qa/basic_coverage/test_mid_firstletter_3args.vb new file mode 100644 index 000000000..72c65099f --- /dev/null +++ b/basic/qa/basic_coverage/test_mid_firstletter_3args.vb @@ -0,0 +1,15 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + If (Mid("abc", 1, 1) = "a") Then + doUnitTest = 1 + Else + doUnitTest = 0 + End If +End Function diff --git a/basic/qa/basic_coverage/test_mid_replace_less.vb b/basic/qa/basic_coverage/test_mid_replace_less.vb new file mode 100644 index 000000000..27a02382c --- /dev/null +++ b/basic/qa/basic_coverage/test_mid_replace_less.vb @@ -0,0 +1,19 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +' cf. <https://bugs.documentfoundation.org/show_bug.cgi?id=62090> "Mid statement doesn't work as +' expected": +Function doUnitTest as Integer + s = "The lightbrown fox" + Mid(s, 5, 10, "lazy") + If (s = "The lazy fox") Then + doUnitTest = 1 + Else + doUnitTest = 0 + End If +End Function diff --git a/basic/qa/basic_coverage/test_mid_replace_more.vb b/basic/qa/basic_coverage/test_mid_replace_more.vb new file mode 100644 index 000000000..880a3f200 --- /dev/null +++ b/basic/qa/basic_coverage/test_mid_replace_more.vb @@ -0,0 +1,19 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +' cf. examples at <https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/ +' statements/mid-statement>: +Function doUnitTest as Integer + s = "The fox jumps" + Mid(s, 5, 3, "duck") + If (s = "The duc jumps") Then + doUnitTest = 1 + Else + doUnitTest = 0 + End If +End Function diff --git a/basic/qa/basic_coverage/test_mid_replace_more_end.vb b/basic/qa/basic_coverage/test_mid_replace_more_end.vb new file mode 100644 index 000000000..c5d26a46a --- /dev/null +++ b/basic/qa/basic_coverage/test_mid_replace_more_end.vb @@ -0,0 +1,19 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +' cf. examples at <https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/ +' statements/mid-statement>: +Function doUnitTest as Integer + s = "The fox jumps" + Mid(s, 5, 100, "cow jumped over") + If (s = "The cow jumpe") Then + doUnitTest = 1 + Else + doUnitTest = 0 + End If +End Function diff --git a/basic/qa/basic_coverage/test_mid_sub2letters_2args.vb b/basic/qa/basic_coverage/test_mid_sub2letters_2args.vb new file mode 100644 index 000000000..76c5360d8 --- /dev/null +++ b/basic/qa/basic_coverage/test_mid_sub2letters_2args.vb @@ -0,0 +1,15 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + If (Mid("abc", 2) = "bc") Then + doUnitTest = 1 + Else + doUnitTest = 0 + End If +End Function diff --git a/basic/qa/basic_coverage/test_minute_method.vb b/basic/qa/basic_coverage/test_minute_method.vb new file mode 100644 index 000000000..0f1230462 --- /dev/null +++ b/basic/qa/basic_coverage/test_minute_method.vb @@ -0,0 +1,16 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' MINUTE + If ( Minute(TimeSerial(12,30,41)) <> 30 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_month_method.vb b/basic/qa/basic_coverage/test_month_method.vb new file mode 100644 index 000000000..38d8ae406 --- /dev/null +++ b/basic/qa/basic_coverage/test_month_method.vb @@ -0,0 +1,18 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + dim aDate as Date + aDate = Date() + ' MONTH + If ( DatePart( "m", aDate ) <> Month( aDate ) ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_nowtimevalue_methods.vb b/basic/qa/basic_coverage/test_nowtimevalue_methods.vb new file mode 100644 index 000000000..42dce2fc6 --- /dev/null +++ b/basic/qa/basic_coverage/test_nowtimevalue_methods.vb @@ -0,0 +1,20 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + dim aDate as Date + dim aTime as Date + aDate = Date() + aTime = Time() + ' NOW TIMEVALUE + If ( Now() < aDate + TimeValue(aTime) ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_numeric_constant_parameter.vb b/basic/qa/basic_coverage/test_numeric_constant_parameter.vb new file mode 100644 index 000000000..96a7e8f9c --- /dev/null +++ b/basic/qa/basic_coverage/test_numeric_constant_parameter.vb @@ -0,0 +1,34 @@ +'
+' This file is part of the LibreOffice project.
+'
+' This Source Code Form is subject to the terms of the Mozilla Public
+' License, v. 2.0. If a copy of the MPL was not distributed with this
+' file, You can obtain one at http://mozilla.org/MPL/2.0/.
+'
+
+' assigns a numeric constant (integer) to a parameter of type variant
+Function assignInteger( numericConstant ) As String
+ numericConstant = 1
+ assignInteger = TypeName( numericConstant )
+End Function
+
+' assigns a numeric constant (long) to a parameter of type variant
+Function assignLong( numericConstant ) As String
+ numericConstant = 32768
+ assignLong = TypeName( numericConstant )
+End Function
+ +Function doUnitTest() As Integer + ' tdf#133913 - check if numeric constants are converted correctly to
+ ' their respective types, if they are passed as arguments to a function
+ ' with variant parameter types.
+ On Error GoTo errorHandler
+ If (assignInteger( 1 ) = "Integer" And assignLong( 1 ) = "Long") Then
+ doUnitTest = 1
+ Else
+ doUnitTest = 0
+ End If
+ Exit Function
+errorHandler:
+ doUnitTest = 0 +End Function
\ No newline at end of file diff --git a/basic/qa/basic_coverage/test_oct_method.vb b/basic/qa/basic_coverage/test_oct_method.vb new file mode 100644 index 000000000..4c610539d --- /dev/null +++ b/basic/qa/basic_coverage/test_oct_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' OCT + If ( Oct(100) <> "144" ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_optional_paramter_type.vb b/basic/qa/basic_coverage/test_optional_paramter_type.vb new file mode 100644 index 000000000..37198ea38 --- /dev/null +++ b/basic/qa/basic_coverage/test_optional_paramter_type.vb @@ -0,0 +1,33 @@ +REM ***** BASIC *****
+Option Compatible
+
+Function doUnitTest() As Integer
+ doUnitTest = 0
+ If CheckType1(32) = 0 Then
+ Exit Function
+ End If
+ If CheckType2(32) = 0 Then
+ Exit Function
+ End If
+ If CheckType2() = 0 Then
+ Exit Function
+ End If
+ doUnitTest = 1
+End Function
+
+Function CheckType1(x As Integer) As Integer
+ If TypeName(x) = "Integer" Then
+ CheckType1 = 1
+ Else
+ CheckType1 = 0
+ End If
+End Function
+
+
+Function CheckType2(Optional y As Integer = 32 ) As Integer
+ If TypeName(y) = "Integer" Then
+ CheckType2 = 1
+ Else
+ CheckType2 = 0
+ End If
+End Function
\ No newline at end of file diff --git a/basic/qa/basic_coverage/test_optional_paramters_basic.vb b/basic/qa/basic_coverage/test_optional_paramters_basic.vb new file mode 100644 index 000000000..92a81a861 --- /dev/null +++ b/basic/qa/basic_coverage/test_optional_paramters_basic.vb @@ -0,0 +1,208 @@ +Dim passCount As Integer +Dim failCount As Integer +Dim result As String + +Function doUnitTest() As String + result = verify_testOptionalsBasic() + If failCount <> 0 Or passCount = 0 Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function + +' tdf#36737 - Test optionals with different datatypes. In LO Basic, optional +' parameters are allowed, but without any default values. Missing optional +' parameters will not be initialized to their respective default values of +' its datatype, either. +Function verify_testOptionalsBasic() As String + + passCount = 0 + failCount = 0 + + result = "Test Results" & Chr$(10) & "============" & Chr$(10) + testName = "Test optionals (Basic)" + On Error GoTo errorHandler + + ' optionals with variant datatypes + TestLog_ASSERT TestOptVariant(), 0, "TestOptVariant()" + TestLog_ASSERT TestOptVariant(123), 123, "TestOptVariant(123)" + TestLog_ASSERT TestOptVariant(, 456), 456, "TestOptVariant(, 456)" + TestLog_ASSERT TestOptVariant(123, 456), 579, "TestOptVariant(123, 456)" + + ' optionals with variant datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptVariantByRefByVal(), 0, "TestOptVariantByRefByVal()" + TestLog_ASSERT TestOptVariantByRefByVal(123), 123, "TestOptVariantByRefByVal(123)" + TestLog_ASSERT TestOptVariantByRefByVal(, 456), 456, "TestOptVariantByRefByVal(, 456)" + TestLog_ASSERT TestOptVariantByRefByVal(123, 456), 579, "TestOptVariantByRefByVal(123, 456)" + + ' optionals with double datatypes + TestLog_ASSERT TestOptDouble(), 0, "TestOptDouble()" + TestLog_ASSERT TestOptDouble(123.4), 123.4, "TestOptDouble(123.4)" + TestLog_ASSERT TestOptDouble(, 567.8), 567.8, "TestOptDouble(, 567.8)" + TestLog_ASSERT CDbl(Format(TestOptDouble(123.4, 567.8), "0.0")), 691.2, "TestOptDouble(123.4, 567.8)" + + ' optionals with double datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptDoubleByRefByVal(), 0, "TestOptDouble()" + TestLog_ASSERT TestOptDoubleByRefByVal(123.4), 123.4, "TestOptDouble(123.4)" + TestLog_ASSERT TestOptDoubleByRefByVal(, 567.8), 567.8, "TestOptDoubleByRefByVal(, 567.8)" + TestLog_ASSERT CDbl(Format(TestOptDoubleByRefByVal(123.4, 567.8), "0.0")), 691.2, "TestOptDoubleByRefByVal(123.4, 567.8)" + + ' optionals with integer datatypes + TestLog_ASSERT TestOptInteger(), 0, "TestOptInteger()" + TestLog_ASSERT TestOptInteger(123), 123, "TestOptInteger(123)" + TestLog_ASSERT TestOptInteger(, 456), 456, "TestOptInteger(, 456)" + TestLog_ASSERT TestOptInteger(123, 456), 579, "TestOptInteger(123, 456)" + + ' optionals with integer datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptIntegerByRefByVal(), 0, "TestOptIntegerByRefByVal()" + TestLog_ASSERT TestOptIntegerByRefByVal(123), 123, "TestOptIntegerByRefByVal(123)" + TestLog_ASSERT TestOptIntegerByRefByVal(, 456), 456, "TestOptIntegerByRefByVal(, 456)" + TestLog_ASSERT TestOptIntegerByRefByVal(123, 456), 579, "TestOptIntegerByRefByVal(123, 456)" + + ' optionals with string datatypes + TestLog_ASSERT TestOptString(), "", "TestOptString()" + TestLog_ASSERT TestOptString("123"), "123", "TestOptString(""123"")" + TestLog_ASSERT TestOptString(, "456"), "456", "TestOptString(, ""456"")" + TestLog_ASSERT TestOptString("123", "456"), "123456", "TestOptString(""123"", ""456"")" + + ' optionals with string datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptStringByRefByVal(), "", "TestOptStringByRefByVal()" + TestLog_ASSERT TestOptStringByRefByVal("123"), "123", "TestOptStringByRefByVal(""123"")" + TestLog_ASSERT TestOptStringByRefByVal(, "456"), "456", "TestOptStringByRefByVal(, ""456"")" + TestLog_ASSERT TestOptStringByRefByVal("123", "456"), "123456", "TestOptStringByRefByVal(""123"", ""456"")" + + ' optionals with object datatypes + Dim cA As New Collection + cA.Add (123) + cA.Add (456) + Dim cB As New Collection + cB.Add (123.4) + cB.Add (567.8) + TestLog_ASSERT TestOptObject(), 0, "TestOptObject()" + TestLog_ASSERT TestOptObject(cA), 579, "TestOptObject(A)" + TestLog_ASSERT CDbl(Format(TestOptObject(, cB), "0.0")), 691.2, "TestOptObject(, B)" + TestLog_ASSERT CDbl(Format(TestOptObject(cA, cB), "0.0")), 1270.2, "TestOptObject(A, B)" + + ' optionals with object datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptObjectByRefByVal(), 0, "TestOptObjectByRefByVal()" + TestLog_ASSERT TestOptObjectByRefByVal(cA), 579, "TestOptObjectByRefByVal(A)" + TestLog_ASSERT CDbl(Format(TestOptObjectByRefByVal(, cB), "0.0")), 691.2, "TestOptObjectByRefByVal(, B)" + TestLog_ASSERT CDbl(Format(TestOptObjectByRefByVal(cA, cB), "0.0")), 1270.2, "TestOptObjectByRefByVal(A, B)" + + ' optionals with array datatypes + Dim aA(0 To 1) As Integer + aA(0) = 123 + aA(1) = 456 + Dim aB(0 To 1) As Variant + aB(0) = 123.4 + aB(1) = 567.8 + TestLog_ASSERT TestOptArray(), 0, "TestOptArray()" + TestLog_ASSERT TestOptArray(aA), 579, "TestOptArray(A)" + TestLog_ASSERT CDbl(Format(TestOptArray(, aB), "0.0")), 691.2, "TestOptArray(, B)" + TestLog_ASSERT CDbl(Format(TestOptArray(aA, aB), "0.0")), 1270.2, "TestOptArray(A, B)" + + ' optionals with array datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptArrayByRefByVal(), 0, "TestOptArrayByRefByVal()" + TestLog_ASSERT TestOptArrayByRefByVal(aA), 579, "TestOptArrayByRefByVal(A)" + TestLog_ASSERT CDbl(Format(TestOptArrayByRefByVal(, aB), "0.0")), 691.2, "TestOptArrayByRefByVal(, B)" + TestLog_ASSERT CDbl(Format(TestOptArrayByRefByVal(aA, aB), "0.0")), 1270.2, "TestOptArrayByRefByVal(A, B)" + + result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10) + verify_testOptionalsBasic = result + + Exit Function +errorHandler: + TestLog_ASSERT False, True, Err.Description +End Function + +Function TestOptVariant(Optional A, Optional B As Variant) + TestOptVariant = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptVariantByRefByVal(Optional ByRef A, Optional ByVal B As Variant) + TestOptVariantByRefByVal = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptDouble(Optional A As Double, Optional B As Double) + TestOptDouble = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptDoubleByRefByVal(Optional ByRef A As Double, Optional ByVal B As Double) + TestOptDoubleByRefByVal = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptInteger(Optional A As Integer, Optional B As Integer) + TestOptInteger = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptIntegerByRefByVal(Optional ByRef A As Integer, Optional ByVal B As Integer) + TestOptIntegerByRefByVal = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptString(Optional A As String, Optional B As String) + TestOptString = OptStringConcat(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptStringByRefByVal(Optional ByRef A As String, Optional ByVal B As String) + TestOptStringByRefByVal = OptStringConcat(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptObject(Optional A As Collection, Optional B As Collection) + TestOptObject = 0 + If Not IsMissing(A) Then TestOptObject = CollectionSum(A) + If Not IsMissing(B) Then TestOptObject = TestOptObject + CollectionSum(B) +End Function + +Function TestOptObjectByRefByVal(Optional ByRef A As Collection, Optional ByVal B As Collection) + TestOptObjectByRefByVal = 0 + If Not IsMissing(A) Then TestOptObjectByRefByVal = CollectionSum(A) + If Not IsMissing(B) Then TestOptObjectByRefByVal = TestOptObjectByRefByVal + CollectionSum(B) +End Function + +Function TestOptArray(Optional A() As Integer, Optional B() As Variant) + TestOptArray = ArraySum(IsMissing(A), A) + ArraySum(IsMissing(B), B) +End Function + +Function TestOptArrayByRefByVal(Optional ByRef A() As Integer, Optional ByVal B() As Variant) + TestOptArrayByRefByVal = ArraySum(IsMissing(A), A) + ArraySum(IsMissing(B), B) +End Function + +Function OptNumberSum(is_missingA As Boolean, A, is_missingB As Boolean, B) + OptNumberSum = 0 + If Not is_missingA Then OptNumberSum = A + If Not is_missingB Then OptNumberSum = OptNumberSum + B +End Function + +Function OptStringConcat(is_missingA As Boolean, A, is_missingB As Boolean, B) + OptStringConcat = "" + If Not is_missingA Then OptStringConcat = A + If Not is_missingB Then OptStringConcat = OptStringConcat & B +End Function + +Function CollectionSum(C) + Dim idx As Integer + CollectionSum = 0 + For idx = 1 To C.Count + CollectionSum = CollectionSum + C.Item(idx) + Next idx +End Function + +Function ArraySum(is_missingC As Boolean, C) + Dim idx As Integer + ArraySum = 0 + If Not is_missingC Then + For idx = LBound(C) To UBound(C) + ArraySum = ArraySum + C(idx) + Next idx + End If +End Function + +Sub TestLog_ASSERT(actual As Variant, expected As Variant, testName As String) + If expected = actual Then + passCount = passCount + 1 + Else + result = result & Chr$(10) & " Failed: " & testName & " returned " & actual & ", expected " & expected + failCount = failCount + 1 + End If +End Sub
\ No newline at end of file diff --git a/basic/qa/basic_coverage/test_optional_paramters_compatible.vb b/basic/qa/basic_coverage/test_optional_paramters_compatible.vb new file mode 100644 index 000000000..9ea475508 --- /dev/null +++ b/basic/qa/basic_coverage/test_optional_paramters_compatible.vb @@ -0,0 +1,210 @@ +Option Compatible + +Dim passCount As Integer +Dim failCount As Integer +Dim result As String + +Function doUnitTest() As String + result = verify_testOptionalsCompatible() + If failCount <> 0 Or passCount = 0 Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function + +' tdf#36737 - Test optionals with different datatypes. In LO Basic +' with option Compatible, optional parameters are allowed with default values. +' Missing optional parameters that don't have explicit default values will +' not be initialized to their default values of its datatype. +Function verify_testOptionalsCompatible() As String + + passCount = 0 + failCount = 0 + + result = "Test Results" & Chr$(10) & "============" & Chr$(10) + testName = "Test optionals (Compatible)" + On Error GoTo errorHandler + + ' optionals with variant datatypes + TestLog_ASSERT TestOptVariant(), 123, "TestOptVariant()" + TestLog_ASSERT TestOptVariant(123), 246, "TestOptVariant(123)" + TestLog_ASSERT TestOptVariant(, 456), 456, "TestOptVariant(, 456)" + TestLog_ASSERT TestOptVariant(123, 456), 579, "TestOptVariant(123, 456)" + + ' optionals with variant datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptVariantByRefByVal(), 123, "TestOptVariantByRefByVal()" + TestLog_ASSERT TestOptVariantByRefByVal(123), 246, "TestOptVariantByRefByVal(123)" + TestLog_ASSERT TestOptVariantByRefByVal(, 456), 456, "TestOptVariantByRefByVal(, 456)" + TestLog_ASSERT TestOptVariantByRefByVal(123, 456), 579, "TestOptVariantByRefByVal(123, 456)" + + ' optionals with double datatypes + TestLog_ASSERT TestOptDouble(), 123.4, "TestOptDouble()" + TestLog_ASSERT TestOptDouble(123.4), 246.8, "TestOptDouble(123.4)" + TestLog_ASSERT TestOptDouble(, 567.8), 567.8, "TestOptDouble(, 567.8)" + TestLog_ASSERT CDbl(Format(TestOptDouble(123.4, 567.8), "0.0")), 691.2, "TestOptDouble(123.4, 567.8)" + + ' optionals with double datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptDoubleByRefByVal(), 123.4, "TestOptDouble()" + TestLog_ASSERT TestOptDoubleByRefByVal(123.4), 246.8, "TestOptDouble(123.4)" + TestLog_ASSERT TestOptDoubleByRefByVal(, 567.8), 567.8, "TestOptDoubleByRefByVal(, 567.8)" + TestLog_ASSERT CDbl(Format(TestOptDoubleByRefByVal(123.4, 567.8), "0.0")), 691.2, "TestOptDoubleByRefByVal(123.4, 567.8)" + + ' optionals with integer datatypes + TestLog_ASSERT TestOptInteger(), 123, "TestOptInteger()" + TestLog_ASSERT TestOptInteger(123), 246, "TestOptInteger(123)" + TestLog_ASSERT TestOptInteger(, 456), 456, "TestOptInteger(, 456)" + TestLog_ASSERT TestOptInteger(123, 456), 579, "TestOptInteger(123, 456)" + + ' optionals with integer datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptIntegerByRefByVal(), 123, "TestOptIntegerByRefByVal()" + TestLog_ASSERT TestOptIntegerByRefByVal(123), 246, "TestOptIntegerByRefByVal(123)" + TestLog_ASSERT TestOptIntegerByRefByVal(, 456), 456, "TestOptIntegerByRefByVal(, 456)" + TestLog_ASSERT TestOptIntegerByRefByVal(123, 456), 579, "TestOptIntegerByRefByVal(123, 456)" + + ' optionals with string datatypes + TestLog_ASSERT TestOptString(), "123", "TestOptString()" + TestLog_ASSERT TestOptString("123"), "123123", "TestOptString(""123"")" + TestLog_ASSERT TestOptString(, "456"), "456", "TestOptString(, ""456"")" + TestLog_ASSERT TestOptString("123", "456"), "123456", "TestOptString(""123"", ""456"")" + + ' optionals with string datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptStringByRefByVal(), "123", "TestOptStringByRefByVal()" + TestLog_ASSERT TestOptStringByRefByVal("123"), "123123", "TestOptStringByRefByVal(""123"")" + TestLog_ASSERT TestOptStringByRefByVal(, "456"), "456", "TestOptStringByRefByVal(, ""456"")" + TestLog_ASSERT TestOptStringByRefByVal("123", "456"), "123456", "TestOptStringByRefByVal(""123"", ""456"")" + + ' optionals with object datatypes + Dim cA As New Collection + cA.Add (123) + cA.Add (456) + Dim cB As New Collection + cB.Add (123.4) + cB.Add (567.8) + TestLog_ASSERT TestOptObject(), 0, "TestOptObject()" + TestLog_ASSERT TestOptObject(cA), 579, "TestOptObject(A)" + TestLog_ASSERT CDbl(Format(TestOptObject(, cB), "0.0")), 691.2, "TestOptObject(, B)" + TestLog_ASSERT CDbl(Format(TestOptObject(cA, cB), "0.0")), 1270.2, "TestOptObject(A, B)" + + ' optionals with object datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptObjectByRefByVal(), 0, "TestOptObjectByRefByVal()" + TestLog_ASSERT TestOptObjectByRefByVal(cA), 579, "TestOptObjectByRefByVal(A)" + TestLog_ASSERT CDbl(Format(TestOptObjectByRefByVal(, cB), "0.0")), 691.2, "TestOptObjectByRefByVal(, B)" + TestLog_ASSERT CDbl(Format(TestOptObjectByRefByVal(cA, cB), "0.0")), 1270.2, "TestOptObjectByRefByVal(A, B)" + + ' optionals with array datatypes + Dim aA(0 To 1) As Integer + aA(0) = 123 + aA(1) = 456 + Dim aB(0 To 1) As Variant + aB(0) = 123.4 + aB(1) = 567.8 + TestLog_ASSERT TestOptArray(), 0, "TestOptArray()" + TestLog_ASSERT TestOptArray(aA), 579, "TestOptArray(A)" + TestLog_ASSERT CDbl(Format(TestOptArray(, aB), "0.0")), 691.2, "TestOptArray(, B)" + TestLog_ASSERT CDbl(Format(TestOptArray(aA, aB), "0.0")), 1270.2, "TestOptArray(A, B)" + + ' optionals with array datatypes (ByRef and ByVal) + TestLog_ASSERT TestOptArrayByRefByVal(), 0, "TestOptArrayByRefByVal()" + TestLog_ASSERT TestOptArrayByRefByVal(aA), 579, "TestOptArrayByRefByVal(A)" + TestLog_ASSERT CDbl(Format(TestOptArrayByRefByVal(, aB), "0.0")), 691.2, "TestOptArrayByRefByVal(, B)" + TestLog_ASSERT CDbl(Format(TestOptArrayByRefByVal(aA, aB), "0.0")), 1270.2, "TestOptArrayByRefByVal(A, B)" + + result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10) + verify_testOptionalsCompatible = result + + Exit Function +errorHandler: + TestLog_ASSERT False, True, Err.Description +End Function + +Function TestOptVariant(Optional A, Optional B As Variant = 123) + TestOptVariant = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptVariantByRefByVal(Optional ByRef A, Optional ByVal B As Variant = 123) + TestOptVariantByRefByVal = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptDouble(Optional A As Double, Optional B As Double = 123.4) + TestOptDouble = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptDoubleByRefByVal(Optional ByRef A As Double, Optional ByVal B As Double = 123.4) + TestOptDoubleByRefByVal = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptInteger(Optional A As Integer, Optional B As Integer = 123) + TestOptInteger = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptIntegerByRefByVal(Optional ByRef A As Integer, Optional ByVal B As Integer = 123) + TestOptIntegerByRefByVal = OptNumberSum(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptString(Optional A As String, Optional B As String = "123") + TestOptString = OptStringConcat(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptStringByRefByVal(Optional ByRef A As String, Optional ByVal B As String = "123") + TestOptStringByRefByVal = OptStringConcat(IsMissing(A), A, IsMissing(B), B) +End Function + +Function TestOptObject(Optional A As Collection, Optional B As Collection) + TestOptObject = 0 + If Not IsMissing(A) Then TestOptObject = CollectionSum(A) + If Not IsMissing(B) Then TestOptObject = TestOptObject + CollectionSum(B) +End Function + +Function TestOptObjectByRefByVal(Optional ByRef A As Collection, Optional ByVal B As Collection) + TestOptObjectByRefByVal = 0 + If Not IsMissing(A) Then TestOptObjectByRefByVal = CollectionSum(A) + If Not IsMissing(B) Then TestOptObjectByRefByVal = TestOptObjectByRefByVal + CollectionSum(B) +End Function + +Function TestOptArray(Optional A() As Integer, Optional B() As Variant) + TestOptArray = ArraySum(IsMissing(A), A) + ArraySum(IsMissing(B), B) +End Function + +Function TestOptArrayByRefByVal(Optional ByRef A() As Integer, Optional ByVal B() As Variant) + TestOptArrayByRefByVal = ArraySum(IsMissing(A), A) + ArraySum(IsMissing(B), B) +End Function + +Function OptNumberSum(is_missingA As Boolean, A, is_missingB As Boolean, B) + OptNumberSum = 0 + If Not is_missingA Then OptNumberSum = A + If Not is_missingB Then OptNumberSum = OptNumberSum + B +End Function + +Function OptStringConcat(is_missingA As Boolean, A, is_missingB As Boolean, B) + OptStringConcat = "" + If Not is_missingA Then OptStringConcat = A + If Not is_missingB Then OptStringConcat = OptStringConcat & B +End Function + +Function CollectionSum(C) + Dim idx As Integer + CollectionSum = 0 + For idx = 1 To C.Count + CollectionSum = CollectionSum + C.Item(idx) + Next idx +End Function + +Function ArraySum(is_missingC As Boolean, C) + Dim idx As Integer + ArraySum = 0 + If Not is_missingC Then + For idx = LBound(C) To UBound(C) + ArraySum = ArraySum + C(idx) + Next idx + End If +End Function + +Sub TestLog_ASSERT(actual As Variant, expected As Variant, testName As String) + If expected = actual Then + passCount = passCount + 1 + Else + result = result & Chr$(10) & " Failed: " & testName & " returned " & actual & ", expected " & expected + failCount = failCount + 1 + End If +End Sub
\ No newline at end of file diff --git a/basic/qa/basic_coverage/test_qbcolor_method.vb b/basic/qa/basic_coverage/test_qbcolor_method.vb new file mode 100644 index 000000000..8051a80b6 --- /dev/null +++ b/basic/qa/basic_coverage/test_qbcolor_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' QBCOLOR + If ( QBColor(7) <> 12632256 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_random_methods.vb b/basic/qa/basic_coverage/test_random_methods.vb new file mode 100644 index 000000000..ea5d1c979 --- /dev/null +++ b/basic/qa/basic_coverage/test_random_methods.vb @@ -0,0 +1,16 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + Randomize 42 + ' RND + If ( Rnd >= 1 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_resolvepath_method.vb b/basic/qa/basic_coverage/test_resolvepath_method.vb new file mode 100644 index 000000000..888a29dfb --- /dev/null +++ b/basic/qa/basic_coverage/test_resolvepath_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' RESOLVEPATH + If ( ResolvePath( "" ) <> "" ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_rgb_method.vb b/basic/qa/basic_coverage/test_rgb_method.vb new file mode 100644 index 000000000..7bdaf9660 --- /dev/null +++ b/basic/qa/basic_coverage/test_rgb_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' RGB + If ( RGB( 128, 50, 200 ) <> 8401608 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_rtrim_method.vb b/basic/qa/basic_coverage/test_rtrim_method.vb new file mode 100644 index 000000000..79a8093fe --- /dev/null +++ b/basic/qa/basic_coverage/test_rtrim_method.vb @@ -0,0 +1,17 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + dim aString as Variant + aString = "Hello" + ' RTRIM + If ( RTrim( "Hello " ) <> aString ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_second_method.vb b/basic/qa/basic_coverage/test_second_method.vb new file mode 100644 index 000000000..77311e9d3 --- /dev/null +++ b/basic/qa/basic_coverage/test_second_method.vb @@ -0,0 +1,16 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' SECOND + If ( Second(TimeSerial(12,30,41)) <> 41 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_sgn_method.vb b/basic/qa/basic_coverage/test_sgn_method.vb new file mode 100644 index 000000000..da2cf6757 --- /dev/null +++ b/basic/qa/basic_coverage/test_sgn_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' SGN + If ( Sgn(-3.14) <> -1 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_space_method.vb b/basic/qa/basic_coverage/test_space_method.vb new file mode 100644 index 000000000..8b35b108b --- /dev/null +++ b/basic/qa/basic_coverage/test_space_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' SPACE + If ( Space(3) <> " " ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_spc_method.vb b/basic/qa/basic_coverage/test_spc_method.vb new file mode 100644 index 000000000..7ed291e13 --- /dev/null +++ b/basic/qa/basic_coverage/test_spc_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' SPC + If ( Spc(3) <> " " ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_split_method.vb b/basic/qa/basic_coverage/test_split_method.vb new file mode 100644 index 000000000..d09e8c3e7 --- /dev/null +++ b/basic/qa/basic_coverage/test_split_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' SPLIT + If ( Split( "Hello world" )(1) <> "world" ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_sqr_method.vb b/basic/qa/basic_coverage/test_sqr_method.vb new file mode 100644 index 000000000..55db95403 --- /dev/null +++ b/basic/qa/basic_coverage/test_sqr_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' SQR + If ( Sqr( 4 ) <> 2 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_strcomp_method.vb b/basic/qa/basic_coverage/test_strcomp_method.vb new file mode 100644 index 000000000..aeb146e57 --- /dev/null +++ b/basic/qa/basic_coverage/test_strcomp_method.vb @@ -0,0 +1,17 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + dim aString as Variant + aString = "Hello" + ' STRCOMP + If ( StrComp( aString, "Hello" ) <> 0 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_string_method.vb b/basic/qa/basic_coverage/test_string_method.vb new file mode 100644 index 000000000..8664ac011 --- /dev/null +++ b/basic/qa/basic_coverage/test_string_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' STRING + If ( String( 3, "H" ) <> "HHH" ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_string_overflow_safe.vb b/basic/qa/basic_coverage/test_string_overflow_safe.vb new file mode 100644 index 000000000..148cc910c --- /dev/null +++ b/basic/qa/basic_coverage/test_string_overflow_safe.vb @@ -0,0 +1,22 @@ +Option Explicit + +Function doUnitTest As Integer + ' Trying to create too long string should generate proper BASIC overflow error. + ' Longest possible string is 2147483638 wchar_t (2G - 10). + ' This tries to create string with 2G wchar_t. If it does not overflow, test fails. + ' If overflow is not safe, it segfaults. + On Error GoTo errorHandler + Dim s As String, i As Integer + s = "0" + For i=1 To 31 + s = s & s + Next i + doUnitTest = 0 + Exit Function +errorHandler: + If ( Err <> 6 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + Endif +End Function diff --git a/basic/qa/basic_coverage/test_string_replace.vb b/basic/qa/basic_coverage/test_string_replace.vb new file mode 100644 index 000000000..99eafdba6 --- /dev/null +++ b/basic/qa/basic_coverage/test_string_replace.vb @@ -0,0 +1,37 @@ +Dim passCount As Integer +Dim failCount As Integer +Dim result As String + +Function doUnitTest() As String + result = verify_stringReplace() + If failCount <> 0 Or passCount = 0 Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function + +Function verify_stringReplace() As String + passCount = 0 + failCount = 0 + + result = "Test Results" & Chr$(10) & "============" & Chr$(10) + + ' tdf#132389 - case-insensitive operation for non-ASCII characters + retStr = Replace("ABCabc", "b", "*") + TestLog_ASSERT retStr, "A*Ca*c", "case-insensitive ASCII: " & retStr + retStr = Replace("АБВабв", "б", "*") + TestLog_ASSERT retStr, "А*Ва*в", "case-insensitive non-ASCII: " & retStr + + result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10) + verify_stringReplace = result +End Function + +Sub TestLog_ASSERT(actual As Variant, expected As Variant, testName As String) + If expected = actual Then + passCount = passCount + 1 + Else + result = result & Chr$(10) & "Failed: " & testName & " returned " & actual & ", expected " & expected + failCount = failCount + 1 + End If +End Sub diff --git a/basic/qa/basic_coverage/test_strtrim_methods.vb b/basic/qa/basic_coverage/test_strtrim_methods.vb new file mode 100644 index 000000000..b9da11d7f --- /dev/null +++ b/basic/qa/basic_coverage/test_strtrim_methods.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' STR TRIM + If ( Trim( Str( 4 ) ) <> "4" ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_switch_method.vb b/basic/qa/basic_coverage/test_switch_method.vb new file mode 100644 index 000000000..9dc00fa52 --- /dev/null +++ b/basic/qa/basic_coverage/test_switch_method.vb @@ -0,0 +1,20 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + dim aVariant as Object + ' SWITCH + If ( Switch( False, 10,_ + True, 11,_ + False, 12,_ + True, 13 ) <> 11 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_tab_method.vb b/basic/qa/basic_coverage/test_tab_method.vb new file mode 100644 index 000000000..a5e4e9815 --- /dev/null +++ b/basic/qa/basic_coverage/test_tab_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' TAB + If ( "Hello" & Tab(0) & "World" <> "HelloWorld" ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_tan_method.vb b/basic/qa/basic_coverage/test_tan_method.vb new file mode 100644 index 000000000..117d2824b --- /dev/null +++ b/basic/qa/basic_coverage/test_tan_method.vb @@ -0,0 +1,15 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' TAN + If ( Abs( Tan(PI/4) - 1 ) > 1E-6 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_timer_method.vb b/basic/qa/basic_coverage/test_timer_method.vb new file mode 100644 index 000000000..3ccb120f6 --- /dev/null +++ b/basic/qa/basic_coverage/test_timer_method.vb @@ -0,0 +1,16 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' TIMER max value = 24*3600 + If ( Timer() > 86400 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_timeserialtimevalue_methods.vb b/basic/qa/basic_coverage/test_timeserialtimevalue_methods.vb new file mode 100644 index 000000000..6e84329d0 --- /dev/null +++ b/basic/qa/basic_coverage/test_timeserialtimevalue_methods.vb @@ -0,0 +1,16 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' TIMESERIAL TIMEVALUE + If ( TimeSerial(13,54,48) <> TimeValue("13:54:48") ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_twipsperpixelx_method.vb b/basic/qa/basic_coverage/test_twipsperpixelx_method.vb new file mode 100644 index 000000000..2b8890ad7 --- /dev/null +++ b/basic/qa/basic_coverage/test_twipsperpixelx_method.vb @@ -0,0 +1,16 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' TWIPSPERPIXELX + If ( TwipsPerPixelX < 0 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_twipsperpixely_method.vb b/basic/qa/basic_coverage/test_twipsperpixely_method.vb new file mode 100644 index 000000000..efc41e1ff --- /dev/null +++ b/basic/qa/basic_coverage/test_twipsperpixely_method.vb @@ -0,0 +1,16 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' TWIPSPERPIXELY + If ( TwipsPerPixelY < 0 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_typelen_method.vb b/basic/qa/basic_coverage/test_typelen_method.vb new file mode 100644 index 000000000..468479007 --- /dev/null +++ b/basic/qa/basic_coverage/test_typelen_method.vb @@ -0,0 +1,16 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' TYPELEN + If ( TypeLen("Hello") <> 5 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_typename_method.vb b/basic/qa/basic_coverage/test_typename_method.vb new file mode 100644 index 000000000..eba2d86c4 --- /dev/null +++ b/basic/qa/basic_coverage/test_typename_method.vb @@ -0,0 +1,16 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' TYPENAME + If ( TypeName("Hello") <> "String" ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_types_conversion.vb b/basic/qa/basic_coverage/test_types_conversion.vb new file mode 100644 index 000000000..0868f4d3e --- /dev/null +++ b/basic/qa/basic_coverage/test_types_conversion.vb @@ -0,0 +1,64 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' +Option Explicit + +Dim nTotalCount As Integer +Dim nPassCount As Integer +Dim nFailCount As Integer + +' For the following tests the en-US (English - United States) locale is required +Function doUnitTest() As Integer + nTotalCount = 0 + nPassCount = 0 + nFailCount = 0 + + ' Test implicit conversions from string to number + Dim nVal As Double + ' Simple integer + StartTest() + nVal = "123" + AssertTest(nVal = 123) + + ' Negative integer + StartTest() + nVal = "-123" + AssertTest(nVal = -123) + + ' Negative floating-point + StartTest() + nVal = "-123.45" + AssertTest(nVal = -123.45) + + ' Negative floating-point with leading and trailing spaces + StartTest() + nVal = " -123.456 " + AssertTest(nVal = -123.456) + + ' Wrong decimal separator (interpreted as group separator) + StartTest() + nVal = " -123,456 " + AssertTest(nVal = -123456) + + If ((nFailCount > 0) Or (nPassCount <> nTotalCount)) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function + +Sub StartTest() + nTotalCount = nTotalCount + 1 +End Sub + +Sub AssertTest(testResult As Boolean) + If (testResult) Then + nPassCount = nPassCount + 1 + Else + nFailCount = nFailCount + 1 + End If +End Sub diff --git a/basic/qa/basic_coverage/test_ucase_method.vb b/basic/qa/basic_coverage/test_ucase_method.vb new file mode 100644 index 000000000..940c0897b --- /dev/null +++ b/basic/qa/basic_coverage/test_ucase_method.vb @@ -0,0 +1,17 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + dim aString as Variant + aString = "Hello" + ' UCASE + If ( UCase( aString ) <> "HELLO" ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_val_method.vb b/basic/qa/basic_coverage/test_val_method.vb new file mode 100644 index 000000000..c25610ceb --- /dev/null +++ b/basic/qa/basic_coverage/test_val_method.vb @@ -0,0 +1,16 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' VAL + If ( Val("4") <> 4 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_vartype_method.vb b/basic/qa/basic_coverage/test_vartype_method.vb new file mode 100644 index 000000000..bd45adef0 --- /dev/null +++ b/basic/qa/basic_coverage/test_vartype_method.vb @@ -0,0 +1,16 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' VARTYPE + If ( VarType("Hello") <> 8 ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_wait_method.vb b/basic/qa/basic_coverage/test_wait_method.vb new file mode 100644 index 000000000..776a2efad --- /dev/null +++ b/basic/qa/basic_coverage/test_wait_method.vb @@ -0,0 +1,12 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + ' WAIT + Wait(0) + doUnitTest = 1 +End Function diff --git a/basic/qa/basic_coverage/test_weekday_method.vb b/basic/qa/basic_coverage/test_weekday_method.vb new file mode 100644 index 000000000..48279434d --- /dev/null +++ b/basic/qa/basic_coverage/test_weekday_method.vb @@ -0,0 +1,18 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + dim aDate as Date + aDate = Date() + ' WEEKDAY + If ( Weekday( aDate ) <> WeekDay( aDate ) ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/test_year_method.vb b/basic/qa/basic_coverage/test_year_method.vb new file mode 100644 index 000000000..0863e11b3 --- /dev/null +++ b/basic/qa/basic_coverage/test_year_method.vb @@ -0,0 +1,18 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Function doUnitTest as Integer + dim aDate as Date + aDate = Date() + ' YEAR + If ( DatePart( "yyyy", aDate ) <> Year( aDate ) ) Then + doUnitTest = 0 + Else + doUnitTest = 1 + End If +End Function diff --git a/basic/qa/basic_coverage/uno_struct_assign.vb b/basic/qa/basic_coverage/uno_struct_assign.vb new file mode 100644 index 000000000..23812de2c --- /dev/null +++ b/basic/qa/basic_coverage/uno_struct_assign.vb @@ -0,0 +1,15 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + + +Function doUnitTest as Integer + Dim oNamedValue as new com.sun.star.beans.NamedValue + Dim oCellAddress as new com.sun.star.table.CellAddress + oNamedValue.Value = oCellAddress ' fdo#60065 - this would throw an error + doUnitTest = 1 +End Function |