Kaydet (Commit) 8534787f authored tarafından Noel Power's avatar Noel Power

adapt existing tests to use MacroSnipper helper class

Change-Id: I50980d9510b82277a5da04cc4f6c1d3ec8e7c756
üst 49417b0b
......@@ -16,7 +16,7 @@
namespace
{
class Coverage : public BasicTestBase
class Coverage : public test::BootstrapFixture
{
private:
bool m_bError;
......@@ -32,8 +32,6 @@ private:
void test_success(void);
void print_summary() {};
DECL_LINK( CoverageErrorHdl, StarBASIC * );
public:
Coverage();
~Coverage();
......@@ -50,18 +48,9 @@ public:
CPPUNIT_TEST_SUITE_END();
};
IMPL_LINK( Coverage, CoverageErrorHdl, StarBASIC *, /*pBasic*/)
{
fprintf(stderr,"%s:(%d:%d)\n",
rtl::OUStringToOString( m_sCurrentTest, RTL_TEXTENCODING_UTF8 ).getStr(),
StarBASIC::GetLine(), StarBASIC::GetCol1());
fprintf(stderr,"Basic error: %s\n", rtl::OUStringToOString( StarBASIC::GetErrorText(), RTL_TEXTENCODING_UTF8 ).getStr() );
m_bError = true;
return 0;
}
Coverage::Coverage()
: m_bError(false)
: BootstrapFixture(true, false)
, m_bError(false)
, m_nb_tests(0)
, m_nb_tests_ok(0)
, m_nb_tests_skipped(0)
......@@ -94,25 +83,14 @@ void Coverage::test_success()
void Coverage::run_test(OUString /*sFileName*/, OUString sCode)
{
bool result = false;
CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
StarBASICRef pBasic = new StarBASIC();
ResetError();
StarBASIC::SetGlobalErrorHdl( LINK( this, Coverage, CoverageErrorHdl ) );
SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sCode );
pMod->Compile();
if(!m_bError)
MacroSnippet testMacro( sCode );
testMacro.Compile();
if( !testMacro.HasError() )
{
SbMethod* pMeth = static_cast<SbMethod*>(pMod->Find( rtl::OUString("doUnitTest"), SbxCLASS_METHOD ));
if(pMeth)
SbxVariableRef pResult = testMacro.Run();
if( pResult && pResult->GetInteger() == 1 )
{
SbxVariableRef refTemp = pMeth;
// forces a broadcast
SbxVariableRef pNew = new SbxMethod( *((SbxMethod*)pMeth));
if(pNew->GetInteger() == 1 )
{
result = true;
}
result = true;
}
}
if(result)
......
......@@ -15,10 +15,10 @@
#include "basic/sbmeth.hxx"
namespace
{
class EnableTest : public BasicTestBase
class EnableTest : public test::BootstrapFixture
{
public:
EnableTest() {};
EnableTest() : BootstrapFixture(true, false) {};
void testDimEnable();
void testEnableRuntime();
// Adds code needed to register the test suite
......@@ -33,50 +33,34 @@ namespace
};
rtl::OUString sTestEnableRuntime(
"Function Test as Integer\n"
"Function doUnitTest as Integer\n"
"Dim Enable as Integer\n"
"Enable = 1\n"
"Enable = Enable + 2\n"
"Test = Enable\n"
"doUnitTest = Enable\n"
"End Function\n"
);
rtl::OUString sTestDimEnable(
"Sub Test\n"
"Sub doUnitTest\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 ) );
SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sTestEnableRuntime );
pMod->Compile();
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));
MacroSnippet myMacro(sTestEnableRuntime);
myMacro.Compile();
CPPUNIT_ASSERT_MESSAGE("testEnableRuntime fails with compile error",!myMacro.HasError() );
SbxVariableRef pNew = myMacro.Run();
CPPUNIT_ASSERT(pNew->GetInteger() == 3 );
}
void EnableTest::testDimEnable()
{
CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
StarBASICRef pBasic = new StarBASIC();
StarBASIC::SetGlobalErrorHdl( LINK( this, EnableTest, BasicErrorHdl ) );
ResetError();
SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sTestDimEnable );
pMod->Compile();
CPPUNIT_ASSERT_MESSAGE("Dim causes compile error", !HasError() );
MacroSnippet myMacro(sTestDimEnable);
myMacro.Compile();
CPPUNIT_ASSERT_MESSAGE("Dim causes compile error", !myMacro.HasError() );
}
// Put the test suite in the registry
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment