summaryrefslogtreecommitdiff
path: root/sc/qa/unit/macros-test.cxx
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2011-11-14 19:31:39 +0100
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2011-11-14 23:50:55 +0100
commit275110a0956505fa5e7efaef86c053ed65c4e8a6 (patch)
tree12ffbfa3b2bf13d33e2e9ebaf0cc1e0da1c96ed2 /sc/qa/unit/macros-test.cxx
parent51e89c41823e9d64f1f99f239c6900bb1a8bfe0e (diff)
don't use XUnoTunnel directly, use SfxObjectShell::GetShellFromComponent
Diffstat (limited to 'sc/qa/unit/macros-test.cxx')
-rw-r--r--sc/qa/unit/macros-test.cxx33
1 files changed, 13 insertions, 20 deletions
diff --git a/sc/qa/unit/macros-test.cxx b/sc/qa/unit/macros-test.cxx
index 658a603d3dc5..bcf201468ac7 100644
--- a/sc/qa/unit/macros-test.cxx
+++ b/sc/qa/unit/macros-test.cxx
@@ -64,7 +64,6 @@
#include <com/sun/star/task/XInteractionHandler.hpp>
#include <com/sun/star/frame/XDispatchRecorderSupplier.hpp>
#include <com/sun/star/document/MacroExecMode.hpp>
-#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <sfx2/app.hxx>
#include <sfx2/docfilt.hxx>
@@ -116,7 +115,7 @@ public:
virtual bool load(const rtl::OUString &rFilter, const rtl::OUString &rURL, const rtl::OUString &rUserData);
ScDocShellRef load(const rtl::OUString &rFilter, const rtl::OUString &rURL,
const rtl::OUString &rUserData, const rtl::OUString& rTypeName, sal_uLong nFormatType=0);
- uno::Reference< com::sun::star::frame::XModel > loadFromDesktop(const rtl::OUString& rURL);
+ uno::Reference< com::sun::star::lang::XComponent > loadFromDesktop(const rtl::OUString& rURL);
void createFileURL(const rtl::OUString& aFileBase, const rtl::OUString& aFileExtension, rtl::OUString& rFilePath);
@@ -173,7 +172,7 @@ ScDocShellRef ScMacrosTest::load(const rtl::OUString &rFilter, const rtl::OUStri
return xDocShRef;
}
-uno::Reference< com::sun::star::frame::XModel > ScMacrosTest::loadFromDesktop(const rtl::OUString& rURL)
+uno::Reference< com::sun::star::lang::XComponent > ScMacrosTest::loadFromDesktop(const rtl::OUString& rURL)
{
uno::Reference< com::sun::star::frame::XComponentLoader> xLoader = uno::Reference< com::sun::star::frame::XComponentLoader >( mxDesktop, UNO_QUERY );
com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > args(1);
@@ -184,9 +183,8 @@ uno::Reference< com::sun::star::frame::XModel > ScMacrosTest::loadFromDesktop(co
com::sun::star::document::MacroExecMode::ALWAYS_EXECUTE_NO_WARN;
args[0].State = com::sun::star::beans::PropertyState_DIRECT_VALUE;
uno::Reference< com::sun::star::lang::XComponent> xComponent= xLoader->loadComponentFromURL(rURL, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_default")), 0, args);
- uno::Reference< com::sun::star::frame::XModel > xModel( xComponent, UNO_QUERY );
CPPUNIT_ASSERT_MESSAGE("", xComponent.is());
- return xModel;
+ return xComponent;
}
@@ -219,9 +217,9 @@ void ScMacrosTest::testStarBasic()
createFileURL(aFileNameBase, aFileExtension, aFileName);
rtl::OUString aFilterType(aFileFormats[0].pTypeName, strlen(aFileFormats[0].pTypeName), RTL_TEXTENCODING_UTF8);
std::cout << aFileFormats[0].pName << " Test" << std::endl;
- uno::Reference< com::sun::star::frame::XModel > xModel = loadFromDesktop(aFileName);
+ uno::Reference< com::sun::star::lang::XComponent > xComponent = loadFromDesktop(aFileName);
- CPPUNIT_ASSERT_MESSAGE("Failed to load StarBasic.ods", xModel.is());
+ CPPUNIT_ASSERT_MESSAGE("Failed to load StarBasic.ods", xComponent.is());
rtl::OUString aURL(RTL_CONSTASCII_USTRINGPARAM("vnd.sun.Star.script:Standard.Module1.Macro1?language=Basic&location=document"));
String sUrl = aURL;
@@ -230,13 +228,13 @@ void ScMacrosTest::testStarBasic()
Sequence< Any > aOutParam;
Sequence< uno::Any > aParams;
- com::sun::star::uno::Reference< com::sun::star::lang::XUnoTunnel > xObjShellTunnel( xModel,com::sun::star::uno:: UNO_QUERY_THROW );
- SfxObjectShell* pFoundShell = reinterpret_cast<SfxObjectShell*>( xObjShellTunnel->getSomething(SfxObjectShell::getUnoTunnelId()));
+ SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent);
+
CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell);
- ScDocShell* xDocSh = ( ScDocShell*)pFoundShell;
+ ScDocShell* xDocSh = static_cast<ScDocShell*>(pFoundShell);
ScDocument* pDoc = xDocSh->GetDocument();
- pFoundShell->CallXScript(xModel, sUrl, aParams, aRet, aOutParamIndex,aOutParam);
+ pFoundShell->CallXScript(xComponent, sUrl, aParams, aRet, aOutParamIndex,aOutParam);
double aValue;
pDoc->GetValue(0,0,0,aValue);
std::cout << "returned value = " << aValue << std::endl;
@@ -270,26 +268,21 @@ void ScMacrosTest::testVba()
{
rtl::OUString aFileName;
createFileURL(testInfo[i].sFileBaseName, aFileExtension, aFileName);
- uno::Reference< com::sun::star::frame::XModel > xModel = loadFromDesktop(aFileName);
+ uno::Reference< com::sun::star::lang::XComponent > xComponent = loadFromDesktop(aFileName);
rtl::OUString sMsg( RTL_CONSTASCII_USTRINGPARAM("Failed to load ") );
sMsg.concat( aFileName );
- CPPUNIT_ASSERT_MESSAGE( rtl::OUStringToOString( sMsg, RTL_TEXTENCODING_UTF8 ).getStr(), xModel.is() );
+ CPPUNIT_ASSERT_MESSAGE( rtl::OUStringToOString( sMsg, RTL_TEXTENCODING_UTF8 ).getStr(), xComponent.is() );
- //is it really the right way to call a vba macro through CallXScript?
- //it seems that the basic ide does it differently, but then we would need to init all parts ourself
- //the problem is that CallXScript inits the basic part
- ////BasicIDE::RunMethod takes an SbMethod as parametre
String sUrl = testInfo[i].sMacroUrl;
Any aRet;
Sequence< sal_Int16 > aOutParamIndex;
Sequence< Any > aOutParam;
Sequence< uno::Any > aParams;
- com::sun::star::uno::Reference< com::sun::star::lang::XUnoTunnel > xObjShellTunnel( xModel,com::sun::star::uno:: UNO_QUERY_THROW );
- SfxObjectShell* pFoundShell = reinterpret_cast<SfxObjectShell*>( xObjShellTunnel->getSomething(SfxObjectShell::getUnoTunnelId()));
+ SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent);
CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell);
- pFoundShell->CallXScript(xModel, sUrl, aParams, aRet, aOutParamIndex,aOutParam);
+ pFoundShell->CallXScript(xComponent, sUrl, aParams, aRet, aOutParamIndex,aOutParam);
rtl::OUString aStringRes;
aRet >>= aStringRes;
std::cout << "value of Ret " << rtl::OUStringToOString( aStringRes, RTL_TEXTENCODING_UTF8 ).getStr() << std::endl;