split out some common basic test stuff, add intial nested struct test

Change-Id: I8da6b3166e40e92c31ee001ce19938f286e057b9
This commit is contained in:
Noel Power 2012-07-05 13:54:17 +01:00
parent 2fab1a73b1
commit cac7e7cdc2
4 changed files with 139 additions and 46 deletions

View file

@ -37,6 +37,7 @@ $(eval $(call gb_Module_add_targets,basic,\
$(eval $(call gb_Module_add_check_targets,basic,\
CppunitTest_basic_scanner \
CppunitTest_basic_enable \
CppunitTest_basic_nested_struct \
))
endif

View file

@ -0,0 +1,51 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* Copyright 2012 LibreOffice contributors.
*
* 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/.
*/
#ifndef _BASICTEST_HXX
#define _BASICTEST_HXX
#include <sal/types.h>
#include "cppunit/TestFixture.h"
#include "cppunit/extensions/HelperMacros.h"
#include "cppunit/plugin/TestPlugIn.h"
#include <test/bootstrapfixture.hxx>
#include "basic/sbstar.hxx"
#include "basic/basrdll.hxx"
class BasicTestBase : public test::BootstrapFixture
{
private:
bool mbError;
public:
BasicTestBase() : mbError(false) {};
DECL_LINK( BasicErrorHdl, StarBASIC * );
bool HasError() { return mbError; }
void ResetError()
{
StarBASIC::SetGlobalErrorHdl( Link() );
mbError = false;
}
BasicDLL& basicDLL()
{
static BasicDLL maDll; // we need a dll instance for resouce manager etc.
return maDll;
}
};
IMPL_LINK( BasicTestBase, BasicErrorHdl, StarBASIC *, /*pBasic*/)
{
fprintf(stderr,"Got error: \n\t%s!!!\n", rtl::OUStringToOString( StarBASIC::GetErrorText(), RTL_TEXTENCODING_UTF8 ).getStr() );
mbError = true;
return 0;
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View file

@ -6,30 +6,18 @@
* 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/types.h>
#include "cppunit/TestAssert.h"
#include "cppunit/TestFixture.h"
#include "cppunit/extensions/HelperMacros.h"
#include "cppunit/plugin/TestPlugIn.h"
#include <test/bootstrapfixture.hxx>
#include "basictest.hxx"
#include "osl/file.hxx"
#include "osl/process.h"
#include "basic/sbstar.hxx"
#include "basic/sbmod.hxx"
#include "basic/sbmeth.hxx"
#include "basic/basrdll.hxx"
namespace
{
class EnableTest : public test::BootstrapFixture
class EnableTest : public BasicTestBase
{
private:
bool mbError;
public:
EnableTest() : mbError(false) {};
EnableTest() {};
void testDimEnable();
void testEnableRuntime();
// Adds code needed to register the test suite
@ -41,63 +29,53 @@ namespace
// End of test suite definition
CPPUNIT_TEST_SUITE_END();
DECL_LINK( BasicErrorHdl, StarBASIC * );
bool HasError() { return mbError; }
BasicDLL& basicDLL()
{
static BasicDLL maDll; // we need a dll instance for resouce manager etc.
return maDll;
}
};
IMPL_LINK( EnableTest, BasicErrorHdl, StarBASIC *, /*pBasic*/)
{
fprintf(stderr,"Got error: \n\t%s!!!\n", rtl::OUStringToOString( StarBASIC::GetErrorText(), RTL_TEXTENCODING_UTF8 ).getStr() );
mbError = true;
return 0;
}
rtl::OUString sTestEnableRuntime(
"Function Test as Integer\n"
"Dim Enable as Integer\n"
"Enable = 1\n"
"Enable = Enable + 2\n"
"Test = Enable\n"
"End Function\n"
);
rtl::OUString sTestDimEnable(
"Sub Test\n"
"Dim Enable as String\n"
"End Sub\n"
);
void EnableTest::testEnableRuntime()
{
CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
StarBASICRef pBasic = new StarBASIC();
ResetError();
StarBASIC::SetGlobalErrorHdl( LINK( this, EnableTest, BasicErrorHdl ) );
rtl::OUString sSource("Function Test as Integer\n");
sSource += rtl::OUString("Dim Enable as Integer\n");
sSource += rtl::OUString("Enable = 1\n");
sSource += rtl::OUString("Enable = Enable + 2\n");
sSource += rtl::OUString("Test = Enable\n");
sSource += rtl::OUString("End Function\n");
SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sSource );
SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sTestEnableRuntime );
pMod->Compile();
CPPUNIT_ASSERT_MESSAGE("testEnableRuntime fails with compile error",!mbError );
CPPUNIT_ASSERT_MESSAGE("testEnableRuntime fails with compile error",!HasError() );
SbMethod* pMeth = static_cast<SbMethod*>(pMod->Find( rtl::OUString("Test"), SbxCLASS_METHOD ));
CPPUNIT_ASSERT_MESSAGE("testEnableRuntime no method found", pMeth );
SbxVariableRef refTemp = pMeth;
// forces a broadcast
SbxVariableRef pNew = new SbxMethod( *((SbxMethod*)pMeth));
CPPUNIT_ASSERT(pNew->GetInteger() == 3 );
StarBASIC::SetGlobalErrorHdl( Link() );
}
void EnableTest::testDimEnable()
{
CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
StarBASICRef pBasic = new StarBASIC();
StarBASIC::SetGlobalErrorHdl( LINK( this, EnableTest, BasicErrorHdl ) );
rtl::OUString sSource("Sub Test\n");
sSource += rtl::OUString("Dim Enable as String\n");
sSource += rtl::OUString("End Sub\n");
ResetError();
SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sSource );
SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sTestDimEnable );
pMod->Compile();
CPPUNIT_ASSERT_MESSAGE("Dim causes compile error", !mbError );
StarBASIC::SetGlobalErrorHdl( Link() );
CPPUNIT_ASSERT_MESSAGE("Dim causes compile error", !HasError() );
}
// Put the test suite in the registry

