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