Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : */
9 :
10 : #include "basictest.hxx"
11 : #include "osl/file.hxx"
12 : #include "osl/process.h"
13 :
14 : #include "basic/sbmod.hxx"
15 : #include "basic/sbmeth.hxx"
16 : namespace
17 : {
18 8 : class EnableTest : public BasicTestBase
19 : {
20 : public:
21 4 : EnableTest() {};
22 : void testDimEnable();
23 : void testEnableRuntime();
24 : // Adds code needed to register the test suite
25 4 : CPPUNIT_TEST_SUITE(EnableTest);
26 :
27 : // Declares the method as a test to call
28 2 : CPPUNIT_TEST(testDimEnable);
29 2 : CPPUNIT_TEST(testEnableRuntime);
30 :
31 : // End of test suite definition
32 4 : CPPUNIT_TEST_SUITE_END();
33 : };
34 :
35 4 : rtl::OUString sTestEnableRuntime(
36 : "Function Test as Integer\n"
37 : "Dim Enable as Integer\n"
38 : "Enable = 1\n"
39 : "Enable = Enable + 2\n"
40 : "Test = Enable\n"
41 : "End Function\n"
42 2 : );
43 :
44 4 : rtl::OUString sTestDimEnable(
45 : "Sub Test\n"
46 : "Dim Enable as String\n"
47 : "End Sub\n"
48 2 : );
49 :
50 2 : void EnableTest::testEnableRuntime()
51 : {
52 2 : CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
53 2 : StarBASICRef pBasic = new StarBASIC();
54 2 : ResetError();
55 2 : StarBASIC::SetGlobalErrorHdl( LINK( this, EnableTest, BasicErrorHdl ) );
56 :
57 2 : SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sTestEnableRuntime );
58 2 : pMod->Compile();
59 2 : CPPUNIT_ASSERT_MESSAGE("testEnableRuntime fails with compile error",!HasError() );
60 2 : SbMethod* pMeth = static_cast<SbMethod*>(pMod->Find( rtl::OUString("Test"), SbxCLASS_METHOD ));
61 2 : CPPUNIT_ASSERT_MESSAGE("testEnableRuntime no method found", pMeth );
62 2 : SbxVariableRef refTemp = pMeth;
63 : // forces a broadcast
64 2 : SbxVariableRef pNew = new SbxMethod( *((SbxMethod*)pMeth));
65 2 : CPPUNIT_ASSERT(pNew->GetInteger() == 3 );
66 2 : }
67 :
68 2 : void EnableTest::testDimEnable()
69 : {
70 2 : CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
71 2 : StarBASICRef pBasic = new StarBASIC();
72 2 : StarBASIC::SetGlobalErrorHdl( LINK( this, EnableTest, BasicErrorHdl ) );
73 :
74 2 : ResetError();
75 :
76 2 : SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sTestDimEnable );
77 2 : pMod->Compile();
78 :
79 2 : CPPUNIT_ASSERT_MESSAGE("Dim causes compile error", !HasError() );
80 2 : }
81 :
82 : // Put the test suite in the registry
83 2 : CPPUNIT_TEST_SUITE_REGISTRATION(EnableTest);
84 : } // namespace
85 8 : CPPUNIT_PLUGIN_IMPLEMENT();
86 :
87 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|