View file

@ -0,0 +1,63 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* Copyright 2012 LibreOffice contributors.
*
* 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 "osl/file.hxx"
#include "osl/process.h"
#include "basic/sbmod.hxx"
#include "basic/sbmeth.hxx"
namespace
{
class Nested_Struct : public BasicTestBase
{
public:
Nested_Struct() {};
void testAssign1();
// Adds code needed to register the test suite
CPPUNIT_TEST_SUITE(Nested_Struct);
// Declares the method as a test to call
CPPUNIT_TEST(testAssign1);
// End of test suite definition
CPPUNIT_TEST_SUITE_END();
};
rtl::OUString sTestSource1(
"Function simpleNestStructAccess() as Integer\n"
"Dim b0 as new \"com.sun.star.table.TableBorder\"\n"
"b0.HorizontalLine.OuterLineWidth = 9\n"
"simpleNestStructAccess = b0.HorizontalLine.OuterLineWidth\n"
"End Function\n"
);
void Nested_Struct::testAssign1()
{
CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
StarBASICRef pBasic = new StarBASIC();
ResetError();
StarBASIC::SetGlobalErrorHdl( LINK( this, Nested_Struct, BasicErrorHdl ) );
SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sTestSource1 );
pMod->Compile();
CPPUNIT_ASSERT_MESSAGE("testAssign1 fails with compile error",!HasError() );
SbMethod* pMeth = static_cast<SbMethod*>(pMod->Find( rtl::OUString("simpleNestStructAccess"), SbxCLASS_METHOD ));
CPPUNIT_ASSERT_MESSAGE("testAssign1 no method found", pMeth );
SbxVariableRef refTemp = pMeth;
// forces a broadcast
SbxVariableRef pNew = new SbxMethod( *((SbxMethod*)pMeth));
CPPUNIT_ASSERT(pNew->GetInteger() == 9 );
}
// Put the test suite in the registry
CPPUNIT_TEST_SUITE_REGISTRATION(Nested_Struct);
} // namespace
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */