LCOV - code coverage report
Current view: top level - libreoffice/basic/qa/cppunit - test_append.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 35 35 100.0 %
Date: 2012-12-27 Functions: 11 12 91.7 %
Legend: Lines: hit not hit

          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           4 :     class EnableTest : public BasicTestBase
      19             :     {
      20             :         public:
      21           2 :         EnableTest() {};
      22             :         void testDimEnable();
      23             :         void testEnableRuntime();
      24             :         // Adds code needed to register the test suite
      25           2 :         CPPUNIT_TEST_SUITE(EnableTest);
      26             : 
      27             :         // Declares the method as a test to call
      28           1 :         CPPUNIT_TEST(testDimEnable);
      29           1 :         CPPUNIT_TEST(testEnableRuntime);
      30             : 
      31             :         // End of test suite definition
      32           2 :         CPPUNIT_TEST_SUITE_END();
      33             :     };
      34             : 
      35           2 : 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           1 : );
      43             : 
      44           2 : rtl::OUString sTestDimEnable(
      45             :     "Sub Test\n"
      46             :     "Dim Enable as String\n"
      47             :     "End Sub\n"
      48           1 : );
      49             : 
      50           1 : void EnableTest::testEnableRuntime()
      51             : {
      52           1 :     CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
      53           1 :     StarBASICRef pBasic = new StarBASIC();
      54           1 :     ResetError();
      55           1 :     StarBASIC::SetGlobalErrorHdl( LINK( this, EnableTest, BasicErrorHdl ) );
      56             : 
      57           1 :     SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sTestEnableRuntime );
      58           1 :     pMod->Compile();
      59           1 :     CPPUNIT_ASSERT_MESSAGE("testEnableRuntime fails with compile error",!HasError() );
      60           1 :     SbMethod* pMeth = static_cast<SbMethod*>(pMod->Find( rtl::OUString("Test"),  SbxCLASS_METHOD ));
      61           1 :     CPPUNIT_ASSERT_MESSAGE("testEnableRuntime no method found", pMeth );
      62           1 :     SbxVariableRef refTemp = pMeth;
      63             :     // forces a broadcast
      64           1 :     SbxVariableRef pNew = new  SbxMethod( *((SbxMethod*)pMeth));
      65           1 :     CPPUNIT_ASSERT(pNew->GetInteger() == 3 );
      66           1 : }
      67             : 
      68           1 : void EnableTest::testDimEnable()
      69             : {
      70           1 :     CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
      71           1 :     StarBASICRef pBasic = new StarBASIC();
      72           1 :     StarBASIC::SetGlobalErrorHdl( LINK( this, EnableTest, BasicErrorHdl ) );
      73             : 
      74           1 :     ResetError();
      75             : 
      76           1 :     SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sTestDimEnable );
      77           1 :     pMod->Compile();
      78             : 
      79           1 :     CPPUNIT_ASSERT_MESSAGE("Dim causes compile error", !HasError() );
      80           1 : }
      81             : 
      82             :   // Put the test suite in the registry
      83           1 :   CPPUNIT_TEST_SUITE_REGISTRATION(EnableTest);
      84             : } // namespace
      85           4 : CPPUNIT_PLUGIN_IMPLEMENT();
      86             : 
      87             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10