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