split out some common basic test stuff, add intial nested struct test
Change-Id: I8da6b3166e40e92c31ee001ce19938f286e057b9
This commit is contained in:
@@ -37,6 +37,7 @@ $(eval $(call gb_Module_add_targets,basic,\
|
|||||||
$(eval $(call gb_Module_add_check_targets,basic,\
|
$(eval $(call gb_Module_add_check_targets,basic,\
|
||||||
CppunitTest_basic_scanner \
|
CppunitTest_basic_scanner \
|
||||||
CppunitTest_basic_enable \
|
CppunitTest_basic_enable \
|
||||||
|
CppunitTest_basic_nested_struct \
|
||||||
))
|
))
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
51
basic/qa/cppunit/basictest.hxx
Normal file
51
basic/qa/cppunit/basictest.hxx
Normal 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: */
|
@@ -6,30 +6,18 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/.
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
#include "basictest.hxx"
|
||||||
#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 "osl/file.hxx"
|
#include "osl/file.hxx"
|
||||||
#include "osl/process.h"
|
#include "osl/process.h"
|
||||||
|
|
||||||
#include "basic/sbstar.hxx"
|
|
||||||
#include "basic/sbmod.hxx"
|
#include "basic/sbmod.hxx"
|
||||||
#include "basic/sbmeth.hxx"
|
#include "basic/sbmeth.hxx"
|
||||||
#include "basic/basrdll.hxx"
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
class EnableTest : public test::BootstrapFixture
|
class EnableTest : public BasicTestBase
|
||||||
{
|
{
|
||||||
private:
|
|
||||||
bool mbError;
|
|
||||||
public:
|
public:
|
||||||
EnableTest() : mbError(false) {};
|
EnableTest() {};
|
||||||
void testDimEnable();
|
void testDimEnable();
|
||||||
void testEnableRuntime();
|
void testEnableRuntime();
|
||||||
// Adds code needed to register the test suite
|
// Adds code needed to register the test suite
|
||||||
@@ -41,63 +29,53 @@ namespace
|
|||||||
|
|
||||||
// End of test suite definition
|
// End of test suite definition
|
||||||
CPPUNIT_TEST_SUITE_END();
|
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*/)
|
rtl::OUString sTestEnableRuntime(
|
||||||
{
|
"Function Test as Integer\n"
|
||||||
fprintf(stderr,"Got error: \n\t%s!!!\n", rtl::OUStringToOString( StarBASIC::GetErrorText(), RTL_TEXTENCODING_UTF8 ).getStr() );
|
"Dim Enable as Integer\n"
|
||||||
mbError = true;
|
"Enable = 1\n"
|
||||||
return 0;
|
"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()
|
void EnableTest::testEnableRuntime()
|
||||||
{
|
{
|
||||||
CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
|
CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
|
||||||
StarBASICRef pBasic = new StarBASIC();
|
StarBASICRef pBasic = new StarBASIC();
|
||||||
|
ResetError();
|
||||||
StarBASIC::SetGlobalErrorHdl( LINK( this, EnableTest, BasicErrorHdl ) );
|
StarBASIC::SetGlobalErrorHdl( LINK( this, EnableTest, BasicErrorHdl ) );
|
||||||
|
|
||||||
rtl::OUString sSource("Function Test as Integer\n");
|
SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sTestEnableRuntime );
|
||||||
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 );
|
|
||||||
pMod->Compile();
|
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 ));
|
SbMethod* pMeth = static_cast<SbMethod*>(pMod->Find( rtl::OUString("Test"), SbxCLASS_METHOD ));
|
||||||
CPPUNIT_ASSERT_MESSAGE("testEnableRuntime no method found", pMeth );
|
CPPUNIT_ASSERT_MESSAGE("testEnableRuntime no method found", pMeth );
|
||||||
SbxVariableRef refTemp = pMeth;
|
SbxVariableRef refTemp = pMeth;
|
||||||
// forces a broadcast
|
// forces a broadcast
|
||||||
SbxVariableRef pNew = new SbxMethod( *((SbxMethod*)pMeth));
|
SbxVariableRef pNew = new SbxMethod( *((SbxMethod*)pMeth));
|
||||||
CPPUNIT_ASSERT(pNew->GetInteger() == 3 );
|
CPPUNIT_ASSERT(pNew->GetInteger() == 3 );
|
||||||
StarBASIC::SetGlobalErrorHdl( Link() );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnableTest::testDimEnable()
|
void EnableTest::testDimEnable()
|
||||||
{
|
{
|
||||||
CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
|
CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
|
||||||
StarBASICRef pBasic = new StarBASIC();
|
StarBASICRef pBasic = new StarBASIC();
|
||||||
StarBASIC::SetGlobalErrorHdl( LINK( this, EnableTest, BasicErrorHdl ) );
|
StarBASIC::SetGlobalErrorHdl( LINK( this, EnableTest, BasicErrorHdl ) );
|
||||||
|
|
||||||
rtl::OUString sSource("Sub Test\n");
|
ResetError();
|
||||||
sSource += rtl::OUString("Dim Enable as String\n");
|
|
||||||
sSource += rtl::OUString("End Sub\n");
|
|
||||||
|
|
||||||
SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sSource );
|
SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sTestDimEnable );
|
||||||
pMod->Compile();
|
pMod->Compile();
|
||||||
|
|
||||||
CPPUNIT_ASSERT_MESSAGE("Dim causes compile error", !mbError );
|
CPPUNIT_ASSERT_MESSAGE("Dim causes compile error", !HasError() );
|
||||||
StarBASIC::SetGlobalErrorHdl( Link() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put the test suite in the registry
|
// Put the test suite in the registry
|
||||||
|
63
basic/qa/cppunit/test_nested_struct.cxx
Normal file
63
basic/qa/cppunit/test_nested_struct.cxx
Normal 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: */
|
Reference in New Issue
Block a user