Update ooo320-m1
[ooovba.git] / testtools / source / bridgetest / pyuno / samplecomponent.py
blob0958967c321057abee960bc4d7da177eb5221cd8
1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 #
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: samplecomponent.py,v $
11 # $Revision: 1.4 $
13 # This file is part of OpenOffice.org.
15 # OpenOffice.org is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU Lesser General Public License version 3
17 # only, as published by the Free Software Foundation.
19 # OpenOffice.org is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU Lesser General Public License version 3 for more details
23 # (a copy is included in the LICENSE file that accompanied this code).
25 # You should have received a copy of the GNU Lesser General Public License
26 # version 3 along with OpenOffice.org. If not, see
27 # <http://www.openoffice.org/license.html>
28 # for a copy of the LGPLv3 License.
30 #*************************************************************************
31 import uno
32 import unohelper
34 from com.sun.star.lang import IllegalArgumentException,XServiceInfo
35 from com.sun.star.uno import RuntimeException
36 from com.sun.star.beans import UnknownPropertyException
37 from test.testtools.bridgetest import TestData,XRecursiveCall,XBridgeTestBase
39 g_ImplementationHelper = unohelper.ImplementationHelper()
40 g_implName = "org.openoffice.comp.pyuno.PythonTestObject"
42 g_attribs = "RuntimeException", "Bool", "Char", "Byte", "Short", "UShort", \
43 "Long", "ULong", "Hyper", "UHyper", "Float", "Double", "Enum", \
44 "String", "Interface", "Any" , "Sequence" , "Struct"
46 def assign( rData, bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper,\
47 nUHyper, fFloat, fDouble, eEnum, rStr, xTest, rAny ):
48 rData.Bool = bBool;
49 rData.Char = cChar;
50 rData.Byte = nByte;
51 rData.Short = nShort;
52 rData.UShort = nUShort;
53 rData.Long = nLong;
54 rData.ULong = nULong;
55 rData.Hyper = nHyper;
56 rData.UHyper = nUHyper;
57 rData.Float = fFloat;
58 rData.Double = fDouble;
59 rData.Enum = eEnum;
60 rData.String = rStr;
61 rData.Interface = xTest;
62 rData.Any = rAny;
64 class MyRecursiveCall( XRecursiveCall, unohelper.Base ):
65 def callRecursivly( xCall, nToCall ):
66 if nToCall:
67 xCall.callRecursivly( self, nToCall -1 )
69 class SampleUnoComponent( XBridgeTestBase,XServiceInfo ):
70 def __init__(self,ctx):
71 self.__dict__["callid"] = 0
72 self.__dict__["sequenceBroken"] = 0
74 def transportAny( self, value ):
75 return value
77 def raiseException( self, ArgumentPosition, Message, Context ):
78 raise IllegalArgumentException( Message, Context, ArgumentPosition )
80 def raiseRuntimeExceptionOneway(self, Message, Context ):
81 raise RuntimeException( Message, Context )
83 def setValues( self, bBool, cChar, nByte, nShort, nUShort, nLong,\
84 nULong, nHyper, nUHyper, fFloat, fDouble, eEnum, \
85 aString, xInterface, aAny, aSequence, aStruct ):
86 self.__dict__["data"] = TestDataElements( bBool, cChar, nByte, nShort, nUShort, nLong,
87 nULong, nHyper, nUHyper, fFloat, fDouble, eEnum, aStruct, xInterface,
88 aAny, aSequence )
89 self.__dict__["Struct"] = aStruct
91 def setValues2( self, bBool, cChar, nByte, nShort, nUShort, nLong, nULong,\
92 nHyper, nUHyper, fFloat, fDouble, eEnum, \
93 aString, xInterface, aAny, aSequence, aStruct ):
94 self.__dict__["Struct"] = TestData( cChar, nByte, nShort, nUShort, nLong, nULong, nHyper,\
95 nUHyper, fFloat, fDouble, eEnum, aStruct, xInterface,\
96 aAny, aSequence )
97 self.__dict__["Struct"] = aStruct
98 return bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, nULong, \
99 nHyper, nUHyper, fFloat, fDouble, eEnum, aStruct, xInterface, aAny, \
100 (aSequence[1],aSequence[0]), aStruct
102 def getValues(self, a,b,c,d,e,f,g,h, i,j,k,l,m,n):
103 v = self.__dict__["data"]
104 return self.__dict__["Struct"],v.Bool, v.Char, v.Byte, v.Short, v.UShort, v.Long, \
105 v.ULong, v.Hyper, v.UHyper, v.Float, v.Double, v.Enum, v.String, v.Interface, \
106 v.Any, v.Sequence, self.__dict__["Struct"]
108 def call( self, callid, nWaitMUSEC ):
109 if self.__dict__["callid"] >= callid:
110 self.__dict__["sequenceBroken"] = 1
111 else:
112 self.__dict__["callid"] = callid
114 def callOneway( self, nCallId, nWaitMUSEC ):
115 call( nCallId, nWaitMUSEC )
117 def sequenceOfCallTestPassed():
118 return self.__dict__["sequenceBroken"]
120 def startRecursiveCall( xCall , nToCall ):
121 if nToCall:
122 xCall.callRecursivly( MyRecursiveCall(), nToCall -1 )
124 def checkExistence( self, name ):
125 found = 0
126 for x in g_attribs:
127 if x == name:
128 found = 1
129 break
130 if not found:
131 raise UnknownPropertyException( "Property "+name+" is unknown", self )
133 def __setattr__( self, name, value ):
134 checkExistence( name )
135 self.__dict__[name] = value
137 def __getattr__( self, name ):
138 checkExistence( name )
139 return self.__dict__[name]
141 def getSupportedServices( self ):
142 return g_ImplementationHelper.getSupportedServices(g_implName)
143 def supportsService( self, ServiceName ):
144 return g_ImplementationHelper.supportsService( g_implName, ServiceName )
145 def getImplementationName(self):
146 return g_implName
149 g_ImplementationHelper.addImplementation( \
150 SampleUnoComponent,g_implName,("com.sun.star.test.bridge.PythonTestObject",),)
152 #g_ImplementationEntries = \
153 # unohelper.ImplementationEntry( \
154 # "org.openoffice.comp.SamplePythonComponent", \
155 # ("com.sun.star.test.bridge.PythonTestObject",), \
156 # SampleUnoComponent) \