diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /basic/qa/basic_coverage | |
parent | Initial commit. (diff) | |
download | libreoffice-cb75148ebd0135178ff46f89a30139c44f8d2040.tar.xz libreoffice-cb75148ebd0135178ff46f89a30139c44f8d2040.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'basic/qa/basic_coverage')
158 files changed, 4595 insertions, 0 deletions
diff --git a/basic/qa/basic_coverage/da-DK/cdbl-2.bas b/basic/qa/basic_coverage/da-DK/cdbl-2.bas new file mode 100644 index 000000000..a3fb352ea --- /dev/null +++ b/basic/qa/basic_coverage/da-DK/cdbl-2.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest() as String + 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 = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/da-DK/cdbl.bas b/basic/qa/basic_coverage/da-DK/cdbl.bas new file mode 100644 index 000000000..452f168fe --- /dev/null +++ b/basic/qa/basic_coverage/da-DK/cdbl.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest() as String + 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 = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/dateadd.bas b/basic/qa/basic_coverage/dateadd.bas new file mode 100644 index 000000000..409a55a9b --- /dev/null +++ b/basic/qa/basic_coverage/dateadd.bas @@ -0,0 +1,31 @@ +' +' 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 + +Function doUnitTest() As String + TestUtil.TestInit + verify_testDateAdd + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_testDateAdd() + On Error GoTo errorHandler + + ' tdf#117612 + TestUtil.AssertEqual(DateAdd("m", 1, "2014-01-29"), CDate("2014-02-28"), "DateAdd(""m"", 1, ""2014-01-29"")") + + ' tdf#114011 Without the fix in place, this test would have failed with + ' returned 01/31/32767, expected 12/31/32767 + TestUtil.AssertEqual(DateAdd("m", 1, 31012004), CDate("32767-12-31"), "DateAdd(""m"", 1, 31012004)") + TestUtil.AssertEqual(DateAdd("M", 1, 31012005), CDate("32767-12-31"), "DateAdd(""M"", 1, 31012005)") + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_testDateAdd", Err, Error$, Erl) +End Sub diff --git a/basic/qa/basic_coverage/string_left_01.bas b/basic/qa/basic_coverage/string_left_01.bas new file mode 100644 index 000000000..d2ae7ae45 --- /dev/null +++ b/basic/qa/basic_coverage/string_left_01.bas @@ -0,0 +1,26 @@ +' +' 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 + +Function doUnitTest as String + +Dim s1 As String +Dim s2 As String + + s1 = "abc" + + s2 = Left(s1, 2) + + If s2 = "ab" Then + doUnitTest = "OK" + Else + doUnitTest = "FAIL" + End If + +End Function diff --git a/basic/qa/basic_coverage/string_right_01.bas b/basic/qa/basic_coverage/string_right_01.bas new file mode 100644 index 000000000..a291d0704 --- /dev/null +++ b/basic/qa/basic_coverage/string_right_01.bas @@ -0,0 +1,26 @@ +' +' 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 + +Function doUnitTest as String + +Dim s1 As String +Dim s2 As String + + s1 = "abc" + + s2 = Right(s1, 2) + + If s2 = "bc" Then + doUnitTest = "OK" + Else + doUnitTest = "FAIL" + End If + +End Function diff --git a/basic/qa/basic_coverage/test_CallByName.bas b/basic/qa/basic_coverage/test_CallByName.bas new file mode 100644 index 000000000..35578ee47 --- /dev/null +++ b/basic/qa/basic_coverage/test_CallByName.bas @@ -0,0 +1,36 @@ +Option Explicit + +Function doUnitTest() As String + TestUtil.TestInit + verify_CallByName + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_CallByName() + Const _Get = 2, _Let = 4, _Method = 1, _Set = 8 + + On Error GoTo errorHandler + + ' Basic modules are Objects + TestUtil.AssertEqual(CallByName(TestUtil, "failCount", _Get), 0, "CallByName(TestUtil, ""failCount"", _Get") + TestUtil.AssertEqual(CallByName(TestUtil, "passCount", _Get), 1, "CallByName(TestUtil, ""passCount"", _Get") + TestUtil.AssertEqual(CallByName(TestUtil, "GetResult", _Method), "OK", "CallByName(TestUtil, ""GetResult"", _Method") + + ' Collection instances + Dim c As New Collection + c.Add(100, "1st") : c.Add(101) + TestUtil.AssertEqual(CallByName(c,"Count", _Get), 2, "CallByName(c,""Count"", _Get)") + c.Remove(2) + TestUtil.AssertEqual(CallByName(callType:=_Get, object:=c, procName:="Count"), 1, _ + "CallByName(callType:=_Get, object:=c, procName:=""Count"")") + + ' ClassModule instances or UNO services are 'CallByNamable' objects too! + ' see https://help.libreoffice.org/7.4/en-US/text/sbasic/shared/CallByName.html?DbPAR=BASIC#bm_id3150669 + ' for more _Let and _Set examples + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_CallByName", Err, Error$, Erl) + Resume Next + +End Sub
\ No newline at end of file diff --git a/basic/qa/basic_coverage/test_Collection_class.bas b/basic/qa/basic_coverage/test_Collection_class.bas new file mode 100644 index 000000000..06ed6b665 --- /dev/null +++ b/basic/qa/basic_coverage/test_Collection_class.bas @@ -0,0 +1,71 @@ +' +' 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 + +Function doUnitTest() As String + TestUtil.TestInit + Call verify_Collection + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_Collection() +try: On Error GoTo catch + + Dim c As New Collection, planet as String, ndx As Integer + + TestUtil.assertEqual(c.Count, 0,"c.Count") + + ' Let's collect Solar system planets from closest to SUN, + ' ranking them alphabetically using before/after keywords, + ' in order to validate various Add() method syntax variations. + c.Add("Mercury") + c.Add("Venus", "♀") + c.Add("Earth", "♁", before:=1) + TestUtil.assertEqual(c.Count, 3,"c.Count") + TestUtil.assertEqual(c.Item(1), "Earth","c.Item(1)") + TestUtil.assertEqual(c.Item("♁"), "Earth","c.Item(""♁"")") + TestUtil.assertEqual(c.Item(3), "Venus","c.Item(3)") + TestUtil.assertEqual(c.Item("♀"), "Venus","c.Item(""♀"")") + + c.Add("Mars", "♂", after:="♁") + c.Add("Jupiter", after:="♁") + c.Add("Saturn", before:=5) + TestUtil.assertEqual(c.Count, 6,"c.Count") + TestUtil.assertEqual(c.Item(2), "Jupiter","c.Item(2)") + TestUtil.assertEqual(c.Item(3), "Mars","c.Item(3)") + TestUtil.assertEqual(c.Item("♂"), "Mars","c.Item(""♂"")") + TestUtil.assertEqual(c.Item(5), "Saturn","c.Item(5)") + TestUtil.assertEqual(c.Item(6), "Venus","c.Item(6)") + + c.Add("Uranus", before:="♀") + c.Add("Neptune", "♆", after:=4) + TestUtil.assertEqual(c.Count, 8,"c.Count") + TestUtil.assertEqual(c.Item(7), "Uranus","c.Item(7)") + TestUtil.assertEqual(c.Item(5), "Neptune","c.Item(5)") + TestUtil.assertEqual(c.Item("♆"), "Neptune","c.Item(""♆"")") + TestUtil.assertEqual(c.Item(6), "Saturn","c.Item(6)") + + c.remove(4) + c.remove("♁") + + TestUtil.assertEqual(c.Count, 6,"c.Count") + + For ndx = c.Count to 1 Step -1 + c.Remove(ndx) + Next ndx + + TestUtil.assertEqual(c.Count, 0,"c.Count") + +finally: + Exit Sub + +catch: + TestUtil.ReportErrorHandler("verify_Collection", Err, Error$, Erl) + Resume Next +End Sub diff --git a/basic/qa/basic_coverage/test_Date.bas b/basic/qa/basic_coverage/test_Date.bas new file mode 100644 index 000000000..8154da185 --- /dev/null +++ b/basic/qa/basic_coverage/test_Date.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ''' Return 'text' OR 'date' variable ''' + + If ( TypeName(Date$)<>"String" Or Vartype(Date())<>V_DATE) Then + doUnitTest = "FAIL" ' not successful + Else + doUnitTest = "OK" ' Ok + End If +End Function + +Sub DEV_TST : MsgBox doUnitTesT : End Sub
\ No newline at end of file diff --git a/basic/qa/basic_coverage/test_Property.GetLet.bas b/basic/qa/basic_coverage/test_Property.GetLet.bas new file mode 100644 index 000000000..f8fa6dd14 --- /dev/null +++ b/basic/qa/basic_coverage/test_Property.GetLet.bas @@ -0,0 +1,28 @@ +' +' 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 +Option Compatible + +Function doUnitTest as String + ' PROPERTY GET/LET + aString = "Office" + If ( aString <> "LibreOffice") Then + doUnitTest = "FAIL" ' Ko + Else + doUnitTest = "OK" ' 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.bas b/basic/qa/basic_coverage/test_Property.GetSet.bas new file mode 100644 index 000000000..701bcc7f4 --- /dev/null +++ b/basic/qa/basic_coverage/test_Property.GetSet.bas @@ -0,0 +1,38 @@ +' +' 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 +Option Compatible + +Function doUnitTest as String + ' PROPERTY GET/SET for classes or UNO services + + Set objSetter = New Collection ' OR objLetter = New Collection + If ( objGetter.Count <> 3 ) Then + doUnitTest = "FAIL" ' not Ok + Else + doUnitTest = "OK" ' 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.bas b/basic/qa/basic_coverage/test_abs_method.bas new file mode 100644 index 000000000..e9d4b9525 --- /dev/null +++ b/basic/qa/basic_coverage/test_abs_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' ABS + If (Abs(-3.5) <> 3.5) Then + doUnitTest = "FAIL" + ElseIf (Abs(3.5) <> 3.5) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_array_method.bas b/basic/qa/basic_coverage/test_array_method.bas new file mode 100644 index 000000000..145682619 --- /dev/null +++ b/basic/qa/basic_coverage/test_array_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + dim aVector as Variant + ' ARRAY + aVector = Array( "Hello", -3.14) + If (aVector(0) <> "Hello") Then + doUnitTest = "FAIL" + ElseIf ( aVector(1) <> -3.14 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_asc_method.bas b/basic/qa/basic_coverage/test_asc_method.bas new file mode 100644 index 000000000..131c7cbe1 --- /dev/null +++ b/basic/qa/basic_coverage/test_asc_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' ASC + If (Asc("€a") <> 8364) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_atn_method.bas b/basic/qa/basic_coverage/test_atn_method.bas new file mode 100644 index 000000000..9e2f382c1 --- /dev/null +++ b/basic/qa/basic_coverage/test_atn_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' ATN (arc tan) + If (Atn(1) <> PI/4) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_beep_method.bas b/basic/qa/basic_coverage/test_beep_method.bas new file mode 100644 index 000000000..8270341b4 --- /dev/null +++ b/basic/qa/basic_coverage/test_beep_method.bas @@ -0,0 +1,14 @@ +' 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 + +Function doUnitTest as String + ' BEEP + Beep + doUnitTest = "OK" +End Function diff --git a/basic/qa/basic_coverage/test_booltypename.bas b/basic/qa/basic_coverage/test_booltypename.bas new file mode 100644 index 000000000..f8ed1f13e --- /dev/null +++ b/basic/qa/basic_coverage/test_booltypename.bas @@ -0,0 +1,46 @@ +' +' 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 + +Function doUnitTest() As String + TestUtil.TestInit + verify_testTypeNameBoolean + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_testTypeNameBoolean() + On Error GoTo errorHandler + + TestUtil.AssertEqual(TypeName(1>2), "Boolean", "TypeName(1>2)") + TestUtil.AssertEqual(TypeName(2.0>1.0), "Boolean", "TypeName(2.0>1.0)") + TestUtil.AssertEqual(TypeName("A">"B"), "Boolean", "TypeName(""A"">""B"")") + + TestUtil.AssertEqual(Str(2>1), "True", "Str(2>1)") + TestUtil.AssertEqual(Str(1>2), "False", "Str(1>2)") + + TestUtil.AssertEqual(Str(2.0>1.0), "True", "Str(2.0>1.0)") + TestUtil.AssertEqual(Str(1.0>2.0), "False", "Str(1.0>2.0)") + + TestUtil.AssertEqual(Str("B">"A"), "True", "Str(""B"">""A"")") + TestUtil.AssertEqual(Str("A">"B"), "False", "Str(""A"">""B"")") + + ' tdf#145960 - return type of boolean operators should be of type boolean + TestUtil.AssertEqual(TypeName(True Mod True), "Long", "TypeName(True Mod True)") + TestUtil.AssertEqual(TypeName(True \ True), "Long", "TypeName(True \ True)") + TestUtil.AssertEqual(TypeName(True And True), "Boolean", "TypeName(True And True)") + TestUtil.AssertEqual(TypeName(True Or True), "Boolean", "TypeName(True Or True)") + TestUtil.AssertEqual(TypeName(True Xor True), "Boolean", "TypeName(True Xor True)") + TestUtil.AssertEqual(TypeName(True Eqv True), "Boolean", "TypeName(True Eqv True)") + TestUtil.AssertEqual(TypeName(True Imp True), "Boolean", "TypeName(True Imp True)") + TestUtil.AssertEqual(TypeName(Not True), "Boolean", "TypeName(Not True)") + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_testTypeNameBoolean", Err, Error$, Erl) +End Sub diff --git a/basic/qa/basic_coverage/test_cbool_method.bas b/basic/qa/basic_coverage/test_cbool_method.bas new file mode 100644 index 000000000..70d3459ab --- /dev/null +++ b/basic/qa/basic_coverage/test_cbool_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' CBOOL + If (CBool(3) <> True) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_cbyte_method.bas b/basic/qa/basic_coverage/test_cbyte_method.bas new file mode 100644 index 000000000..d8dbe6569 --- /dev/null +++ b/basic/qa/basic_coverage/test_cbyte_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' CBYTE + If (CByte("3") <> 3) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_ccur_method.bas b/basic/qa/basic_coverage/test_ccur_method.bas new file mode 100644 index 000000000..cd700cad3 --- /dev/null +++ b/basic/qa/basic_coverage/test_ccur_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + + doUnitTest = "FAIL" + + ' CCUR + if (CCur("100") <> 100) Then Exit Function + ' tdf#141050 - passing a number with + sign + if (CCur("+100") <> 100) Then Exit Function + ' tdf#141050 - passing a number with - sign + if (CCur("-100") <> -100) Then Exit Function + + doUnitTest = "OK" + +End Function diff --git a/basic/qa/basic_coverage/test_cdate_method.bas b/basic/qa/basic_coverage/test_cdate_method.bas new file mode 100644 index 000000000..2e4bbd1e9 --- /dev/null +++ b/basic/qa/basic_coverage/test_cdate_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' CDATE + If (CDate(100) <> 100) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_cdatetofromiso_methods.bas b/basic/qa/basic_coverage/test_cdatetofromiso_methods.bas new file mode 100644 index 000000000..8cb65b74d --- /dev/null +++ b/basic/qa/basic_coverage/test_cdatetofromiso_methods.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' CDateFromIso CDateToIso + If ( CDateToIso( CDateFromIso("20161016") ) <> "20161016" ) Then + doUnitTest = "FAIL" + ElseIf ( CDateToIso( CDateFromIso("2016-10-16") ) <> "20161016" ) Then + doUnitTest = "FAIL" + ElseIf ( CDateToIso( CDateFromIso("-2016-10-16") ) <> "-20161016" ) Then + doUnitTest = "FAIL" + ElseIf ( CDateToIso( CDateFromIso("-20161016") ) <> "-20161016" ) Then + doUnitTest = "FAIL" + ElseIf ( CDateToIso( CDateFromIso("12016-10-16") ) <> "120161016" ) Then + doUnitTest = "FAIL" + ElseIf ( CDateToIso( CDateFromIso("120161016") ) <> "120161016" ) Then + doUnitTest = "FAIL" + ElseIf ( CDateToIso( CDateFromIso("-12016-10-16") ) <> "-120161016" ) Then + doUnitTest = "FAIL" + ElseIf ( CDateToIso( CDateFromIso("-120161016") ) <> "-120161016" ) Then + doUnitTest = "FAIL" + ElseIf ( CDateToIso( CDateFromIso("0001-01-01") ) <> "00010101" ) Then + doUnitTest = "FAIL" + ElseIf ( CDateToIso( CDateFromIso("00010101") ) <> "00010101" ) Then + doUnitTest = "FAIL" + ElseIf ( CDateToIso( CDateFromIso("-0001-12-31") ) <> "-00011231" ) Then + doUnitTest = "FAIL" + ElseIf ( CDateToIso( CDateFromIso("-00011231") ) <> "-00011231" ) Then + doUnitTest = "FAIL" + ElseIf ( CDateToIso( CDateFromIso("991231") ) <> "19991231" ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + 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.bas b/basic/qa/basic_coverage/test_cdatetounodatecdatefromunodate_methods.bas new file mode 100644 index 000000000..cf7139815 --- /dev/null +++ b/basic/qa/basic_coverage/test_cdatetounodatecdatefromunodate_methods.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + dim aDate as Date + aDate = Date() + ' CDateToUnoDate CDateFromUnoDate + If ( CDateFromUnoDate( CDateToUnoDate( aDate ) ) <> aDate ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_cdatetounodatetimecdatefromunodatetime_methods.bas b/basic/qa/basic_coverage/test_cdatetounodatetimecdatefromunodatetime_methods.bas new file mode 100644 index 000000000..ef8d29683 --- /dev/null +++ b/basic/qa/basic_coverage/test_cdatetounodatetimecdatefromunodatetime_methods.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + dim aDate as Date + aDate = Now() + ' CDateToUnoDateTime CDateFromUnoDateTime + If ( CDateFromUnoDateTime( CDateToUnoDateTime( aDate ) ) <> aDate ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_cdatetounotimecdatefromunotime_methods.bas b/basic/qa/basic_coverage/test_cdatetounotimecdatefromunotime_methods.bas new file mode 100644 index 000000000..ac2664755 --- /dev/null +++ b/basic/qa/basic_coverage/test_cdatetounotimecdatefromunotime_methods.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + dim aDate as Date + aDate = Time() + ' CDateToUnoTime CDateFromUnoTime + If ( CDateFromUnoTime( CDateToUnoTime( aDate ) ) <> aDate ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_cdbl_method.bas b/basic/qa/basic_coverage/test_cdbl_method.bas new file mode 100644 index 000000000..e44c23456 --- /dev/null +++ b/basic/qa/basic_coverage/test_cdbl_method.bas @@ -0,0 +1,30 @@ +'
+' 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
+ +Function doUnitTest() As String
+ TestUtil.TestInit
+ verify_testCdbl
+ doUnitTest = TestUtil.GetResult()
+End Function +
+Sub verify_testCdbl + On Error GoTo errorHandler + + ' CDBL + TestUtil.AssertEqual(CDbl("100"), 100, "CDbl(""100"")") + + ' tdf#146672 - skip spaces and tabs at the end of the scanned string + TestUtil.AssertEqual(CDbl("28.8 "), 28.8, "CDbl(""28.8 "")")
+ TestUtil.AssertEqual(CDbl("28.8 "), 28.8, "CDbl(""28.8 "")")
+
+ Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_testCdbl", Err, Error$, Erl) +End Sub diff --git a/basic/qa/basic_coverage/test_chdircurdir_methods.bas b/basic/qa/basic_coverage/test_chdircurdir_methods.bas new file mode 100644 index 000000000..58e0bab02 --- /dev/null +++ b/basic/qa/basic_coverage/test_chdircurdir_methods.bas @@ -0,0 +1,14 @@ +' 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 + +Function doUnitTest as String + ' CHDIR CURDIR + ChDir( CurDir ) + doUnitTest = "OK" +End Function diff --git a/basic/qa/basic_coverage/test_choose_method.bas b/basic/qa/basic_coverage/test_choose_method.bas new file mode 100644 index 000000000..163a387ba --- /dev/null +++ b/basic/qa/basic_coverage/test_choose_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' CHOOSE + If (Choose(2, 1, 100, 3) <> 100) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_chr_method.bas b/basic/qa/basic_coverage/test_chr_method.bas new file mode 100644 index 000000000..96d6fe3d9 --- /dev/null +++ b/basic/qa/basic_coverage/test_chr_method.bas @@ -0,0 +1,30 @@ +' +' 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 + +Function doUnitTest() As String + TestUtil.TestInit + verify_testCHR + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_testCHR() + On Error GoTo errorHandler + + TestUtil.AssertEqual(Chr(87), "W", "Chr(87)") + TestUtil.AssertEqual(Chr(105), "i", "Chr(105)") + TestUtil.AssertEqual(Chr(35), "#", "Chr(35)") + + ' tdf#145693 - argument name should be 'charcode' instead of 'string' + TestUtil.AssertEqual(Chr(charcode:=35), "#", "Chr(charcode:=35)") + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_testCHR", Err, Error$, Erl) +End Sub diff --git a/basic/qa/basic_coverage/test_chr_overflow_method.bas b/basic/qa/basic_coverage/test_chr_overflow_method.bas new file mode 100644 index 000000000..9c1df6659 --- /dev/null +++ b/basic/qa/basic_coverage/test_chr_overflow_method.bas @@ -0,0 +1,66 @@ +' 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 + +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 String + Chr(-32768) + Chr(65535) + Chr(&H8000) + Chr(&HFFFF) + if (overflow1 = 0) Then + doUnitTest = "FAIL" + Exit Function + Endif + if (overflow2 = 0) Then + doUnitTest = "FAIL" + Exit Function + Endif + if (overflow3 = 0) Then + doUnitTest = "FAIL" + Exit Function + Endif + doUnitTest = "OK" +End Function diff --git a/basic/qa/basic_coverage/test_cint_method.bas b/basic/qa/basic_coverage/test_cint_method.bas new file mode 100644 index 000000000..e3bd74094 --- /dev/null +++ b/basic/qa/basic_coverage/test_cint_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' CINT + If (CInt("100") <> 100) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_compatibilitymode_method.bas b/basic/qa/basic_coverage/test_compatibilitymode_method.bas new file mode 100644 index 000000000..4d8256c1d --- /dev/null +++ b/basic/qa/basic_coverage/test_compatibilitymode_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' CompatibilityMode + If (CompatibilityMode(True) <> True) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_converttofromurl_methods.bas b/basic/qa/basic_coverage/test_converttofromurl_methods.bas new file mode 100644 index 000000000..d1dbcfc5f --- /dev/null +++ b/basic/qa/basic_coverage/test_converttofromurl_methods.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' ConvertFromUrl ConvertToUrl + If ( ConvertToUrl( ConvertFromUrl("") ) <> "") Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_cossin_methods.bas b/basic/qa/basic_coverage/test_cossin_methods.bas new file mode 100644 index 000000000..733a6afa3 --- /dev/null +++ b/basic/qa/basic_coverage/test_cossin_methods.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' COS SIN + If ( Abs(Cos(PI/3) - Sin(PI/6)) > 1E-6 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_createobject_method.bas b/basic/qa/basic_coverage/test_createobject_method.bas new file mode 100644 index 000000000..e8281c7d2 --- /dev/null +++ b/basic/qa/basic_coverage/test_createobject_method.bas @@ -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/. +' + +Option Explicit +Type address + Name1 As String + City As String +End Type + +Function doUnitTest as String + ' CREATEOBJECT + If ( IsObject( CreateObject("address") ) = False ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_createunolistener_method.bas b/basic/qa/basic_coverage/test_createunolistener_method.bas new file mode 100644 index 000000000..cd89716cd --- /dev/null +++ b/basic/qa/basic_coverage/test_createunolistener_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' CreateUnoListener + Dim oListener + oListener = CreateUnoListener( "ContListener_","com.sun.star.container.XContainerListener" ) + doUnitTest = "OK" +End Function diff --git a/basic/qa/basic_coverage/test_createunoservice_method.bas b/basic/qa/basic_coverage/test_createunoservice_method.bas new file mode 100644 index 000000000..33bb875f1 --- /dev/null +++ b/basic/qa/basic_coverage/test_createunoservice_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' CreateUnoService + Dim filepicker + filepicker = CreateUnoService("com.sun.star.ui.dialogs.FilePicker") + doUnitTest = "OK" +End Function diff --git a/basic/qa/basic_coverage/test_createunostruct_method.bas b/basic/qa/basic_coverage/test_createunostruct_method.bas new file mode 100644 index 000000000..26b676aae --- /dev/null +++ b/basic/qa/basic_coverage/test_createunostruct_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' CreateUnoStruct + Dim oStruct + oStruct = CreateUnoStruct( "com.sun.star.beans.Property" ) + doUnitTest = "OK" +End Function diff --git a/basic/qa/basic_coverage/test_createunovalue_method.bas b/basic/qa/basic_coverage/test_createunovalue_method.bas new file mode 100644 index 000000000..3ea82acdd --- /dev/null +++ b/basic/qa/basic_coverage/test_createunovalue_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' CreateUnoValue + Dim oUnoValue as Variant + Dim aValue as Variant + aValue = Array ( 1, 1 ) + oUnoValue = CreateUnoValue( "[]byte", aValue ) + doUnitTest = "OK" +End Function diff --git a/basic/qa/basic_coverage/test_csng_method.bas b/basic/qa/basic_coverage/test_csng_method.bas new file mode 100644 index 000000000..83b4d24e4 --- /dev/null +++ b/basic/qa/basic_coverage/test_csng_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' CSNG + If (CSng("100") <> 100) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_cstr_method.bas b/basic/qa/basic_coverage/test_cstr_method.bas new file mode 100644 index 000000000..c2ac003e8 --- /dev/null +++ b/basic/qa/basic_coverage/test_cstr_method.bas @@ -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 Explicit + +Function doUnitTest() As String + TestUtil.TestInit + verify_testCStr + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_testCStr + On Error GoTo errorHandler + + ' CSTR + TestUtil.AssertEqual(CStr(100), "100", "CStr(100)") + + ' tdf#143575 - round string to their nearest double representation + ' N.B.: check also how current conversion rounds a close number + ' Without the fix in place, this test would have failed with: + ' - Expected: 691.2 + ' - Actual : 691.2000000000001 + TestUtil.AssertEqual(CStr(691.2), "691.2", "CStr(691.2)") + ' Without the fix in place, this test would have failed with: + ' - Expected: 691.2 + ' - Actual : 691.1999999999999 + TestUtil.AssertEqual(CStr(123.4 + 567.8), "691.2", "CStr(123.4 + 567.8)") + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_testCStr", Err, Error$, Erl) +End Sub diff --git a/basic/qa/basic_coverage/test_cvar_method.bas b/basic/qa/basic_coverage/test_cvar_method.bas new file mode 100644 index 000000000..94ebc714f --- /dev/null +++ b/basic/qa/basic_coverage/test_cvar_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' CVAR + If (CVar(100) <> 100) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_cverr_method.bas b/basic/qa/basic_coverage/test_cverr_method.bas new file mode 100644 index 000000000..2142fd335 --- /dev/null +++ b/basic/qa/basic_coverage/test_cverr_method.bas @@ -0,0 +1,30 @@ +' +' 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 + +Function doUnitTest as String + + doUnitTest = "FAIL" + + ' CVERR + If (CVerr(100) <> 100) Then Exit Function + ' tdf#79426 - passing an error object to a function + If (TestCVErr(CVErr(2)) <> 2) Then Exit Function + ' tdf#79426 - test with Error-Code 448 ( ERRCODE_BASIC_NAMED_NOT_FOUND ) + If (TestCVErr(CVErr(448)) <> 448) Then Exit Function + + doUnitTest = "OK" + +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.bas b/basic/qa/basic_coverage/test_date_literal.bas new file mode 100644 index 000000000..3eb4510a3 --- /dev/null +++ b/basic/qa/basic_coverage/test_date_literal.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + If #07/28/1977# = 28334 And #1977-07-28# = 28334 Then + doUnitTest = "OK" + Else + doUnitTest = "FAIL" + End If +End Function diff --git a/basic/qa/basic_coverage/test_datedateadddatediff_methods.bas b/basic/qa/basic_coverage/test_datedateadddatediff_methods.bas new file mode 100644 index 000000000..6de53c011 --- /dev/null +++ b/basic/qa/basic_coverage/test_datedateadddatediff_methods.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + dim aDate as Date + aDate = Date() + ' DATE DATEDIFF DATEADD + If ( DateDiff( "d", aDate, DateAdd("d", 1, aDate) ) <> 1 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_datedatepartday_methods.bas b/basic/qa/basic_coverage/test_datedatepartday_methods.bas new file mode 100644 index 000000000..b81e96422 --- /dev/null +++ b/basic/qa/basic_coverage/test_datedatepartday_methods.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + dim aDate as Date + aDate = Date() + ' DATEPART DAY + If ( DatePart( "d", aDate ) <> Day( aDate ) ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_declare_from_dll.bas b/basic/qa/basic_coverage/test_declare_from_dll.bas new file mode 100644 index 000000000..7bdd1b170 --- /dev/null +++ b/basic/qa/basic_coverage/test_declare_from_dll.bas @@ -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/. +' + +Option Explicit + +' We link to shlwapi in many places, so safe to rely on it here +Declare Function PathFindExtensionA Lib "Shlwapi" (ByVal pszPath As String) As String + +Function doUnitTest() As String + TestUtil.TestInit + verify_testPathFindExtensionA + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_testPathFindExtensionA() + On Error GoTo errorHandler + + ' Only test on Windows + If (GetGUIType() <> 1) Then + TestUtil.Assert(True) ' The test passed + Exit Sub + End If + + ' Without the fix for tdf#147364 in place, the next call would crash in 64-bit version with + ' *** Exception 0xc0000005 occurred *** + TestUtil.AssertEqual(PathFindExtensionA("filename.ext"), ".ext", "PathFindExtensionA(""filename.ext"")") + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_testPathFindExtensionA", Err, Error$, Erl) +End Sub diff --git a/basic/qa/basic_coverage/test_dimarray_method.bas b/basic/qa/basic_coverage/test_dimarray_method.bas new file mode 100644 index 000000000..c5f268b12 --- /dev/null +++ b/basic/qa/basic_coverage/test_dimarray_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + Dim aValue as variant + aValue = DimArray( 1, 2, 4 ) + aValue( 1, 2, 4 ) = 3 + ' DIMARRAY + If ( aValue( 1, 2, 4 ) <> 3 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_empty_parameter.bas b/basic/qa/basic_coverage/test_empty_parameter.bas new file mode 100644 index 000000000..913f8e0cc --- /dev/null +++ b/basic/qa/basic_coverage/test_empty_parameter.bas @@ -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 String + ' 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 = "OK"
+ Else
+ doUnitTest = "FAIL"
+ End If
+End Function diff --git a/basic/qa/basic_coverage/test_environ_method.bas b/basic/qa/basic_coverage/test_environ_method.bas new file mode 100644 index 000000000..4504a3feb --- /dev/null +++ b/basic/qa/basic_coverage/test_environ_method.bas @@ -0,0 +1,14 @@ +' 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 + +Function doUnitTest as String + ' ENVIRON + Environ ("TMP") + doUnitTest = "OK" +End Function diff --git a/basic/qa/basic_coverage/test_equalunoobjects_method.bas b/basic/qa/basic_coverage/test_equalunoobjects_method.bas new file mode 100644 index 000000000..9e7666ae5 --- /dev/null +++ b/basic/qa/basic_coverage/test_equalunoobjects_method.bas @@ -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 String + ' EqualUnoObjects + ' Copy of objects -> same instance + oIntrospection = CreateUnoService( "com.sun.star.beans.Introspection" ) + oIntro2 = oIntrospection + If ( EqualUnoObjects( oIntrospection, oIntro2 ) = False ) Then + doUnitTest = "FAIL" + 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 = "FAIL" + Else + doUnitTest = "OK" + End If + End If +End Function diff --git a/basic/qa/basic_coverage/test_erl_method.bas b/basic/qa/basic_coverage/test_erl_method.bas new file mode 100644 index 000000000..ab834650c --- /dev/null +++ b/basic/qa/basic_coverage/test_erl_method.bas @@ -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 String + ' ERL + On Error GoTo ErrorHandler ' Set up error handler + Dim nVar As Integer + nVar = 0 + nVar = 1/nVar + doUnitTest = "FAIL" + Exit Function +ErrorHandler: + If ( Erl <> 13 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + Endif +End Function diff --git a/basic/qa/basic_coverage/test_err_method.bas b/basic/qa/basic_coverage/test_err_method.bas new file mode 100644 index 000000000..9732a25e6 --- /dev/null +++ b/basic/qa/basic_coverage/test_err_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' ERR + On Error GoTo ErrorHandler ' Set up error handler + Dim nVar As Integer + nVar = 0 + nVar = 1/nVar + doUnitTest = "FAIL" + Exit Function +ErrorHandler: + If ( Err <> 11 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + Endif +End Function diff --git a/basic/qa/basic_coverage/test_falsetrue_method.bas b/basic/qa/basic_coverage/test_falsetrue_method.bas new file mode 100644 index 000000000..10ef7d5fb --- /dev/null +++ b/basic/qa/basic_coverage/test_falsetrue_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' FALSE TRUE + If (False = True) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_filedatetime_nonexistent.bas b/basic/qa/basic_coverage/test_filedatetime_nonexistent.bas new file mode 100644 index 000000000..4478ba416 --- /dev/null +++ b/basic/qa/basic_coverage/test_filedatetime_nonexistent.bas @@ -0,0 +1,23 @@ +' 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 + +Option Explicit + +Function doUnitTest as String + On Error GoTo ErrorHandler ' Set up error handler + Dim result + result = FileDateTime("/bogus/unix/path") + doUnitTest = "FAIL" + Exit Function +ErrorHandler: + If ( Err <> 0 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + Endif +End Function diff --git a/basic/qa/basic_coverage/test_filedatetime_nonexistent2.bas b/basic/qa/basic_coverage/test_filedatetime_nonexistent2.bas new file mode 100644 index 000000000..e95fde34e --- /dev/null +++ b/basic/qa/basic_coverage/test_filedatetime_nonexistent2.bas @@ -0,0 +1,23 @@ +' 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 + +Option Explicit + +Function doUnitTest as String + On Error GoTo ErrorHandler ' Set up error handler + Dim result + result = FileDateTime("\\bogus\smb\path") + doUnitTest = "FAIL" + Exit Function +ErrorHandler: + If ( Err <> 0 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + Endif +End Function diff --git a/basic/qa/basic_coverage/test_fix_method.bas b/basic/qa/basic_coverage/test_fix_method.bas new file mode 100644 index 000000000..7ec5c4ac6 --- /dev/null +++ b/basic/qa/basic_coverage/test_fix_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' FIX + If (Fix(PI) <> 3) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_for_each.bas b/basic/qa/basic_coverage/test_for_each.bas new file mode 100644 index 000000000..3d9b74c27 --- /dev/null +++ b/basic/qa/basic_coverage/test_for_each.bas @@ -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 String + 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 = "OK" +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.bas b/basic/qa/basic_coverage/test_frac_method.bas new file mode 100644 index 000000000..73763f4ee --- /dev/null +++ b/basic/qa/basic_coverage/test_frac_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' FRAC + If ( 3+Frac(PI) <> PI) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_freefile_method.bas b/basic/qa/basic_coverage/test_freefile_method.bas new file mode 100644 index 000000000..03180b7df --- /dev/null +++ b/basic/qa/basic_coverage/test_freefile_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' FREEFILE + If ( FreeFile < 0 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_freelibrary_method.bas b/basic/qa/basic_coverage/test_freelibrary_method.bas new file mode 100644 index 000000000..6dc399de3 --- /dev/null +++ b/basic/qa/basic_coverage/test_freelibrary_method.bas @@ -0,0 +1,14 @@ +' 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 + +Function doUnitTest as String + ' FREELIBRARY + FreeLibrary("") + doUnitTest = "OK" +End Function diff --git a/basic/qa/basic_coverage/test_getdefaultcontext_method.bas b/basic/qa/basic_coverage/test_getdefaultcontext_method.bas new file mode 100644 index 000000000..7eb12dde4 --- /dev/null +++ b/basic/qa/basic_coverage/test_getdefaultcontext_method.bas @@ -0,0 +1,14 @@ +' 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 + +Function doUnitTest as String + ' GetDefaultContext + GetDefaultContext() + doUnitTest = "OK" +End Function diff --git a/basic/qa/basic_coverage/test_getdialogzoomfactorx_method.bas b/basic/qa/basic_coverage/test_getdialogzoomfactorx_method.bas new file mode 100644 index 000000000..989f7ba7a --- /dev/null +++ b/basic/qa/basic_coverage/test_getdialogzoomfactorx_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' GETDIALOGFACTORX + If ( GetDialogZoomFactorX(100) < 0 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_getdialogzoomfactory_method.bas b/basic/qa/basic_coverage/test_getdialogzoomfactory_method.bas new file mode 100644 index 000000000..207447aef --- /dev/null +++ b/basic/qa/basic_coverage/test_getdialogzoomfactory_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' GETDIALOGFACTORY + If ( GetDialogZoomFactorY(100) < 0 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_getguitype_method.bas b/basic/qa/basic_coverage/test_getguitype_method.bas new file mode 100644 index 000000000..76c136c58 --- /dev/null +++ b/basic/qa/basic_coverage/test_getguitype_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' GETGUITYPE + If ( GetGuiType = 0 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_getguiversion_method.bas b/basic/qa/basic_coverage/test_getguiversion_method.bas new file mode 100644 index 000000000..deccf9527 --- /dev/null +++ b/basic/qa/basic_coverage/test_getguiversion_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' GETGUIVERSION + If ( GetGuiVersion = 0 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_getpathseparator_method.bas b/basic/qa/basic_coverage/test_getpathseparator_method.bas new file mode 100644 index 000000000..3d9b74441 --- /dev/null +++ b/basic/qa/basic_coverage/test_getpathseparator_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' GETPATHSEPARATOR + If ( GetPathSeparator = "" ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_getprocessservicemanager_method.bas b/basic/qa/basic_coverage/test_getprocessservicemanager_method.bas new file mode 100644 index 000000000..5e202bd72 --- /dev/null +++ b/basic/qa/basic_coverage/test_getprocessservicemanager_method.bas @@ -0,0 +1,14 @@ +' 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 + +Function doUnitTest as String + ' GetProcessServiceManager + GetProcessServiceManager() + doUnitTest = "OK" +End Function diff --git a/basic/qa/basic_coverage/test_getsolarversion_method.bas b/basic/qa/basic_coverage/test_getsolarversion_method.bas new file mode 100644 index 000000000..f48a5703e --- /dev/null +++ b/basic/qa/basic_coverage/test_getsolarversion_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' GetSolarVersion + If ( GetSolarVersion() < 50000) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_getsystemtype_method.bas b/basic/qa/basic_coverage/test_getsystemtype_method.bas new file mode 100644 index 000000000..93a9a9ceb --- /dev/null +++ b/basic/qa/basic_coverage/test_getsystemtype_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' GETSYSTEMTYPE + If ( GetSystemType <> -1 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_hasunointerfaces_method.bas b/basic/qa/basic_coverage/test_hasunointerfaces_method.bas new file mode 100644 index 000000000..5f0f63832 --- /dev/null +++ b/basic/qa/basic_coverage/test_hasunointerfaces_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' HASUNOINTERFACES + dim aObject as Object + If ( HasUnoInterfaces( aObject, "com.sun.star.beans.XIntrospection" ) ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_hex_method.bas b/basic/qa/basic_coverage/test_hex_method.bas new file mode 100644 index 000000000..8bfcb1c36 --- /dev/null +++ b/basic/qa/basic_coverage/test_hex_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' HEX + If ( Hex(100) <> "64") Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_hour_method.bas b/basic/qa/basic_coverage/test_hour_method.bas new file mode 100644 index 000000000..16f1bdc9d --- /dev/null +++ b/basic/qa/basic_coverage/test_hour_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' HOUR + If ( Hour(TimeSerial(12,30,41)) <> 12 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_iif_method.bas b/basic/qa/basic_coverage/test_iif_method.bas new file mode 100644 index 000000000..b6003d052 --- /dev/null +++ b/basic/qa/basic_coverage/test_iif_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' IIF + If ( IIF(True, 10, 12) <> 10 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_instr_method.bas b/basic/qa/basic_coverage/test_instr_method.bas new file mode 100644 index 000000000..9e4545bb3 --- /dev/null +++ b/basic/qa/basic_coverage/test_instr_method.bas @@ -0,0 +1,30 @@ +' 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 + +Function doUnitTest as String + + doUnitTest = "FAIL" + + Dim aString As Variant + aString = "Hello" + ' InStr + If (InStr(1, aString, "l", 1) <> 3) Then Exit Function + + ' tdf#139840 - case-insensitive operation for non-ASCII characters + If (InStr(1, "α", "Α", 1) <> 1) Then Exit Function + ' tdf#139840 - German Eszett is uppercased to a two-character 'SS'. + ' This test should fail after tdf#110003 has been fixed. + If (InStr(2, "Straße", "s", 1) <> 5) Then Exit Function + + ' Start position is greater than the length of the string being searched. + If (InStr(2, "α", "Α", 1) <> 0) Then Exit Function + + doUnitTest = "OK" + +End Function diff --git a/basic/qa/basic_coverage/test_int_method.bas b/basic/qa/basic_coverage/test_int_method.bas new file mode 100644 index 000000000..563fd5898 --- /dev/null +++ b/basic/qa/basic_coverage/test_int_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' INT + If ( Int(PI) <> 3 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_isarray_method.bas b/basic/qa/basic_coverage/test_isarray_method.bas new file mode 100644 index 000000000..f3080d5fc --- /dev/null +++ b/basic/qa/basic_coverage/test_isarray_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + dim aVector as Variant + aVector = Array( 123, "Hello", -3.14) + ' ISARRAY + If ( IsArray( aVector ) = False ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_isdate_method.bas b/basic/qa/basic_coverage/test_isdate_method.bas new file mode 100644 index 000000000..f4f0dfa6f --- /dev/null +++ b/basic/qa/basic_coverage/test_isdate_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + dim aDate as Date + aDate = Date( ) + ' ISDATE + If ( IsDate( aDate ) = False ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_isempty_method.bas b/basic/qa/basic_coverage/test_isempty_method.bas new file mode 100644 index 000000000..3ea6a4a14 --- /dev/null +++ b/basic/qa/basic_coverage/test_isempty_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + dim aVariant as Variant + aVariant = Date( ) + ' ISEMPTY + If ( IsEmpty( aVariant ) ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_iserror_method.bas b/basic/qa/basic_coverage/test_iserror_method.bas new file mode 100644 index 000000000..83d3f6043 --- /dev/null +++ b/basic/qa/basic_coverage/test_iserror_method.bas @@ -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/. +' + +Option Explicit + +Type MyType + tName as String +End Type + +Function doUnitTest as String + dim aVariant as MyType + aVariant.tName = "A string" + ' ISERROR + If ( IsError( aVariant ) ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_ismissing_basic.bas b/basic/qa/basic_coverage/test_ismissing_basic.bas new file mode 100644 index 000000000..ed43a3ad1 --- /dev/null +++ b/basic/qa/basic_coverage/test_ismissing_basic.bas @@ -0,0 +1,168 @@ +Const IsMissingNone = -1 +Const IsMissingA = 0 +Const IsMissingB = 1 +Const IsMissingAB = 2 + +Option Explicit + +Function doUnitTest() As String + TestUtil.TestInit + verify_testIsMissingBasic + doUnitTest = TestUtil.GetResult() +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. +Sub verify_testIsMissingBasic() + + On Error GoTo errorHandler + + ' optionals with variant datatypes + TestUtil.AssertEqual(TestOptVariant(), IsMissingAB, "TestOptVariant()") + TestUtil.AssertEqual(TestOptVariant(123), IsMissingB, "TestOptVariant(123)") + TestUtil.AssertEqual(TestOptVariant(, 456), IsMissingA, "TestOptVariant(, 456)") + TestUtil.AssertEqual(TestOptVariant(123, 456), IsMissingNone, "TestOptVariant(123, 456)") + + ' optionals with variant datatypes (ByRef and ByVal) + TestUtil.AssertEqual(TestOptVariantByRefByVal(), IsMissingAB, "TestOptVariantByRefByVal()") + TestUtil.AssertEqual(TestOptVariantByRefByVal(123), IsMissingB, "TestOptVariantByRefByVal(123)") + TestUtil.AssertEqual(TestOptVariantByRefByVal(, 456), IsMissingA, "TestOptVariantByRefByVal(, 456)") + TestUtil.AssertEqual(TestOptVariantByRefByVal(123, 456), IsMissingNone, "TestOptVariantByRefByVal(123, 456)") + + ' optionals with double datatypes + TestUtil.AssertEqual(TestOptDouble(), IsMissingAB, "TestOptDouble()") + TestUtil.AssertEqual(TestOptDouble(123.4), IsMissingB, "TestOptDouble(123.4)") + TestUtil.AssertEqual(TestOptDouble(, 567.8), IsMissingA, "TestOptDouble(, 567.8)") + TestUtil.AssertEqual(TestOptDouble(123.4, 567.8), IsMissingNone, "TestOptDouble(123.4, 567.8)") + + ' optionals with double datatypes (ByRef and ByVal) + TestUtil.AssertEqual(TestOptDoubleByRefByVal(), IsMissingAB, "TestOptDouble()") + TestUtil.AssertEqual(TestOptDoubleByRefByVal(123.4), IsMissingB, "TestOptDouble(123.4)") + TestUtil.AssertEqual(TestOptDoubleByRefByVal(, 567.8), IsMissingA, "TestOptDoubleByRefByVal(, 567.8)") + TestUtil.AssertEqual(TestOptDoubleByRefByVal(123.4, 567.8), IsMissingNone, "TestOptDoubleByRefByVal(123.4, 567.8)") + + ' optionals with integer datatypes + TestUtil.AssertEqual(TestOptInteger(), IsMissingAB, "TestOptInteger()") + TestUtil.AssertEqual(TestOptInteger(123), IsMissingB, "TestOptInteger(123)") + TestUtil.AssertEqual(TestOptInteger(, 456), IsMissingA, "TestOptInteger(, 456)") + TestUtil.AssertEqual(TestOptInteger(123, 456), IsMissingNone, "TestOptInteger(123, 456)") + + ' optionals with integer datatypes (ByRef and ByVal) + TestUtil.AssertEqual(TestOptIntegerByRefByVal(), IsMissingAB, "TestOptIntegerByRefByVal()") + TestUtil.AssertEqual(TestOptIntegerByRefByVal(123), IsMissingB, "TestOptIntegerByRefByVal(123)") + TestUtil.AssertEqual(TestOptIntegerByRefByVal(, 456), IsMissingA, "TestOptIntegerByRefByVal(, 456)") + TestUtil.AssertEqual(TestOptIntegerByRefByVal(123, 456), IsMissingNone, "TestOptIntegerByRefByVal(123, 456)") + + ' optionals with string datatypes + TestUtil.AssertEqual(TestOptString(), IsMissingAB, "TestOptString()") + TestUtil.AssertEqual(TestOptString("123"), IsMissingB, "TestOptString(""123"")") + TestUtil.AssertEqual(TestOptString(, "456"), IsMissingA, "TestOptString(, ""456"")") + TestUtil.AssertEqual(TestOptString("123", "456"), IsMissingNone, "TestOptString(""123"", ""456"")") + + ' optionals with string datatypes (ByRef and ByVal) + TestUtil.AssertEqual(TestOptStringByRefByVal(), IsMissingAB, "TestOptStringByRefByVal()") + TestUtil.AssertEqual(TestOptStringByRefByVal("123"), IsMissingB, "TestOptStringByRefByVal(""123"")") + TestUtil.AssertEqual(TestOptStringByRefByVal(, "456"), IsMissingA, "TestOptStringByRefByVal(, ""456"")") + TestUtil.AssertEqual(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) + TestUtil.AssertEqual(TestOptObject(), IsMissingAB, "TestOptObject()") + TestUtil.AssertEqual(TestOptObject(cA), IsMissingB, "TestOptObject(A)") + TestUtil.AssertEqual(TestOptObject(, cB), IsMissingA, "TestOptObject(, B)") + TestUtil.AssertEqual(TestOptObject(cA, cB), IsMissingNone, "TestOptObject(A, B)") + + ' optionals with object datatypes (ByRef and ByVal) + TestUtil.AssertEqual(TestOptObjectByRefByVal(), IsMissingAB, "TestOptObjectByRefByVal()") + TestUtil.AssertEqual(TestOptObjectByRefByVal(cA), IsMissingB, "TestOptObjectByRefByVal(A)") + TestUtil.AssertEqual(TestOptObjectByRefByVal(, cB), IsMissingA, "TestOptObjectByRefByVal(, B)") + TestUtil.AssertEqual(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 + TestUtil.AssertEqual(TestOptArray(), IsMissingAB, "TestOptArray()") + TestUtil.AssertEqual(TestOptArray(aA), IsMissingB, "TestOptArray(A)") + TestUtil.AssertEqual(TestOptArray(, aB), IsMissingA, "TestOptArray(, B)") + TestUtil.AssertEqual(TestOptArray(aA, aB), IsMissingNone, "TestOptArray(A, B)") + + ' optionals with array datatypes (ByRef and ByVal) + TestUtil.AssertEqual(TestOptArrayByRefByVal(), IsMissingAB, "TestOptArrayByRefByVal()") + TestUtil.AssertEqual(TestOptArrayByRefByVal(aA), IsMissingB, "TestOptArrayByRefByVal(A)") + TestUtil.AssertEqual(TestOptArrayByRefByVal(, aB), IsMissingA, "TestOptArrayByRefByVal(, B)") + TestUtil.AssertEqual(TestOptArrayByRefByVal(aA, aB), IsMissingNone, "TestOptArrayByRefByVal(A, B)") + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_testIsMissingBasic", Err, Error$, Erl) +End Sub + +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 diff --git a/basic/qa/basic_coverage/test_ismissing_cascade.bas b/basic/qa/basic_coverage/test_ismissing_cascade.bas new file mode 100644 index 000000000..f2f3a8b20 --- /dev/null +++ b/basic/qa/basic_coverage/test_ismissing_cascade.bas @@ -0,0 +1,29 @@ +Option Explicit + +Function doUnitTest() As String + TestUtil.TestInit + verify_testIsMissingCascade + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_testIsMissingCascade() + + 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. + TestUtil.AssertEqual(TestOpt(), 2, "Cascading optionals") + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_testIsMissingCascade", Err, Error$, Erl) +End Sub + +Function TestOpt(Optional A) + TestOpt = TestOptCascade(A) +End Function + +Function TestOptCascade(Optional A) + If IsMissing(A) Then A = 2 + TestOptCascade = A +End Function diff --git a/basic/qa/basic_coverage/test_ismissing_compatible.bas b/basic/qa/basic_coverage/test_ismissing_compatible.bas new file mode 100644 index 000000000..fb7e6981d --- /dev/null +++ b/basic/qa/basic_coverage/test_ismissing_compatible.bas @@ -0,0 +1,168 @@ +Option Compatible +Option Explicit +Const IsMissingNone = -1 +Const IsMissingA = 0 +Const IsMissingB = 1 +Const IsMissingAB = 2 + +Function doUnitTest() As String + TestUtil.TestInit + verify_testIsMissingCompatible + doUnitTest = TestUtil.GetResult() +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. +Sub verify_testIsMissingCompatible() + On Error GoTo errorHandler + + ' optionals with variant datatypes + TestUtil.AssertEqual(TestOptVariant(), IsMissingA, "TestOptVariant()") + TestUtil.AssertEqual(TestOptVariant(123), IsMissingNone, "TestOptVariant(123)") + TestUtil.AssertEqual(TestOptVariant(, 456), IsMissingA, "TestOptVariant(, 456)") + TestUtil.AssertEqual(TestOptVariant(123, 456), IsMissingNone, "TestOptVariant(123, 456)") + + ' optionals with variant datatypes (ByRef and ByVal) + TestUtil.AssertEqual(TestOptVariantByRefByVal(), IsMissingA, "TestOptVariantByRefByVal()") + TestUtil.AssertEqual(TestOptVariantByRefByVal(123), IsMissingNone, "TestOptVariantByRefByVal(123)") + TestUtil.AssertEqual(TestOptVariantByRefByVal(, 456), IsMissingA, "TestOptVariantByRefByVal(, 456)") + TestUtil.AssertEqual(TestOptVariantByRefByVal(123, 456), IsMissingNone, "TestOptVariantByRefByVal(123, 456)") + + ' optionals with double datatypes + TestUtil.AssertEqual(TestOptDouble(), IsMissingA, "TestOptDouble()") + TestUtil.AssertEqual(TestOptDouble(123.4), IsMissingNone, "TestOptDouble(123.4)") + TestUtil.AssertEqual(TestOptDouble(, 567.8), IsMissingA, "TestOptDouble(, 567.8)") + TestUtil.AssertEqual(TestOptDouble(123.4, 567.8), IsMissingNone, "TestOptDouble(123.4, 567.8)") + + ' optionals with double datatypes (ByRef and ByVal) + TestUtil.AssertEqual(TestOptDoubleByRefByVal(), IsMissingA, "TestOptDouble()") + TestUtil.AssertEqual(TestOptDoubleByRefByVal(123.4), IsMissingNone, "TestOptDouble(123.4)") + TestUtil.AssertEqual(TestOptDoubleByRefByVal(, 567.8), IsMissingA, "TestOptDoubleByRefByVal(, 567.8)") + TestUtil.AssertEqual(TestOptDoubleByRefByVal(123.4, 567.8), IsMissingNone, "TestOptDoubleByRefByVal(123.4, 567.8)") + + ' optionals with integer datatypes + TestUtil.AssertEqual(TestOptInteger(), IsMissingA, "TestOptInteger()") + TestUtil.AssertEqual(TestOptInteger(123), IsMissingNone, "TestOptInteger(123)") + TestUtil.AssertEqual(TestOptInteger(, 456), IsMissingA, "TestOptInteger(, 456)") + TestUtil.AssertEqual(TestOptInteger(123, 456), IsMissingNone, "TestOptInteger(123, 456)") + + ' optionals with integer datatypes (ByRef and ByVal) + TestUtil.AssertEqual(TestOptIntegerByRefByVal(), IsMissingA, "TestOptIntegerByRefByVal()") + TestUtil.AssertEqual(TestOptIntegerByRefByVal(123), IsMissingNone, "TestOptIntegerByRefByVal(123)") + TestUtil.AssertEqual(TestOptIntegerByRefByVal(, 456), IsMissingA, "TestOptIntegerByRefByVal(, 456)") + TestUtil.AssertEqual(TestOptIntegerByRefByVal(123, 456), IsMissingNone, "TestOptIntegerByRefByVal(123, 456)") + + ' optionals with string datatypes + TestUtil.AssertEqual(TestOptString(), IsMissingA, "TestOptString()") + TestUtil.AssertEqual(TestOptString("123"), IsMissingNone, "TestOptString(""123"")") + TestUtil.AssertEqual(TestOptString(, "456"), IsMissingA, "TestOptString(, ""456"")") + TestUtil.AssertEqual(TestOptString("123", "456"), IsMissingNone, "TestOptString(""123"", ""456"")") + + ' optionals with string datatypes (ByRef and ByVal) + TestUtil.AssertEqual(TestOptStringByRefByVal(), IsMissingA, "TestOptStringByRefByVal()") + TestUtil.AssertEqual(TestOptStringByRefByVal("123"), IsMissingNone, "TestOptStringByRefByVal(""123"")") + TestUtil.AssertEqual(TestOptStringByRefByVal(, "456"), IsMissingA, "TestOptStringByRefByVal(, ""456"")") + TestUtil.AssertEqual(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) + TestUtil.AssertEqual(TestOptObject(), IsMissingAB, "TestOptObject()") + TestUtil.AssertEqual(TestOptObject(cA), IsMissingB, "TestOptObject(A)") + TestUtil.AssertEqual(TestOptObject(, cB), IsMissingA, "TestOptObject(, B)") + TestUtil.AssertEqual(TestOptObject(cA, cB), IsMissingNone, "TestOptObject(A, B)") + + ' optionals with object datatypes (ByRef and ByVal) + TestUtil.AssertEqual(TestOptObjectByRefByVal(), IsMissingAB, "TestOptObjectByRefByVal()") + TestUtil.AssertEqual(TestOptObjectByRefByVal(cA), IsMissingB, "TestOptObjectByRefByVal(A)") + TestUtil.AssertEqual(TestOptObjectByRefByVal(, cB), IsMissingA, "TestOptObjectByRefByVal(, B)") + TestUtil.AssertEqual(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 + TestUtil.AssertEqual(TestOptArray(), IsMissingAB, "TestOptArray()") + TestUtil.AssertEqual(TestOptArray(aA), IsMissingB, "TestOptArray(A)") + TestUtil.AssertEqual(TestOptArray(, aB), IsMissingA, "TestOptArray(, B)") + TestUtil.AssertEqual(TestOptArray(aA, aB), IsMissingNone, "TestOptArray(A, B)") + + ' optionals with array datatypes (ByRef and ByVal) + TestUtil.AssertEqual(TestOptArrayByRefByVal(), IsMissingAB, "TestOptArrayByRefByVal()") + TestUtil.AssertEqual(TestOptArrayByRefByVal(aA), IsMissingB, "TestOptArrayByRefByVal(A)") + TestUtil.AssertEqual(TestOptArrayByRefByVal(, aB), IsMissingA, "TestOptArrayByRefByVal(, B)") + TestUtil.AssertEqual(TestOptArrayByRefByVal(aA, aB), IsMissingNone, "TestOptArrayByRefByVal(A, B)") + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_testIsMissingCompatible", Err, Error$, Erl) +End Sub + +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 diff --git a/basic/qa/basic_coverage/test_isnull_method.bas b/basic/qa/basic_coverage/test_isnull_method.bas new file mode 100644 index 000000000..28000e9fb --- /dev/null +++ b/basic/qa/basic_coverage/test_isnull_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + dim aVariant as Variant + aVariant = Null + ' ISNULL + If ( IsNull( aVariant ) = False ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_isnumeric_method.bas b/basic/qa/basic_coverage/test_isnumeric_method.bas new file mode 100644 index 000000000..1b454aa8d --- /dev/null +++ b/basic/qa/basic_coverage/test_isnumeric_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + dim aVariant as Variant + aVariant = 3 + ' ISNUMERIC + If ( IsNumeric( aVariant ) = False ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_isobject_method.bas b/basic/qa/basic_coverage/test_isobject_method.bas new file mode 100644 index 000000000..1299b3a88 --- /dev/null +++ b/basic/qa/basic_coverage/test_isobject_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + dim aVariant as Object + ' ISOBJECT + If ( IsObject( aVariant ) = False ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_isunostruct_method.bas b/basic/qa/basic_coverage/test_isunostruct_method.bas new file mode 100644 index 000000000..85b6ab27d --- /dev/null +++ b/basic/qa/basic_coverage/test_isunostruct_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + dim aVariant as Object + ' ISUNOSTRUCT + If ( IsUnoStruct( aVariant ) ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_join_method.bas b/basic/qa/basic_coverage/test_join_method.bas new file mode 100644 index 000000000..9076a0f8d --- /dev/null +++ b/basic/qa/basic_coverage/test_join_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' Join + Dim aStrings(2) as String + aStrings(0) = "Hello" + aStrings(1) = "world" + If ( Join( aStrings, " " ) <> "Hello world " ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_lbound_method.bas b/basic/qa/basic_coverage/test_lbound_method.bas new file mode 100644 index 000000000..b79b60410 --- /dev/null +++ b/basic/qa/basic_coverage/test_lbound_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + dim aVector as Variant + ' ARRAY + aVector = Array( "Hello", -3.14) + ' LBOUND + If ( LBound( aVector() ) <> 0 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_lcase_method.bas b/basic/qa/basic_coverage/test_lcase_method.bas new file mode 100644 index 000000000..9e2a2af66 --- /dev/null +++ b/basic/qa/basic_coverage/test_lcase_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + dim aString as Variant + aString = "Hello" + ' LCASE + If ( LCase( aString ) <> "hello" ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_len_method.bas b/basic/qa/basic_coverage/test_len_method.bas new file mode 100644 index 000000000..58211fc93 --- /dev/null +++ b/basic/qa/basic_coverage/test_len_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + dim aString as Variant + aString = "Hello" + ' LEN + If ( Len( aString ) <> 5 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_lenb_method.bas b/basic/qa/basic_coverage/test_lenb_method.bas new file mode 100644 index 000000000..2a907e209 --- /dev/null +++ b/basic/qa/basic_coverage/test_lenb_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + dim aString as Variant + aString = "Hello" + ' LENB + If ( LenB( aString ) <> 5 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_logexp_methods.bas b/basic/qa/basic_coverage/test_logexp_methods.bas new file mode 100644 index 000000000..c120f7218 --- /dev/null +++ b/basic/qa/basic_coverage/test_logexp_methods.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' EXP LOG + If ( Log( Exp(1) ) <> 1 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_ltrim_method.bas b/basic/qa/basic_coverage/test_ltrim_method.bas new file mode 100644 index 000000000..3395f5f24 --- /dev/null +++ b/basic/qa/basic_coverage/test_ltrim_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + dim aString as Variant + aString = "Hello" + ' LTRIM + If ( LTrim( " Hello" ) <> aString ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_method_name_variable.bas b/basic/qa/basic_coverage/test_method_name_variable.bas new file mode 100644 index 000000000..da9e83bca --- /dev/null +++ b/basic/qa/basic_coverage/test_method_name_variable.bas @@ -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 Explicit + +Function assignVarToMethod() As Integer + + ' method name used as dimension specifier + Dim fieldOfLongs() As Long + ReDim fieldOfLongs(assignVarToMethod) As Long + + ' method name used as loop index + Dim sum As Integer + For assignVarToMethod = 1 To 3 + sum = sum + assignVarToMethod + Next assignVarToMethod + assignVarToMethod = sum + +End Function + +Function doUnitTest() As String + + doUnitTest = "FAIL" + + ' tdf#85371 - check if the name of the method can be used as a variable in certain statements + If (assignVarToMethod() <> 6) Then Exit Function + ' tdf#85371 - check if an assignment to the function fails outside of the function itself + assignVarToMethod = 0 + If (assignVarToMethod() <> 6) Then Exit Function + + doUnitTest = "OK" + +End Function diff --git a/basic/qa/basic_coverage/test_mid_CountNegative_3args.bas b/basic/qa/basic_coverage/test_mid_CountNegative_3args.bas new file mode 100644 index 000000000..3df3ae741 --- /dev/null +++ b/basic/qa/basic_coverage/test_mid_CountNegative_3args.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + If (Mid("abc", 5, -3) = "") Then + doUnitTest = "OK" + Else + doUnitTest = "FAIL" + End If +End Function diff --git a/basic/qa/basic_coverage/test_mid_EndOutOfBounds_3args.bas b/basic/qa/basic_coverage/test_mid_EndOutOfBounds_3args.bas new file mode 100644 index 000000000..525a9cd2a --- /dev/null +++ b/basic/qa/basic_coverage/test_mid_EndOutOfBounds_3args.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + If (Mid("abc", 1, 4) = "abc") Then + doUnitTest = "OK" + Else + doUnitTest = "FAIL" + End If +End Function diff --git a/basic/qa/basic_coverage/test_mid_StartOutOfBounds_2args.bas b/basic/qa/basic_coverage/test_mid_StartOutOfBounds_2args.bas new file mode 100644 index 000000000..89c6cd309 --- /dev/null +++ b/basic/qa/basic_coverage/test_mid_StartOutOfBounds_2args.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + If (Mid("abc", 5) = "") Then + doUnitTest = "OK" + Else + doUnitTest = "FAIL" + End If +End Function diff --git a/basic/qa/basic_coverage/test_mid_StartOutOfBounds_3args.bas b/basic/qa/basic_coverage/test_mid_StartOutOfBounds_3args.bas new file mode 100644 index 000000000..1f538788b --- /dev/null +++ b/basic/qa/basic_coverage/test_mid_StartOutOfBounds_3args.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + If (Mid("abc", 5, 1) = "") Then + doUnitTest = "OK" + Else + doUnitTest = "FAIL" + End If +End Function diff --git a/basic/qa/basic_coverage/test_mid_firstletter_3args.bas b/basic/qa/basic_coverage/test_mid_firstletter_3args.bas new file mode 100644 index 000000000..e9bcb1378 --- /dev/null +++ b/basic/qa/basic_coverage/test_mid_firstletter_3args.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + If (Mid("abc", 1, 1) = "a") Then + doUnitTest = "OK" + Else + doUnitTest = "FAIL" + End If +End Function diff --git a/basic/qa/basic_coverage/test_mid_replace_less.bas b/basic/qa/basic_coverage/test_mid_replace_less.bas new file mode 100644 index 000000000..008856388 --- /dev/null +++ b/basic/qa/basic_coverage/test_mid_replace_less.bas @@ -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 String + s = "The lightbrown fox" + Mid(s, 5, 10, "lazy") + If (s = "The lazy fox") Then + doUnitTest = "OK" + Else + doUnitTest = "FAIL" + End If +End Function diff --git a/basic/qa/basic_coverage/test_mid_replace_more.bas b/basic/qa/basic_coverage/test_mid_replace_more.bas new file mode 100644 index 000000000..40b9ac337 --- /dev/null +++ b/basic/qa/basic_coverage/test_mid_replace_more.bas @@ -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 String + s = "The fox jumps" + Mid(s, 5, 3, "duck") + If (s = "The duc jumps") Then + doUnitTest = "OK" + Else + doUnitTest = "FAIL" + End If +End Function diff --git a/basic/qa/basic_coverage/test_mid_replace_more_end.bas b/basic/qa/basic_coverage/test_mid_replace_more_end.bas new file mode 100644 index 000000000..593cf1abb --- /dev/null +++ b/basic/qa/basic_coverage/test_mid_replace_more_end.bas @@ -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 String + s = "The fox jumps" + Mid(s, 5, 100, "cow jumped over") + If (s = "The cow jumpe") Then + doUnitTest = "OK" + Else + doUnitTest = "FAIL" + End If +End Function diff --git a/basic/qa/basic_coverage/test_mid_sub2letters_2args.bas b/basic/qa/basic_coverage/test_mid_sub2letters_2args.bas new file mode 100644 index 000000000..2cbb21ecf --- /dev/null +++ b/basic/qa/basic_coverage/test_mid_sub2letters_2args.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + If (Mid("abc", 2) = "bc") Then + doUnitTest = "OK" + Else + doUnitTest = "FAIL" + End If +End Function diff --git a/basic/qa/basic_coverage/test_minute_method.bas b/basic/qa/basic_coverage/test_minute_method.bas new file mode 100644 index 000000000..4f120cc3f --- /dev/null +++ b/basic/qa/basic_coverage/test_minute_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' MINUTE + If ( Minute(TimeSerial(12,30,41)) <> 30 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_mod_operator.bas b/basic/qa/basic_coverage/test_mod_operator.bas new file mode 100644 index 000000000..79ad49fda --- /dev/null +++ b/basic/qa/basic_coverage/test_mod_operator.bas @@ -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 Explicit + +Function doUnitTest as String + + doUnitTest = "FAIL" + + Dim a As Double, b as Double + a = 16.4 + b = 5.9 + + ' tdf#141201 - MOD operands are rounded to Integer values before the operation is performed + if (a MOD b <> 4) Then Exit Function + if (16.4 MOD 5.9 <> 4) Then Exit Function + if (15.9 MOD 6.4 <> 4) Then Exit Function + if (2147483647.4 MOD 4 <> 3) Then Exit Function + + doUnitTest = "OK" + +End Function diff --git a/basic/qa/basic_coverage/test_month_method.bas b/basic/qa/basic_coverage/test_month_method.bas new file mode 100644 index 000000000..cbef221c9 --- /dev/null +++ b/basic/qa/basic_coverage/test_month_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + dim aDate as Date + aDate = Date() + ' MONTH + If ( DatePart( "m", aDate ) <> Month( aDate ) ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_non_ascii_names.bas b/basic/qa/basic_coverage/test_non_ascii_names.bas new file mode 100644 index 000000000..c85c9cae1 --- /dev/null +++ b/basic/qa/basic_coverage/test_non_ascii_names.bas @@ -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 Explicit + +Function doUnitTest as String + [Prüfung] + doUnitTest = TestUtil.GetResult() +End Function + +Function [Функция]([😁]) + [Функция] = [😁] & " and some text" +End Function + +Function TestNonAsciiNative as Integer + Dim [Абв] as Integer + [Абв] = 5 + TestNonAsciiNative = [абв] +End Function + +Sub [Prüfung] + On Error GoTo errorHandler + + TestUtil.AssertEqual([Функция]("Smiley"), "Smiley and some text", "[Функция](""Smiley"")") + + ' tdf#148358 - compare Non-ASCII variable names case-insensitive + TestUtil.AssertEqual(TestNonAsciiNative(), 5, "TestNonAsciiNative()") + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("Prüfung", Err, Error$, Erl) +End Sub diff --git a/basic/qa/basic_coverage/test_non_ascii_names_compatible.bas b/basic/qa/basic_coverage/test_non_ascii_names_compatible.bas new file mode 100644 index 000000000..1abc27244 --- /dev/null +++ b/basic/qa/basic_coverage/test_non_ascii_names_compatible.bas @@ -0,0 +1,45 @@ +' +' 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 +Option Explicit + +Function doUnitTest as String + [Prüfung] + doUnitTest = TestUtil.GetResult() +End Function + +Function [Функция]([😁]) + [Функция] = [😁] & " and some text" +End Function + +Function TestNonAscii as Integer + Dim Абв as Integer + Абв = 10 + TestNonAscii = абв +End Function + +Function TestNonAsciiNative as Integer + Dim [Абв] as Integer + [Абв] = 5 + TestNonAsciiNative = [абв] +End Function + +Sub [Prüfung] + On Error GoTo errorHandler + + TestUtil.AssertEqual([Функция]("Smiley"), "Smiley and some text", "[Функция](""Smiley"")") + + ' tdf#148358 - compare Non-ASCII variable names case-insensitive + TestUtil.AssertEqual(TestNonAscii(), 10, "TestNonAscii()") + TestUtil.AssertEqual(TestNonAsciiNative(), 5, "TestNonAsciiNative()") + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("Prüfung Compatible", Err, Error$, Erl) +End Sub diff --git a/basic/qa/basic_coverage/test_nowtimevalue_methods.bas b/basic/qa/basic_coverage/test_nowtimevalue_methods.bas new file mode 100644 index 000000000..b99b9a383 --- /dev/null +++ b/basic/qa/basic_coverage/test_nowtimevalue_methods.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + dim aDate as Date + dim aTime as Date + aDate = Date() + aTime = Time() + ' NOW TIMEVALUE + If ( Now() < aDate + TimeValue(aTime) ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_numeric_constant_parameter.bas b/basic/qa/basic_coverage/test_numeric_constant_parameter.bas new file mode 100644 index 000000000..4f93f3f45 --- /dev/null +++ b/basic/qa/basic_coverage/test_numeric_constant_parameter.bas @@ -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 Explicit + +' 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 String + ' 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 = "OK"
+ Else
+ doUnitTest = "FAIL"
+ End If
+ Exit Function
+errorHandler:
+ doUnitTest = "FAIL" +End Function diff --git a/basic/qa/basic_coverage/test_oct_method.bas b/basic/qa/basic_coverage/test_oct_method.bas new file mode 100644 index 000000000..31028195b --- /dev/null +++ b/basic/qa/basic_coverage/test_oct_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' OCT + If ( Oct(100) <> "144" ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_option_base.bas b/basic/qa/basic_coverage/test_option_base.bas new file mode 100644 index 000000000..11afea50d --- /dev/null +++ b/basic/qa/basic_coverage/test_option_base.bas @@ -0,0 +1,43 @@ +Option Base 1 +Option Explicit + +Function doUnitTest() As String + TestUtil.TestInit + verify_optionBase + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_optionBase() As String + On Error GoTo errorHandler + + ' tdf#54912 - with option base arrays should start at index 1. + ' Without option compatible the upper bound is changed as well (#109275). + Dim strArray(2) As String + TestUtil.AssertEqual(LBound(strArray), 1, "Lower bound of a string array (before assignment): " & LBound(strArray)) + TestUtil.AssertEqual(UBound(strArray), 3, "Upper bound of a string array (before assignment): " & UBound(strArray)) + strArray = Array("a", "b") + TestUtil.AssertEqual(LBound(strArray), 1, "Lower bound of a string array (after assignment): " & LBound(strArray)) + TestUtil.AssertEqual(UBound(strArray), 2, "Upper bound of a string array (after assignment): " & UBound(strArray)) + + Dim intArray(2) As Integer + TestUtil.AssertEqual(LBound(intArray), 1, "Lower bound of an integer array (before assignment): " & LBound(intArray)) + TestUtil.AssertEqual(UBound(intArray), 3, "Upper bound of an integer array (before assignment): " & UBound(intArray)) + intArray = Array(1, 2) + TestUtil.AssertEqual(LBound(intArray), 1, "Lower bound of an integer array (after assignment): " & LBound(intArray)) + TestUtil.AssertEqual(UBound(intArray), 2, "Upper bound of an integer array (after assignment): " & UBound(intArray)) + + Dim byteArray(2) As Byte + TestUtil.AssertEqual(LBound(byteArray), 1, "Lower bound of a byte array (before assignment): " & LBound(byteArray)) + TestUtil.AssertEqual(UBound(byteArray), 3, "Upper bound of a byte array (before assignment): " & UBound(byteArray)) + byteArray = StrConv("ab", 128) + TestUtil.AssertEqual(LBound(byteArray), 1, "Lower bound of a byte array (StrConv): " & LBound(byteArray)) + TestUtil.AssertEqual(UBound(byteArray), 2, "Upper bound of a byte array (StrConv): " & UBound(byteArray)) + + ReDim byteArray(3) + TestUtil.AssertEqual(LBound(byteArray), 1, "Lower bound of a byte array (ReDim): " & LBound(byteArray)) + TestUtil.AssertEqual(UBound(byteArray), 4, "Upper bound of a byte array (ReDim): " & UBound(byteArray)) + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_optionBase", Err, Error$, Erl) +End Sub diff --git a/basic/qa/basic_coverage/test_option_base_compatible.bas b/basic/qa/basic_coverage/test_option_base_compatible.bas new file mode 100644 index 000000000..8001106a7 --- /dev/null +++ b/basic/qa/basic_coverage/test_option_base_compatible.bas @@ -0,0 +1,45 @@ +Option Base 1 +Option Compatible +Option Explicit + +Function doUnitTest() As String + TestUtil.TestInit + verify_optionBase + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_optionBase() + + On Error GoTo errorHandler + + ' tdf#54912 - with option base arrays should start at index 1. + ' With option compatible the upper bound is not changed (#109275). + Dim strArray(2) As String + TestUtil.AssertEqual(LBound(strArray), 1, "Lower bound of a string array (before assignment): " & LBound(strArray)) + TestUtil.AssertEqual(UBound(strArray), 2, "Upper bound of a string array (before assignment): " & UBound(strArray)) + strArray = Array("a", "b") + TestUtil.AssertEqual(LBound(strArray), 1, "Lower bound of a string array (after assignment): " & LBound(strArray)) + TestUtil.AssertEqual(UBound(strArray), 2, "Upper bound of a string array (after assignment): " & UBound(strArray)) + + Dim intArray(2) As Integer + TestUtil.AssertEqual(LBound(intArray), 1, "Lower bound of an integer array (before assignment): " & LBound(intArray)) + TestUtil.AssertEqual(UBound(intArray), 2, "Upper bound of an integer array (before assignment): " & UBound(intArray)) + intArray = Array(1, 2) + TestUtil.AssertEqual(LBound(intArray), 1, "Lower bound of an integer array (after assignment): " & LBound(intArray)) + TestUtil.AssertEqual(UBound(intArray), 2, "Upper bound of an integer array (after assignment): " & UBound(intArray)) + + Dim byteArray(2) As Byte + TestUtil.AssertEqual(LBound(byteArray), 1, "Lower bound of a byte array (before assignment): " & LBound(byteArray)) + TestUtil.AssertEqual(UBound(byteArray), 2, "Upper bound of a byte array (before assignment): " & UBound(byteArray)) + byteArray = StrConv("ab", 128) + TestUtil.AssertEqual(LBound(byteArray), 1, "Lower bound of a byte array (StrConv): " & LBound(byteArray)) + TestUtil.AssertEqual(UBound(byteArray), 2, "Upper bound of a byte array (StrConv): " & UBound(byteArray)) + + ReDim byteArray(3) + TestUtil.AssertEqual(LBound(byteArray), 1, "Lower bound of a byte array (ReDim): " & LBound(byteArray)) + TestUtil.AssertEqual(UBound(byteArray), 3, "Upper bound of a byte array (ReDim): " & UBound(byteArray)) + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_optionBase", Err, Error$, Erl) +End Sub diff --git a/basic/qa/basic_coverage/test_optional_paramter_type.bas b/basic/qa/basic_coverage/test_optional_paramter_type.bas new file mode 100644 index 000000000..2a616c240 --- /dev/null +++ b/basic/qa/basic_coverage/test_optional_paramter_type.bas @@ -0,0 +1,34 @@ +REM ***** BASIC *****
+Option Compatible
+Option Explicit
+
+Function doUnitTest() As String
+ doUnitTest = "FAIL"
+ 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 = "OK"
+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.bas b/basic/qa/basic_coverage/test_optional_paramters_basic.bas new file mode 100644 index 000000000..40475664f --- /dev/null +++ b/basic/qa/basic_coverage/test_optional_paramters_basic.bas @@ -0,0 +1,263 @@ +Option Explicit + +Type testObject + testInt As Integer +End Type + +Function doUnitTest() As String + TestUtil.TestInit + verify_testOptionalsBasic + doUnitTest = TestUtil.GetResult() +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. +Sub verify_testOptionalsBasic() + On Error GoTo errorHandler + + ' optionals with variant datatypes + TestUtil.AssertEqual(TestOptVariant(), 0, "TestOptVariant()") + TestUtil.AssertEqual(TestOptVariant(123), 123, "TestOptVariant(123)") + TestUtil.AssertEqual(TestOptVariant(, 456), 456, "TestOptVariant(, 456)") + TestUtil.AssertEqual(TestOptVariant(123, 456), 579, "TestOptVariant(123, 456)") + + ' optionals with variant datatypes (ByRef and ByVal) + TestUtil.AssertEqual(TestOptVariantByRefByVal(), 0, "TestOptVariantByRefByVal()") + TestUtil.AssertEqualApprox(TestOptVariantByRefByVal(123), 123, "TestOptVariantByRefByVal(123)") + TestUtil.AssertEqualApprox(TestOptVariantByRefByVal(, 456), 456, "TestOptVariantByRefByVal(, 456)") + TestUtil.AssertEqualApprox(TestOptVariantByRefByVal(123, 456), 579, "TestOptVariantByRefByVal(123, 456)") + + ' optionals with double datatypes + TestUtil.AssertEqual(TestOptDouble(), 0, "TestOptDouble()") + TestUtil.AssertEqualApprox(TestOptDouble(123.4), 123.4, 1E-5, "TestOptDouble(123.4)") + TestUtil.AssertEqualApprox(TestOptDouble(, 567.8), 567.8, 1E-5, "TestOptDouble(, 567.8)") + TestUtil.AssertEqualApprox(TestOptDouble(123.4, 567.8), 691.2, 1E-5, "TestOptDouble(123.4, 567.8)") + + ' optionals with double datatypes (ByRef and ByVal) + TestUtil.AssertEqual(TestOptDoubleByRefByVal(), 0, "TestOptDoubleByRefByVal()") + TestUtil.AssertEqualApprox(TestOptDoubleByRefByVal(123.4), 123.4, 1E-5, "TestOptDoubleByRefByVal(123.4)") + TestUtil.AssertEqualApprox(TestOptDoubleByRefByVal(, 567.8), 567.8, 1E-5, "TestOptDoubleByRefByVal(, 567.8)") + TestUtil.AssertEqualApprox(TestOptDoubleByRefByVal(123.4, 567.8), 691.2, 1E-5, "TestOptDoubleByRefByVal(123.4, 567.8)") + + ' optionals with integer datatypes + TestUtil.AssertEqual(TestOptInteger(), 0, "TestOptInteger()") + TestUtil.AssertEqual(TestOptInteger(123), 123, "TestOptInteger(123)") + TestUtil.AssertEqual(TestOptInteger(, 456), 456, "TestOptInteger(, 456)") + TestUtil.AssertEqual(TestOptInteger(123, 456), 579, "TestOptInteger(123, 456)") + + ' optionals with integer datatypes (ByRef and ByVal) + TestUtil.AssertEqual(TestOptIntegerByRefByVal(), 0, "TestOptIntegerByRefByVal()") + TestUtil.AssertEqual(TestOptIntegerByRefByVal(123), 123, "TestOptIntegerByRefByVal(123)") + TestUtil.AssertEqual(TestOptIntegerByRefByVal(, 456), 456, "TestOptIntegerByRefByVal(, 456)") + TestUtil.AssertEqual(TestOptIntegerByRefByVal(123, 456), 579, "TestOptIntegerByRefByVal(123, 456)") + + ' optionals with string datatypes + TestUtil.AssertEqual(TestOptString(), "", "TestOptString()") + TestUtil.AssertEqual(TestOptString("123"), "123", "TestOptString(""123"")") + TestUtil.AssertEqual(TestOptString(, "456"), "456", "TestOptString(, ""456"")") + TestUtil.AssertEqual(TestOptString("123", "456"), "123456", "TestOptString(""123"", ""456"")") + + ' optionals with string datatypes (ByRef and ByVal) + TestUtil.AssertEqual(TestOptStringByRefByVal(), "", "TestOptStringByRefByVal()") + TestUtil.AssertEqual(TestOptStringByRefByVal("123"), "123", "TestOptStringByRefByVal(""123"")") + TestUtil.AssertEqual(TestOptStringByRefByVal(, "456"), "456", "TestOptStringByRefByVal(, ""456"")") + TestUtil.AssertEqual(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) + TestUtil.AssertEqual(TestOptObject(), 0, "TestOptObject()") + TestUtil.AssertEqual(TestOptObject(cA), 579, "TestOptObject(A)") + TestUtil.AssertEqualApprox(TestOptObject(, cB), 691.2, 1E-5, "TestOptObject(, B)") + TestUtil.AssertEqualApprox(TestOptObject(cA, cB), 1270.2, 1E-5, "TestOptObject(A, B)") + + ' optionals with object datatypes (ByRef and ByVal) + TestUtil.AssertEqual(TestOptObjectByRefByVal(), 0, "TestOptObjectByRefByVal()") + TestUtil.AssertEqual(TestOptObjectByRefByVal(cA), 579, "TestOptObjectByRefByVal(A)") + TestUtil.AssertEqualApprox(TestOptObjectByRefByVal(, cB), 691.2, 1E-5, "TestOptObjectByRefByVal(, B)") + TestUtil.AssertEqualApprox(TestOptObjectByRefByVal(cA, cB), 1270.2, 1E-5, "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 + TestUtil.AssertEqual(TestOptArray(), 0, "TestOptArray()") + TestUtil.AssertEqual(TestOptArray(aA), 579, "TestOptArray(A)") + TestUtil.AssertEqualApprox(TestOptArray(, aB), 691.2, 1E-5, "TestOptArray(, B)") + TestUtil.AssertEqualApprox(TestOptArray(aA, aB), 1270.2, 1E-5, "TestOptArray(A, B)") + + ' optionals with array datatypes (ByRef and ByVal) + TestUtil.AssertEqual(TestOptArrayByRefByVal(), 0, "TestOptArrayByRefByVal()") + TestUtil.AssertEqual(TestOptArrayByRefByVal(aA), 579, "TestOptArrayByRefByVal(A)") + TestUtil.AssertEqualApprox(TestOptArrayByRefByVal(, aB), 691.2, 1E-5, "TestOptArrayByRefByVal(, B)") + TestUtil.AssertEqualApprox(TestOptArrayByRefByVal(aA, aB), 1270.2, 1E-5, "TestOptArrayByRefByVal(A, B)") + + ' tdf#144353 - error handling of missing optional parameters (arithmetic operator) + ' Without the fix in place, this test would have failed with: + ' - Expected: 449 (ERRCODE_BASIC_NOT_OPTIONAL - Argument not optional) + ' - Actual : 549 (Actual value of the variable) + TestUtil.AssertEqual(TestArithmeticOperator, 449, "TestArithmeticOperator") + + ' tdf#144353 - error handling of missing optional parameters (unary operator) + ' Without the fix in place, this test would have failed with: + ' - Expected: 449 (ERRCODE_BASIC_NOT_OPTIONAL - Argument not optional) + ' - Actual : 100 (Actual value of the variable) + TestUtil.AssertEqual(TestUnaryOperator, 449, "TestUnaryOperator") + + ' tdf#144353 - error handling of missing optional parameters (assigning to a collection) + ' Without the fix in place, this test would have failed with: + ' - Expected: 449 (ERRCODE_BASIC_NOT_OPTIONAL - Argument not optional) + ' - Actual : 549 (Actual value of the variable) + TestUtil.AssertEqual(TestCollection, 449, "TestCollection") + + ' tdf#144353 - error handling of missing optional parameters + ' Without the fix in place, this test would have failed with: + ' - Expected: 449 (ERRCODE_BASIC_NOT_OPTIONAL - Argument not optional) + ' - Actual : 448 (Actual value of the variable) + TestUtil.AssertEqual(TestObjectError, 449, "TestObjectError") + + ' tdf#151503 - error handling of missing optional parameters (boolean operations) + ' Without the fix in place, this test would have failed with: + ' - Expected: 449 (ERRCODE_BASIC_NOT_OPTIONAL - Argument not optional) + ' - Actual : 0 (No error code since a missing parameter evaluates to true) + TestUtil.AssertEqual(TestBooleanOperations, 449, "TestBooleanOperations") + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_testOptionalsBasic", Err, Error$, Erl) +End Sub + +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 TestArithmeticOperator(Optional optInt) +On Error GoTo errorHandler + optInt = optInt + 100 + TestArithmeticOperator = optInt +errorHandler: + TestArithmeticOperator = Err() +End Function + +Function TestUnaryOperator(Optional optInt) +On Error GoTo errorHandler + If (Not optInt) Then optInt = 100 + TestUnaryOperator = optInt +errorHandler: + TestUnaryOperator = Err() +End Function + +Function TestCollection(Optional optInt) +On Error GoTo errorHandler + Dim cA As New Collection + cA.Add(optInt) + TestCollection = cA.Item(1) + 100 +errorHandler: + TestCollection = Err() +End Function + +Function TestObjectError(Optional optInt) +On Error GoTo errorHandler + Dim aTestObject As Variant + aTestObject = CreateObject("testObject") + aTestObject.testInt = optInt + TestObjectError = optInt +errorHandler: + TestObjectError = Err() +End Function + +Function TestBooleanOperations(Optional optBool As Boolean) +On Error GoTo errorHandler + if optBool then + TestBooleanOperations = 0 + end if +errorHandler: + TestBooleanOperations = Err() +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 diff --git a/basic/qa/basic_coverage/test_optional_paramters_compatible.bas b/basic/qa/basic_coverage/test_optional_paramters_compatible.bas new file mode 100644 index 000000000..fc3ca3859 --- /dev/null +++ b/basic/qa/basic_coverage/test_optional_paramters_compatible.bas @@ -0,0 +1,265 @@ +Option Compatible +Option Explicit + +Type testObject + testInt As Integer +End Type + +Function doUnitTest() As String + TestUtil.TestInit + verify_testOptionalsCompatible + doUnitTest = TestUtil.GetResult() +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. +Sub verify_testOptionalsCompatible() + + On Error GoTo errorHandler + + ' optionals with variant datatypes + TestUtil.AssertEqual(TestOptVariant(), 123, "TestOptVariant()") + TestUtil.AssertEqual(TestOptVariant(123), 246, "TestOptVariant(123)") + TestUtil.AssertEqual(TestOptVariant(, 456), 456, "TestOptVariant(, 456)") + TestUtil.AssertEqual(TestOptVariant(123, 456), 579, "TestOptVariant(123, 456)") + + ' optionals with variant datatypes (ByRef and ByVal) + TestUtil.AssertEqual(TestOptVariantByRefByVal(), 123, "TestOptVariantByRefByVal()") + TestUtil.AssertEqual(TestOptVariantByRefByVal(123), 246, "TestOptVariantByRefByVal(123)") + TestUtil.AssertEqual(TestOptVariantByRefByVal(, 456), 456, "TestOptVariantByRefByVal(, 456)") + TestUtil.AssertEqual(TestOptVariantByRefByVal(123, 456), 579, "TestOptVariantByRefByVal(123, 456)") + + ' optionals with double datatypes + TestUtil.AssertEqualApprox(TestOptDouble(), 123.4, 1E-5, "TestOptDouble()") + TestUtil.AssertEqualApprox(TestOptDouble(123.4), 246.8, 1E-5, "TestOptDouble(123.4)") + TestUtil.AssertEqualApprox(TestOptDouble(, 567.8), 567.8, 1E-5, "TestOptDouble(, 567.8)") + TestUtil.AssertEqualApprox(TestOptDouble(123.4, 567.8), 691.2, 1E-5, "TestOptDouble(123.4, 567.8)") + + ' optionals with double datatypes (ByRef and ByVal) + TestUtil.AssertEqualApprox(TestOptDoubleByRefByVal(), 123.4, 1E-5, "TestOptDoubleByRefByVal()") + TestUtil.AssertEqualApprox(TestOptDoubleByRefByVal(123.4), 246.8, 1E-5, "TestOptDoubleByRefByVal(123.4)") + TestUtil.AssertEqualApprox(TestOptDoubleByRefByVal(, 567.8), 567.8, 1E-5, "TestOptDoubleByRefByVal(, 567.8)") + TestUtil.AssertEqualApprox(TestOptDoubleByRefByVal(123.4, 567.8), 691.2, 1E-5, "TestOptDoubleByRefByVal(123.4, 567.8)") + + ' optionals with integer datatypes + TestUtil.AssertEqual(TestOptInteger(), 123, "TestOptInteger()") + TestUtil.AssertEqual(TestOptInteger(123), 246, "TestOptInteger(123)") + TestUtil.AssertEqual(TestOptInteger(, 456), 456, "TestOptInteger(, 456)") + TestUtil.AssertEqual(TestOptInteger(123, 456), 579, "TestOptInteger(123, 456)") + + ' optionals with integer datatypes (ByRef and ByVal) + TestUtil.AssertEqual(TestOptIntegerByRefByVal(), 123, "TestOptIntegerByRefByVal()") + TestUtil.AssertEqual(TestOptIntegerByRefByVal(123), 246, "TestOptIntegerByRefByVal(123)") + TestUtil.AssertEqual(TestOptIntegerByRefByVal(, 456), 456, "TestOptIntegerByRefByVal(, 456)") + TestUtil.AssertEqual(TestOptIntegerByRefByVal(123, 456), 579, "TestOptIntegerByRefByVal(123, 456)") + + ' optionals with string datatypes + TestUtil.AssertEqual(TestOptString(), "123", "TestOptString()") + TestUtil.AssertEqual(TestOptString("123"), "123123", "TestOptString(""123"")") + TestUtil.AssertEqual(TestOptString(, "456"), "456", "TestOptString(, ""456"")") + TestUtil.AssertEqual(TestOptString("123", "456"), "123456", "TestOptString(""123"", ""456"")") + + ' optionals with string datatypes (ByRef and ByVal) + TestUtil.AssertEqual(TestOptStringByRefByVal(), "123", "TestOptStringByRefByVal()") + TestUtil.AssertEqual(TestOptStringByRefByVal("123"), "123123", "TestOptStringByRefByVal(""123"")") + TestUtil.AssertEqual(TestOptStringByRefByVal(, "456"), "456", "TestOptStringByRefByVal(, ""456"")") + TestUtil.AssertEqual(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) + TestUtil.AssertEqual(TestOptObject(), 0, "TestOptObject()") + TestUtil.AssertEqual(TestOptObject(cA), 579, "TestOptObject(A)") + TestUtil.AssertEqualApprox(TestOptObject(, cB), 691.2, 1E-5, "TestOptObject(, B)") + TestUtil.AssertEqualApprox(TestOptObject(cA, cB), 1270.2, 1E-5, "TestOptObject(A, B)") + + ' optionals with object datatypes (ByRef and ByVal) + TestUtil.AssertEqual(TestOptObjectByRefByVal(), 0, "TestOptObjectByRefByVal()") + TestUtil.AssertEqual(TestOptObjectByRefByVal(cA), 579, "TestOptObjectByRefByVal(A)") + TestUtil.AssertEqualApprox(TestOptObjectByRefByVal(, cB), 691.2, 1E-5, "TestOptObjectByRefByVal(, B)") + TestUtil.AssertEqualApprox(TestOptObjectByRefByVal(cA, cB), 1270.2, 1E-5, "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 + TestUtil.AssertEqual(TestOptArray(), 0, "TestOptArray()") + TestUtil.AssertEqual(TestOptArray(aA), 579, "TestOptArray(A)") + TestUtil.AssertEqualApprox(TestOptArray(, aB), 691.2, 1E-5, "TestOptArray(, B)") + TestUtil.AssertEqualApprox(TestOptArray(aA, aB), 1270.2, 1E-5, "TestOptArray(A, B)") + + ' optionals with array datatypes (ByRef and ByVal) + TestUtil.AssertEqual(TestOptArrayByRefByVal(), 0, "TestOptArrayByRefByVal()") + TestUtil.AssertEqual(TestOptArrayByRefByVal(aA), 579, "TestOptArrayByRefByVal(A)") + TestUtil.AssertEqualApprox(TestOptArrayByRefByVal(, aB), 691.2, 1E-5, "TestOptArrayByRefByVal(, B)") + TestUtil.AssertEqualApprox(TestOptArrayByRefByVal(aA, aB), 1270.2, 1E-5, "TestOptArrayByRefByVal(A, B)") + + ' tdf#144353 - error handling of missing optional parameters (arithmetic operator) + ' Without the fix in place, this test would have failed with: + ' - Expected: 449 (ERRCODE_BASIC_NOT_OPTIONAL - Argument not optional) + ' - Actual : 549 (Actual value of the variable) + TestUtil.AssertEqual(TestArithmeticOperator, 449, "TestArithmeticOperator") + + ' tdf#144353 - error handling of missing optional parameters (unary operator) + ' Without the fix in place, this test would have failed with: + ' - Expected: 449 (ERRCODE_BASIC_NOT_OPTIONAL - Argument not optional) + ' - Actual : 100 (Actual value of the variable) + TestUtil.AssertEqual(TestUnaryOperator, 449, "TestUnaryOperator") + + ' tdf#144353 - error handling of missing optional parameters (assigning to a collection) + ' Without the fix in place, this test would have failed with: + ' - Expected: 449 (ERRCODE_BASIC_NOT_OPTIONAL - Argument not optional) + ' - Actual : 549 (Actual value of the variable) + TestUtil.AssertEqual(TestCollection, 449, "TestCollection") + + ' tdf#144353 - error handling of missing optional parameters (assigning to an object) + ' Without the fix in place, this test would have failed with: + ' - Expected: 449 (ERRCODE_BASIC_NOT_OPTIONAL - Argument not optional) + ' - Actual : 448 (Actual value of the variable) + TestUtil.AssertEqual(TestObjectError, 449, "TestObjectError") + + ' tdf#151503 - error handling of missing optional parameters (boolean operations) + ' Without the fix in place, this test would have failed with: + ' - Expected: 449 (ERRCODE_BASIC_NOT_OPTIONAL - Argument not optional) + ' - Actual : 0 (No error code since a missing parameter evaluates to true) + TestUtil.AssertEqual(TestBooleanOperations, 449, "TestBooleanOperations") + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_testOptionalsCompatible", Err, Error$, Erl) +End Sub + +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 TestArithmeticOperator(Optional optInt) +On Error GoTo errorHandler + optInt = optInt + 100 + TestArithmeticOperator = optInt +errorHandler: + TestArithmeticOperator = Err() +End Function + +Function TestUnaryOperator(Optional optInt) +On Error GoTo errorHandler + If (Not optInt) Then optInt = 100 + TestUnaryOperator = optInt +errorHandler: + TestUnaryOperator = Err() +End Function + +Function TestCollection(Optional optInt) +On Error GoTo errorHandler + Dim cA As New Collection + cA.Add(optInt) + TestCollection = cA.Item(1) + 100 +errorHandler: + TestCollection = Err() +End Function + +Function TestObjectError(Optional optInt) +On Error GoTo errorHandler + Dim aTestObject As Variant + aTestObject = CreateObject("testObject") + aTestObject.testInt = optInt + TestObjectError = optInt +errorHandler: + TestObjectError = Err() +End Function + +Function TestBooleanOperations(Optional optBool As Boolean) +On Error GoTo errorHandler + if optBool then + TestBooleanOperations = 0 + end if +errorHandler: + TestBooleanOperations = Err() +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 diff --git a/basic/qa/basic_coverage/test_qbcolor_method.bas b/basic/qa/basic_coverage/test_qbcolor_method.bas new file mode 100644 index 000000000..8c2b6ed7a --- /dev/null +++ b/basic/qa/basic_coverage/test_qbcolor_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' QBCOLOR + If ( QBColor(7) <> 12632256 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_random_methods.bas b/basic/qa/basic_coverage/test_random_methods.bas new file mode 100644 index 000000000..5df5e9313 --- /dev/null +++ b/basic/qa/basic_coverage/test_random_methods.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + Randomize 42 + ' RND + If ( Rnd >= 1 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_redim_objects.bas b/basic/qa/basic_coverage/test_redim_objects.bas new file mode 100644 index 000000000..b2699956d --- /dev/null +++ b/basic/qa/basic_coverage/test_redim_objects.bas @@ -0,0 +1,35 @@ +' 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 + +Type testType + iNr As Integer + sType As String + aValue As Variant + oColor As Object +End Type + +Function doUnitTest as String + + doUnitTest = "FAIL" + + ' tdf#136755 - ReDim did not work on an array of objects + Dim aPropertyValues(1) As New com.sun.star.beans.PropertyValue + If (UBound(aPropertyValues) <> 1) Then Exit Function + ReDim aPropertyValues(5) As com.sun.star.beans.PropertyValue + If (UBound(aPropertyValues) <> 5) Then Exit Function + + ' tdf#124008 - ReDim did not work on an array of individual declared types + Dim aType(1) As testType + If (UBound(aType) <> 1) Then Exit Function + ReDim aType(5) As testType + If (UBound(aType) <> 5) Then Exit Function + + doUnitTest = "OK" + +End Function diff --git a/basic/qa/basic_coverage/test_resolvepath_method.bas b/basic/qa/basic_coverage/test_resolvepath_method.bas new file mode 100644 index 000000000..249900c3b --- /dev/null +++ b/basic/qa/basic_coverage/test_resolvepath_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' RESOLVEPATH + If ( ResolvePath( "" ) <> "" ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_rgb_method.bas b/basic/qa/basic_coverage/test_rgb_method.bas new file mode 100644 index 000000000..3665af50c --- /dev/null +++ b/basic/qa/basic_coverage/test_rgb_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' RGB + If ( RGB( 128, 50, 200 ) <> 8401608 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_rtrim_method.bas b/basic/qa/basic_coverage/test_rtrim_method.bas new file mode 100644 index 000000000..f74c04a66 --- /dev/null +++ b/basic/qa/basic_coverage/test_rtrim_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + dim aString as Variant + aString = "Hello" + ' RTRIM + If ( RTrim( "Hello " ) <> aString ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_second_method.bas b/basic/qa/basic_coverage/test_second_method.bas new file mode 100644 index 000000000..d06ee2076 --- /dev/null +++ b/basic/qa/basic_coverage/test_second_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' SECOND + If ( Second(TimeSerial(12,30,41)) <> 41 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_sgn_method.bas b/basic/qa/basic_coverage/test_sgn_method.bas new file mode 100644 index 000000000..7e4dd5d4b --- /dev/null +++ b/basic/qa/basic_coverage/test_sgn_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' SGN + If ( Sgn(-3.14) <> -1 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_space_method.bas b/basic/qa/basic_coverage/test_space_method.bas new file mode 100644 index 000000000..6c44482de --- /dev/null +++ b/basic/qa/basic_coverage/test_space_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' SPACE + If ( Space(3) <> " " ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_spc_method.bas b/basic/qa/basic_coverage/test_spc_method.bas new file mode 100644 index 000000000..81f43d40b --- /dev/null +++ b/basic/qa/basic_coverage/test_spc_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' SPC + If ( Spc(3) <> " " ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_split_method.bas b/basic/qa/basic_coverage/test_split_method.bas new file mode 100644 index 000000000..52ba91fe3 --- /dev/null +++ b/basic/qa/basic_coverage/test_split_method.bas @@ -0,0 +1,59 @@ +' 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 + +Function doUnitTest() As String + TestUtil.TestInit + verify_testSplit + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_testSplit + On Error GoTo errorHandler + + ' SPLIT + TestUtil.AssertEqual(Split( "Hello world" )(1), "world", "Split( ""Hello world"" )(1)") + + ' tdf#123025 - split function sets the datatype of the array to empty, + ' preventing any subsequent assignments of values to the array and to the elements itself. + Dim arr(1) As String + arr = Split("a/b", "/") + TestUtil.AssertEqual(arr(0), "a", "Split(""a/b"", ""/"")(0)") + TestUtil.AssertEqual(arr(1), "b", "Split(""a/b"", ""/"")(1)") + ReDim Preserve arr(1) + TestUtil.AssertEqual(arr(0), "a", "ReDim Preserve arr(1)(0)") + TestUtil.AssertEqual(arr(1), "b", "ReDim Preserve arr(1)(1)") + ReDim arr(1) + TestUtil.AssertEqual(arr(0), "", "ReDim arr(1)(0)") + TestUtil.AssertEqual(arr(1), "", "ReDim arr(1)(1)") + + arr(0) = "a" + arr(1) = "b" + TestUtil.AssertEqual(arr(0), "a", "arr(0)") + TestUtil.AssertEqual(arr(1), "b", "arr(1)") + ReDim Preserve arr(1) + TestUtil.AssertEqual(arr(0), "a", "ReDim Preserve arr(1)(0) after assignment") + TestUtil.AssertEqual(arr(1), "b", "ReDim Preserve arr(1)(1) after assignment") + + ' tdf#144924 - allow the assignment of different data types to the individual elements + Dim splitArr + splitArr = Split("a/b&&c/d", "&&") + Dim i As Integer + For i = 0 To UBound(splitArr) + ' Without the fix in place, this assignment would have failed + splitArr(i) = Split(splitArr(i), "/") + ' Without the fix in place, this test would have failed with: + ' - Expected: 8200 (8192 for Array and 8 for String) + ' - Actual : 8 (8 for String) + TestUtil.AssertEqual(VarType(splitArr(i)), 8200, "VarType(splitArr(i))") + Next + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_testSplit", Err, Error$, Erl) +End Sub diff --git a/basic/qa/basic_coverage/test_sqr_method.bas b/basic/qa/basic_coverage/test_sqr_method.bas new file mode 100644 index 000000000..064a870d1 --- /dev/null +++ b/basic/qa/basic_coverage/test_sqr_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' SQR + If ( Sqr( 4 ) <> 2 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_strcomp_method.bas b/basic/qa/basic_coverage/test_strcomp_method.bas new file mode 100644 index 000000000..73ee3002f --- /dev/null +++ b/basic/qa/basic_coverage/test_strcomp_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + dim aString as Variant + aString = "Hello" + ' STRCOMP + If ( StrComp( aString, "Hello" ) <> 0 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_string_literal_comparison.bas b/basic/qa/basic_coverage/test_string_literal_comparison.bas new file mode 100644 index 000000000..814463284 --- /dev/null +++ b/basic/qa/basic_coverage/test_string_literal_comparison.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' tdf#142180 - Invalid text comparison result in Basic + + doUnitTest = "FAIL" + If ( "Z" < "A" ) Then Exit Function + If ( "A" > "Z" ) Then Exit Function + If ( "A" < "A" ) Then Exit Function + If ( "A" > "A" ) Then Exit Function + If ( "Z" <= "A" ) Then Exit Function + If ( "A" >= "Z" ) Then Exit Function + doUnitTest = "OK" +End Function diff --git a/basic/qa/basic_coverage/test_string_method.bas b/basic/qa/basic_coverage/test_string_method.bas new file mode 100644 index 000000000..b06726e60 --- /dev/null +++ b/basic/qa/basic_coverage/test_string_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' STRING + If ( String( 3, "H" ) <> "HHH" ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_string_overflow_safe.bas b/basic/qa/basic_coverage/test_string_overflow_safe.bas new file mode 100644 index 000000000..f245e14ab --- /dev/null +++ b/basic/qa/basic_coverage/test_string_overflow_safe.bas @@ -0,0 +1,22 @@ +Option Explicit + +Function doUnitTest As String + ' 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 = "FAIL" + Exit Function +errorHandler: + If ( Err <> 6 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + Endif +End Function diff --git a/basic/qa/basic_coverage/test_string_replace.bas b/basic/qa/basic_coverage/test_string_replace.bas new file mode 100644 index 000000000..d68f36fbb --- /dev/null +++ b/basic/qa/basic_coverage/test_string_replace.bas @@ -0,0 +1,39 @@ +Option VBASupport 0 +Option Explicit + +Function doUnitTest() As String + TestUtil.TestInit + verify_stringReplace + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_stringReplace() + On Error GoTo errorHandler + ' tdf#132389 - case-insensitive operation for non-ASCII characters + Dim retStr + retStr = Replace("ABCabc", "b", "*") + TestUtil.AssertEqual(retStr, "A*Ca*c", "case-insensitive ASCII: " & retStr) + retStr = Replace("АБВабв", "б", "*") + TestUtil.AssertEqual(retStr, "А*Ва*в", "case-insensitive non-ASCII: " & retStr) + + ' tdf#141045 - different length of search and replace string. It is important + ' that the search string starts with the original string in order to test the error. + ' Without the fix in place, the string index calculations result in a crash. + retStr = Replace("a", "abc", "ab") + TestUtil.AssertEqual(retStr, "a", "different length of search and replace string: " & retStr) + + ' tdf#143081 - Without the fix in place, this test would have crashed here + retStr = Replace("""Straße""", """", """) + TestUtil.AssertEqual(retStr, ""Straße"", "replace doesn't crash: " & retStr) + + ' tdf#142487 - replace of special unicode characters. + ' Without the fix in place, this test would have failed with: + ' - Expected: Straßen + ' - Actual : Straßeen + retStr = Replace("Straße", "e", "en") + TestUtil.AssertEqual(retStr, "Straßen", "special unicode character: " & retStr) + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_stringReplace", Err, Error$, Erl) +End Sub diff --git a/basic/qa/basic_coverage/test_strtrim_methods.bas b/basic/qa/basic_coverage/test_strtrim_methods.bas new file mode 100644 index 000000000..97875933a --- /dev/null +++ b/basic/qa/basic_coverage/test_strtrim_methods.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' STR TRIM + If ( Trim( Str( 4 ) ) <> "4" ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_switch_method.bas b/basic/qa/basic_coverage/test_switch_method.bas new file mode 100644 index 000000000..ec4c8a14c --- /dev/null +++ b/basic/qa/basic_coverage/test_switch_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + dim aVariant as Object + ' SWITCH + If ( Switch( False, 10,_ + True, 11,_ + False, 12,_ + True, 13 ) <> 11 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_tab_method.bas b/basic/qa/basic_coverage/test_tab_method.bas new file mode 100644 index 000000000..997d9fb10 --- /dev/null +++ b/basic/qa/basic_coverage/test_tab_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' TAB + If ( "Hello" & Tab(0) & "World" <> "HelloWorld" ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_tan_method.bas b/basic/qa/basic_coverage/test_tan_method.bas new file mode 100644 index 000000000..f780f978e --- /dev/null +++ b/basic/qa/basic_coverage/test_tan_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' TAN + If ( Abs( Tan(PI/4) - 1 ) > 1E-6 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_tdf111313.bas b/basic/qa/basic_coverage/test_tdf111313.bas new file mode 100644 index 000000000..3a2604732 --- /dev/null +++ b/basic/qa/basic_coverage/test_tdf111313.bas @@ -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 String + + ' Without the fix in place, this test would have crashed + s = "abc" + Mid(s,1) = "d" + If (s = "d") Then + doUnitTest = "OK" + Else + doUnitTest = "FAIL" + End If +End Function diff --git a/basic/qa/basic_coverage/test_tdf125637.bas b/basic/qa/basic_coverage/test_tdf125637.bas new file mode 100644 index 000000000..e4eff75c2 --- /dev/null +++ b/basic/qa/basic_coverage/test_tdf125637.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest() As String + TestUtil.TestInit + verify_tdf125637 + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_tdf125637 + On Error GoTo errorHandler + + ' tdf#125637 - correctly hand names ending with an underscore character at the end of the line + Dim test As Long + Dim test_ As Long + test_ = 1234 + test = test_ + + ' Without the fix in place, this test would have failed with: + ' - Expected: 1234 + ' - Actual : 0 + TestUtil.AssertEqual(test, 1234, "Assignment of the variable failed (tdf#125637)") + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_tdf125637", Err, Error$, Erl) +End Sub diff --git a/basic/qa/basic_coverage/test_tdf132388_ReplacePerformance.bas b/basic/qa/basic_coverage/test_tdf132388_ReplacePerformance.bas new file mode 100644 index 000000000..1bb3b3de2 --- /dev/null +++ b/basic/qa/basic_coverage/test_tdf132388_ReplacePerformance.bas @@ -0,0 +1,28 @@ +' +' 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 String + TestUtil.TestInit + TestReplacePerformance() + doUnitTest = TestUtil.GetResult() +End Function + +Sub TestReplacePerformance() + On Error GoTo errorHandler + ' Assume the normal case to be much faster than 60 s even on slow boxes, and the test string + ' is long enough to cause serious performance regressions make it perform much longer + n = 10000000 + s = Space(n) + t = Now + s = Replace(s, " ", "*", 1, -1, 1) + t = Now - t + TestUtil.Assert(t <= TimeSerial(0, 2, 0), "TestReplacePerformance", Format(t, """t = ""[s]"" s""")) + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("TestReplacePerformance", Err, Error$, Erl) +End Sub diff --git a/basic/qa/basic_coverage/test_tdf134692.bas b/basic/qa/basic_coverage/test_tdf134692.bas new file mode 100644 index 000000000..c310280fe --- /dev/null +++ b/basic/qa/basic_coverage/test_tdf134692.bas @@ -0,0 +1,31 @@ +Option VBASupport 0 +Option Explicit + +Function doUnitTest() As String + TestUtil.TestInit + verify_tdf134692 + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_tdf134692() + On Error GoTo errorHandler + + dim a(2 to 5) + dim b, i, s + b = a + redim preserve b(4 to 6) + for i = lbound(b) to ubound(b) + b(i) = i + next i + for i = lbound(a) to ubound(a) + s = s & " a(" & i & ")=" & a(i) + next i + for i = lbound(b) to ubound(b) + s = s & " b(" & i & ")=" & b(i) + next i + TestUtil.AssertEqual(s, " a(2)= a(3)= a(4)= a(5)= b(4)=4 b(5)=5 b(6)=6", "tdf#134692") + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_tdf134692", Err, Error$, Erl) +End Sub diff --git a/basic/qa/basic_coverage/test_tdf147089_idiv.bas b/basic/qa/basic_coverage/test_tdf147089_idiv.bas new file mode 100644 index 000000000..3d5e22711 --- /dev/null +++ b/basic/qa/basic_coverage/test_tdf147089_idiv.bas @@ -0,0 +1,30 @@ +'
+' 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
+ +Function doUnitTest() As String
+ TestUtil.TestInit
+ verify_testIDiv
+ doUnitTest = TestUtil.GetResult()
+End Function +
+Sub verify_testIDiv + On Error GoTo errorHandler
+
+ ' tdf#147089 - IDIV operands are rounded to Integer values before the operation is performed
+ TestUtil.AssertEqual(8.4 \ 2, 4, "8.4 \ 2")
+ TestUtil.AssertEqual(9.9 \ 2, 5, "9.9 \ 2")
+ TestUtil.AssertEqual(20 \ 4.9, 4, "20 \ 4.9")
+ TestUtil.AssertEqual(20 \ 4.4, 5, "20 \ 4.4")
+ TestUtil.AssertEqual(16.4 \ 5.9, 2, "16.4 \ 5.9")
+
+ Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_testIDiv", Err, Error$, Erl) +End Sub diff --git a/basic/qa/basic_coverage/test_tdf147529_optional_parameters_msgbox.bas b/basic/qa/basic_coverage/test_tdf147529_optional_parameters_msgbox.bas new file mode 100755 index 000000000..67378213e --- /dev/null +++ b/basic/qa/basic_coverage/test_tdf147529_optional_parameters_msgbox.bas @@ -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/.
+'
+
+Option Explicit
+ +Function doUnitTest() As String
+ TestUtil.TestInit
+ verify_testOptionalParametersMsgBox
+ doUnitTest = TestUtil.GetResult()
+End Function +
+Sub verify_testOptionalParametersMsgBox + On Error GoTo errorHandler
+
+ ' tdf#147529 - check for missing optional parameters
+ TestUtil.AssertEqual(TestOptionalParametersMsgBox(), True, "TestOptionalParametersMsgBox()")
+
+ Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_testOptionalParametersMsgBox", Err, Error$, Erl) +End Sub
+
+Function TestOptionalParametersMsgBox(Optional text, Optional dialogType, Optional dialogTitle) As Boolean
+On Error GoTo errorHandler
+ MsgBox(text, dialogType, dialogTitle)
+ TestOptionalParametersMsgBox = False
+ Exit Function
+errorHandler:
+ TestUtil.AssertEqual(Err, 449, "Argument not optional (Error 449)")
+ TestOptionalParametersMsgBox = True
+End Function
diff --git a/basic/qa/basic_coverage/test_tdf98778.bas b/basic/qa/basic_coverage/test_tdf98778.bas new file mode 100644 index 000000000..0228e5060 --- /dev/null +++ b/basic/qa/basic_coverage/test_tdf98778.bas @@ -0,0 +1,22 @@ +Option VBASupport 0 +Option Explicit + +Function doUnitTest() As String + TestUtil.TestInit + verify_tdf98778 + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_tdf98778() + On Error GoTo errorHandler + + dim d as double + dim s as string + s="1.0E-5" + d=s + TestUtil.AssertEqual(d, 1E-05, "tdf#98778") + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_tdf98778", Err, Error$, Erl) +End Sub diff --git a/basic/qa/basic_coverage/test_timer_method.bas b/basic/qa/basic_coverage/test_timer_method.bas new file mode 100644 index 000000000..8e2842582 --- /dev/null +++ b/basic/qa/basic_coverage/test_timer_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' TIMER max value = 24*3600 + If ( Timer() > 86400 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_timeserialtimevalue_methods.bas b/basic/qa/basic_coverage/test_timeserialtimevalue_methods.bas new file mode 100644 index 000000000..ce3ea1cf0 --- /dev/null +++ b/basic/qa/basic_coverage/test_timeserialtimevalue_methods.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' TIMESERIAL TIMEVALUE + If ( TimeSerial(13,54,48) <> TimeValue("13:54:48") ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_twipsperpixelx_method.bas b/basic/qa/basic_coverage/test_twipsperpixelx_method.bas new file mode 100644 index 000000000..ababb7aa7 --- /dev/null +++ b/basic/qa/basic_coverage/test_twipsperpixelx_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' TWIPSPERPIXELX + If ( TwipsPerPixelX < 0 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_twipsperpixely_method.bas b/basic/qa/basic_coverage/test_twipsperpixely_method.bas new file mode 100644 index 000000000..a29affb88 --- /dev/null +++ b/basic/qa/basic_coverage/test_twipsperpixely_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' TWIPSPERPIXELY + If ( TwipsPerPixelY < 0 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_typelen_method.bas b/basic/qa/basic_coverage/test_typelen_method.bas new file mode 100644 index 000000000..cb86d1569 --- /dev/null +++ b/basic/qa/basic_coverage/test_typelen_method.bas @@ -0,0 +1,58 @@ +' +' 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 int16 As Integer, int32 As Long, flt32 As Single, flt64 As Double, _ + curr As Currency, dat As Date, str As String, _ + myErr As Variant, var As Variant, byt3 As Byte, bool As Boolean + +Dim int_%, long_&, single_!, double_#, currency_@, string_$, array_ + +Function doUnitTest + ' TypeLen() + + dat = #02/17/2012# : myErr = CVErr("errMsg") + assert( TypeLen(int16) = 2 , "TypeLen(int16) is not 2") + assert( TypeLen(int32) = 4 , "TypeLen(int32) is not 4") + assert( TypeLen(flt32) = 4 , "TypeLen(flt32) is not 4" ) + assert( TypeLen(flt64) = 8 , "TypeLen(flt64) is not 8" ) + assert( TypeLen(curr) = 8 , "TypeLen(curr) is not 8" ) + assert( TypeLen(dat) = 8 , "TypeLen(dat) is not 8" ) + assert( TypeLen(str) = 0 , "TypeLen(str) is not 0" ) ' when empty + assert( TypeLen(myErr) = 2 , "TypeLen(myErr) is not 2" ) + assert( TypeLen(bool) = 1 , "TypeLen(bool) is not 1" ) + assert( TypeLen(var) = 0 , "TypeLen(var) is not 0" ) ' when empty + assert( TypeLen(byt3) = 1 , "TypeLen(byt3) is not 1" ) + + assert( TypeLen(int_) = 2 , "TypeLen(int_) is not 2" ) + assert( TypeLen(long_) = 4 , "TypeLen(long_) is not 4" ) + assert( TypeLen(single_) = 4 , "TypeLen(single_) is not 4" ) + assert( TypeLen(double_) = 8 , "TypeLen(double_) is not 8" ) + assert( TypeLen(currency_) = 8 , "TypeLen(currency_) is not 8" ) + assert( TypeLen(string_) = 0 , "TypeLen(string_) is not 0" ) + + If FailedAssertion Then + doUnitTest = "test_typelen_method.vb fails" + messages + Exit Function + EndIf + doUnitTest = "OK" ' All checks passed +End Function + +Sub DEV_TEST + MsgBox doUnitTest +End Sub + +Dim failedAssertion As Boolean, messages As String + +Sub assert(expression As Boolean, errMessage As String) + If ( Not expression ) Then + messages = messages + Chr(10) + ErrMessage + failedAssertion = True + EndIf +End Sub diff --git a/basic/qa/basic_coverage/test_typename_method.bas b/basic/qa/basic_coverage/test_typename_method.bas new file mode 100644 index 000000000..80a9658d2 --- /dev/null +++ b/basic/qa/basic_coverage/test_typename_method.bas @@ -0,0 +1,78 @@ +' +' 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 + +Type UDF ' User defined type + l As Object + s as String +End Type +Dim myUDF as UDF + +Dim int16 As Integer, int32 As Long, flt32 As Single, flt64 As Double, _ + curr As Currency, dat As Date, str As String, obj As Object, _ + myErr As Variant, var As Variant, byt3 As Byte, bool As Boolean + +Dim int_%, long_&, single_!, double_#, currency_@, string_$, array_ + +Dim intArray() As Integer, lngArray(5) As Long, sngArray!() As Single, dblArray#(8) As Double, _ + curArray@() As Currency, datArray() As Date, strArray$() As String, objArray(5,15) As Object, _ + varArray() As Variant, byteArray() As Byte, boolArray() As Boolean + +Function doUnitTest ' TypeName() + + myErr = CVErr(0.56E-41) + assert( TypeName(int16) = "Integer" , "TypeName(int16) is not ""Integer""") + assert( TypeName(int32) = "Long" , "TypeName(int32) is not ""Long""") + assert( TypeName(flt32) = "Single" , "TypeName(flt32) is not ""Single""" ) + assert( TypeName(flt64) = "Double" , "TypeName(flt64) is not ""Double""" ) + assert( TypeName(curr) = "Currency", "TypeName(curr) is not ""Currency""" ) + assert( TypeName(dat) = "Date" , "TypeName(dat) is not ""Date""" ) + assert( TypeName(byt3) = "Byte" , "TypeName(byt3) is not ""Byte""" ) + assert( TypeName(MyErr) = "Error" , "TypeName(MyErr) is not ""Error""" ) + assert( TypeName(bool) = "Boolean" , "TypeName(bool) is not ""Boolean""" ) + assert( TypeName(str) = "String" , "TypeName(str) is not ""String""" ) + assert( TypeName(obj) = "Object" , "TypeName(obj) is not ""Object""" ) + assert( TypeName(myUDF) = "Object" , "TypeName(myUDF) is not ""Object""" ) + assert( TypeName(var) = "Empty" , "TypeName(var) is not ""Empty""" ) + + assert( TypeName(int_) = "Integer" , "TypeName(int_) is not ""Integer""" ) + assert( TypeName(long_) = "Long" , "TypeName(long_) is not ""Long""" ) + assert( TypeName(single_) = "Single" , "TypeName(single_) is not ""Single""" ) + assert( TypeName(double_) = "Double" , "TypeName(double_) is not ""Double""" ) + assert( TypeName(currency_) = "Currency", "TypeName(currency_) is not ""Currency""" ) + assert( TypeName(string_) = "String" , "TypeName(string_) is not ""String""" ) + + assert( TypeName(intArray) = "Integer()" , "TypeName(intArray) is not ""Integer()""" ) + assert( TypeName(lngArray) = "Long()" , "TypeName(lngArray) is not ""Long()""" ) + assert( TypeName(sngArray) = "Single()" , "TypeName(sngArray) is not ""Single()""" ) + assert( TypeName(dblArray) = "Double()" , "TypeName(dblArray) is not ""Double()""" ) + assert( TypeName(curArray) = "Currency()", "TypeName(curArray) is not ""Currency()""" ) + assert( TypeName(datArray) = "Date()" , "TypeName(datArray) is not ""Date()""" ) + assert( TypeName(strArray) = "String()" , "TypeName(strArray) is not ""String()""" ) + assert( TypeName(objArray) = "Object()" , "TypeName(objArray) is not ""Object()""" ) + assert( TypeName(boolArray) = "Boolean()" , "TypeName(boolArray) is not ""Boolean()""" ) + assert( TypeName(varArray) = "Variant()" , "TypeName(varArray) is not ""Variant()""" ) + assert( TypeName(byteArray) = "Byte()" , "TypeName(byteArray) is not ""Byte()""" ) + If FailedAssertion Then + doUnitTest = "test_typename_method.vb failed" + messages + Exit Function + EndIf + doUnitTest = "OK" ' All checks passed +End Function + +Sub DEV_TEST : Print doUnitTest : End Sub + +Dim failedAssertion As Boolean, messages As String + +Sub assert(expression As Boolean, errMessage As String) + if ( Not expression ) Then + messages = messages + Chr(10) + ErrMessage + failedAssertion = True + EndIf +End Sub diff --git a/basic/qa/basic_coverage/test_types_conversion.bas b/basic/qa/basic_coverage/test_types_conversion.bas new file mode 100644 index 000000000..2d9311453 --- /dev/null +++ b/basic/qa/basic_coverage/test_types_conversion.bas @@ -0,0 +1,86 @@ +' +' 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 + +' See LibreOffice6FloatingPointMode in basic/source/runtime/methods1.cxx +Function LibreOffice6FloatingPointMode() As Boolean + Dim bMode As Boolean + bMode = Environ("LIBREOFFICE6FLOATINGPOINTMODE") <> "" + If (Not bMode) Then + Dim oConfigProvider As Object, aNodePath(0) As New com.sun.star.beans.PropertyValue, oRegistryKey As Object + oConfigProvider = createUnoService("com.sun.star.configuration.ConfigurationProvider") + aNodePath(0).Name = "nodepath" + aNodePath(0).Value = "org.openoffice.Office.Scripting/Basic/Compatibility" + oRegistryKey = oConfigProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", aNodePath) + bMode = oRegistryKey.getPropertyValue("UseLibreOffice6FloatingPointConversion") + End If + LibreOffice6FloatingPointMode = bMode +End Function + +' For the following tests the en-US (English - United States) locale is required +Function doUnitTest() As String + 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) + + If LibreOffice6FloatingPointMode() Then + ' Wrong decimal separator (and not even interpreted as group separator) + StartTest() + nVal = " -123,45 " + AssertTest(nVal = -123) + Else + ' Wrong decimal separator (interpreted as group separator) + StartTest() + nVal = " -123,456 " + AssertTest(nVal = -123456) + End If + + If ((nFailCount > 0) Or (nPassCount <> nTotalCount)) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + 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.bas b/basic/qa/basic_coverage/test_ucase_method.bas new file mode 100644 index 000000000..21779e148 --- /dev/null +++ b/basic/qa/basic_coverage/test_ucase_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + dim aString as Variant + aString = "Hello" + ' UCASE + If ( UCase( aString ) <> "HELLO" ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_val_method.bas b/basic/qa/basic_coverage/test_val_method.bas new file mode 100644 index 000000000..306d15b4f --- /dev/null +++ b/basic/qa/basic_coverage/test_val_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + ' VAL + If ( Val("4") <> 4 ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_vartype_method.bas b/basic/qa/basic_coverage/test_vartype_method.bas new file mode 100644 index 000000000..3ab6f1f44 --- /dev/null +++ b/basic/qa/basic_coverage/test_vartype_method.bas @@ -0,0 +1,93 @@ +' +' 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 + +Type UDF ' User defined type + l As Object + s as String +End Type +Dim myUDF As UDF + +Dim int16 As Integer, int32 As Long, flt32 As Single, flt64 As Double, _ + curr As Currency, dat As Date, str As String, obj As Object, _ + myErr As Variant, var As Variant, byt3 As Byte, bool As Boolean + +Dim int_%, long_&, single_!, double_#, currency_@, string_$, array_ + +Dim intArray() As Integer, lngArray(5) As Long, sngArray!() As Single, dblArray#(8) As Double, _ + curArray@() As Currency, datArray() As Date, strArray$() As String, objArray() As Object, _ + varArray() As Variant, byteArray() As Byte, boolArray() As Boolean + +' Constants that candidate for public exposure +Private Const V_ARRAY=8192, V_OBJECT=9, V_ERROR=10, V_BOOLEAN=11, V_VARIANT=12, V_BYTE=17 + +Function doUnitTest() As String + TestUtil.TestInit + verify_testvartype + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_testvartype() + On Error GoTo errorHandler + + ' VarType() + + TestUtil.AssertEqual( V_EMPTY, 0 , "V_EMPTY is not 0") + TestUtil.AssertEqual( V_NULL, 1 , "V_NULL is not 1") + TestUtil.AssertEqual( V_INTEGER, 2 , "V_INTEGER is not 2") + TestUtil.AssertEqual( V_LONG, 3 , "V_LONG is not 3") + TestUtil.AssertEqual( V_SINGLE, 4 , "V_SINGLE is not 4") + TestUtil.AssertEqual( V_DOUBLE, 5 , "V_DOUBLE is not 5") + TestUtil.AssertEqual( V_CURRENCY, 6, "V_CURRENCY is not 6") + TestUtil.AssertEqual( V_DATE, 7 , "V_DATE is not 7") + TestUtil.AssertEqual( V_STRING, 8 , "V_STRING is not 8") + + TestUtil.AssertEqual( VarType(Empty) , V_EMPTY , "Vartype(Empty) is not V_EMPTY") + TestUtil.AssertEqual( VarType(Null) , V_NULL , "Vartype(Empty) is not V_NULL") + TestUtil.AssertEqual( VarType(Nothing), V_OBJECT, "Vartype(Empty) is not V_OBJECT") + + myErr = CVErr("errMsg") + TestUtil.AssertEqual( VarType(int16), V_INTEGER , "VarType(int16) is not V_INTEGER") + TestUtil.AssertEqual( VarType(int32), V_LONG , "VarType(int32) is not V_LONG") + TestUtil.AssertEqual( VarType(flt32), V_SINGLE , "VarType(flt32) is not V_SINGLE" ) + TestUtil.AssertEqual( VarType(flt64), V_DOUBLE , "VarType(flt64) is not V_DOUBLE" ) + TestUtil.AssertEqual( VarType(curr) , V_CURRENCY, "VarType(curr) is not V_CURRENCY" ) + TestUtil.AssertEqual( VarType(dat) , V_DATE , "VarType(dat) is not V_DATE" ) + TestUtil.AssertEqual( VarType(str) , V_STRING , "VarType(str) is not V_STRING" ) + TestUtil.AssertEqual( VarType(obj) , V_OBJECT , "VarType(obj) is not V_OBJECT" ) + TestUtil.AssertEqual( VarType(myUDF), V_OBJECT , "VarType(myUDF) is not V_OBJECT" ) + TestUtil.AssertEqual( VarType(myErr), V_ERROR , "VarType(myErr) is not V_ERROR" ) + TestUtil.AssertEqual( VarType(bool) , V_BOOLEAN , "VarType(bool) is not V_BOOLEAN" ) + TestUtil.AssertEqual( VarType(var) , V_EMPTY , "VarType(var) is not V_EMPTY" ) + TestUtil.AssertEqual( VarType(byt3) , V_BYTE , "VarType(byt3) is not V_BYTE" ) + + TestUtil.AssertEqual( VarType(int_) , V_INTEGER , "VarType(int_) is not V_INTEGER" ) + TestUtil.AssertEqual( VarType(long_) , V_LONG , "VarType(long_) is not V_LONG" ) + TestUtil.AssertEqual( VarType(single_) , V_SINGLE , "VarType(single_) is not V_SINGLE" ) + TestUtil.AssertEqual( VarType(double_) , V_DOUBLE , "VarType(double_) is not V_CURRENCY" ) + TestUtil.AssertEqual( VarType(currency_), V_CURRENCY, "VarType(currency_) is not V_CURRENCY" ) + TestUtil.AssertEqual( VarType(string_) , V_STRING , "VarType(string_) is not V_STRING" ) + + TestUtil.AssertEqual( VarType(intArray) , V_ARRAY+V_INTEGER , "VarType(intArray) is not V_ARRAY+V_INTEGER" ) + TestUtil.AssertEqual( VarType(lngArray) , V_ARRAY+V_LONG , "VarType(lngArray) is not V_ARRAY+V_LONG" ) + TestUtil.AssertEqual( VarType(sngArray) , V_ARRAY+V_SINGLE , "VarType(sngArray) is not V_ARRAY+V_SINGLE" ) + TestUtil.AssertEqual( VarType(dblArray) , V_ARRAY+V_DOUBLE , "VarType(dblArray) is not V_ARRAY+V_DOUBLE" ) + TestUtil.AssertEqual( VarType(curArray) , V_ARRAY+V_CURRENCY, "VarType(curArray) is not V_ARRAY+V_CURRENCY" ) + TestUtil.AssertEqual( VarType(datArray) , V_ARRAY+V_DATE , "VarType(datArray) is not V_ARRAY+V_DATE" ) + TestUtil.AssertEqual( VarType(strArray) , V_ARRAY+V_STRING , "VarType(strArray) is not V_ARRAY+V_STRING" ) + TestUtil.AssertEqual( VarType(objArray) , V_ARRAY+V_OBJECT , "VarType(objArray) is not V_ARRAY+V_OBJECT" ) + 'TestUtil.AssertEqual( VarType(***Array) , V_ARRAY+V_ERROR , "VarType(***Array) is not V_ARRAY+V_ERROR" ) + TestUtil.AssertEqual( VarType(boolArray), V_ARRAY+V_BOOLEAN , "VarType(boolArray) is not V_ARRAY+V_BOOLEAN" ) + TestUtil.AssertEqual( VarType(varArray) , V_ARRAY+V_VARIANT , "VarType(varArray) is not V_ARRAY+V_VARIANT" ) + TestUtil.AssertEqual( VarType(byteArray), V_ARRAY+V_BYTE , "VarType(byteArray) is not V_ARRAY+V_BYTE" ) + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_testvartype", Err, Error$, Erl) +End Sub diff --git a/basic/qa/basic_coverage/test_wait_method.bas b/basic/qa/basic_coverage/test_wait_method.bas new file mode 100644 index 000000000..b9bd0e5f0 --- /dev/null +++ b/basic/qa/basic_coverage/test_wait_method.bas @@ -0,0 +1,14 @@ +' 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 + +Function doUnitTest as String + ' WAIT + Wait(0) + doUnitTest = "OK" +End Function diff --git a/basic/qa/basic_coverage/test_weekday_method.bas b/basic/qa/basic_coverage/test_weekday_method.bas new file mode 100644 index 000000000..3c66c0dfa --- /dev/null +++ b/basic/qa/basic_coverage/test_weekday_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + dim aDate as Date + aDate = Date() + ' WEEKDAY + If ( Weekday( aDate ) <> WeekDay( aDate ) ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/test_year_method.bas b/basic/qa/basic_coverage/test_year_method.bas new file mode 100644 index 000000000..6852f3986 --- /dev/null +++ b/basic/qa/basic_coverage/test_year_method.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + dim aDate as Date + aDate = Date() + ' YEAR + If ( DatePart( "yyyy", aDate ) <> Year( aDate ) ) Then + doUnitTest = "FAIL" + Else + doUnitTest = "OK" + End If +End Function diff --git a/basic/qa/basic_coverage/uno_struct_assign.bas b/basic/qa/basic_coverage/uno_struct_assign.bas new file mode 100644 index 000000000..f004762c5 --- /dev/null +++ b/basic/qa/basic_coverage/uno_struct_assign.bas @@ -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/. +' + +Option Explicit + +Function doUnitTest as String + 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 = "OK" +End Function |