summaryrefslogtreecommitdiff
path: root/pyuno
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2013-04-05 23:07:18 +0200
committerDavid Ostrovsky <David.Ostrovsky@gmx.de>2013-04-09 05:52:49 +0000
commitebeae438dbaa3e9f1cda33a17c4a6530feac80d9 (patch)
tree8506c0fc72da662187c11a00950ac17a240623eb /pyuno
parent0e68bac85293e2d60fa6db3e46de8b74ab5d502b (diff)
move Python tests in-process
This is nice to make them more easily debuggable. A series of crude hacks are employed to bootstrap enough services from python so the current tests run. This is only tested with system python3 on Fedora. Change-Id: I5e06741e55ead7fddec41ff776ff8ca5d2399469 Reviewed-on: https://gerrit.libreoffice.org/3215 Reviewed-by: David Ostrovsky <David.Ostrovsky@gmx.de> Tested-by: David Ostrovsky <David.Ostrovsky@gmx.de>
Diffstat (limited to 'pyuno')
-rw-r--r--pyuno/source/module/pyuno_module.cxx42
1 files changed, 42 insertions, 0 deletions
diff --git a/pyuno/source/module/pyuno_module.cxx b/pyuno/source/module/pyuno_module.cxx
index 768b6d735a8a..62851c4741c0 100644
--- a/pyuno/source/module/pyuno_module.cxx
+++ b/pyuno/source/module/pyuno_module.cxx
@@ -320,6 +320,47 @@ static PyObject* getComponentContext(
return ret.getAcquired();
}
+static PyObject* initPoniesMode(
+ SAL_UNUSED_PARAMETER PyObject*, SAL_UNUSED_PARAMETER PyObject*)
+{
+ // this tries to bootstrap enough of the soffice from python to run
+ // unit tests, which is only possible indirectly because pyuno is URE
+ // so load "test" library and invoke a function there to do the work
+ try
+ {
+ PyObject *const ctx(getComponentContext(0, 0));
+ if (!ctx) { abort(); }
+ Runtime const runtime;
+ Any const a(runtime.pyObject2Any(ctx));
+ Reference<XComponentContext> xContext;
+ a >>= xContext;
+ if (!xContext.is()) { abort(); }
+ using com::sun::star::lang::XMultiServiceFactory;
+ Reference<XMultiServiceFactory> const xMSF(
+ xContext->getServiceManager(),
+ com::sun::star::uno::UNO_QUERY_THROW);
+ if (!xMSF.is()) { abort(); }
+ char *const outdir = getenv("OUTDIR");
+ if (!outdir) { abort(); }
+ OStringBuffer libname(outdir);
+ libname.append("/lib/");
+ libname.append(SAL_DLLPREFIX "test" SAL_DLLEXTENSION);
+ oslModule const mod( osl_loadModuleAscii(libname.getStr(),
+ SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL) );
+ if (!mod) { abort(); }
+ oslGenericFunction const pFunc(
+ osl_getAsciiFunctionSymbol(mod, "test_init"));
+ if (!pFunc) { abort(); }
+ // guess casting pFunc is undefined behavior but don't see a better way
+ ((void (SAL_CALL *)(XMultiServiceFactory*)) pFunc) (xMSF.get());
+ }
+ catch (const com::sun::star::uno::Exception & e)
+ {
+ abort();
+ }
+ return Py_None;
+}
+
PyObject * extractOneStringArg( PyObject *args, char const *funcName )
{
if( !PyTuple_Check( args ) || PyTuple_Size( args) != 1 )
@@ -797,6 +838,7 @@ static PyObject *setCurrentContext(
struct PyMethodDef PyUNOModule_methods [] =
{
+ {"experimentalExtraMagic", initPoniesMode, METH_VARARGS, NULL},
{"getComponentContext", getComponentContext, METH_VARARGS, NULL},
{"_createUnoStructHelper", reinterpret_cast<PyCFunction>(createUnoStructHelper), METH_VARARGS | METH_KEYWORDS, NULL},
{"getTypeByName", getTypeByName, METH_VARARGS, NULL},