1*a0428e9eSAndrew Rist#**************************************************************
2*a0428e9eSAndrew Rist#
3*a0428e9eSAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
4*a0428e9eSAndrew Rist#  or more contributor license agreements.  See the NOTICE file
5*a0428e9eSAndrew Rist#  distributed with this work for additional information
6*a0428e9eSAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
7*a0428e9eSAndrew Rist#  to you under the Apache License, Version 2.0 (the
8*a0428e9eSAndrew Rist#  "License"); you may not use this file except in compliance
9*a0428e9eSAndrew Rist#  with the License.  You may obtain a copy of the License at
10*a0428e9eSAndrew Rist#
11*a0428e9eSAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
12*a0428e9eSAndrew Rist#
13*a0428e9eSAndrew Rist#  Unless required by applicable law or agreed to in writing,
14*a0428e9eSAndrew Rist#  software distributed under the License is distributed on an
15*a0428e9eSAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*a0428e9eSAndrew Rist#  KIND, either express or implied.  See the License for the
17*a0428e9eSAndrew Rist#  specific language governing permissions and limitations
18*a0428e9eSAndrew Rist#  under the License.
19*a0428e9eSAndrew Rist#
20*a0428e9eSAndrew Rist#**************************************************************
21cdf0e10cSrcweirimport uno
22cdf0e10cSrcweirimport unohelper
23cdf0e10cSrcweir
24cdf0e10cSrcweirfrom com.sun.star.lang import IllegalArgumentException,XServiceInfo
25cdf0e10cSrcweirfrom com.sun.star.uno import RuntimeException
26cdf0e10cSrcweirfrom com.sun.star.beans import UnknownPropertyException
27cdf0e10cSrcweirfrom test.testtools.bridgetest import TestData,XRecursiveCall,XBridgeTestBase
28cdf0e10cSrcweir
29cdf0e10cSrcweirg_ImplementationHelper = unohelper.ImplementationHelper()
30cdf0e10cSrcweirg_implName = "org.openoffice.comp.pyuno.PythonTestObject"
31cdf0e10cSrcweir
32cdf0e10cSrcweirg_attribs = "RuntimeException", "Bool", "Char", "Byte", "Short", "UShort", \
33cdf0e10cSrcweir            "Long", "ULong", "Hyper", "UHyper", "Float", "Double", "Enum", \
34cdf0e10cSrcweir	    "String", "Interface", "Any" , "Sequence" , "Struct"
35cdf0e10cSrcweir
36cdf0e10cSrcweirdef assign( rData, bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper,\
37cdf0e10cSrcweir	      nUHyper, fFloat, fDouble, eEnum, rStr, xTest, rAny  ):
38cdf0e10cSrcweir    rData.Bool = bBool;
39cdf0e10cSrcweir    rData.Char = cChar;
40cdf0e10cSrcweir    rData.Byte = nByte;
41cdf0e10cSrcweir    rData.Short = nShort;
42cdf0e10cSrcweir    rData.UShort = nUShort;
43cdf0e10cSrcweir    rData.Long = nLong;
44cdf0e10cSrcweir    rData.ULong = nULong;
45cdf0e10cSrcweir    rData.Hyper = nHyper;
46cdf0e10cSrcweir    rData.UHyper = nUHyper;
47cdf0e10cSrcweir    rData.Float = fFloat;
48cdf0e10cSrcweir    rData.Double = fDouble;
49cdf0e10cSrcweir    rData.Enum = eEnum;
50cdf0e10cSrcweir    rData.String = rStr;
51cdf0e10cSrcweir    rData.Interface = xTest;
52cdf0e10cSrcweir    rData.Any = rAny;
53cdf0e10cSrcweir
54cdf0e10cSrcweirclass MyRecursiveCall( XRecursiveCall, unohelper.Base ):
55cdf0e10cSrcweir      def callRecursivly( xCall, nToCall ):
56cdf0e10cSrcweir	  if nToCall:
57cdf0e10cSrcweir	     xCall.callRecursivly( self, nToCall -1 )
58cdf0e10cSrcweir
59cdf0e10cSrcweirclass SampleUnoComponent( XBridgeTestBase,XServiceInfo ):
60cdf0e10cSrcweir      def __init__(self,ctx):
61cdf0e10cSrcweir	  self.__dict__["callid"] = 0
62cdf0e10cSrcweir	  self.__dict__["sequenceBroken"] = 0
63cdf0e10cSrcweir
64cdf0e10cSrcweir      def transportAny( self, value ):
65cdf0e10cSrcweir	  return value
66cdf0e10cSrcweir
67cdf0e10cSrcweir      def raiseException( self, ArgumentPosition, Message, Context ):
68cdf0e10cSrcweir	  raise IllegalArgumentException( Message, Context, ArgumentPosition )
69cdf0e10cSrcweir
70cdf0e10cSrcweir      def raiseRuntimeExceptionOneway(self, Message, Context ):
71cdf0e10cSrcweir	  raise RuntimeException( Message, Context )
72cdf0e10cSrcweir
73cdf0e10cSrcweir      def setValues( self, bBool, cChar, nByte, nShort, nUShort, nLong,\
74cdf0e10cSrcweir		     nULong, nHyper, nUHyper, fFloat, fDouble, eEnum, \
75cdf0e10cSrcweir		     aString, xInterface, aAny, aSequence, aStruct ):
76cdf0e10cSrcweir         self.__dict__["data"] = TestDataElements( bBool, cChar, nByte, nShort, nUShort, nLong,
77cdf0e10cSrcweir	                  nULong, nHyper, nUHyper, fFloat, fDouble, eEnum, aStruct, xInterface,
78cdf0e10cSrcweir			  aAny, aSequence )
79cdf0e10cSrcweir         self.__dict__["Struct"] = aStruct
80cdf0e10cSrcweir
81cdf0e10cSrcweir      def setValues2( self, bBool, cChar, nByte, nShort, nUShort, nLong, nULong,\
82cdf0e10cSrcweir		      nHyper, nUHyper, fFloat, fDouble, eEnum,		\
83cdf0e10cSrcweir		      aString, xInterface, aAny, aSequence, aStruct ):
84cdf0e10cSrcweir          self.__dict__["Struct"] = TestData( cChar, nByte, nShort, nUShort, nLong, nULong, nHyper,\
85cdf0e10cSrcweir	                                      nUHyper, fFloat, fDouble, eEnum, aStruct, xInterface,\
86cdf0e10cSrcweir					      aAny, aSequence )
87cdf0e10cSrcweir          self.__dict__["Struct"] = aStruct
88cdf0e10cSrcweir	  return bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, nULong, \
89cdf0e10cSrcweir	         nHyper, nUHyper, fFloat, fDouble, eEnum, aStruct, xInterface, aAny,	       \
90cdf0e10cSrcweir		 (aSequence[1],aSequence[0]), aStruct
91cdf0e10cSrcweir
92cdf0e10cSrcweir      def getValues(self, a,b,c,d,e,f,g,h, i,j,k,l,m,n):
93cdf0e10cSrcweir	  v = self.__dict__["data"]
94cdf0e10cSrcweir	  return self.__dict__["Struct"],v.Bool, v.Char, v.Byte, v.Short, v.UShort, v.Long,	\
95cdf0e10cSrcweir	         v.ULong, v.Hyper, v.UHyper, v.Float, v.Double, v.Enum, v.String, v.Interface,	\
96cdf0e10cSrcweir		 v.Any, v.Sequence, self.__dict__["Struct"]
97cdf0e10cSrcweir
98cdf0e10cSrcweir      def call( self, callid, nWaitMUSEC ):
99cdf0e10cSrcweir	  if self.__dict__["callid"] >= callid:
100cdf0e10cSrcweir	     self.__dict__["sequenceBroken"] = 1
101cdf0e10cSrcweir	  else:
102cdf0e10cSrcweir	     self.__dict__["callid"] = callid
103cdf0e10cSrcweir
104cdf0e10cSrcweir      def callOneway( self, nCallId, nWaitMUSEC ):
105cdf0e10cSrcweir	  call( nCallId, nWaitMUSEC )
106cdf0e10cSrcweir
107cdf0e10cSrcweir      def sequenceOfCallTestPassed():
108cdf0e10cSrcweir	  return self.__dict__["sequenceBroken"]
109cdf0e10cSrcweir
110cdf0e10cSrcweir      def startRecursiveCall( xCall , nToCall ):
111cdf0e10cSrcweir	  if nToCall:
112cdf0e10cSrcweir	     xCall.callRecursivly( MyRecursiveCall(), nToCall -1 )
113cdf0e10cSrcweir
114cdf0e10cSrcweir      def checkExistence( self, name ):
115cdf0e10cSrcweir	  found = 0
116cdf0e10cSrcweir	  for x in g_attribs:
117cdf0e10cSrcweir	      if x == name:
118cdf0e10cSrcweir		 found = 1
119cdf0e10cSrcweir		 break
120cdf0e10cSrcweir	  if not found:
121cdf0e10cSrcweir	     raise UnknownPropertyException( "Property "+name+" is unknown", self )
122cdf0e10cSrcweir
123cdf0e10cSrcweir      def __setattr__( self, name, value ):
124cdf0e10cSrcweir	  checkExistence( name )
125cdf0e10cSrcweir	  self.__dict__[name] = value
126cdf0e10cSrcweir
127cdf0e10cSrcweir      def __getattr__( self, name ):
128cdf0e10cSrcweir	  checkExistence( name )
129cdf0e10cSrcweir	  return self.__dict__[name]
130cdf0e10cSrcweir
131cdf0e10cSrcweir      def getSupportedServices( self ):
132cdf0e10cSrcweir	  return g_ImplementationHelper.getSupportedServices(g_implName)
133cdf0e10cSrcweir      def supportsService( self, ServiceName ):
134cdf0e10cSrcweir	  return g_ImplementationHelper.supportsService( g_implName, ServiceName )
135cdf0e10cSrcweir      def getImplementationName(self):
136cdf0e10cSrcweir	  return g_implName
137cdf0e10cSrcweir
138cdf0e10cSrcweir
139cdf0e10cSrcweirg_ImplementationHelper.addImplementation( \
140cdf0e10cSrcweir	SampleUnoComponent,g_implName,("com.sun.star.test.bridge.PythonTestObject",),)
141cdf0e10cSrcweir
142cdf0e10cSrcweir#g_ImplementationEntries = \
143cdf0e10cSrcweir#    unohelper.ImplementationEntry(				\
144cdf0e10cSrcweir#	      "org.openoffice.comp.SamplePythonComponent",	\
145cdf0e10cSrcweir#	      ("com.sun.star.test.bridge.PythonTestObject",),	\
146cdf0e10cSrcweir#	      SampleUnoComponent)				\
147cdf0e10cSrcweir#	   ,
148cdf0e10cSrcweir
149