[Libreoffice-commits] core.git: basic/CppunitTest_basic_macros.mk basic/qa basic/source
basic/CppunitTest_basic_macros.mk |1 basic/qa/cppunit/test_global_array.cxx | 89 + basic/source/comp/dim.cxx | 11 ++-- 3 files changed, 97 insertions(+), 4 deletions(-) New commits: commit 27d96bfaea5f7967a11dc3a7e2bc9d88dd6f5666 Author: Andreas Heinisch AuthorDate: Fri Oct 29 08:40:14 2021 +0200 Commit: Andreas Heinisch CommitDate: Sat Oct 30 18:28:17 2021 +0200 tdf#145371 - Delete array variable only before ReDim Otherwise, global array variables don't maintain their state. Change-Id: I10dafd9e2946630c5476c9858f765d67ef2f6d6c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124368 Tested-by: Jenkins Reviewed-by: Andreas Heinisch diff --git a/basic/CppunitTest_basic_macros.mk b/basic/CppunitTest_basic_macros.mk index c70bfff42c68..83a9221369f0 100644 --- a/basic/CppunitTest_basic_macros.mk +++ b/basic/CppunitTest_basic_macros.mk @@ -20,6 +20,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,basic_macros, \ basic/qa/cppunit/test_nested_struct \ basic/qa/cppunit/test_vba \ basic/qa/cppunit/test_global_as_new \ + basic/qa/cppunit/test_global_array \ )) $(eval $(call gb_CppunitTest_use_libraries,basic_macros, \ diff --git a/basic/qa/cppunit/test_global_array.cxx b/basic/qa/cppunit/test_global_array.cxx new file mode 100644 index ..0b83d5efddee --- /dev/null +++ b/basic/qa/cppunit/test_global_array.cxx @@ -0,0 +1,89 @@ +/* -*- 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 +#include +#include +#include +#include +#include +#include + +namespace +{ +class GlobalArrayTest : public CppUnit::TestFixture +{ +void testMaintainsValueAcrossCalls(); + +CPPUNIT_TEST_SUITE(GlobalArrayTest); +CPPUNIT_TEST(testMaintainsValueAcrossCalls); +CPPUNIT_TEST_SUITE_END(); + +BasicDLL lib; +StarBASICRef interpreter; + +SbModuleRef Module() +{ +interpreter = new StarBASIC(); +auto mod = interpreter->MakeModule("GlobalArray", R"BAS( + +Type testType +iNrAs Integer +sType As String +End Type + +Global aTestTypes(2) As New testType + +Function Macro1 As String +aTestTypes(0).iNr = 1 +aTestTypes(0).sType = "A" +Macro1 = aTestTypes(0).iNr & aTestTypes(0).sType +End Function + +Function Macro2 As String +aTestTypes(1).iNr = 2 +aTestTypes(1).sType = "B" +Macro2 = aTestTypes(0).iNr & aTestTypes(0).sType & aTestTypes(1).iNr & aTestTypes(1).sType +End Function + +)BAS"); +CPPUNIT_ASSERT(mod->Compile()); +CPPUNIT_ASSERT_EQUAL(StarBASIC::GetErrBasic(), ERRCODE_NONE); +CPPUNIT_ASSERT_EQUAL(SbxBase::GetError(), ERRCODE_NONE); +CPPUNIT_ASSERT(mod->IsCompiled()); +return mod; +} +}; + +void GlobalArrayTest::testMaintainsValueAcrossCalls() +{ +auto m = Module(); +auto Macro1 = m->FindMethod("Macro1", SbxClassType::Method); +CPPUNIT_ASSERT_MESSAGE("Could not Find Macro1 in module", Macro1 != nullptr); + +// There is no SbxMethod::call(), the basic code is exercised here in the copy ctor +SbxVariableRef returned = new SbxMethod{ *Macro1 }; +CPPUNIT_ASSERT(returned->IsString()); +CPPUNIT_ASSERT_EQUAL(OUString{ "1A" }, returned->GetOUString()); + +auto Macro2 = m->FindMethod("Macro2", SbxClassType::Method); +CPPUNIT_ASSERT_MESSAGE("Could not Find Macro2 in module", Macro2 != nullptr); +returned = new SbxMethod{ *Macro2 }; +CPPUNIT_ASSERT(returned->IsString()); +// tdf#145371 - check if the global array has maintained its state +// Without the fix in place, this test would have failed with: +// - Expected: 1A2B +// - Actual : 02B +CPPUNIT_ASSERT_EQUAL(OUString("1A2B"), returned->GetOUString()); +} + +// Put the test suite in the registry +CPPUNIT_TEST_SUITE_REGISTRATION(GlobalArrayTest); + +} // namespace diff --git a/basic/source/comp/dim.cxx b/basic/source/comp/dim.cxx index 56bbab29587a..cbc25b0152b4 100644 --- a/basic/source/comp/dim.cxx +++ b/basic/source/comp/dim.cxx @@ -431,10 +431,13 @@ void SbiParser::DefVar( SbiOpcode eOp, bool bStatic ) } else { -// tdf#136755 - delete the variable beforehand REDIM -SbiExpression aExpr(this, *pDef, nullptr); -aExpr.Gen(); -aGen.Gen(bVBASupportOn ? SbiOpcode::ERASE_CLEAR_ : SbiOpcode::ERASE_); +// tdf#145371, tdf#136755 - only delete the variable beforehand REDIM +if (eOp == SbiOpcode::REDIM_) +{ +
[Libreoffice-commits] core.git: basic/CppunitTest_basic_macros.mk basic/qa basic/source
basic/CppunitTest_basic_macros.mk |1 basic/qa/basic_coverage/test_string_replace.bas |9 basic/source/runtime/methods.cxx| 44 +--- 3 files changed, 34 insertions(+), 20 deletions(-) New commits: commit 7e5c9220ef5d51ac23e618c5c9eeda9cf4339c88 Author: Andreas Heinisch AuthorDate: Sun Jul 11 21:06:23 2021 +0200 Commit: Andreas Heinisch CommitDate: Mon Jul 12 20:30:19 2021 +0200 tdf#142487 - use utl::TextSearch in order to implement the replace algorithm In the old algorithm, some special unicode characters lead to a malfunction of basic's replace function. For instance, replacing a German ß to uppercase in the insensitive case will lead to SS, breaking the replace positions. Change-Id: I4e6f6e5fba3d560b8cfd0786fa2439ed5174a928 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118760 Tested-by: Jenkins Reviewed-by: Andreas Heinisch diff --git a/basic/CppunitTest_basic_macros.mk b/basic/CppunitTest_basic_macros.mk index c2c1eb5b7a04..c70bfff42c68 100644 --- a/basic/CppunitTest_basic_macros.mk +++ b/basic/CppunitTest_basic_macros.mk @@ -61,6 +61,7 @@ $(eval $(call gb_CppunitTest_use_vcl,basic_macros)) $(eval $(call gb_CppunitTest_use_components,basic_macros,\ configmgr/source/configmgr \ + i18npool/source/search/i18nsearch \ i18npool/util/i18npool \ ucb/source/core/ucb1 \ ucb/source/ucp/file/ucpfile1 \ diff --git a/basic/qa/basic_coverage/test_string_replace.bas b/basic/qa/basic_coverage/test_string_replace.bas index 4dfac668109d..d68f36fbb662 100644 --- a/basic/qa/basic_coverage/test_string_replace.bas +++ b/basic/qa/basic_coverage/test_string_replace.bas @@ -24,7 +24,14 @@ Sub verify_stringReplace() ' 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) +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: diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx index 41f0d38ec1b0..e745fa2fd1c6 100644 --- a/basic/source/runtime/methods.cxx +++ b/basic/source/runtime/methods.cxx @@ -67,6 +67,14 @@ #include #include +// include search util +#include +#include +#include +#include + + + using namespace comphelper; using namespace osl; using namespace com::sun::star; @@ -1283,34 +1291,32 @@ void SbRtl_Replace(StarBASIC *, SbxArray & rPar, bool) } const OUString aExpStr = rPar.Get(1)->GetOUString(); -OUString aFindStr = rPar.Get(2)->GetOUString(); +const OUString aFindStr = rPar.Get(2)->GetOUString(); const OUString aReplaceStr = rPar.Get(3)->GetOUString(); +const sal_Int32 nExpStrLen = aExpStr.getLength(); +const sal_Int32 nFindStrLen = aFindStr.getLength(); -OUString aSrcStr(aExpStr); +// tdf#142487 - use utl::TextSearch in order to implement the replace algorithm +i18nutil::SearchOptions2 aSearchOptions; +aSearchOptions.searchString = aFindStr; +aSearchOptions.AlgorithmType2 = util::SearchAlgorithms2::ABSOLUTE; if (bCaseInsensitive) -{ -// tdf#132389 - case-insensitive operation for non-ASCII characters -const css::lang::Locale& rLocale = Application::GetSettings().GetLanguageTag().getLocale(); -css::uno::Reference xCharClass -= vcl::unohelper::CreateCharacterClassification(); -aSrcStr = xCharClass->toUpper(aSrcStr, 0, aSrcStr.getLength(), rLocale); -aFindStr = xCharClass->toUpper(aFindStr, 0, aFindStr.getLength(), rLocale); -} -const sal_Int32 nSrcStrLen = aSrcStr.getLength(); -const sal_Int32 nFindStrLen = aFindStr.getLength(); +aSearchOptions.transliterateFlags |= TransliterationFlags::IGNORE_CASE; +utl::TextSearch textSearch(aSearchOptions); // Note: the result starts from lStartPos, removing everything to the left. See i#94895. -sal_Int32 nPrevPos = std::min(lStartPos - 1, nSrcStrLen); -OUStringBuffer sResult(nSrcStrLen - nPrevPos); +sal_Int32 nPrevPos = std::min(lStartPos - 1, nExpStrLen); +OUStringBuffer sResult(nExpStrLen - nPrevPos); sal_Int32 nCounts = 0; while (lCount == -1 || lCount > nCounts) { -sal_Int32 nPos = aSrcStr.indexOf(aFindStr, nPrevPos); -if (nPos >= 0) +sal_Int32 nStartPos = nPrevPos; +sal_Int32 aEndPos = aExpStr.getLength(); +if (textSearch.SearchForward(aExpStr, , )) { -sResult.append(aExpStr.getStr() + nPrevPos, nPos
[Libreoffice-commits] core.git: basic/CppunitTest_basic_macros.mk basic/qa basic/source
basic/CppunitTest_basic_macros.mk |1 basic/qa/cppunit/test_global_as_new.cxx | 86 basic/source/comp/dim.cxx | 27 ++ basic/source/inc/runtime.hxx|1 basic/source/runtime/runtime.cxx| 34 ++-- 5 files changed, 143 insertions(+), 6 deletions(-) New commits: commit b80069e133d30e80e50a792b2bc1d0c2f9a31bfa Author: John AuthorDate: Thu Mar 4 01:50:25 2021 -0500 Commit: Mike Kaganski CommitDate: Sun Mar 21 21:54:11 2021 +0100 tdf#88442 SBasic: Don't double-initialize a Global ... As New ... "As New" variables use lazy instantiation, but that should not re-apply each time one re-enters the module. If the object is still there, don't replace it. Change-Id: Ic568a56b93db9bc9139d434d97a4a4deb05840df Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112018 Tested-by: Jenkins Reviewed-by: Mike Kaganski diff --git a/basic/CppunitTest_basic_macros.mk b/basic/CppunitTest_basic_macros.mk index 6cce94737113..c2c1eb5b7a04 100644 --- a/basic/CppunitTest_basic_macros.mk +++ b/basic/CppunitTest_basic_macros.mk @@ -19,6 +19,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,basic_macros, \ basic/qa/cppunit/test_language_conditionals \ basic/qa/cppunit/test_nested_struct \ basic/qa/cppunit/test_vba \ + basic/qa/cppunit/test_global_as_new \ )) $(eval $(call gb_CppunitTest_use_libraries,basic_macros, \ diff --git a/basic/qa/cppunit/test_global_as_new.cxx b/basic/qa/cppunit/test_global_as_new.cxx new file mode 100644 index ..db64a974cb0f --- /dev/null +++ b/basic/qa/cppunit/test_global_as_new.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 +#include +#include +#include +#include +#include +#include + +namespace +{ +class GlobalAsNewTest : public CppUnit::TestFixture +{ +void testMaintainsValueAcrossCalls(); + +CPPUNIT_TEST_SUITE(GlobalAsNewTest); +CPPUNIT_TEST(testMaintainsValueAcrossCalls); +CPPUNIT_TEST_SUITE_END(); + +BasicDLL lib; +StarBASICRef interpreter; + +SbModuleRef Module() +{ +interpreter = new StarBASIC(); +auto mod = interpreter->MakeModule("GlobalAsNew", R"BAS( +Global aDate As New "com.sun.star.util.Date" + +Function GetDateAsString As String +DIM local_Date As New "com.sun.star.util.Date" +GetDateAsString = TRIM(STR(aDate.Year)) + "-" + TRIM(STR(local_Date.Year)) + TRIM(STR(aDate.Month)) + "-" + TRIM(STR(aDate.Day)) +End Function + +Function SetDate + aDate.Month = 6 + aDate.Day = 30 + aDate.Year = 2019 + SetDate = GetDateAsString() +End Function + +)BAS"); +CPPUNIT_ASSERT(mod->Compile()); +CPPUNIT_ASSERT_EQUAL(StarBASIC::GetErrBasic(), ERRCODE_NONE); +CPPUNIT_ASSERT_EQUAL(SbxBase::GetError(), ERRCODE_NONE); +CPPUNIT_ASSERT(mod->IsCompiled()); +return mod; +} +}; + +void GlobalAsNewTest::testMaintainsValueAcrossCalls() +{ +auto m = Module(); +auto GetDateAsString = m->FindMethod("GetDateAsString", SbxClassType::Method); +CPPUNIT_ASSERT_MESSAGE("Could not Find GetDateAsString in module", GetDateAsString != nullptr); + +// There is no SbxMethod::call(), the basic code is exercised here in the copy ctor +SbxVariableRef returned = new SbxMethod{ *GetDateAsString }; +CPPUNIT_ASSERT(returned->IsString()); +//0-00-0 is the result of reading the default-initialized date +CPPUNIT_ASSERT_EQUAL(OUString{ "0-00-0" }, returned->GetOUString()); + +auto SetDate = m->FindMethod("SetDate", SbxClassType::Method); +CPPUNIT_ASSERT_MESSAGE("Could not Find SetDate in module", SetDate != nullptr); +returned = new SbxMethod{ *SetDate }; +CPPUNIT_ASSERT(returned->IsString()); +OUString set_val("2019-06-30"); +CPPUNIT_ASSERT_EQUAL(set_val, returned->GetOUString()); + +returned = new SbxMethod{ *GetDateAsString }; +CPPUNIT_ASSERT(returned->IsString()); +//tdf#88442 The global should have maintained its state! +CPPUNIT_ASSERT_EQUAL(set_val, returned->GetOUString()); +} + +// Put the test suite in the registry +CPPUNIT_TEST_SUITE_REGISTRATION(GlobalAsNewTest); + +} // namespace diff --git a/basic/source/comp/dim.cxx b/basic/source/comp/dim.cxx index 20396cd729ad..cf14d1c7818c 100644 --- a/basic/source/comp/dim.cxx +++ b/basic/source/comp/dim.cxx @@ -446,12 +446,39 @@ void SbiParser::DefVar( SbiOpcode eOp, bool bStatic ) { SbiExpression aExpr( this, *pDef ); aExpr.Gen(); + +/* tdf#88442 + * Don't initialize
[Libreoffice-commits] core.git: basic/CppunitTest_basic_macros.mk basic/qa basic/source
basic/CppunitTest_basic_macros.mk |1 + basic/qa/cppunit/basictest.cxx|3 +++ basic/qa/cppunit/basictest.hxx|2 ++ basic/qa/cppunit/test_complier_checks.cxx | 27 +++ basic/source/comp/dim.cxx |5 +++-- 5 files changed, 36 insertions(+), 2 deletions(-) New commits: commit 840c3a662012c77b5972c869587acd15ee5a3f03 Author: Mike Kaganski AuthorDate: Sat Dec 7 15:27:08 2019 +0100 Commit: Mike Kaganski CommitDate: Sat Dec 7 17:30:27 2019 +0100 tdf#59327: DIM should fail in procedures when same-name argument is present Change-Id: I0a6828bd0b0c27018dc02c36ee207b8666f88ec0 Reviewed-on: https://gerrit.libreoffice.org/84682 Tested-by: Jenkins Reviewed-by: Mike Kaganski diff --git a/basic/CppunitTest_basic_macros.mk b/basic/CppunitTest_basic_macros.mk index 0ca767e1ddba..2d9959c9b6c9 100644 --- a/basic/CppunitTest_basic_macros.mk +++ b/basic/CppunitTest_basic_macros.mk @@ -15,6 +15,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,basic_macros, \ basic/qa/cppunit/basictest \ basic/qa/cppunit/basic_coverage \ basic/qa/cppunit/test_append \ + basic/qa/cppunit/test_complier_checks \ basic/qa/cppunit/test_language_conditionals \ basic/qa/cppunit/test_nested_struct \ basic/qa/cppunit/test_vba \ diff --git a/basic/qa/cppunit/basictest.cxx b/basic/qa/cppunit/basictest.cxx index 9a414b7f5e1a..3a22c84e9007 100644 --- a/basic/qa/cppunit/basictest.cxx +++ b/basic/qa/cppunit/basictest.cxx @@ -108,12 +108,15 @@ bool MacroSnippet::Compile() bool MacroSnippet::HasError() const { return mbError; } +const ErrCode& MacroSnippet::getError() const { return maErrCode; } + IMPL_LINK( MacroSnippet, BasicErrorHdl, StarBASIC *, /*pBasic*/, bool) { fprintf(stderr,"(%d:%d)\n", StarBASIC::GetLine(), StarBASIC::GetCol1()); fprintf(stderr,"Basic error: %s\n", OUStringToOString( StarBASIC::GetErrorText(), RTL_TEXTENCODING_UTF8 ).getStr() ); mbError = true; +maErrCode = StarBASIC::GetErrorCode(); return false; } diff --git a/basic/qa/cppunit/basictest.hxx b/basic/qa/cppunit/basictest.hxx index 8b92acf93d69..c8d262ee6def 100644 --- a/basic/qa/cppunit/basictest.hxx +++ b/basic/qa/cppunit/basictest.hxx @@ -24,6 +24,7 @@ class MacroSnippet { private: bool mbError; +ErrCode maErrCode; BasicDLL maDll; // we need a dll instance for resource manager etc. SbModuleRef mpMod; StarBASICRef mpBasic; @@ -46,6 +47,7 @@ public: DECL_LINK( BasicErrorHdl, StarBASIC *, bool ); bool HasError() const; +const ErrCode& getError() const; }; #endif diff --git a/basic/qa/cppunit/test_complier_checks.cxx b/basic/qa/cppunit/test_complier_checks.cxx new file mode 100644 index ..aad058040c31 --- /dev/null +++ b/basic/qa/cppunit/test_complier_checks.cxx @@ -0,0 +1,27 @@ +/* -*- 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 +#include "basictest.hxx" +#include +#include + +CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testRedefineArgument) +{ +MacroSnippet aMacro("Sub doUnitTest(argName)\n" +" If False Then\n" +"Dim argName\n" +" End If\n" +"End Sub\n"); +aMacro.Compile(); +CPPUNIT_ASSERT(aMacro.HasError()); +CPPUNIT_ASSERT_EQUAL(ERRCODE_BASIC_VAR_DEFINED, aMacro.getError().StripDynamic()); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/basic/source/comp/dim.cxx b/basic/source/comp/dim.cxx index bfe8b3184b36..d6b2bff6ccc6 100644 --- a/basic/source/comp/dim.cxx +++ b/basic/source/comp/dim.cxx @@ -318,8 +318,9 @@ void SbiParser::DefVar( SbiOpcode eOp, bool bStatic ) } if( pOld && !(eOp == SbiOpcode::REDIM_ || eOp == SbiOpcode::REDIMP_) ) { -if( pDef->GetScope() == SbLOCAL && pOld->GetScope() != SbLOCAL ) -pOld = nullptr; +if( pDef->GetScope() == SbLOCAL ) +if (auto eOldScope = pOld->GetScope(); eOldScope != SbLOCAL && eOldScope != SbPARAM) +pOld = nullptr; } if( pOld ) { ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] core.git: basic/CppunitTest_basic_macros.mk basic/qa basic/source
basic/CppunitTest_basic_macros.mk |1 basic/qa/cppunit/test_language_conditionals.cxx | 174 basic/qa/cppunit/test_scanner.cxx |8 + basic/source/comp/exprtree.cxx |3 4 files changed, 186 insertions(+) New commits: commit 9f71d0f3f98db02ad28712f229665ce910dc0e6e Author: Jens Carl AuthorDate: Thu Apr 25 15:04:57 2019 -0700 Commit: Jens Carl CommitDate: Fri May 3 08:24:18 2019 +0200 tdf#68339 Other: BASIC Syntax error Allow expressions (operands) of comparison operators prefixed with the Logical Operator "Not". Change-Id: I1b070e2288dac26b1f1186d38cf5d2f4ad99a406 Reviewed-on: https://gerrit.libreoffice.org/71332 Tested-by: Jenkins Reviewed-by: Mike Kaganski Reviewed-by: Jens Carl diff --git a/basic/CppunitTest_basic_macros.mk b/basic/CppunitTest_basic_macros.mk index 7b9aed16dfaf..0ca767e1ddba 100644 --- a/basic/CppunitTest_basic_macros.mk +++ b/basic/CppunitTest_basic_macros.mk @@ -15,6 +15,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,basic_macros, \ basic/qa/cppunit/basictest \ basic/qa/cppunit/basic_coverage \ basic/qa/cppunit/test_append \ + basic/qa/cppunit/test_language_conditionals \ basic/qa/cppunit/test_nested_struct \ basic/qa/cppunit/test_vba \ )) diff --git a/basic/qa/cppunit/test_language_conditionals.cxx b/basic/qa/cppunit/test_language_conditionals.cxx new file mode 100644 index ..1723a98bae5c --- /dev/null +++ b/basic/qa/cppunit/test_language_conditionals.cxx @@ -0,0 +1,174 @@ +/* -*- 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 "basictest.hxx" +#include + +#include +#include +#include +#include + +namespace +{ +class Language_Conditionals : public CppUnit::TestFixture +{ +public: +void testIfNot(); +void testIfAndNot(); +void testNENot(); + +CPPUNIT_TEST_SUITE(Language_Conditionals); + +CPPUNIT_TEST(testIfNot); +CPPUNIT_TEST(testIfAndNot); +CPPUNIT_TEST(testNENot); + +CPPUNIT_TEST_SUITE_END(); +}; + +void Language_Conditionals::testIfNot() +{ +{ // need a block to ensure MacroSnippet is cleaned properly +const OUString aSnippet("Option VBASupport 1\n" +"Option Explicit\n" +"\n" +"Function doUnitTest() As Integer\n" +"Dim op1 As Boolean\n" +"op1 = False\n" +"If Not op1 Then\n" +"doUnitTest = 1\n" +"Else\n" +"doUnitTest = 0\n" +"End If\n" +"End Function\n"); +MacroSnippet myMacro(aSnippet); +myMacro.Compile(); +CPPUNIT_ASSERT(!myMacro.HasError()); +SbxVariableRef pNew = myMacro.Run(); +CPPUNIT_ASSERT_EQUAL(static_cast(1), pNew->GetInteger()); +} +{ // need a block to ensure MacroSnippet is cleaned properly +const OUString aSnippet("Option VBASupport 0\n" +"Option Explicit\n" +"\n" +"Function doUnitTest() As Integer\n" +"Dim op1 As Boolean\n" +"op1 = False\n" +"If Not op1 Then\n" +"doUnitTest = 1\n" +"Else\n" +"doUnitTest = 0\n" +"End If\n" +"End Function\n"); +MacroSnippet myMacro(aSnippet); +myMacro.Compile(); +CPPUNIT_ASSERT(!myMacro.HasError()); +SbxVariableRef pNew = myMacro.Run(); +CPPUNIT_ASSERT_EQUAL(static_cast(1), pNew->GetInteger()); +} +} + +void Language_Conditionals::testIfAndNot() +{ +{ // need a block to ensure MacroSnippet is cleaned properly +const OUString aSnippet("Option VBASupport 1\n" +"Option Explicit\n" +"\n" +"Function doUnitTest() As Integer\n" +"Dim op1 As Boolean\n" +"Dim op2 As Boolean\n" +"op1 = True\n" +"op2 = False\n" +"If op1 And Not op2 Then\n" +"doUnitTest = 1\n" +