diff options
Diffstat (limited to 'basic/qa')
75 files changed, 1541 insertions, 184 deletions
diff --git a/basic/qa/basic_coverage/da-DK/test_ccur_da_DK_locale.bas b/basic/qa/basic_coverage/da-DK/test_ccur_da_DK_locale.bas new file mode 100644 index 000000000000..52b8d3b6f1aa --- /dev/null +++ b/basic/qa/basic_coverage/da-DK/test_ccur_da_DK_locale.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 + TestUtil.TestInit + verify_testCCurDaDKLocale + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_testCCurDaDKLocale + On Error GoTo errorHandler + + ' tdf#141050 - characteristic test for CCur() with the da_DK locale + TestUtil.AssertEqual(CCur("75,50"), 75.5, "CCur(75,50)") + TestUtil.AssertEqual(CCur("75,50 kr."), 75.5, "CCur(75,50 kr.)") + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_testCCurDaDKLocale", 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 deleted file mode 100644 index d2ae7ae45ff8..000000000000 --- a/basic/qa/basic_coverage/string_left_01.bas +++ /dev/null @@ -1,26 +0,0 @@ -' -' This file is part of the LibreOffice project. -' -' This Source Code Form is subject to the terms of the Mozilla Public -' License, v. 2.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 deleted file mode 100644 index a291d0704bf3..000000000000 --- a/basic/qa/basic_coverage/string_right_01.bas +++ /dev/null @@ -1,26 +0,0 @@ -' -' This file is part of the LibreOffice project. -' -' This Source Code Form is subject to the terms of the Mozilla Public -' License, v. 2.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 000000000000..3eca805fb1a9 --- /dev/null +++ b/basic/qa/basic_coverage/test_CallByName.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 + 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 000000000000..06ed6b66588d --- /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_ccur_method.bas b/basic/qa/basic_coverage/test_ccur_method.bas index cd700cad3c8e..c42dcb938590 100644 --- a/basic/qa/basic_coverage/test_ccur_method.bas +++ b/basic/qa/basic_coverage/test_ccur_method.bas @@ -9,16 +9,73 @@ Option Explicit Function doUnitTest as String + TestUtil.TestInit + verify_testCCur + doUnitTest = TestUtil.GetResult() +End Function - doUnitTest = "FAIL" +Sub verify_testCCur + On Error GoTo errorHandler ' CCUR - if (CCur("100") <> 100) Then Exit Function + TestUtil.AssertEqual(CCur("100"), 100, "CCur(100)") + ' tdf#141050 - passing a number with + sign - if (CCur("+100") <> 100) Then Exit Function + TestUtil.AssertEqual(CCur("+100"), 100, "CCur(100)") ' tdf#141050 - passing a number with - sign - if (CCur("-100") <> -100) Then Exit Function + TestUtil.AssertEqual(CCur("-100"), -100, "CCur(-100)") - doUnitTest = "OK" + ' tdf#128122 - verify en_US locale currency format behavior + TestUtil.AssertEqual(CCur("$100"), 100, "CCur($100)") + TestUtil.AssertEqual(CCur("$1.50"), 1.5, "CCur($1.50)") -End Function + verify_testCCurUnderflow + verify_testCCurOverflow + verify_testCCurInvalidFormat + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_testCCur", Err, Error$, Erl) +End Sub + +sub verify_testCCurUnderflow + On Error GoTo underflowHandler + + ' tdf$128122 - test underflow condition + CCur("-9223372036854775809") + TestUtil.Assert(False, "verify_testCCur", "underflow error not raised") + + Exit Sub +underflowHandler: + If(Err <> 6) Then + TestUtil.Assert(False, "verify_testCCur", "underflow error incorrect type") + Endif +End Sub + +sub verify_testCCurOverflow + On Error GoTo overflowHandler + + ' tdf$128122 - test overflow condition + CCur("9223372036854775808") + TestUtil.Assert(False, "verify_testCCur", "overflow error not raised") + + Exit Sub +overflowHandler: + If(Err <> 6) Then + TestUtil.Assert(False, "verify_testCCur", "overflow error incorrect type") + Endif +End Sub + +sub verify_testCCurInvalidFormat + On Error GoTo invalidFormatHandler + + ' tdf$128122 - test invalid format in en_US locale + CCur("75,50 kr") + TestUtil.Assert(False, "verify_testCCur", "invalid format error not raised") + + Exit Sub +invalidFormatHandler: + If(Err <> 13) Then + TestUtil.Assert(False, "verify_testCCur", "invalid format error incorrect type") + Endif +End Sub diff --git a/basic/qa/basic_coverage/test_cdbl_method.bas b/basic/qa/basic_coverage/test_cdbl_method.bas index 1c7837fcaa4b..e44c23456ff1 100644 --- a/basic/qa/basic_coverage/test_cdbl_method.bas +++ b/basic/qa/basic_coverage/test_cdbl_method.bas @@ -1,18 +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/. -' +'
+' This file is part of the LibreOffice project.
+'
+' This Source Code Form is subject to the terms of the Mozilla Public
+' License, v. 2.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 Explicit +Function doUnitTest() As String
+ TestUtil.TestInit
+ verify_testCdbl
+ doUnitTest = TestUtil.GetResult()
+End Function +
+Sub verify_testCdbl + On Error GoTo errorHandler -Function doUnitTest as String ' CDBL - If (CDbl("100") <> 100) Then - doUnitTest = "FAIL" - Else - doUnitTest = "OK" - End If -End Function + 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_converttofromurl_methods.bas b/basic/qa/basic_coverage/test_converttofromurl_methods.bas index d1dbcfc5ff73..c17d17e631e3 100644 --- a/basic/qa/basic_coverage/test_converttofromurl_methods.bas +++ b/basic/qa/basic_coverage/test_converttofromurl_methods.bas @@ -7,11 +7,28 @@ Option Explicit -Function doUnitTest as String - ' ConvertFromUrl ConvertToUrl - If ( ConvertToUrl( ConvertFromUrl("") ) <> "") Then - doUnitTest = "FAIL" +Function doUnitTest() As String + TestUtil.TestInit + verify_testConvertToFromUrl + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_testConvertToFromUrl + On Error GoTo errorHandler + + TestUtil.AssertEqual( ConvertToUrl( ConvertFromUrl("") ), "", "ConvertToUrl( ConvertFromUrl("") )") + + ' tdf#152917: Without the fix in place, this test would have failed with + ' Failed: ConvertFromUrl("file:///foo/bar/test.txt") returned , expected /foo/bar/test.txt + If (GetGUIType() <> 1) Then + 'Linux + TestUtil.AssertEqual( ConvertFromUrl("file:///foo/bar/test.txt"), "/foo/bar/test.txt", "ConvertFromUrl(""file:///foo/bar/test.txt"")") Else - doUnitTest = "OK" + 'Windows + TestUtil.AssertEqual( ConvertFromUrl("file://foo/bar/test.txt"), "\\foo\bar\test.txt", "ConvertFromUrl(""file://foo/bar/test.txt"")") End If -End Function + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_testConvertToFromUrl", Err, Error$, Erl) +End Sub diff --git a/basic/qa/basic_coverage/test_cstr_method.bas b/basic/qa/basic_coverage/test_cstr_method.bas index 48b27640c275..c2ac003e8c8c 100644 --- a/basic/qa/basic_coverage/test_cstr_method.bas +++ b/basic/qa/basic_coverage/test_cstr_method.bas @@ -21,6 +21,7 @@ Sub verify_testCStr 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 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 000000000000..7bdd1b170492 --- /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_ismissing_basic.bas b/basic/qa/basic_coverage/test_ismissing_basic.bas index ed43a3ad19ee..0996da0f82a4 100644 --- a/basic/qa/basic_coverage/test_ismissing_basic.bas +++ b/basic/qa/basic_coverage/test_ismissing_basic.bas @@ -1,3 +1,10 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + Const IsMissingNone = -1 Const IsMissingA = 0 Const IsMissingB = 1 diff --git a/basic/qa/basic_coverage/test_ismissing_cascade.bas b/basic/qa/basic_coverage/test_ismissing_cascade.bas index f2f3a8b20564..3c6d9a71c09a 100644 --- a/basic/qa/basic_coverage/test_ismissing_cascade.bas +++ b/basic/qa/basic_coverage/test_ismissing_cascade.bas @@ -1,3 +1,10 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.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 diff --git a/basic/qa/basic_coverage/test_ismissing_compatible.bas b/basic/qa/basic_coverage/test_ismissing_compatible.bas index fb7e6981d74c..6d11ab0902be 100644 --- a/basic/qa/basic_coverage/test_ismissing_compatible.bas +++ b/basic/qa/basic_coverage/test_ismissing_compatible.bas @@ -1,3 +1,10 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.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 Const IsMissingNone = -1 diff --git a/basic/qa/basic_coverage/test_join_method.bas b/basic/qa/basic_coverage/test_join_method.bas index 9076a0f8d83e..a3769ae188ff 100644 --- a/basic/qa/basic_coverage/test_join_method.bas +++ b/basic/qa/basic_coverage/test_join_method.bas @@ -7,14 +7,28 @@ Option Explicit -Function doUnitTest as String - ' Join +Function doUnitTest() As String + TestUtil.TestInit + verify_Join_method + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_Join_method + On Error GoTo errorHandler + + ' 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 + TestUtil.AssertEqual(Join( aStrings, " " ), "Hello world ", "Join(aStrings, "" "" is not ""Hello world """) + + ' tdf#141474 keyword names need to match that of VBA + Dim aList(0 to 7) As String : aList = Array("(", "Star", "|", "Open", "|", "Libre", ")", "Office") + TestUtil.AssertEqual(Join(sourceArray:=aList), "( Star | Open | Libre ) Office", "Join() with 1 keyword name") + TestUtil.AssertEqual(Join(delimiter:="", sourceArray:=aList), "(Star|Open|Libre)Office", "Join() with 2 keyword names") + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_Join_method", Err, Error$, Erl) +End Sub + diff --git a/basic/qa/basic_coverage/test_left_method.bas b/basic/qa/basic_coverage/test_left_method.bas new file mode 100644 index 000000000000..1c33bc9a711c --- /dev/null +++ b/basic/qa/basic_coverage/test_left_method.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 + +Function doUnitTest() As String + TestUtil.TestInit + verify_Left_method + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_Left_method + On Error GoTo errorHandler + + ' LEFT + TestUtil.AssertEqual(Left("abc", 2), "ab", "Left(""abc"",2)") + + ' tdf#141474 keyword names need to match that of VBA + TestUtil.AssertEqual(Left(Length:=4, String:="sometext"), "some", "Left(Length:=4, String:=""sometext"")") + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_Left_method", Err, Error$, Erl) +End Sub diff --git a/basic/qa/basic_coverage/test_like.bas b/basic/qa/basic_coverage/test_like.bas new file mode 100644 index 000000000000..2d018bf64f01 --- /dev/null +++ b/basic/qa/basic_coverage/test_like.bas @@ -0,0 +1,41 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Option Explicit + +Function doUnitTest() As String + TestUtil.TestInit + verify_testLike + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_testLike() + On Error GoTo errorHandler + ' Negation test + TestUtil.AssertEqual("!" Like "[.!?]", True, "Negation1") + TestUtil.AssertEqual("a" Like "[!abc]", False, "Negation2") + TestUtil.AssertEqual("!" Like "[!!?]", False, "Negation3") + TestUtil.AssertEqual("^" Like "[.!?]", False, "Negation4") + TestUtil.AssertEqual("^" Like "[.^?]", True, "Negation5") + ' Like test from microsoft vba + TestUtil.AssertEqual("aBBBa" Like "a*a", True, "Like1") + TestUtil.AssertEqual("F" Like "[A-Z]", True, "Like2") + TestUtil.AssertEqual("F" Like "[!A-Z]", False, "Like3") + TestUtil.AssertEqual("a2a" Like "a#a", True, "Like4") + TestUtil.AssertEqual("aM5b" Like "a[L-P]#[!c-e]", True, "Like5") + TestUtil.AssertEqual("BAT123khg" Like "B?T*", True, "Like6") + TestUtil.AssertEqual("CAT123khg" Like "B?T*", False, "Like7") + TestUtil.AssertEqual("ab" Like "a*b", True, "Like8") + TestUtil.AssertEqual("a*b" Like "a [*]b", False, "Like9") + TestUtil.AssertEqual("axxxxxb" Like "a [*]b", False, "Like10") + TestUtil.AssertEqual("a [xyz" Like "a [[]*", True, "Like11") + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_testLike", Err, Error$, Erl) +End Sub diff --git a/basic/qa/basic_coverage/test_mid_keyword_names.bas b/basic/qa/basic_coverage/test_mid_keyword_names.bas new file mode 100644 index 000000000000..abe56043ad29 --- /dev/null +++ b/basic/qa/basic_coverage/test_mid_keyword_names.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 + TestUtil.TestInit + verify_Mid_method + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_Mid_method + On Error GoTo errorHandler + + ' tdf#141474 keyword names need to match that of VBA + TestUtil.AssertEqual(Mid(start:=6, string:="LibreOffice" ), "Office", "Mid() with 2 keyword names" ) + TestUtil.AssertEqual(Mid(length:=5, start:=1, string:="LibreOffice" ), "Libre", "Mid() with 3 keyword names" ) + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_Mid_method", Err, Error$, Erl) +End Sub
\ No newline at end of file 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 000000000000..c85c9cae12cb --- /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 000000000000..1abc272443c5 --- /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_option_base.bas b/basic/qa/basic_coverage/test_option_base.bas index 11afea50d75b..69282f80bec6 100644 --- a/basic/qa/basic_coverage/test_option_base.bas +++ b/basic/qa/basic_coverage/test_option_base.bas @@ -1,3 +1,10 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.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 Base 1 Option Explicit diff --git a/basic/qa/basic_coverage/test_option_base_compatible.bas b/basic/qa/basic_coverage/test_option_base_compatible.bas index 8001106a7bfc..296b208f582b 100644 --- a/basic/qa/basic_coverage/test_option_base_compatible.bas +++ b/basic/qa/basic_coverage/test_option_base_compatible.bas @@ -1,3 +1,10 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.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 Base 1 Option Compatible Option Explicit diff --git a/basic/qa/basic_coverage/test_optional_paramter_type.bas b/basic/qa/basic_coverage/test_optional_paramter_type.bas index 2a616c24044d..a98e422cd004 100644 --- a/basic/qa/basic_coverage/test_optional_paramter_type.bas +++ b/basic/qa/basic_coverage/test_optional_paramter_type.bas @@ -1,34 +1,40 @@ -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 +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.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 + 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 diff --git a/basic/qa/basic_coverage/test_optional_paramters_basic.bas b/basic/qa/basic_coverage/test_optional_paramters_basic.bas index a684fc256054..82880e11bdde 100644 --- a/basic/qa/basic_coverage/test_optional_paramters_basic.bas +++ b/basic/qa/basic_coverage/test_optional_paramters_basic.bas @@ -1,3 +1,10 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.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 testObject @@ -125,6 +132,12 @@ Sub verify_testOptionalsBasic() ' - 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) @@ -229,6 +242,15 @@ 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 diff --git a/basic/qa/basic_coverage/test_optional_paramters_compatible.bas b/basic/qa/basic_coverage/test_optional_paramters_compatible.bas index 56b314288e7a..78d14eb152eb 100644 --- a/basic/qa/basic_coverage/test_optional_paramters_compatible.bas +++ b/basic/qa/basic_coverage/test_optional_paramters_compatible.bas @@ -1,3 +1,10 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.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 @@ -127,6 +134,12 @@ Sub verify_testOptionalsCompatible() ' - 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) @@ -231,6 +244,15 @@ 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 diff --git a/basic/qa/basic_coverage/test_right_method.bas b/basic/qa/basic_coverage/test_right_method.bas new file mode 100644 index 000000000000..45801d5d8686 --- /dev/null +++ b/basic/qa/basic_coverage/test_right_method.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 + +Function doUnitTest() As String + TestUtil.TestInit + verify_Right_method + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_Right_method + On Error GoTo errorHandler + + ' RIGHT + TestUtil.AssertEqual(Right("abc", 2), "bc", "Right(""abc"",2)") + + ' tdf#141474 keyword names need to match that of VBA + TestUtil.AssertEqual(Right(Length:=4, String:="sometext"), "text", "Right(Length:=4, String:=""sometext"")") + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_Right_method", Err, Error$, Erl) +End Sub diff --git a/basic/qa/basic_coverage/test_split_method.bas b/basic/qa/basic_coverage/test_split_method.bas index 52ba91fe3a65..e53dfd9705f1 100644 --- a/basic/qa/basic_coverage/test_split_method.bas +++ b/basic/qa/basic_coverage/test_split_method.bas @@ -53,6 +53,12 @@ Sub verify_testSplit TestUtil.AssertEqual(VarType(splitArr(i)), 8200, "VarType(splitArr(i))") Next + ' tdf#141474 keyword names need to match that of VBA + TestUtil.AssertEqual(Split(expression:="LibreOffice StarOffice")(1), "StarOffice", "Split with 1 keyword name" ) + Dim txt As String : txt = "Libre_Office_Star_Office" + TestUtil.AssertEqual(Split(delimiter:="_", expression:=txt)(2), "Star", "Split with 2 keyword names" ) + TestUtil.AssertEqual(Split(limit:=3, delimiter:="_", expression:=txt)(2), "Star_Office", "Split with 3 keyword names" ) + Exit Sub errorHandler: TestUtil.ReportErrorHandler("verify_testSplit", Err, Error$, Erl) diff --git a/basic/qa/basic_coverage/test_string_method.bas b/basic/qa/basic_coverage/test_string_method.bas index b06726e6045f..39b567a7882f 100644 --- a/basic/qa/basic_coverage/test_string_method.bas +++ b/basic/qa/basic_coverage/test_string_method.bas @@ -7,11 +7,25 @@ Option Explicit -Function doUnitTest as String - ' STRING - If ( String( 3, "H" ) <> "HHH" ) Then - doUnitTest = "FAIL" - Else - doUnitTest = "OK" - End If +Dim failedAssertion As Boolean, messages As String + +Function doUnitTest ' String(Number As Long, Character As String) + + assert(String(3, "H")= "HHH", "String(3, ""H"") is not ""HHH""") + assert(String(5.8, "à")= "àààààà", "String(5.8, ""à"") is not ""àààààà""") + assert(String(Number:=3.45, Character:="test")="ttt", "String(Number:=3.45, Character:=""test"") is not ""ttt""") + assert(String(Character:="☺😎", Number:=7)= "☺☺☺☺☺☺☺", "String(Character:=""☺😎"", Number:=7) is not ""☺☺☺☺☺☺☺""") + + If FailedAssertion Then + doUnitTest = "test_string_method.vb failed" + messages + Exit Function + EndIf + doUnitTest = "OK" ' All checks passed End Function + +Sub assert(expression As Boolean, errMessage As String) + if ( Not expression ) Then + messages = messages + Chr(10) + ErrMessage + failedAssertion = True + EndIf +End Sub
\ No newline at end of file diff --git a/basic/qa/basic_coverage/test_string_overflow_safe.bas b/basic/qa/basic_coverage/test_string_overflow_safe.bas index f245e14abc4e..0b4fec15f0bd 100644 --- a/basic/qa/basic_coverage/test_string_overflow_safe.bas +++ b/basic/qa/basic_coverage/test_string_overflow_safe.bas @@ -1,3 +1,10 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.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 diff --git a/basic/qa/basic_coverage/test_string_replace.bas b/basic/qa/basic_coverage/test_string_replace.bas index d68f36fbb662..2b0f6354cd04 100644 --- a/basic/qa/basic_coverage/test_string_replace.bas +++ b/basic/qa/basic_coverage/test_string_replace.bas @@ -1,3 +1,10 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.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 VBASupport 0 Option Explicit 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 000000000000..1bb3b3de21c9 --- /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 index c310280fecdb..1f389f06cc86 100644 --- a/basic/qa/basic_coverage/test_tdf134692.bas +++ b/basic/qa/basic_coverage/test_tdf134692.bas @@ -1,3 +1,10 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.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 VBASupport 0 Option Explicit 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 000000000000..3d5e2271140c --- /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 100644 index 000000000000..67378213e287 --- /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_tdf149622.bas b/basic/qa/basic_coverage/test_tdf149622.bas new file mode 100644 index 000000000000..5c4738c068b2 --- /dev/null +++ b/basic/qa/basic_coverage/test_tdf149622.bas @@ -0,0 +1,48 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.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_tdf149622() + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_tdf149622() + On Error GoTo errorHandler + + ' Testing fixed-type return value (Handler_handleEvent(...) As Boolean) + Dim oHandler + oHandler = CreateUnoListener("Handler_", "com.sun.star.awt.XEventHandler") + TestUtil.AssertEqualStrict(oHandler.handleEvent(0), True, "oHandler.handleEvent(0)") + ' Before the fix for tdf#149622, this returned the previous return value + TestUtil.AssertEqualStrict(oHandler.handleEvent(1), False, "oHandler.handleEvent(1)") + + ' Testing Variant return value (Transfer_getData) + Dim oTransferable, aId0(0) As Byte, aId1(1) As Byte + oTransferable = CreateUnoListener("Transfer_", "com.sun.star.datatransfer.XSystemTransferable") + TestUtil.AssertEqualStrict(oTransferable.getData(aId0), True, "oTransferable.getData(aId0)") + ' Before the fix for tdf#149622, this returned the previous return value + TestUtil.AssertEqualStrict(oTransferable.getData(aId1), Empty, "oTransferable.getData(aId1)") + + Exit Sub + +errorHandler: + TestUtil.ReportErrorHandler("verify_tdf149622", Err, Error$, Erl) +End Sub + +Function Handler_handleEvent(Event) As Boolean + If Event = 0 Then Handler_handleEvent = True + ' Do not define return value explicitly in Else case +End Function + +Function Transfer_getData(aProcessId()) + If UBound(aProcessId) - LBound(aProcessId) = 0 Then Transfer_getData = True ' only for 1-element array + ' Do not define return value explicitly in Else case +End Function diff --git a/basic/qa/basic_coverage/test_tdf150137_parse_fail.bas b/basic/qa/basic_coverage/test_tdf150137_parse_fail.bas new file mode 100644 index 000000000000..fdf9f1e9948e --- /dev/null +++ b/basic/qa/basic_coverage/test_tdf150137_parse_fail.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 + On Error GoTo ErrorHandler ' Set up error handler + + Dim Xml As String + Dim XmlLen As Long + ' Not namespace-well-formed XML, parse is expected to fail + Xml = "<a:xml/>" + XmlLen = Len(Xml) + Dim XmlByte(1 To XmlLen) As Byte + Dim Index As Integer + For Index = 1 To XmlLen + XmlByte(Index) = Asc(Mid(Xml, Index, 1)) + Next + Dim source As Object + source = CreateUnoStruct("com.sun.star.xml.sax.InputSource") + source.aInputStream = com.sun.star.io.SequenceInputStream.createStreamFromSequence(XmlByte) + Dim parser As Object + parser = CreateUnoService("com.sun.star.xml.sax.FastParser") + ' Parse crashed before the fix + parser.ParseStream(source) + + ' Shouldn't end up here + doUnitTest = "FAIL" + Exit Function +ErrorHandler: + doUnitTest = "OK" +End Function diff --git a/basic/qa/basic_coverage/test_tdf98778.bas b/basic/qa/basic_coverage/test_tdf98778.bas index 0228e5060ba8..451d4bde70bc 100644 --- a/basic/qa/basic_coverage/test_tdf98778.bas +++ b/basic/qa/basic_coverage/test_tdf98778.bas @@ -1,3 +1,10 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.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 VBASupport 0 Option Explicit diff --git a/basic/qa/basic_coverage/test_transliteration.bas b/basic/qa/basic_coverage/test_transliteration.bas new file mode 100644 index 000000000000..dd5f24fb4dae --- /dev/null +++ b/basic/qa/basic_coverage/test_transliteration.bas @@ -0,0 +1,52 @@ +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.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_testTransliteration + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_testTransliteration + On Error GoTo errorHandler + + Dim oTr As Object, s$, oLoc as new com.sun.star.lang.Locale + + With oLoc + .Country="US" + .Language="en" + .Variant="" + End With + + s="AB cd. eF. " + oTr = CreateUnoService("com.sun.star.i18n.Transliteration") + + oTr.LoadModuleByImplName("LOWERCASE_UPPERCASE", oLoc) + TestUtil.AssertEqual(oTr.transliterateString2String(s, 0, Len(s)), "AB CD. EF. ", "LOWERCASE_UPPERCASE") + + oTr.LoadModuleByImplName("UPPERCASE_LOWERCASE", oLoc) + TestUtil.AssertEqual(oTr.transliterateString2String(s, 0, Len(s)), "ab cd. ef. ", "UPPERCASE_LOWERCASE") + + oTr.LoadModuleByImplName("TOGGLE_CASE", oLoc) + TestUtil.AssertEqual(oTr.transliterateString2String(s, 0, Len(s)), "ab CD. Ef. ", "TOGGLE_CASE") + + oTr.LoadModuleByImplName("IGNORE_CASE", oLoc) + TestUtil.AssertEqual(oTr.transliterateString2String(s, 0, Len(s)), "ab cd. ef. ", "IGNORE_CASE") + + ' tdf#152520: Without the fix in place, this test would have crashed here + oTr.LoadModuleByImplName("TITLE_CASE", oLoc) + TestUtil.AssertEqual(oTr.transliterateString2String(s, 0, Len(s)), "Ab cd. ef. ", "TITLE_CASE") + + oTr.LoadModuleByImplName("SENTENCE_CASE", oLoc) + TestUtil.AssertEqual(oTr.transliterateString2String(s, 0, Len(s)), "Ab cd. ef. ", "SENTENCE_CASE") + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_testTransliteration", Err, Error$, Erl) +End Sub diff --git a/basic/qa/basic_coverage/test_typename_method.bas b/basic/qa/basic_coverage/test_typename_method.bas index 80a9658d25a7..028f57f0e8db 100644 --- a/basic/qa/basic_coverage/test_typename_method.bas +++ b/basic/qa/basic_coverage/test_typename_method.bas @@ -27,6 +27,8 @@ Dim intArray() As Integer, lngArray(5) As Long, sngArray!() As Single, dblArra Function doUnitTest ' TypeName() myErr = CVErr(0.56E-41) + assert(TypeName(varName:=int16) = "Integer", "TypeName(varName:=int16) is not ""Integer""") + 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""" ) diff --git a/basic/qa/basic_coverage/test_unsigned_integers.bas b/basic/qa/basic_coverage/test_unsigned_integers.bas new file mode 100644 index 000000000000..d7f2385ecff5 --- /dev/null +++ b/basic/qa/basic_coverage/test_unsigned_integers.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_testUnsignedIntegers + doUnitTest = TestUtil.GetResult() +End Function + +Function convertToDouble(n) + Dim conv As Object + conv = CreateUnoService("com.sun.star.script.Converter") + convertToDouble = conv.convertToSimpleType(n, com.sun.star.uno.TypeClass.DOUBLE) +End Function + +Sub verify_testUnsignedIntegers() + On Error GoTo errorHandler + + Dim t As New com.sun.star.util.Time ' has both unsigned long and unsigned short + t.Seconds = 201 + t.NanoSeconds = 202 + Dim u8 As Byte, u16, u32 + u8 = 200 + u16 = t.Seconds ' UShort + u32 = t.NanoSeconds ' ULong + + TestUtil.AssertEqual(TypeName(u8), "Byte", "TypeName(u8)") + TestUtil.AssertEqual(convertToDouble(u8), 200, "convertToDouble(u8)") + + TestUtil.AssertEqual(TypeName(u16), "UShort", "TypeName(u16)") + TestUtil.AssertEqual(convertToDouble(u16), 201, "convertToDouble(u16)") + + TestUtil.AssertEqual(TypeName(u32), "ULong", "TypeName(u32)") + TestUtil.AssertEqual(convertToDouble(u32), 202, "convertToDouble(u32)") + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_testUnsignedIntegers", Err, Error$, Erl) +End Sub diff --git a/basic/qa/basic_coverage/test_vartype_method.bas b/basic/qa/basic_coverage/test_vartype_method.bas index 3ab6f1f44358..1b7372b27933 100644 --- a/basic/qa/basic_coverage/test_vartype_method.bas +++ b/basic/qa/basic_coverage/test_vartype_method.bas @@ -53,6 +53,8 @@ Sub verify_testvartype() TestUtil.AssertEqual( VarType(Nothing), V_OBJECT, "Vartype(Empty) is not V_OBJECT") myErr = CVErr("errMsg") + TestUtil.AssertEqual(VarType(varName:=int16), V_INTEGER, "VarType(varName:=int16) is not V_INTEGER") + 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" ) diff --git a/basic/qa/basic_coverage/zh-CN/test_ccur_zh_CN_locale.bas b/basic/qa/basic_coverage/zh-CN/test_ccur_zh_CN_locale.bas new file mode 100644 index 000000000000..38a084e36c7f --- /dev/null +++ b/basic/qa/basic_coverage/zh-CN/test_ccur_zh_CN_locale.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 + TestUtil.TestInit + verify_testCCurZhCNLocale + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_testCCurZhCNLocale + On Error GoTo errorHandler + + ' tdf#141050 - characteristic test for CCur() with the zh_CN locale + TestUtil.AssertEqual(CCur("75.50"), 75.5, "CCur(75.50)") + TestUtil.AssertEqual(CCur("¥75.50"), 75.5, "CCur(¥75.50)") + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_testCCurZhCNLocale", Err, Error$, Erl) +End Sub diff --git a/basic/qa/cppunit/_test_asserts.bas b/basic/qa/cppunit/_test_asserts.bas index 51442a0590a6..0c3e0b371f14 100644 --- a/basic/qa/cppunit/_test_asserts.bas +++ b/basic/qa/cppunit/_test_asserts.bas @@ -34,8 +34,8 @@ Sub Assert(Assertion As Boolean, Optional testId As String, Optional testComment If Not IsMissing(testId) Then testMsg = " " + testId End If - If Not IsMissing(testComment) And Not (testComment = "") Then - testMsg = testMsg + " (" + testComment + ")" + If Not IsMissing(testComment) Then + If Not (testComment = "") Then testMsg = testMsg + " (" + testComment + ")" End If result = result & Chr$(10) & " Failed:" & testMsg @@ -52,6 +52,12 @@ Sub AssertEqual(actual As Variant, expected As Variant, testName As String) End If End Sub +' Same as AssertEqual, but also checks actual and expected types +Sub AssertEqualStrict(actual As Variant, expected As Variant, testName As String) + AssertEqual actual, expected, testName + AssertEqual TypeName(actual), TypeName(expected), testName & " type mismatch:" +End Sub + Sub AssertEqualApprox(actual, expected, epsilon, testName As String) If Abs(expected - actual) <= epsilon Then passCount = passCount + 1 diff --git a/basic/qa/cppunit/_test_asserts.vb b/basic/qa/cppunit/_test_asserts.vb index 0f1d0d88610f..2130ce02f454 100644 --- a/basic/qa/cppunit/_test_asserts.vb +++ b/basic/qa/cppunit/_test_asserts.vb @@ -35,8 +35,8 @@ Sub Assert(Assertion As Boolean, Optional testId As String, Optional testComment If Not IsMissing(testId) Then testMsg = " " + testId End If - If Not IsMissing(testComment) And Not (testComment = "") Then - testMsg = testMsg + " (" + testComment + ")" + If Not IsMissing(testComment) Then + If Not (testComment = "") Then testMsg = testMsg + " (" + testComment + ")" End If result = result & Chr$(10) & " Failed:" & testMsg @@ -53,6 +53,12 @@ Sub AssertEqual(actual As Variant, expected As Variant, testName As String) End If End Sub +' Same as AssertEqual, but also checks actual and expected types +Sub AssertEqualStrict(actual As Variant, expected As Variant, testName As String) + AssertEqual actual, expected, testName + AssertEqual TypeName(actual), TypeName(expected), testName & " type mismatch:" +End Sub + Sub AssertEqualApprox(actual, expected, epsilon, testName As String) If Abs(expected - actual) <= epsilon Then passCount = passCount + 1 diff --git a/basic/qa/cppunit/basictest.cxx b/basic/qa/cppunit/basictest.cxx index 8cf9812d5212..13dc8c72e4cb 100644 --- a/basic/qa/cppunit/basictest.cxx +++ b/basic/qa/cppunit/basictest.cxx @@ -108,7 +108,7 @@ bool MacroSnippet::Compile() bool MacroSnippet::HasError() const { return mbError; } -const ErrCode& MacroSnippet::getError() const { return maErrCode; } +const ErrCodeMsg& MacroSnippet::getError() const { return maErrCode; } IMPL_LINK( MacroSnippet, BasicErrorHdl, StarBASIC *, /*pBasic*/, bool) { diff --git a/basic/qa/cppunit/basictest.hxx b/basic/qa/cppunit/basictest.hxx index 1901492bcfab..46af3542b82b 100644 --- a/basic/qa/cppunit/basictest.hxx +++ b/basic/qa/cppunit/basictest.hxx @@ -23,7 +23,7 @@ class MacroSnippet { private: bool mbError; - ErrCode maErrCode; + ErrCodeMsg maErrCode; BasicDLL maDll; // we need a dll instance for resource manager etc. SbModuleRef mpMod; StarBASICRef mpBasic; @@ -46,7 +46,7 @@ public: DECL_LINK(BasicErrorHdl, StarBASIC*, bool); bool HasError() const; - const ErrCode& getError() const; + const ErrCodeMsg& getError() const; }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basic/qa/cppunit/data/tdf149714.png b/basic/qa/cppunit/data/tdf149714.png Binary files differnew file mode 100644 index 000000000000..d22b8451864d --- /dev/null +++ b/basic/qa/cppunit/data/tdf149714.png diff --git a/basic/qa/cppunit/test_compiler_checks.cxx b/basic/qa/cppunit/test_compiler_checks.cxx index 24b380ed2a9a..2b8e72997c64 100644 --- a/basic/qa/cppunit/test_compiler_checks.cxx +++ b/basic/qa/cppunit/test_compiler_checks.cxx @@ -21,7 +21,7 @@ CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testRedefineArgument) "End Sub\n"); aMacro.Compile(); CPPUNIT_ASSERT(aMacro.HasError()); - CPPUNIT_ASSERT_EQUAL(ERRCODE_BASIC_VAR_DEFINED, aMacro.getError().StripDynamic()); + CPPUNIT_ASSERT_EQUAL(ERRCODE_BASIC_VAR_DEFINED, aMacro.getError().GetCode()); } CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testDoubleArgument) @@ -30,7 +30,141 @@ CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testDoubleArgument) "End Sub\n"); aMacro.Compile(); CPPUNIT_ASSERT(aMacro.HasError()); - CPPUNIT_ASSERT_EQUAL(ERRCODE_BASIC_VAR_DEFINED, aMacro.getError().StripDynamic()); + CPPUNIT_ASSERT_EQUAL(ERRCODE_BASIC_VAR_DEFINED, aMacro.getError().GetCode()); } +CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf149157) +{ + MacroSnippet aMacro("Function extentComment() As Integer\n" + " ' _\n" + " If Not extentComment Then\n" + " extentComment = 1\n" + " End If\n" + "End Function\n"); + aMacro.Compile(); + CPPUNIT_ASSERT(!aMacro.HasError()); +} + +CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf149157_compatible) +{ + MacroSnippet aMacro("Option Compatible\n" + "Function extentComment() As Integer\n" + " ' _\n" + "\n" + " If Not extentComment Then\n" + " extentComment = 1\n" + " End If\n" + "End Function\n"); + aMacro.Compile(); + CPPUNIT_ASSERT(!aMacro.HasError()); +} + +CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf149157_vba) +{ + MacroSnippet aMacro("Option VBASupport 1\n" + "Function extentComment() As Integer\n" + " ' _\n" + "\n" + " If Not extentComment Then\n" + " extentComment = 1\n" + " End If\n" + "End Function\n"); + aMacro.Compile(); + CPPUNIT_ASSERT(!aMacro.HasError()); +} + +CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf149402) +{ + MacroSnippet aMacro("Function extentComment() As Integer\n" + " ' _ \n" + " If Not extentComment Then\n" + " extentComment = 1\n" + " Else\n" + " End If\n" + "End Function\n"); + aMacro.Compile(); + CPPUNIT_ASSERT(!aMacro.HasError()); +} + +CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf149402_compatible) +{ + MacroSnippet aMacro("Option Compatible\n" + "Function extentComment() As Integer\n" + " ' _ \n" + " If Not extentComment Then\n" + " extentComment = 1\n" + " Else\n" + " End If\n" + "End Function\n"); + aMacro.Compile(); + CPPUNIT_ASSERT(!aMacro.HasError()); +} + +CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf149402_vba) +{ + MacroSnippet aMacro("Option VBASupport 1\n" + "Function extentComment() As Integer\n" + " ' _ \n" + " If Not extentComment Then\n" + " extentComment = 1\n" + " Else\n" + " End If\n" + "End Function\n"); + aMacro.Compile(); + CPPUNIT_ASSERT(!aMacro.HasError()); +} + +CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf93727_if) +{ + // #If and #End directive + MacroSnippet aMacro("Sub doUnitTest\n" + " #If 1 = 1 Then\n" + " Const a = 10\n" + " #End If\n" + "End Sub\n"); + aMacro.Compile(); + CPPUNIT_ASSERT_MESSAGE("#If directive causes compile error", !aMacro.HasError()); +} + +CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf93727_else) +{ + // #Else directive + MacroSnippet aMacro("Sub doUnitTest\n" + "a = 0\n" + "#If 1 = 0 Then\n" + " a = 10\n" + "#Else\n" + " a = 20\n" + "#End If\n" + "End Sub\n"); + aMacro.Compile(); + CPPUNIT_ASSERT_MESSAGE("#Else directive causes compile error", !aMacro.HasError()); +} + +CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf93727_elseif) +{ + // #ElseIf directive + MacroSnippet aMacro("Sub doUnitTest\n" + "a = 0\n" + " #If 1 = 0 Then\n" + " a = 10\n" + " #ElseIf 2 = 2 Then\n" + " a = 20\n" + " #End If\n" + "End Sub\n"); + aMacro.Compile(); + CPPUNIT_ASSERT_MESSAGE("#ElseIf directive causes compile error", !aMacro.HasError()); +} + +CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf93727_const) +{ + // #Const directive + MacroSnippet aMacro("#Const MaxValue = 1000\n" + "Sub doUnitTest\n" + " Dim value As Integer\n" + " value = MaxValue\n" + "End Sub\n"); + aMacro.Compile(); + CPPUNIT_ASSERT_MESSAGE("#Const directive causes compile error", !aMacro.HasError()); +} /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/basic/qa/cppunit/test_global_array.cxx b/basic/qa/cppunit/test_global_array.cxx index 5317e8701858..d2dafcfbda00 100644 --- a/basic/qa/cppunit/test_global_array.cxx +++ b/basic/qa/cppunit/test_global_array.cxx @@ -51,8 +51,8 @@ End Function )BAS"); CPPUNIT_ASSERT(mod->Compile()); - CPPUNIT_ASSERT_EQUAL(StarBASIC::GetErrBasic(), ERRCODE_NONE); - CPPUNIT_ASSERT_EQUAL(SbxBase::GetError(), ERRCODE_NONE); + CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, StarBASIC::GetErrBasic()); + CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, SbxBase::GetError()); CPPUNIT_ASSERT(mod->IsCompiled()); return mod; } diff --git a/basic/qa/cppunit/test_global_as_new.cxx b/basic/qa/cppunit/test_global_as_new.cxx index ea5b6fcc527c..868f62d3ec15 100644 --- a/basic/qa/cppunit/test_global_as_new.cxx +++ b/basic/qa/cppunit/test_global_as_new.cxx @@ -45,8 +45,8 @@ End Function )BAS"); CPPUNIT_ASSERT(mod->Compile()); - CPPUNIT_ASSERT_EQUAL(StarBASIC::GetErrBasic(), ERRCODE_NONE); - CPPUNIT_ASSERT_EQUAL(SbxBase::GetError(), ERRCODE_NONE); + CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, StarBASIC::GetErrBasic()); + CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, SbxBase::GetError()); CPPUNIT_ASSERT(mod->IsCompiled()); return mod; } diff --git a/basic/qa/cppunit/test_scanner.cxx b/basic/qa/cppunit/test_scanner.cxx index 6559b3e35d48..f17750c89a6e 100644 --- a/basic/qa/cppunit/test_scanner.cxx +++ b/basic/qa/cppunit/test_scanner.cxx @@ -69,12 +69,12 @@ private: CPPUNIT_TEST_SUITE_END(); }; -const OUString cr = "\n"; -const OUString rem = "REM"; -const OUString asdf = "asdf"; -const OUString dot = "."; -const OUString goto_ = "goto"; -const OUString excl = "!"; +constexpr OUString cr = u"\n"_ustr; +constexpr OUString rem = u"REM"_ustr; +constexpr OUString asdf = u"asdf"_ustr; +constexpr OUString dot = u"."_ustr; +constexpr OUString goto_ = u"goto"_ustr; +constexpr OUString excl = u"!"_ustr; std::vector<Symbol> getSymbols(const OUString& source, sal_Int32& errors, bool bCompatible = false) { @@ -160,14 +160,14 @@ void ScannerTest::testBlankLines() void ScannerTest::testOperators() { - const OUString sourceE("="); - const OUString sourceLT("<"); - const OUString sourceGT(">"); - const OUString sourceLTE("<="); - const OUString sourceGTE(">="); - const OUString sourceNE("<>"); - const OUString sourceA(":="); - const OUString sourceNot("Not"); + constexpr OUString sourceE(u"="_ustr); + constexpr OUString sourceLT(u"<"_ustr); + constexpr OUString sourceGT(u">"_ustr); + constexpr OUString sourceLTE(u"<="_ustr); + constexpr OUString sourceGTE(u">="_ustr); + constexpr OUString sourceNE(u"<>"_ustr); + constexpr OUString sourceA(u":="_ustr); + constexpr OUString sourceNot(u"Not"_ustr); std::vector<Symbol> symbols; @@ -239,12 +239,12 @@ void ScannerTest::testOperators() void ScannerTest::testAlphanum() { - const OUString source1("asdfghefg"); - const OUString source3("AdfsaAUdsl10987"); - const OUString source4("asdfa_mnvcnm"); - const OUString source5("_asdf1"); - const OUString source6("_6"); - const OUString source7("joxclk_"); + constexpr OUString source1(u"asdfghefg"_ustr); + constexpr OUString source3(u"AdfsaAUdsl10987"_ustr); + constexpr OUString source4(u"asdfa_mnvcnm"_ustr); + constexpr OUString source5(u"_asdf1"_ustr); + constexpr OUString source6(u"_6"_ustr); + constexpr OUString source7(u"joxclk_"_ustr); std::vector<Symbol> symbols; diff --git a/basic/qa/cppunit/test_tdf149714.cxx b/basic/qa/cppunit/test_tdf149714.cxx new file mode 100644 index 000000000000..76713508560c --- /dev/null +++ b/basic/qa/cppunit/test_tdf149714.cxx @@ -0,0 +1,86 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <sal/config.h> +#include <basic/sbstar.hxx> +#include <basic/sbmeth.hxx> +#include <cppunit/extensions/HelperMacros.h> + +#include <unotest/directories.hxx> + +namespace +{ +class TestTdf149714 : public CppUnit::TestFixture +{ + void testBitsPerPixel(); + + CPPUNIT_TEST_SUITE(TestTdf149714); + CPPUNIT_TEST(testBitsPerPixel); + CPPUNIT_TEST_SUITE_END(); + + StarBASICRef interpreter; + + SbModuleRef Module() + { + test::Directories aDirectories; + OUString aDataFileName + = aDirectories.getURLFromSrc(u"basic/qa/cppunit/data/") + u"tdf149714.png"; + OUString sBasic = uR"BAS( + +Function GetBitsPerPixelAsString As String + DIM oProps(0) As New "com.sun.star.beans.PropertyValue" + DIM oProvider, oGraphic + + oProps(0).Name = "URL" + oProps(0).Value = "$PNGFILENAME" + + oProvider = createUnoService("com.sun.star.graphic.GraphicProvider") + oGraphic = oProvider.queryGraphic(oProps()) + + GetBitsPerPixelAsString = oGraphic.BitsPerPixel + +End Function + +)BAS"_ustr; + + sBasic = sBasic.replaceFirst("$PNGFILENAME", aDataFileName); + + interpreter = new StarBASIC(); + auto mod = interpreter->MakeModule("BitsPerPixel", sBasic); + + CPPUNIT_ASSERT(mod->Compile()); + CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, StarBASIC::GetErrBasic()); + CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, SbxBase::GetError()); + CPPUNIT_ASSERT(mod->IsCompiled()); + return mod; + } +}; + +void TestTdf149714::testBitsPerPixel() +{ + auto m = Module(); + auto GetBitsPerPixelAsString = m->FindMethod("GetBitsPerPixelAsString", SbxClassType::Method); + CPPUNIT_ASSERT_MESSAGE("Could not Find GetBitsPerPixelAsString in module", + GetBitsPerPixelAsString != nullptr); + + SbxVariableRef returned = new SbxMethod{ *GetBitsPerPixelAsString }; + CPPUNIT_ASSERT(returned->IsString()); + + // Without the fix in place this would fail with: + // - Expected: 24 + // - Actual: True + CPPUNIT_ASSERT_EQUAL(OUString{ "24" }, returned->GetOUString()); +} + +// Put the test suite in the registry +CPPUNIT_TEST_SUITE_REGISTRATION(TestTdf149714); + +} // namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/basic/qa/cppunit/test_vba.cxx b/basic/qa/cppunit/test_vba.cxx index 818ba1c5f4c0..8a15ba7234e8 100644 --- a/basic/qa/cppunit/test_vba.cxx +++ b/basic/qa/cppunit/test_vba.cxx @@ -14,11 +14,7 @@ #include <comphelper/processfactory.hxx> #include <o3tl/char16_t2wchar_t.hxx> -#if !defined WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN -#endif -#include <windows.h> -#include <odbcinst.h> +#include <systools/win32/odbccp32.hxx> #endif using namespace ::com::sun::star; @@ -94,6 +90,7 @@ void VBATest::testMiscVBAFunctions() "hex.vb", "hour.vb", "formatnumber.vb", + "formatpercent.vb", "iif.vb", "instr.vb", "instrrev.vb", @@ -117,6 +114,7 @@ void VBATest::testMiscVBAFunctions() "minute.vb", "month.vb", "monthname.vb", + "like.vb", "oct.vb", "optional_paramters.vb", "qbcolor.vb", @@ -134,6 +132,9 @@ void VBATest::testMiscVBAFunctions() "string.vb", "strreverse.vb", "switch.vb", + "tdf147089_idiv.vb", + "tdf147529_optional_parameters_msgbox.vb", + "tdf148358_non_ascii_names.vb", "timeserial.vb", "timevalue.vb", "trim.vb", @@ -157,7 +158,7 @@ void VBATest::testMiscVBAFunctions() SvtSysLocaleOptions aLocalOptions; aLocalOptions.SetLocaleConfigString( aLocale.getBcp47() ); - for ( size_t i=0; i<SAL_N_ELEMENTS( macroSource ); ++i ) + for ( size_t i=0; i<std::size( macroSource ); ++i ) { OUString sMacroURL = sMacroPathURL + OUString::createFromAscii( macroSource[ i ] ); @@ -207,7 +208,8 @@ void VBATest::testMiscOLEStuff() const int nBufSize = 1024 * 4; wchar_t sBuf[nBufSize]; - SQLGetInstalledDriversW( sBuf, nBufSize, nullptr ); + if (!sal::systools::odbccp32().SQLGetInstalledDrivers(sBuf, nBufSize)) + return; const wchar_t *pODBCDriverName = sBuf; bool bFound = false; @@ -234,11 +236,11 @@ void VBATest::testMiscOLEStuff() uno::Sequence< uno::Any > aArgs { - uno::makeAny(sPath), - uno::makeAny(OUString(o3tl::toU(pODBCDriverName))) + uno::Any(sPath), + uno::Any(OUString(o3tl::toU(pODBCDriverName))) }; - for ( sal_uInt32 i=0; i<SAL_N_ELEMENTS( macroSource ); ++i ) + for ( sal_uInt32 i=0; i<std::size( macroSource ); ++i ) { OUString sMacroURL = sMacroPathURL + OUString::createFromAscii( macroSource[ i ] ); diff --git a/basic/qa/vba_tests/Err.Raise.vb b/basic/qa/vba_tests/Err.Raise.vb index 914906c342c0..d7714facb3bb 100644 --- a/basic/qa/vba_tests/Err.Raise.vb +++ b/basic/qa/vba_tests/Err.Raise.vb @@ -45,7 +45,7 @@ catch: TestUtil.Assert(Err.Source = CurErrSource, "Err.Source failure", "Err.Source = " & Err.Source) TestUtil.Assert(Err.Description = CurErrDescription, "Err.Description failure", "Err.Description = " & Err.Description) - TestUtil.Assert(Erl = 32, "line# failure", "Erl = " & Erl ' WATCH OUT for HARDCODED LINE # HERE !) + TestUtil.Assert(Erl = 32, "line# failure", "Erl = " & Erl ) ' WATCH OUT for HARDCODED LINE # HERE TestUtil.Assert(Err = CurErrNo, "Err# failure", "Err = " & Err) TestUtil.Assert(Error = CurErrDescription, "Error description failure", "Error$ = " & Error$) diff --git a/basic/qa/vba_tests/cdbl.vb b/basic/qa/vba_tests/cdbl.vb index f29271f082d6..8a7d09cd5a2e 100644 --- a/basic/qa/vba_tests/cdbl.vb +++ b/basic/qa/vba_tests/cdbl.vb @@ -23,6 +23,11 @@ Sub verify_testCdbl() TestUtil.AssertEqual(CDbl(0.005 * 0.01), 0.00005, "CDbl(0.005 * 0.01)") TestUtil.AssertEqual(CDbl("20"), 20, "CDbl(""20"")") + + ' 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) diff --git a/basic/qa/vba_tests/chr.vb b/basic/qa/vba_tests/chr.vb index 5dc85a0c9157..f9bc7ea12aa5 100644 --- a/basic/qa/vba_tests/chr.vb +++ b/basic/qa/vba_tests/chr.vb @@ -21,7 +21,7 @@ Sub verify_testCHR() 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)") diff --git a/basic/qa/vba_tests/constants.vb b/basic/qa/vba_tests/constants.vb index be7add515e83..c31444889fae 100644 --- a/basic/qa/vba_tests/constants.vb +++ b/basic/qa/vba_tests/constants.vb @@ -25,6 +25,15 @@ Sub verify_testConstants() TestUtil.AssertEqual(vbNewLine, vbLf, "vbNewline") End If + ' tdf#153543 - check for vba shell constants + ' See https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/shell-constants + TestUtil.AssertEqual(vbHide, 0, "vbHide") + TestUtil.AssertEqual(vbNormalFocus, 1, "vbNormalFocus") + TestUtil.AssertEqual(vbMinimizedFocus, 2, "vbMinimizedFocus") + TestUtil.AssertEqual(vbMaximizedFocus, 3, "vbMaximizedFocus") + TestUtil.AssertEqual(vbNormalNoFocus, 4, "vbNormalNoFocus") + TestUtil.AssertEqual(vbMinimizedNoFocus, 6, "vbMinimizedNoFocus") + ' tdf#131563 - check for vba color constants ' See https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/color-constants TestUtil.AssertEqual(vbBlack, RGB(0, 0, 0), "vbBlack") diff --git a/basic/qa/vba_tests/cstr.vb b/basic/qa/vba_tests/cstr.vb index dfa77b7db1f0..5eb43738f10c 100644 --- a/basic/qa/vba_tests/cstr.vb +++ b/basic/qa/vba_tests/cstr.vb @@ -24,6 +24,7 @@ Sub verify_testCStr() TestUtil.AssertEqual(CStr(500), "500", "CStr(500)") ' 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 diff --git a/basic/qa/vba_tests/format.vb b/basic/qa/vba_tests/format.vb index 0e997ca824db..67abc5ffe24a 100644 --- a/basic/qa/vba_tests/format.vb +++ b/basic/qa/vba_tests/format.vb @@ -135,7 +135,7 @@ Sub Custom_Number_Format_Sample() TestUtil.AssertEqual(Format(12345.25, "#,###.##"), "12,345.25", "Format(12345.25, ""#,###.##"")") TestUtil.AssertEqual(Format(0.25, "##.00%"), "25.00%", "Format(0.25, ""##.00%"")") TestUtil.AssertEqual(Format(1000000, "#,###"), "1,000,000", "Format(1000000, ""#,###"")") - TestUtil.AssertEqual(Format(1.09837555, "#.#####E+###"), "1.09838E+000", "Format(1.09837555, ""#.#####E+###"")") + TestUtil.AssertEqual(Format(1.09837555, "#.#####E+000"), "1.09838E+000", "Format(1.09837555, ""#.#####E+000"")") TestUtil.AssertEqual(Format(1.09837555, "###.####E#"), "1.0984E0", "Format(1.09837555, ""###.####E#"")") TestUtil.AssertEqual(Format(1098.37555, "###.####E#"), "1.0984E3", "Format(1098.37555, ""###.####E#"")") TestUtil.AssertEqual(Format(1098375.55, "###.####E#"), "1.0984E6", "Format(1098375.55, ""###.####E#"")") @@ -148,7 +148,8 @@ Sub Custom_Number_Format_Sample() TestUtil.AssertEqual(Format(123456, "####E0"), "12E4", "Format(123456, ""####E0"")") TestUtil.AssertEqual(Format(2345.25, "$#,###.##"), "$2,345.25", "Format(2345.25, ""$#,###.##"")") TestUtil.AssertEqual(Format(0.25, "##.###\%"), ".25%", "Format(0.25, ""##.###\%"")") - TestUtil.AssertEqual(Format(12.25, "0.???"), "12.25 ", "Format(12.25, ""0.???"")") + ' tdf#158890 blank replaced by figure blank + TestUtil.AssertEqual(Format(12.25, "0.???"), "12.25 ", "Format(12.25, ""0.???"")") Exit Sub errorHandler: diff --git a/basic/qa/vba_tests/formatpercent.vb b/basic/qa/vba_tests/formatpercent.vb new file mode 100644 index 000000000000..0a8c551c27f1 --- /dev/null +++ b/basic/qa/vba_tests/formatpercent.vb @@ -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 VBASupport 1 +Option Explicit + +Function doUnitTest() As String + TestUtil.TestInit + verify_testFormatPercent + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_testFormatPercent() + On Error GoTo errorHandler + + TestUtil.AssertEqual(FormatPercent("12.2", 2, vbFalse, vbFalse, vbFalse), "1220.00%", "FormatPercent(""12.2"", 2, vbFalse, vbFalse, vbFalse)") + TestUtil.AssertEqual(FormatPercent("-.2", 2, vbTrue, vbFalse, vbFalse), "-20.00%", "FormatPercent(""-.2"", 20, vbTrue, vbFalse, vbFalse)") + TestUtil.AssertEqual(FormatPercent("-0.2", 2, vbFalse, vbFalse, vbFalse), "-20.00%", "FormatPercent(""-0.2"", 20, vbFalse, vbFalse, vbFalse)") + TestUtil.AssertEqual(FormatPercent("-0.2", -1, vbFalse, vbTrue, vbFalse), "(20.00)%", "FormatPercent(""-0.2"", -1, vbFalse, vbTrue, vbFalse)") + TestUtil.AssertEqual(FormatPercent("-0.2", -1, vbUseDefault, vbTrue, vbFalse), "(20.00)%", "FormatPercent(""-0.2"", -1, vbUseDefault, vbTrue, vbFalse)") + TestUtil.AssertEqual(FormatPercent("-12345678", -1, vbUseDefault, vbUseDefault, vbTrue), "-1,234,567,800.00%", "FormatPercent(""-12345678"", -1, vbUseDefault, vbUseDefault, vbTrue)") + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_testFormatPercent", Err, Error$, Erl) +End Sub diff --git a/basic/qa/vba_tests/instrrev.vb b/basic/qa/vba_tests/instrrev.vb index 7d047fc74aa6..3849d60c5f7e 100644 --- a/basic/qa/vba_tests/instrrev.vb +++ b/basic/qa/vba_tests/instrrev.vb @@ -37,6 +37,13 @@ Sub verify_testInStrRev() ' This test should fail after tdf#110003 has been fixed. TestUtil.AssertEqual(InStrRev("Straße", "s", -1, 1), 5, "InStrRev(""Straße"", ""s"", -1, 1)") + ' tdf#141474 keyword names need to match that of VBA + Const vbBinaryCompare = 0, vbTextCompare = 1 + TestUtil.AssertEqual(InStrRev(stringMatch:="Star", stringCheck:="LibreOffice"), 0, "InStrRev(stringMatch:=""Star"", stringCheck:=""LibreOffice"")") + TestUtil.AssertEqual(InStrRev(Start:=-1, stringMatch:="Libre", stringCheck:="LibreOfficeLibre"), 12, "InStrRev(Start:=-1, stringMatch:=""Libre"", stringCheck:=""LibreOfficeLibre"")") + TestUtil.AssertEqual(InStrRev(Start:=12, stringMatch:="Libre", stringCheck:="LibreOfficeLibre"), 1, "InStrRev(Start:=12, stringMatch:=""Libre"", stringCheck:=""LibreOfficeLibre"")") + TestUtil.AssertEqual(InStrRev(Compare:=vbBinaryCompare, Start:=12, stringMatch:="Libre", stringCheck:="LibreOfficeLibre"), 1, "InStrRev(Compare:=vbBinaryCompare, Start:=12, stringMatch:=""Libre"", stringCheck:=""LibreOfficeLibre"")") + Exit Sub errorHandler: TestUtil.ReportErrorHandler("verify_testInStrRev", Err, Error$, Erl) diff --git a/basic/qa/vba_tests/join.vb b/basic/qa/vba_tests/join.vb index c4f568f812e1..8d6dd46dcd65 100644 --- a/basic/qa/vba_tests/join.vb +++ b/basic/qa/vba_tests/join.vb @@ -27,6 +27,11 @@ Sub verify_testJoin() TestUtil.AssertEqual(Join(vaArray, "<>"), "string1<>string2<>string3", "Join(vaArray, ""<>"")") TestUtil.AssertEqual(Join(vaArray, ""), "string1string2string3", "Join(vaArray, """")") + ' tdf#141474 keyword names need to match that of VBA + Dim aList(0 to 7) As String : aList = Array("(", "Star", "|", "Open", "|", "Libre", ")", "Office") + TestUtil.AssertEqual(Join(sourceArray:=aList), "( Star | Open | Libre ) Office", "Join() with 1 keyword name") + TestUtil.AssertEqual(Join(delimiter:="", sourceArray:=aList), "(Star|Open|Libre)Office", "Join() with 2 keyword names") + Exit Sub errorHandler: TestUtil.ReportErrorHandler("verify_testJoin", Err, Error$, Erl) diff --git a/basic/qa/vba_tests/left.vb b/basic/qa/vba_tests/left.vb index 047497ef0333..21ce3cefc6e0 100644 --- a/basic/qa/vba_tests/left.vb +++ b/basic/qa/vba_tests/left.vb @@ -22,6 +22,9 @@ Sub verify_testLeft() TestUtil.AssertEqual(Left("sometext", 48), "sometext", "Left(""sometext"", 48)") TestUtil.AssertEqual(Left("", 4), "", "Left("""", 4)") + ' tdf#141474 keyword names need to match that of VBA + TestUtil.AssertEqual(Left(Length:=4, String:="sometext"), "some", "Left(Length:=4, String:=""sometext"")") + Exit Sub errorHandler: TestUtil.ReportErrorHandler("verify_testLeft", Err, Error$, Erl) diff --git a/basic/qa/vba_tests/like.vb b/basic/qa/vba_tests/like.vb new file mode 100644 index 000000000000..c3be1e081b16 --- /dev/null +++ b/basic/qa/vba_tests/like.vb @@ -0,0 +1,42 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.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 VBASupport 1 +Option Explicit + +Function doUnitTest() As String + TestUtil.TestInit + verify_testLike + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_testLike() + On Error GoTo errorHandler + ' Negation test + TestUtil.AssertEqual("!" Like "[.!?]", True, "Negation1") + TestUtil.AssertEqual("a" Like "[!abc]", False, "Negation2") + TestUtil.AssertEqual("!" Like "[!!?]", False, "Negation3") + TestUtil.AssertEqual("^" Like "[.!?]", False, "Negation4") + TestUtil.AssertEqual("^" Like "[.^?]", True, "Negation5") + ' Like test from microsoft vba + TestUtil.AssertEqual("aBBBa" Like "a*a", True, "Like1") + TestUtil.AssertEqual("F" Like "[A-Z]", True, "Like2") + TestUtil.AssertEqual("F" Like "[!A-Z]", False, "Like3") + TestUtil.AssertEqual("a2a" Like "a#a", True, "Like4") + TestUtil.AssertEqual("aM5b" Like "a[L-P]#[!c-e]", True, "Like5") + TestUtil.AssertEqual("BAT123khg" Like "B?T*", True, "Like6") + TestUtil.AssertEqual("CAT123khg" Like "B?T*", False, "Like7") + TestUtil.AssertEqual("ab" Like "a*b", True, "Like8") + TestUtil.AssertEqual("a*b" Like "a [*]b", False, "Like9") + TestUtil.AssertEqual("axxxxxb" Like "a [*]b", False, "Like10") + TestUtil.AssertEqual("a [xyz" Like "a [[]*", True, "Like11") + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_testLike", Err, Error$, Erl) +End Sub diff --git a/basic/qa/vba_tests/mid.vb b/basic/qa/vba_tests/mid.vb index 863e24784512..ebd326109f5d 100644 --- a/basic/qa/vba_tests/mid.vb +++ b/basic/qa/vba_tests/mid.vb @@ -22,6 +22,10 @@ Sub verify_testMid() TestUtil.AssertEqual(Mid("Mid Function Demo", 14, 4), "Demo", "Mid(""Mid Function Demo"", 14, 4)") TestUtil.AssertEqual(Mid("Mid Function Demo", 5), "Function Demo", "Mid(""Mid Function Demo"", 5)") + ' tdf#141474 keyword names need to match that of VBA + TestUtil.AssertEqual(Mid(start:=6, string:="LibreOffice" ), "Office", "Mid() with 2 keyword names" ) + TestUtil.AssertEqual(Mid(length:=5, start:=1, string:="LibreOffice" ), "Libre", "Mid() with 3 keyword names" ) + Exit Sub errorHandler: TestUtil.ReportErrorHandler("verify_testMid", Err, Error$, Erl) diff --git a/basic/qa/vba_tests/ole_ObjAssignNoDflt.vb b/basic/qa/vba_tests/ole_ObjAssignNoDflt.vb index b1a591b0c94d..9817aa7437dc 100644 --- a/basic/qa/vba_tests/ole_ObjAssignNoDflt.vb +++ b/basic/qa/vba_tests/ole_ObjAssignNoDflt.vb @@ -1,3 +1,11 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.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 VBASupport 1 Function doUnitTest(TestData as String, Driver as String) as String Rem Ensure object assignment is by reference diff --git a/basic/qa/vba_tests/ole_ObjAssignToNothing.vb b/basic/qa/vba_tests/ole_ObjAssignToNothing.vb index d68664b41b72..9a0a557cdf31 100644 --- a/basic/qa/vba_tests/ole_ObjAssignToNothing.vb +++ b/basic/qa/vba_tests/ole_ObjAssignToNothing.vb @@ -1,3 +1,11 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.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 VBASupport 1 Function doUnitTest(TestData as String, Driver as String) as String Rem Ensure object assignment is by reference diff --git a/basic/qa/vba_tests/right.vb b/basic/qa/vba_tests/right.vb index c7cb583724d1..742fc43c3b79 100644 --- a/basic/qa/vba_tests/right.vb +++ b/basic/qa/vba_tests/right.vb @@ -22,6 +22,9 @@ Sub verify_testRight() TestUtil.AssertEqual(Right("sometext", 48), "sometext", "Right(""sometext"", 48)") TestUtil.AssertEqual(Right("", 4), "", "Right("""", 4)") + ' tdf#141474 keyword names need to match that of VBA + TestUtil.AssertEqual(Right(Length:=4, String:="sometext"), "text", "Right(Length:=4, String:=""sometext"")") + Exit Sub errorHandler: TestUtil.ReportErrorHandler("verify_testRight", Err, Error$, Erl) diff --git a/basic/qa/vba_tests/split.vb b/basic/qa/vba_tests/split.vb index 56d4522180b0..13f4d66a9539 100644 --- a/basic/qa/vba_tests/split.vb +++ b/basic/qa/vba_tests/split.vb @@ -51,6 +51,12 @@ Sub verify_testSplit ' - Actual : 8200 (8192 for Array and 8 for String) TestUtil.AssertEqual(VarType(splitArr(0)), 8, "VarType(splitArr(0))") + ' tdf#141474 keyword names need to match that of VBA + TestUtil.AssertEqual(Split(expression:="LibreOffice StarOffice")(1), "StarOffice", "Split with 1 keyword name" ) + Dim txt As String : txt = "Libre_Office_Star_Office" + TestUtil.AssertEqual(Split(delimiter:="_", expression:=txt)(2), "Star", "Split with 2 keyword names" ) + TestUtil.AssertEqual(Split(limit:=3, delimiter:="_", expression:=txt)(2), "Star_Office", "Split with 3 keyword names" ) + Exit Sub errorHandler: TestUtil.ReportErrorHandler("verify_testSplit", Err, Error$, Erl) diff --git a/basic/qa/vba_tests/strconv.vb b/basic/qa/vba_tests/strconv.vb index b0295df428b2..9b7dfaf21866 100644 --- a/basic/qa/vba_tests/strconv.vb +++ b/basic/qa/vba_tests/strconv.vb @@ -18,25 +18,30 @@ End Function Sub verify_testStrConv() On Error GoTo errorHandler - TestUtil.AssertEqual(StrConv("abc EFG hij", vbUpperCase), "ABC EFG HIJ", "StrConv(""abc EFG hij"", vbUpperCase)") - TestUtil.AssertEqual(StrConv("abc EFG hij", vbLowerCase), "abc efg hij", "StrConv(""abc EFG hij"", vbLowerCase)") - TestUtil.AssertEqual(StrConv("abc EFG hij", vbProperCase), "Abc Efg Hij", "StrConv(""abc EFG hij"", vbProperCase)") + TestUtil.AssertEqual(StrConv("abc EFG hij αβγ ΔΕΖ ηθι", vbUpperCase), "ABC EFG HIJ ΑΒΓ ΔΕΖ ΗΘΙ", "StrConv(""abc EFG hij αβγ ΔΕΖ ηθι"", vbUpperCase)") + TestUtil.AssertEqual(StrConv("abc EFG hij αβγ ΔΕΖ ηθι", vbLowerCase), "abc efg hij αβγ δεζ ηθι", "StrConv(""abc EFG hij αβγ ΔΕΖ ηθι"", vbLowerCase)") + TestUtil.AssertEqual(StrConv("abc EFG hij αβγ ΔΕΖ ηθι", vbProperCase), "Abc Efg Hij Αβγ Δεζ Ηθι", "StrConv(""abc EFG hij αβγ ΔΕΖ ηθι"", vbProperCase)") ' Converts narrow (single-byte) characters in string to wide TestUtil.AssertEqual(StrConv("ABCDEVB¥ì¥¹¥¥å©", vbWide), "ABCDEVB¥ì¥¹¥¥å©", "StrConv(""ABCDEVB¥ì¥¹¥¥å©"", vbWide)") + TestUtil.AssertEqual(StrConv("ABCDEVB¥ì¥¹¥¥å©", vbWide + vbLowerCase), "abcdevb¥ì¥¹¥¥å©", "StrConv(""ABCDEVB¥ì¥¹¥¥å©"", vbWide + vbLowerCase)") ' Converts wide (double-byte) characters in string to narrow (single-byte) characters TestUtil.AssertEqual(StrConv("ABCD@$%23'?EG", vbNarrow), "ABCD@$%23'?EG", "StrConv(""ABCD@$%23'?EG"", vbNarrow)") + TestUtil.AssertEqual(StrConv("ABCD@$%23'?EG", vbNarrow + vbLowerCase), "abcd@$%23'?eg", "StrConv(""ABCD@$%23'?EG"", vbNarrow + vbLowerCase)") ' Converts Hiragana characters in string to Katakana characters TestUtil.AssertEqual(StrConv("かたかな", vbKatakana), "カタカナ", "StrConv(""かたかな"", vbKatakana)") + TestUtil.AssertEqual(StrConv("かたかな abc", vbKatakana + vbUpperCase + vbWide), "カタカナ ABC", "StrConv(""かたかな abc"", vbKatakana + vbUpperCase + vbWide)") ' Converts Katakana characters in string to Hiragana characters TestUtil.AssertEqual(StrConv("カタカナ", vbHiragana), "かたかな", "StrConv(""カタカナ"", vbHiragana)") + TestUtil.AssertEqual(StrConv("カタカナ ABC", vbLowerCase + vbNarrow), "カタカナ abc", "StrConv(""カタカナ ABC"", vbLowerCase + vbNarrow)") - ' Assumes CP-1252 encoding associated with en-US locale used in unit tests. Dim x() As Byte - x = StrConv("ÉϺ£ÊÐABC", vbFromUnicode) + Const Cp1252TestString = "ÉϺ£ÊÐABC" + + x = StrConv(Cp1252TestString, vbFromUnicode, &h0409)' CP-1252 encoding associated with en-US locale TestUtil.AssertEqual(UBound(x), 8, "UBound(x)") TestUtil.AssertEqual(x(0), 201, "x(0)") TestUtil.AssertEqual(x(1), 207, "x(1)") @@ -47,7 +52,11 @@ Sub verify_testStrConv() TestUtil.AssertEqual(x(6), 65, "x(6)") TestUtil.AssertEqual(x(7), 66, "x(7)") TestUtil.AssertEqual(x(8), 67, "x(8)") - TestUtil.AssertEqual(StrConv(x, vbUnicode), "ÉϺ£ÊÐABC", "StrConv(x, vbUnicode)") + TestUtil.AssertEqual(StrConv(x, vbUnicode, &h0409), Cp1252TestString, "StrConv(x, vbUnicode, &h0409)") + + x = StrConv(Cp1252TestString, vbUnicode, &h0409) + TestUtil.AssertEqual(UBound(x), 35, "UBound(x)") + TestUtil.AssertEqual(StrConv(x, vbFromUnicode, &h0409), Cp1252TestString, "StrConv(x, vbFromUnicode, &h0409)") Exit Sub errorHandler: diff --git a/basic/qa/vba_tests/string.vb b/basic/qa/vba_tests/string.vb index eca3fce3baec..239141d8173f 100644 --- a/basic/qa/vba_tests/string.vb +++ b/basic/qa/vba_tests/string.vb @@ -11,18 +11,22 @@ Option Explicit Function doUnitTest() As String TestUtil.TestInit - verify_testString + verify_String doUnitTest = TestUtil.GetResult() End Function -Sub verify_testString() +Sub verify_String() On Error GoTo errorHandler TestUtil.AssertEqual(String(5, "P"), "PPPPP", "String(5, ""P"")") TestUtil.AssertEqual(String(5, "a"), "aaaaa", "String(5, ""a"")") TestUtil.AssertEqual(String(0, "P"), "", "String(0, ""P"")") + TestUtil.AssertEqual(String(5.8, "à"), "àààààà", "String(5.8, ""à"")") + TestUtil.AssertEqual(String(Number:=3.45, Character:="test"), "ttt", "String(Number:=3.45, Character:=""test"")") + TestUtil.AssertEqual(String(Character:="☺😎", Number:=7), "☺☺☺☺☺☺☺", "String(Character:=""☺😎"", Number:=7)") + Exit Sub errorHandler: - TestUtil.ReportErrorHandler("verify_testString", Err, Error$, Erl) + TestUtil.ReportErrorHandler("verify_String", Err, Error$, Erl) End Sub diff --git a/basic/qa/vba_tests/tdf147089_idiv.vb b/basic/qa/vba_tests/tdf147089_idiv.vb new file mode 100644 index 000000000000..515f1e00cf63 --- /dev/null +++ b/basic/qa/vba_tests/tdf147089_idiv.vb @@ -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 VBASupport 1
+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/vba_tests/tdf147529_optional_parameters_msgbox.vb b/basic/qa/vba_tests/tdf147529_optional_parameters_msgbox.vb new file mode 100644 index 000000000000..e599f46eedf1 --- /dev/null +++ b/basic/qa/vba_tests/tdf147529_optional_parameters_msgbox.vb @@ -0,0 +1,37 @@ +'
+' This file is part of the LibreOffice project.
+'
+' This Source Code Form is subject to the terms of the Mozilla Public
+' License, v. 2.0. If a copy of the MPL was not distributed with this
+' file, You can obtain one at http://mozilla.org/MPL/2.0/.
+'
+
+Option VBASupport 1
+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/vba_tests/tdf148358_non_ascii_names.vb b/basic/qa/vba_tests/tdf148358_non_ascii_names.vb new file mode 100644 index 000000000000..95e7105407f5 --- /dev/null +++ b/basic/qa/vba_tests/tdf148358_non_ascii_names.vb @@ -0,0 +1,33 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.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 VBASupport 1 +Option Explicit + +Function doUnitTest as String + TestUtil.TestInit + verify_testNonAsciiNames + doUnitTest = TestUtil.GetResult() +End Function + +Function TestNonAscii as Integer + Dim Абв as Integer + Абв = 10 + TestNonAscii = абв +End Function + +Sub verify_testNonAsciiNames + On Error GoTo errorHandler + + ' tdf#148358 - compare Non-ASCII variable names case-insensitive + TestUtil.AssertEqual(TestNonAscii(), 10, "TestNonAscii()") + + Exit Sub +errorHandler: + TestUtil.ReportErrorHandler("verify_testNonAsciiNames", Err, Error$, Erl) +End Sub diff --git a/basic/qa/vba_tests/typename.vb b/basic/qa/vba_tests/typename.vb index 98bfd58feda4..b21d34cc4e0e 100644 --- a/basic/qa/vba_tests/typename.vb +++ b/basic/qa/vba_tests/typename.vb @@ -32,6 +32,8 @@ Sub verify_testTypeName() Dim TestCurrSign@ Dim TestStrSign$ + TestUtil.AssertEqual(TypeName(varname:=s1), "String", "TypeName(varname:=s1") + TestUtil.AssertEqual(TypeName(s1), "String", "TypeName(s1)") TestUtil.AssertEqual(TypeName(b1), "Boolean", "TypeName(b1)") TestUtil.AssertEqual(TypeName(c1), "Byte", "TypeName(c1)") diff --git a/basic/qa/vba_tests/vartype.vb b/basic/qa/vba_tests/vartype.vb index 2d8345ed1d86..066255b2b7e3 100644 --- a/basic/qa/vba_tests/vartype.vb +++ b/basic/qa/vba_tests/vartype.vb @@ -42,6 +42,8 @@ Sub verify_testVarType() TestUtil.AssertEqual(vbString, 8, "vbString") TestUtil.AssertEqual(vbBoolean, 11, "vbBoolean") + TestUtil.AssertEqual(VarType(varname:=TestStr), vbString, "VarType(varname:=TestStr)") + TestUtil.AssertEqual(VarType(TestStr), vbString, "VarType(TestStr)") TestUtil.AssertEqual(VarType(TestBoo), vbBoolean, "VarType(TestBoo)") TestUtil.AssertEqual(VarType(TestDouble), vbDouble, "VarType(TestDouble)") |