1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <basic/sbstar.hxx>
11 #include <basic/sbmeth.hxx>
12 #include <basic/basrdll.hxx>
13 #include <cppunit/extensions/HelperMacros.h>
17 class GlobalArrayTest
: public CppUnit::TestFixture
19 void testMaintainsValueAcrossCalls();
21 CPPUNIT_TEST_SUITE(GlobalArrayTest
);
22 CPPUNIT_TEST(testMaintainsValueAcrossCalls
);
23 CPPUNIT_TEST_SUITE_END();
26 StarBASICRef interpreter
;
30 interpreter
= new StarBASIC();
31 auto mod
= interpreter
->MakeModule(u
"GlobalArray"_ustr
, uR
"BAS(
38 Global aTestTypes(2) As New testType
40 Function Macro1 As String
42 aTestTypes(0).sType = "A
"
43 Macro1 = aTestTypes(0).iNr & aTestTypes(0).sType
46 Function Macro2 As String
48 aTestTypes(1).sType = "B
"
49 Macro2 = aTestTypes(0).iNr & aTestTypes(0).sType & aTestTypes(1).iNr & aTestTypes(1).sType
53 CPPUNIT_ASSERT(mod
->Compile());
54 CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE
, StarBASIC::GetErrBasic());
55 CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE
, SbxBase::GetError());
56 CPPUNIT_ASSERT(mod
->IsCompiled());
61 void GlobalArrayTest::testMaintainsValueAcrossCalls()
64 auto Macro1
= m
->FindMethod(u
"Macro1"_ustr
, SbxClassType::Method
);
65 CPPUNIT_ASSERT_MESSAGE("Could not Find Macro1 in module", Macro1
!= nullptr);
67 // There is no SbxMethod::call(), the basic code is exercised here in the copy ctor
68 SbxVariableRef returned
= new SbxMethod
{ *Macro1
};
69 CPPUNIT_ASSERT(returned
->IsString());
70 CPPUNIT_ASSERT_EQUAL(u
"1A"_ustr
, returned
->GetOUString());
72 auto Macro2
= m
->FindMethod(u
"Macro2"_ustr
, SbxClassType::Method
);
73 CPPUNIT_ASSERT_MESSAGE("Could not Find Macro2 in module", Macro2
!= nullptr);
74 returned
= new SbxMethod
{ *Macro2
};
75 CPPUNIT_ASSERT(returned
->IsString());
76 // tdf#145371 - check if the global array has maintained its state
77 // Without the fix in place, this test would have failed with:
80 CPPUNIT_ASSERT_EQUAL(u
"1A2B"_ustr
, returned
->GetOUString());
83 // Put the test suite in the registry
84 CPPUNIT_TEST_SUITE_REGISTRATION(GlobalArrayTest
);