1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: samplecomponent.py,v $
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 #*************************************************************************
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
):
52 rData
.UShort
= nUShort
;
56 rData
.UHyper
= nUHyper
;
58 rData
.Double
= fDouble
;
61 rData
.Interface
= xTest
;
64 class MyRecursiveCall( XRecursiveCall
, unohelper
.Base
):
65 def callRecursivly( xCall
, 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
):
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
,
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
,\
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
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
):
122 xCall
.callRecursivly( MyRecursiveCall(), nToCall
-1 )
124 def checkExistence( self
, name
):
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
):
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) \