summaryrefslogtreecommitdiffstats
path: root/testtools/source/bridgetest/pyuno
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
commited5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch)
tree7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /testtools/source/bridgetest/pyuno
parentInitial commit. (diff)
downloadlibreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz
libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testtools/source/bridgetest/pyuno')
-rw-r--r--testtools/source/bridgetest/pyuno/core.py358
-rw-r--r--testtools/source/bridgetest/pyuno/impl.py187
-rw-r--r--testtools/source/bridgetest/pyuno/importer.py69
-rw-r--r--testtools/source/bridgetest/pyuno/main.py40
-rw-r--r--testtools/source/bridgetest/pyuno/makefile.mk117
-rw-r--r--testtools/source/bridgetest/pyuno/pyuno2
-rw-r--r--testtools/source/bridgetest/pyuno/samplecomponent.py189
-rw-r--r--testtools/source/bridgetest/pyuno/testcomp.py31
8 files changed, 993 insertions, 0 deletions
diff --git a/testtools/source/bridgetest/pyuno/core.py b/testtools/source/bridgetest/pyuno/core.py
new file mode 100644
index 000000000..c56e9f144
--- /dev/null
+++ b/testtools/source/bridgetest/pyuno/core.py
@@ -0,0 +1,358 @@
+#
+# This file is part of the LibreOffice project.
+#
+# 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/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed
+# with this work for additional information regarding copyright
+# ownership. The ASF licenses this file to you under the Apache
+# License, Version 2.0 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.apache.org/licenses/LICENSE-2.0 .
+#
+import pyuno
+import uno
+import unittest
+import exceptions
+import types
+
+def suite(ctx):
+ suite = unittest.TestSuite()
+ suite.addTest(TestCase("testErrors",ctx))
+ suite.addTest(TestCase("testBaseTypes",ctx))
+ suite.addTest(TestCase("testOutparam",ctx))
+ suite.addTest(TestCase("testStruct",ctx))
+ suite.addTest(TestCase("testType",ctx))
+ suite.addTest(TestCase("testEnum",ctx))
+ suite.addTest(TestCase("testBool",ctx))
+ suite.addTest(TestCase("testChar",ctx))
+ suite.addTest(TestCase("testUnicode",ctx))
+ suite.addTest(TestCase("testConstant",ctx))
+ suite.addTest(TestCase("testExceptions",ctx))
+ suite.addTest(TestCase("testInterface",ctx))
+ suite.addTest(TestCase("testByteSequence",ctx))
+ suite.addTest(TestCase("testInvoke",ctx))
+ return suite
+
+def equalsEps( a,b,eps ):
+ if a - eps <= b and a+eps >= b:
+ return 1
+ return 0
+
+def assign( rData, bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper,\
+ nUHyper, fFloat, fDouble, eEnum, rStr, xTest, rAny ):
+ rData.Bool = bBool;
+ rData.Char = cChar;
+ rData.Byte = nByte;
+ rData.Short = nShort;
+ rData.UShort = nUShort;
+ rData.Long = nLong;
+ rData.ULong = nULong;
+ rData.Hyper = nHyper;
+ rData.UHyper = nUHyper;
+ rData.Float = fFloat;
+ rData.Double = fDouble;
+ rData.Enum = eEnum;
+ rData.String = rStr;
+ rData.Interface = xTest;
+ rData.Any = rAny;
+
+
+class PythonTransporter:
+ def __init__( self ):
+ pass
+
+ def transportAny( self, arg ):
+ return arg
+
+class TestCase( unittest.TestCase):
+
+ def __init__(self,method,ctx):
+ unittest.TestCase.__init__(self,method)
+ self.ctx = ctx
+
+ def setUp(self):
+ # the testcomponent from the testtools project
+ self.tobj = self.ctx.ServiceManager.createInstanceWithContext(
+ 'com.sun.star.test.bridge.CppTestObject' , self.ctx )
+
+ self.tobj.Bool = 1
+ self.tobj.Char = 'h'
+ self.tobj.Byte = 43
+ self.tobj.Short = -42
+ self.tobj.UShort = 44
+ self.tobj.Long = 42
+ self.tobj.ULong = 41
+ self.tobj.Hyper = 46
+ self.tobj.UHyper = 47
+ self.tobj.Float = 4.3
+ self.tobj.Double = 4.2
+ self.tobj.Enum = 4
+ self.tobj.String = "yabadabadoo"
+ self.tobj.Interface = self.ctx
+ self.tobj.Any = self.tobj.String
+ mystruct = uno.createUnoStruct( "test.testtools.bridgetest.TestData" )
+ assign( mystruct, 1, 'h', 43, -42,44,42,41,46,47,4.3,4.2,4,"yabadabadoo",self.ctx,"yabadabadoo")
+ self.tobj.Struct = mystruct
+
+ self.testElement = uno.createUnoStruct( "test.testtools.bridgetest.TestElement" )
+ self.testElement.String = "foo"
+ self.testElement2 = uno.createUnoStruct( "test.testtools.bridgetest.TestElement" )
+ self.testElement2.String = "42"
+ self.tobj.Sequence = (self.testElement,self.testElement2)
+
+ def testBaseTypes(self):
+ self.failUnless( 42 == self.tobj.Long , "Long attribute" )
+ self.failUnless( 41 == self.tobj.ULong , "ULong attribute" )
+ self.failUnless( 43 == self.tobj.Byte , "Byte attribute" )
+ self.failUnless( 44 == self.tobj.UShort , "UShort attribute" )
+ self.failUnless( -42 == self.tobj.Short , "Short attribute" )
+ self.failUnless( 46 == self.tobj.Hyper , "Hyper attribute" )
+ self.failUnless( 47 == self.tobj.UHyper , "UHyper attribute" )
+ self.failUnless( self.tobj.Bool , "Bool attribute2" )
+ self.failUnless( "yabadabadoo" == self.tobj.String , "String attribute" )
+ self.failUnless( self.tobj.Sequence[0] == self.testElement , "Sequence test")
+ self.failUnless( self.tobj.Sequence[1] == self.testElement2 , "Sequence2 test")
+ self.failUnless( equalsEps( 4.3,self.tobj.Float,0.0001) , "float test" )
+ self.failUnless( 4.2 == self.tobj.Double , "double test" )
+ self.failUnless( self.ctx == self.tobj.Interface ,
+ "object identity test with C++ object" )
+ self.failUnless( not self.ctx == self.tobj , "object not identical test " )
+ self.failUnless( 42 == self.tobj.transportAny( 42 ), "transportAny long" )
+ self.failUnless( "woo, this is python" == self.tobj.transportAny( "woo, this is python" ), \
+ "string roundtrip via any test" )
+
+ def testEnum( self ):
+ e1 = uno.Enum( "com.sun.star.uno.TypeClass" , "LONG" )
+ e2 = uno.Enum( "com.sun.star.uno.TypeClass" , "LONG" )
+ e3 = uno.Enum( "com.sun.star.uno.TypeClass" , "UNSIGNED_LONG" )
+ e4 = uno.Enum( "test.testtools.bridgetest.TestEnum" , "TWO" )
+ self.failUnless( e1 == e2 , "equal enum test" )
+ self.failUnless( not (e1 == e3) , "different enums test" )
+ self.failUnless( self.tobj.transportAny( e3 ) == e3, "enum roundtrip test" )
+ self.tobj.Enum = e4
+ self.failUnless( e4 == self.tobj.Enum , "enum assignment failed" )
+
+ def testType(self ):
+ t1 = uno.getTypeByName( "com.sun.star.lang.XComponent" )
+ t2 = uno.getTypeByName( "com.sun.star.lang.XComponent" )
+ t3 = uno.getTypeByName( "com.sun.star.lang.EventObject" )
+ self.failUnless( t1.typeClass == \
+ uno.Enum( "com.sun.star.uno.TypeClass", "INTERFACE" ), "typeclass of type test" )
+ self.failUnless( t3.typeClass == \
+ uno.Enum( "com.sun.star.uno.TypeClass", "STRUCT" ), "typeclass of type test")
+ self.failUnless( t1 == t2 , "equal type test" )
+ self.failUnless( t1 == t2 , "equal type test" )
+ self.failUnless( t1 == self.tobj.transportAny( t1 ), "type roundtrip test" )
+
+ def testBool( self ):
+ self.failUnless( uno.Bool(1) , "uno.Bool true test" )
+ self.failUnless( not uno.Bool(0) , "uno.Bool false test" )
+ self.failUnless( uno.Bool( "true") , "uno.Bool true1 test" )
+ self.failUnless( not uno.Bool( "false") , "uno.Bool true1 test" )
+
+ self.tobj.Bool = uno.Bool(1)
+ self.failUnless( self.tobj.Bool , "bool true attribute test" )
+ self.tobj.Bool = uno.Bool(0)
+ self.failUnless( not self.tobj.Bool , "bool true attribute test" )
+
+ # new boolean semantic
+ self.failUnless( id( self.tobj.transportAny( True ) ) == id(True) , "boolean preserve test")
+ self.failUnless( id( self.tobj.transportAny( False ) ) == id(False) , "boolean preserve test" )
+ self.failUnless( id( self.tobj.transportAny(1) ) != id( True ), "boolean preserve test" )
+ self.failUnless( id( self.tobj.transportAny(0) ) != id( False ), "boolean preserve test" )
+
+ def testChar( self ):
+ self.tobj.Char = uno.Char( u'h' )
+ self.failUnless( self.tobj.Char == uno.Char( u'h' ), "char type test" )
+ self.failUnless( isinstance( self.tobj.transportAny( uno.Char(u'h') ),uno.Char),"char preserve test" )
+
+ def testStruct( self ):
+ mystruct = uno.createUnoStruct( "test.testtools.bridgetest.TestData" )
+ assign( mystruct, 1, 'h', 43, -42,44,42,41,46,47,4.3,4.2,4,"yabadabadoo",self.ctx,"yabadabadoo")
+ self.tobj.Struct = mystruct
+ aSecondStruct = self.tobj.Struct
+
+ self.failUnless( self.tobj.Struct == mystruct, "struct roundtrip for equality test" )
+ self.failUnless( aSecondStruct == mystruct, "struct roundtrip for equality test2" )
+ aSecondStruct.Short = 720
+ self.failUnless( not aSecondStruct == mystruct , "different structs equality test" )
+ self.failUnless( not self.ctx == mystruct , "object is not equal to struct test" )
+ self.failUnless( mystruct == self.tobj.transportAny( mystruct ), "struct roundtrip with any test" )
+ my2ndstruct = uno.createUnoStruct( "test.testtools.bridgetest.TestData", \
+ 1, 'h', 43, -42,44,42,41,46,47,4.3,4.2,4,"yabadabadoo",self.ctx,"yabadabadoo",())
+ self.failUnless( my2ndstruct == mystruct, "struct non-default ctor test" )
+ def testUnicode( self ):
+ uni = u'\0148'
+ self.tobj.String = uni
+ self.failUnless( uni == self.tobj.String )
+
+
+ self.tobj.String = u'dubidu'
+ self.failUnless( u'dubidu' == self.tobj.String , "unicode comparison test")
+ self.failUnless( 'dubidu' == self.tobj.String , "unicode vs. string comparison test" )
+
+ def testConstant( self ):
+ self.failUnless( uno.getConstantByName( "com.sun.star.beans.PropertyConcept.ATTRIBUTES" ) == 4,\
+ "constant retrieval test" )
+
+ def testExceptions( self ):
+ unoExc = uno.getClass( "com.sun.star.uno.Exception" )
+ ioExc = uno.getClass( "com.sun.star.io.IOException" )
+ dispExc = uno.getClass( "com.sun.star.lang.DisposedException" )
+ wasHere = 0
+ try:
+ raise ioExc( "huhuh" , self.tobj )
+ except unoExc , instance:
+ wasHere = 1
+ self.failUnless( wasHere , "exception test 1" )
+
+ wasHere = 0
+ try:
+ raise ioExc
+ except ioExc:
+ wasHere = 1
+ else:
+ self.failUnless( wasHere, "exception test 2" )
+
+ wasHere = 0
+ try:
+ raise dispExc
+ except ioExc:
+ pass
+ except unoExc:
+ wasHere = 1
+ self.failUnless(wasHere, "exception test 3")
+
+ illegalArg = uno.getClass( "com.sun.star.lang.IllegalArgumentException" )
+ wasHere = 0
+ try:
+ self.tobj.raiseException( 1 , "foo" , self.tobj )
+ self.failUnless( 0 , "exception test 5a" )
+ except ioExc:
+ self.failUnless( 0 , "exception test 5b" )
+ except illegalArg, i:
+ self.failUnless( 1 == i.ArgumentPosition , "exception member test" )
+ self.failUnless( "foo" == i.Message , "exception member test 2 " )
+ wasHere = 1
+ else:
+ self.failUnless( 0, "except test 5c" )
+ self.failUnless( wasHere, "illegal argument exception test failed" )
+
+ def testInterface(self):
+ clazz = uno.getClass( "com.sun.star.lang.XComponent" )
+ self.failUnless( "com.sun.star.lang.XComponent" == clazz.__pyunointerface__ )
+ self.failUnless( issubclass( clazz, uno.getClass( "com.sun.star.uno.XInterface" ) ) )
+ self.tobj.Interface = None
+
+
+ def testOutparam( self):
+ # outparameter
+ struct, mybool,mychar,mybyte,myshort,myushort,mylong,myulong,myhyper,myuhyper,myfloat, \
+ mydouble,myenum,mystring,myinterface,myany,myseq,my2ndstruct = self.tobj.getValues( \
+ None,None,None,None,None,None,None,None,None,None, \
+ None,None,None,None,None,None,None)
+ self.failUnless(struct == self.tobj.Struct, "outparam 1 test")
+ self.failUnless(self.tobj.Bool, "outparam 2 test")
+ self.failUnless(mychar == self.tobj.Char, "outparam 3 test")
+ self.failUnless(mybyte == self.tobj.Byte, "outparam 4 test")
+ self.failUnless(myshort == self.tobj.Short, "outparam 5 test")
+ self.failUnless(myushort == self.tobj.UShort, "outparam 6 test")
+ self.failUnless(mylong == self.tobj.Long, "outparam 7 test")
+ self.failUnless(myulong == self.tobj.ULong, "outparam 8 test")
+ self.failUnless(myhyper == self.tobj.Hyper, "outparam 9 test")
+ self.failUnless(myuhyper == self.tobj.UHyper, "outparam 10 test")
+ self.failUnless(myfloat == self.tobj.Float, "outparam 11 test")
+ self.failUnless(mydouble == self.tobj.Double, "outparam 12 test")
+ self.failUnless(myenum == self.tobj.Enum, "outparam 13 test")
+ self.failUnless(mystring == self.tobj.String, "outparam 14 test")
+ self.failUnless(myinterface == self.tobj.Interface, "outparam 15 test")
+ self.failUnless(myany == self.tobj.Any, "outparam 16 test")
+ self.failUnless(myseq == self.tobj.Sequence, "outparam 17 test")
+ self.failUnless(my2ndstruct == struct, "outparam 18 test")
+
+# should work, debug on windows, why not
+# struct, mybool,mychar,mybyte,myshort,myushort,mylong,myulong,myhyper,myuhyper,myfloat,\
+# mydouble,myenum,mystring,myinterface,myany,myseq,my2ndstruct = self.tobj.setValues2( \
+# mybool,mychar,mybyte,myshort,myushort,mylong,myulong,myhyper,myuhyper,myfloat,\
+# mydouble,myenum,mystring,myinterface,myany,myseq,my2ndstruct)
+# self.failUnless(struct == self.tobj.Struct, "outparam 1 test")
+# self.failUnless( mybool and self.tobj.Bool, "outparam 2 test")
+# self.failUnless(mychar == self.tobj.Char, "outparam 3 test")
+# self.failUnless(mybyte == self.tobj.Byte, "outparam 4 test")
+# self.failUnless(myshort == self.tobj.Short, "outparam 5 test")
+# self.failUnless(myushort == self.tobj.UShort, "outparam 6 test")
+# self.failUnless(mylong == self.tobj.Long, "outparam 7 test")
+# self.failUnless(myulong == self.tobj.ULong, "outparam 8 test")
+# self.failUnless(myhyper == self.tobj.Hyper, "outparam 9 test")
+# self.failUnless(myuhyper == self.tobj.UHyper, "outparam 10 test")
+# self.failUnless(myfloat == self.tobj.Float, "outparam 11 test")
+# self.failUnless(mydouble == self.tobj.Double, "outparam 12 test")
+# self.failUnless(myenum == self.tobj.Enum, "outparam 13 test")
+# self.failUnless(mystring == self.tobj.String, "outparam 14 test")
+# self.failUnless(myinterface == self.tobj.Interface, "outparam 15 test")
+# self.failUnless(myany == self.tobj.Any, "outparam 16 test")
+# self.failUnless(myseq == self.tobj.Sequence, "outparam 17 test")
+# self.failUnless(my2ndstruct == struct, "outparam 18 test")
+
+ def testErrors( self ):
+
+ wasHere = 0
+ try:
+ self.tobj.a = 5
+ self.fail("attribute a shouldn't exist")
+ except AttributeError:
+ wasHere = 1
+ except IllegalArgumentException:
+ wasHere = 1
+ self.failUnless( wasHere, "wrong attribute test" )
+
+ IllegalArgumentException = uno.getClass("com.sun.star.lang.IllegalArgumentException" )
+ RuntimeException = uno.getClass("com.sun.star.uno.RuntimeException" )
+
+# TODO: Remove this once it is done
+# wrong number of arguments bug !?
+ self.failUnlessRaises( IllegalArgumentException, self.tobj.transportAny, 42, 43 )
+ self.failUnlessRaises( IllegalArgumentException, self.tobj.transportAny )
+ self.failUnlessRaises( RuntimeException, uno.getClass, "a.b" )
+ self.failUnlessRaises( RuntimeException, uno.getClass, "com.sun.star.uno.TypeClass" )
+
+ self.failUnlessRaises( RuntimeException, uno.Enum, "a" , "b" )
+ self.failUnlessRaises( RuntimeException, uno.Enum, "com.sun.star.uno.TypeClass" , "b" )
+ self.failUnlessRaises( RuntimeException, uno.Enum, "com.sun.star.uno.XInterface" , "b" )
+
+ tcInterface =uno.Enum( "com.sun.star.uno.TypeClass" , "INTERFACE" )
+ self.failUnlessRaises( RuntimeException, uno.Type, "a", tcInterface )
+ self.failUnlessRaises( RuntimeException, uno.Type, "com.sun.star.uno.Exception", tcInterface )
+
+ self.failUnlessRaises( (RuntimeException,exceptions.RuntimeError), uno.getTypeByName, "a" )
+
+ self.failUnlessRaises( (RuntimeException), uno.getConstantByName, "a" )
+ self.failUnlessRaises( (RuntimeException), uno.getConstantByName, "com.sun.star.uno.XInterface" )
+
+ def testByteSequence( self ):
+ s = uno.ByteSequence( b"ab" )
+ self.failUnless( s == uno.ByteSequence( b"ab" ) )
+ self.failUnless( uno.ByteSequence( b"abc" ) == s + uno.ByteSequence( b"c" ) )
+ self.failUnless( uno.ByteSequence( b"abc" ) == s + "c" )
+ self.failUnless( s + "c" == "abc" )
+ self.failUnless( s == uno.ByteSequence( s ) )
+ self.failUnless( s[0] == 'a' )
+ self.failUnless( s[1] == 'b' )
+
+
+ def testInvoke( self ):
+ self.failUnless( 5 == uno.invoke( self.tobj , "transportAny" , (uno.Any("byte", 5),) ) )
+ self.failUnless( 5 == uno.invoke(
+ PythonTransporter(), "transportAny" , (uno.Any( "byte", 5 ),) ) )
+ t = uno.getTypeByName( "long" )
+ mystruct = uno.createUnoStruct(
+ "com.sun.star.beans.PropertyValue", "foo",0,uno.Any(t,2),0 )
+ mystruct.Value = uno.Any(t, 1)
+
+
diff --git a/testtools/source/bridgetest/pyuno/impl.py b/testtools/source/bridgetest/pyuno/impl.py
new file mode 100644
index 000000000..7fe940424
--- /dev/null
+++ b/testtools/source/bridgetest/pyuno/impl.py
@@ -0,0 +1,187 @@
+#
+# This file is part of the LibreOffice project.
+#
+# 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/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed
+# with this work for additional information regarding copyright
+# ownership. The ASF licenses this file to you under the Apache
+# License, Version 2.0 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.apache.org/licenses/LICENSE-2.0 .
+#
+"tests bridging python implementations of UNO objects"
+import unittest
+import uno
+import unohelper
+import os
+import sys
+
+from com.sun.star.io import XOutputStream, XInputStream, typeOfXOutputStream, typeOfXInputStream
+from com.sun.star.lang import XTypeProvider, typeOfXTypeProvider, XEventListener
+from com.sun.star.uno import XCurrentContext
+
+class SequenceOutputStream( unohelper.Base, XOutputStream ):
+ def __init__( self ):
+ self.s = uno.ByteSequence("")
+ self.closed = 0
+
+ def closeOutput(self):
+ self.closed = 1
+
+ def writeBytes( self, seq ):
+ self.s = self.s + seq
+
+ def flush( self ):
+ pass
+
+ def getSequence( self ):
+ return self.s
+
+
+class SequenceInputStream( XInputStream, unohelper.Base ):
+ def __init__( self, seq ):
+ self.s = seq
+ self.nIndex = 0
+ self.closed = 0
+
+ def closeInput( self):
+ self.closed = 1
+ self.s = None
+
+ def skipBytes( self, nByteCount ):
+ if( nByteCount + self.nIndex > len(self.s) ):
+ nByteCount = len(self.s) - self.nIndex
+ self.nIndex += nByteCount
+
+ def readBytes( self, retSeq, nByteCount ):
+ nRet = 0
+ if( self.nIndex + nByteCount > len(self.s) ):
+ nRet = len(self.s) - self.nIndex
+ else:
+ nRet = nByteCount
+ retSeq = uno.ByteSequence(self.s.value[self.nIndex : self.nIndex + nRet ])
+ self.nIndex = self.nIndex + nRet
+ return nRet, retSeq
+
+ def readSomeBytes( self, retSeq , nByteCount ):
+ #as we never block !
+ return readBytes( retSeq, nByteCount )
+
+ def available( self ):
+ return len( self.s ) - self.nIndex
+
+class SequenceInputStream2( SequenceInputStream ):
+ def __init__( self, seq ):
+ SequenceInputStream.__init__( self, seq )
+
+class TestCase(unittest.TestCase):
+ def __init__(self,method,ctx):
+ unittest.TestCase.__init__(self,method)
+ self.ctx = ctx
+
+ def setUp(self):
+ self.tobj = self.ctx.ServiceManager.createInstanceWithContext( \
+ "com.sun.star.test.bridge.CppTestObject",self.ctx)
+ self.pipe = self.ctx.ServiceManager.createInstanceWithContext( \
+ "com.sun.star.io.Pipe" , self.ctx )
+
+ def testStandard( self ):
+ dataOut = self.ctx.ServiceManager.createInstanceWithContext( \
+ "com.sun.star.io.DataOutputStream", self.ctx )
+ streamOut = SequenceOutputStream()
+ dataOut.setOutputStream( streamOut )
+ dataOut.writeShort( 42 )
+ dataOut.writeLong( 43 )
+ dataOut.closeOutput()
+
+ dataInput = self.ctx.ServiceManager.createInstanceWithContext( \
+ "com.sun.star.io.DataInputStream", self.ctx )
+
+ dataInput.setInputStream( SequenceInputStream2( streamOut.getSequence() ) )
+
+ self.failUnless( 42 == dataInput.readShort() )
+ self.failUnless( 43 == dataInput.readLong() )
+ self.failUnless( self.tobj.transportAny( streamOut ) == streamOut )
+
+
+class NullDevice:
+ def write( self, string ):
+ pass
+
+
+class EventListener( unohelper.Base, XEventListener ):
+ def __init__( self ):
+ self.disposingCalled = False
+
+ def disposing( self , eventObject ):
+ self.disposingCalled = True
+
+class TestHelperCase( unittest.TestCase ):
+
+ def __init__(self,method):
+ unittest.TestCase.__init__(self,method)
+
+ def testUrlHelper( self ):
+ systemPath = os.getcwd()
+ if systemPath.startswith( "/" ):
+ self.failUnless( "/tmp" == unohelper.fileUrlToSystemPath( "file:///tmp" ) )
+ self.failUnless( "file:///tmp" == unohelper.systemPathToFileUrl( "/tmp" ))
+ else:
+ self.failUnless( "c:\\temp" == unohelper.fileUrlToSystemPath( "file:///c:/temp" ) )
+ self.failUnless( "file:///c:/temp" == unohelper.systemPathToFileUrl( "c:\\temp" ) )
+
+ systemPath = unohelper.systemPathToFileUrl( systemPath )
+ self.failUnless( systemPath + "/a" == unohelper.absolutize( systemPath, "a" ) )
+ def testInspect( self ):
+ dev = NullDevice()
+# dev = sys.stdout
+ unohelper.inspect( uno.getComponentContext() , dev )
+ unohelper.inspect( uno.getComponentContext().ServiceManager , dev )
+ unohelper.inspect( uno.getTypeByName( "com.sun.star.lang.XComponent" ) , dev )
+
+ def testListener( self ):
+ smgr = uno.getComponentContext().ServiceManager.createInstance(
+ "com.sun.star.lang.ServiceManager" )
+
+ # check, whether listeners
+ listener = EventListener()
+ smgr.addEventListener( listener )
+ smgr.dispose()
+ self.failUnless( listener.disposingCalled )
+
+ # check, whether listeners can be removed
+ smgr = uno.getComponentContext().ServiceManager.createInstance(
+ "com.sun.star.lang.ServiceManager" )
+ listener = EventListener()
+ smgr.addEventListener( listener )
+ smgr.removeEventListener( listener )
+ smgr.dispose()
+ self.failUnless( not listener.disposingCalled )
+
+ def testCurrentContext( self ):
+ oldContext = uno.getCurrentContext()
+ try:
+ uno.setCurrentContext(
+ unohelper.CurrentContext( oldContext,{"My42":42}) )
+ self.failUnless( 42 == uno.getCurrentContext().getValueByName( "My42" ) )
+ self.failUnless( None == uno.getCurrentContext().getValueByName( "My43" ) )
+ finally:
+ uno.setCurrentContext( oldContext )
+
+
+
+def suite( ctx ):
+ suite = unittest.TestSuite()
+ suite.addTest(TestCase("testStandard",ctx))
+ suite.addTest(TestHelperCase( "testUrlHelper" ))
+ suite.addTest(TestHelperCase( "testInspect" ))
+ suite.addTest(TestHelperCase( "testListener" ) )
+ suite.addTest(TestHelperCase( "testCurrentContext" ) )
+ return suite
+
diff --git a/testtools/source/bridgetest/pyuno/importer.py b/testtools/source/bridgetest/pyuno/importer.py
new file mode 100644
index 000000000..c4ce8c175
--- /dev/null
+++ b/testtools/source/bridgetest/pyuno/importer.py
@@ -0,0 +1,69 @@
+#
+# This file is part of the LibreOffice project.
+#
+# 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/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed
+# with this work for additional information regarding copyright
+# ownership. The ASF licenses this file to you under the Apache
+# License, Version 2.0 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.apache.org/licenses/LICENSE-2.0 .
+#
+import unittest
+import uno
+import unohelper
+
+from com.sun.star.lang import EventObject,IllegalArgumentException,typeOfIllegalArgumentException
+from test.testtools.bridgetest.TestEnum import TWO
+from com.sun.star.uno.TypeClass import UNSIGNED_LONG,EXCEPTION
+class ImporterTestCase(unittest.TestCase):
+ def __init__(self,method,ctx):
+ unittest.TestCase.__init__(self,method)
+ self.ctx = ctx
+
+ def setUp(self):
+ self.tobj = self.ctx.ServiceManager.createInstanceWithContext( \
+ "com.sun.star.test.bridge.CppTestObject",self.ctx)
+
+ def testStandard( self ):
+ self.failUnless( IllegalArgumentException != None, "none-test" )
+ self.failUnlessRaises( IllegalArgumentException, self.tobj.raiseException, 1,"foo",self.tobj)
+
+ self.failUnless( TWO == uno.Enum( "test.testtools.bridgetest.TestEnum","TWO"), "enum" )
+ self.failUnless( UNSIGNED_LONG == uno.Enum( "com.sun.star.uno.TypeClass", "UNSIGNED_LONG" ) )
+ self.failUnless( typeOfIllegalArgumentException ==
+ uno.Type( "com.sun.star.lang.IllegalArgumentException", EXCEPTION) )
+
+ # should not throw an exception
+ e = EventObject()
+ e.Source = self.ctx
+ e = EventObject( self.ctx )
+ e = EventObject( e )
+
+ def testDynamicComponentRegistration( self ):
+ ctx = uno.getComponentContext()
+ self.failUnless(
+ not ("com.sun.star.connection.Acceptor" in ctx.ServiceManager.getAvailableServiceNames()),
+ "precondition for dynamic component registration test is not fulfilled" )
+ self.failUnless(
+ not ("com.sun.star.connection.Connector" in ctx.ServiceManager.getAvailableServiceNames()),
+ "precondition for dynamic component registration test is not fulfilled" )
+ unohelper.addComponentsToContext(
+ ctx , ctx, ("acceptor.uno","connector.uno"), "com.sun.star.loader.SharedLibrary" )
+ self.failUnless(
+ ("com.sun.star.connection.Acceptor" in ctx.ServiceManager.getAvailableServiceNames()) )
+ self.failUnless(
+ ("com.sun.star.connection.Connector" in ctx.ServiceManager.getAvailableServiceNames()))
+
+def suite( ctx ):
+ suite = unittest.TestSuite()
+ suite.addTest(ImporterTestCase("testStandard",ctx))
+ suite.addTest(ImporterTestCase("testDynamicComponentRegistration",ctx))
+ return suite
+
diff --git a/testtools/source/bridgetest/pyuno/main.py b/testtools/source/bridgetest/pyuno/main.py
new file mode 100644
index 000000000..9dc101a2e
--- /dev/null
+++ b/testtools/source/bridgetest/pyuno/main.py
@@ -0,0 +1,40 @@
+#
+# This file is part of the LibreOffice project.
+#
+# 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/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed
+# with this work for additional information regarding copyright
+# ownership. The ASF licenses this file to you under the Apache
+# License, Version 2.0 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.apache.org/licenses/LICENSE-2.0 .
+#
+import uno
+import unohelper
+import importer
+import unittest
+import core
+import impl
+import os
+import sys
+
+ctx = uno.getComponentContext()
+# needed for the tests
+unohelper.addComponentsToContext(ctx,ctx,(os.environ["FOO"]+"/cppobj.uno",os.environ["FOO"]+"/bridgetest.uno","streams.uno","bootstrap.uno"),"com.sun.star.loader.SharedLibrary")
+
+unohelper.addComponentsToContext(ctx,ctx,("vnd.openoffice.pymodule:samplecomponent",),"com.sun.star.loader.Python")
+
+runner = unittest.TextTestRunner(sys.stderr,1,2)
+
+suite = unittest.TestSuite()
+suite.addTest(importer.suite(ctx))
+suite.addTest(core.suite(ctx))
+suite.addTest(impl.suite(ctx))
+
+runner.run(suite)
diff --git a/testtools/source/bridgetest/pyuno/makefile.mk b/testtools/source/bridgetest/pyuno/makefile.mk
new file mode 100644
index 000000000..112be23c9
--- /dev/null
+++ b/testtools/source/bridgetest/pyuno/makefile.mk
@@ -0,0 +1,117 @@
+#
+# This file is part of the LibreOffice project.
+#
+# 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/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed
+# with this work for additional information regarding copyright
+# ownership. The ASF licenses this file to you under the Apache
+# License, Version 2.0 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.apache.org/licenses/LICENSE-2.0 .
+#
+
+PRJ=..$/..$/..
+
+PRJNAME=pyuno
+TARGET=test
+LIBTARGET=NO
+TARGETTYPE=CUI
+ENABLE_EXCEPTIONS=TRUE
+
+my_components = pythonloader
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE : settings.mk
+
+.IF "$(CROSS_COMPILING)"=="YES"
+
+all:
+# nothing
+
+.ENDIF
+
+# --- Files --------------------------------------------------------
+.IF "$(DISABLE_PYTHON)" != "TRUE"
+.IF "$(L10N_framework)"==""
+PYEXC=$(DLLDEST)$/python$(EXECPOST)
+REGEXC=$(DLLDEST)$/regcomp$(EXECPOST)
+
+.IF "$(SYSTEM_PYTHON)"!="YES"
+PYTHON=$(AUGMENT_LIBRARY_PATH) $(WRAPCMD) $(SOLARBINDIR)/python
+.ELSE # "$(SYSTEM_PYTHON)"!="YES"
+PYTHON=$(AUGMENT_LIBRARY_PATH) $(WRAPCMD) $(PYTHON_FOR_BUILD)
+.ENDIF # "$(SYSTEM_PYTHON)"!="YES"
+.IF "$(OS)"=="WNT"
+PYTHONPATH:=$(SOLARLIBDIR)$/pyuno;$(PWD);$(SOLARLIBDIR);$(SOLARLIBDIR)$/python;$(SOLARLIBDIR)$/python$/lib-dynload
+.ELSE # "$(OS)"=="WNT"
+PYTHONPATH:=$(SOLARLIBDIR)$/pyuno:$(PWD):$(SOLARLIBDIR):$(SOLARLIBDIR)$/python:$(SOLARLIBDIR)$/python$/lib-dynload
+.ENDIF # "$(OS)"=="WNT"
+.EXPORT: PYTHONPATH
+
+.IF "$(OS)"!="WNT"
+TEST_ENV=export FOO=file://$(shell @pwd)$/$(DLLDEST) \
+ UNO_TYPES=uno_types.rdb UNO_SERVICES=pyuno_services.rdb
+.ELSE # "$(OS)" != "WNT"
+# aaaaaa, how to get the current working directory on windows ???
+CWD_TMP=$(strip $(shell @echo "import os;print os.getcwd()" | $(PYTHON)))
+TEST_ENV=export FOO=file:///$(strip $(subst,\,/ $(CWD_TMP)$/$(DLLDEST))) && \
+ export UNO_TYPES=uno_types.rdb && export UNO_SERVICES=pyuno_services.rdb
+.ENDIF # "$(OS)"!="WNT"
+PYFILES = \
+ $(DLLDEST)$/core.py \
+ $(DLLDEST)$/importer.py \
+ $(DLLDEST)$/main.py \
+ $(DLLDEST)$/impl.py \
+ $(DLLDEST)$/samplecomponent.py \
+ $(DLLDEST)$/testcomp.py \
+
+PYCOMPONENTS = \
+ samplecomponent
+
+ALL : \
+ $(PYFILES) \
+ $(DLLDEST)/pyuno_services.rdb \
+ doc \
+ ALLTAR
+.ENDIF # L10N_framework
+.ENDIF # DISABLE_PYTHON
+
+.INCLUDE : target.mk
+
+.IF "$(DISABLE_PYTHON)" != "TRUE"
+.IF "$(L10N_framework)"==""
+$(DLLDEST)$/%.py: %.py
+ cp $? $@
+
+$(DLLDEST)$/python$(EXECPOST) : $(SOLARBINDIR)$/python$(EXECPOST)
+ cp $? $@
+
+$(DLLDEST)$/regcomp$(EXECPOST) : $(SOLARBINDIR)$/regcomp$(EXECPOST)
+ cp $? $@
+
+$(DLLDEST)$/pyuno_services.rdb .ERRREMOVE : \
+ $(SOLARENV)/bin/packcomponents.xslt $(MISC)/pyuno_services.input \
+ $(my_components:^"$(SOLARXMLDIR)/":+".component")
+ $(XSLTPROC) --nonet --stringparam prefix $(SOLARXMLDIR)/ -o $@ \
+ $(SOLARENV)/bin/packcomponents.xslt $(MISC)/pyuno_services.input
+
+$(MISC)/pyuno_services.input :
+ echo \
+ '<list>$(my_components:^"<filename>":+".component</filename>")</list>' \
+ > $@
+
+doc .PHONY:
+ @echo start test with dmake runtest
+
+runtest : ALL
+ cd $(DLLDEST) && $(TEST_ENV) && $(PYTHON) main.py
+.ENDIF # L10N_framework
+.ENDIF # DISABLE_PYTHON
+
diff --git a/testtools/source/bridgetest/pyuno/pyuno b/testtools/source/bridgetest/pyuno/pyuno
new file mode 100644
index 000000000..cf2da2cad
--- /dev/null
+++ b/testtools/source/bridgetest/pyuno/pyuno
@@ -0,0 +1,2 @@
+UNO_TYPES=uno_types.rdb
+UNO_SERVICES=pyuno_services.rdb
diff --git a/testtools/source/bridgetest/pyuno/samplecomponent.py b/testtools/source/bridgetest/pyuno/samplecomponent.py
new file mode 100644
index 000000000..4778a7602
--- /dev/null
+++ b/testtools/source/bridgetest/pyuno/samplecomponent.py
@@ -0,0 +1,189 @@
+#
+# This file is part of the LibreOffice project.
+#
+# 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/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed
+# with this work for additional information regarding copyright
+# ownership. The ASF licenses this file to you under the Apache
+# License, Version 2.0 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.apache.org/licenses/LICENSE-2.0 .
+#
+import uno
+import unohelper
+
+from com.sun.star.lang import IllegalArgumentException,XServiceInfo
+from com.sun.star.uno import RuntimeException
+from com.sun.star.beans import UnknownPropertyException
+from test.testtools.bridgetest import TestData,XRecursiveCall,XBridgeTestBase
+
+g_ImplementationHelper = unohelper.ImplementationHelper()
+g_implName = "org.openoffice.comp.pyuno.PythonTestObject"
+
+g_attribs = "RuntimeException", "Bool", "Char", "Byte", "Short", "UShort", \
+ "Long", "ULong", "Hyper", "UHyper", "Float", "Double", "Enum", \
+ "String", "Interface", "Any" , "Sequence" , "Struct"
+
+def assign( rData, bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper,\
+ nUHyper, fFloat, fDouble, eEnum, rStr, xTest, rAny ):
+ rData.Bool = bBool;
+ rData.Char = cChar;
+ rData.Byte = nByte;
+ rData.Short = nShort;
+ rData.UShort = nUShort;
+ rData.Long = nLong;
+ rData.ULong = nULong;
+ rData.Hyper = nHyper;
+ rData.UHyper = nUHyper;
+ rData.Float = fFloat;
+ rData.Double = fDouble;
+ rData.Enum = eEnum;
+ rData.String = rStr;
+ rData.Interface = xTest;
+ rData.Any = rAny;
+
+class MyRecursiveCall( XRecursiveCall, unohelper.Base ):
+ def callRecursivly( xCall, nToCall ):
+ if nToCall:
+ xCall.callRecursivly( self, nToCall -1 )
+
+class SampleUnoComponent( XBridgeTestBase,XServiceInfo ):
+ def __init__(self,ctx):
+ self.__dict__["callid"] = 0
+ self.__dict__["sequenceBroken"] = 0
+
+ def transportAny( self, value ):
+ return value
+
+ def raiseException( self, ArgumentPosition, Message, Context ):
+ raise IllegalArgumentException( Message, Context, ArgumentPosition )
+
+ def raiseRuntimeExceptionOneway(self, Message, Context ):
+ raise RuntimeException( Message, Context )
+
+ def setValues( self, \
+ bBool, \
+ cChar, \
+ nByte, \
+ nShort, \
+ nUShort, \
+ nLong, \
+ nULong, \
+ nHyper, \
+ nUHyper, \
+ fFloat, \
+ fDouble, \
+ eEnum, \
+ aString, \
+ xInterface, \
+ aAny, \
+ aSequence, \
+ aStruct ):
+ self.__dict__["data"] = TestDataElements( bBool, cChar, nByte, nShort, nUShort, nLong,
+ nULong, nHyper, nUHyper, fFloat, fDouble, eEnum, aStruct, xInterface,
+ aAny, aSequence )
+ self.__dict__["Struct"] = aStruct
+
+ def setValues2( self, \
+ bBool, \
+ cChar, \
+ nByte, \
+ nShort, \
+ nUShort, \
+ nLong, \
+ nULong,\
+ nHyper, \
+ nUHyper, \
+ fFloat, \
+ fDouble, \
+ eEnum, \
+ aString, \
+ xInterface, \
+ aAny, \
+ aSequence, \
+ aStruct ):
+ self.__dict__["Struct"] = TestData( cChar, nByte, nShort, nUShort, nLong, nULong, nHyper,\
+ nUHyper, fFloat, fDouble, eEnum, aStruct, xInterface,\
+ aAny, aSequence )
+ self.__dict__["Struct"] = aStruct
+ return bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, nULong, \
+ nHyper, nUHyper, fFloat, fDouble, eEnum, aStruct, xInterface, aAny, \
+ (aSequence[1],aSequence[0]), aStruct
+
+ def getValues(self, \
+ a, \
+ b, \
+ c, \
+ d, \
+ e, \
+ f, \
+ g, \
+ h, \
+ i, \
+ j, \
+ k, \
+ l, \
+ m, \
+ n):
+ v = self.__dict__["data"]
+ return self.__dict__["Struct"],v.Bool, v.Char, v.Byte, v.Short, v.UShort, v.Long, \
+ v.ULong, v.Hyper, v.UHyper, v.Float, v.Double, v.Enum, v.String, v.Interface, \
+ v.Any, v.Sequence, self.__dict__["Struct"]
+
+ def call( self, callid, nWaitMUSEC ):
+ if self.__dict__["callid"] >= callid:
+ self.__dict__["sequenceBroken"] = 1
+ else:
+ self.__dict__["callid"] = callid
+
+ def callOneway( self, nCallId, nWaitMUSEC ):
+ call( nCallId, nWaitMUSEC )
+
+ def sequenceOfCallTestPassed():
+ return self.__dict__["sequenceBroken"]
+
+ def startRecursiveCall( xCall , nToCall ):
+ if nToCall:
+ xCall.callRecursivly( MyRecursiveCall(), nToCall -1 )
+
+ def checkExistence( self, name ):
+ found = 0
+ for x in g_attribs:
+ if x == name:
+ found = 1
+ break
+ if not found:
+ raise UnknownPropertyException( "Property "+name+" is unknown", self )
+
+ def __setattr__( self, name, value ):
+ checkExistence( name )
+ self.__dict__[name] = value
+
+ def __getattr__( self, name ):
+ checkExistence( name )
+ return self.__dict__[name]
+
+ def getSupportedServices( self ):
+ return g_ImplementationHelper.getSupportedServices(g_implName)
+ def supportsService( self, ServiceName ):
+ return g_ImplementationHelper.supportsService( g_implName, ServiceName )
+ def getImplementationName(self):
+ return g_implName
+
+
+g_ImplementationHelper.addImplementation( \
+ SampleUnoComponent,g_implName,("com.sun.star.test.bridge.PythonTestObject",),)
+
+#g_ImplementationEntries = \
+# unohelper.ImplementationEntry( \
+# "org.openoffice.comp.SamplePythonComponent", \
+# ("com.sun.star.test.bridge.PythonTestObject",), \
+# SampleUnoComponent) \
+# ,
+
diff --git a/testtools/source/bridgetest/pyuno/testcomp.py b/testtools/source/bridgetest/pyuno/testcomp.py
new file mode 100644
index 000000000..e519d5e8e
--- /dev/null
+++ b/testtools/source/bridgetest/pyuno/testcomp.py
@@ -0,0 +1,31 @@
+#
+# This file is part of the LibreOffice project.
+#
+# 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/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed
+# with this work for additional information regarding copyright
+# ownership. The ASF licenses this file to you under the Apache
+# License, Version 2.0 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.apache.org/licenses/LICENSE-2.0 .
+#
+import uno
+import pythonloader
+
+ctx = uno.getComponentContext()
+
+loader = pythonloader.Loader( ctx )
+comp = loader.activate( "org.openoffice.comp.pyuno.PythonTestObject" , "", "samplecomponent", ctx )
+ctx.ServiceManager.insert( comp)
+
+bridgetest = ctx.ServiceManager.createInstanceWithContext( "com.sun.star.test.bridge.BridgeTest", ctx )
+#bridgetest.run( "com.sun.star.test.bridge.PythonTestObject" )
+
+
+