diff options
Diffstat (limited to 'py/test')
-rwxr-xr-x | py/test/Ice/faultTolerance/run.py | 3 | ||||
-rwxr-xr-x | py/test/Ice/operations/ServerAMD.py | 6 | ||||
-rw-r--r-- | py/test/Ice/operations/Test.ice | 10 | ||||
-rw-r--r-- | py/test/Ice/operations/TestAMD.ice | 10 | ||||
-rw-r--r-- | py/test/Ice/operations/TestI.py | 6 | ||||
-rw-r--r-- | py/test/Ice/operations/Twoways.py | 27 | ||||
-rw-r--r-- | py/test/Ice/operations/TwowaysAMI.py | 51 | ||||
-rw-r--r-- | py/test/Ice/protobuf/AllTests.py | 75 | ||||
-rwxr-xr-x | py/test/Ice/protobuf/Client.py | 58 | ||||
-rwxr-xr-x | py/test/Ice/protobuf/Server.py | 68 | ||||
-rw-r--r-- | py/test/Ice/protobuf/Test.ice | 54 | ||||
-rw-r--r-- | py/test/Ice/protobuf/Test.proto | 16 | ||||
-rwxr-xr-x | py/test/Ice/protobuf/run.py | 33 | ||||
-rw-r--r-- | py/test/Slice/keyword/Key.ice | 1 | ||||
-rwxr-xr-x | py/test/Slice/keyword/run.py | 3 |
15 files changed, 419 insertions, 2 deletions
diff --git a/py/test/Ice/faultTolerance/run.py b/py/test/Ice/faultTolerance/run.py index a7d9403143f..1b4a6840bf1 100755 --- a/py/test/Ice/faultTolerance/run.py +++ b/py/test/Ice/faultTolerance/run.py @@ -37,8 +37,9 @@ ports = "" for i in range(0, num): ports = "%s %d" % (ports, base + i) print "starting client...", -clientProc = TestUtil.startClient(client, ports) +clientProc = TestUtil.startClient(client, ports, startReader = False) print "ok" +clientProc.startReader() clientProc.waitTestSuccess() for p in serverProc: diff --git a/py/test/Ice/operations/ServerAMD.py b/py/test/Ice/operations/ServerAMD.py index a7d09dfe07f..b678605d03a 100755 --- a/py/test/Ice/operations/ServerAMD.py +++ b/py/test/Ice/operations/ServerAMD.py @@ -191,6 +191,12 @@ class MyDerivedClassI(Test.MyDerivedClass): r.update(p2) cb.ice_response(r, p3) + def opMyStructMyEnumD_async(self, cb, p1, p2, current=None): + p3 = p1.copy() + r = p1.copy() + r.update(p2) + cb.ice_response(r, p3) + def opIntS_async(self, cb, s, current=None): cb.ice_response([-x for x in s]) diff --git a/py/test/Ice/operations/Test.ice b/py/test/Ice/operations/Test.ice index 4fc80b45195..a69a320eeb9 100644 --- a/py/test/Ice/operations/Test.ice +++ b/py/test/Ice/operations/Test.ice @@ -60,11 +60,18 @@ sequence<MyClassS> MyClassSS; sequence<StringSS> StringSSS; +struct MyStruct +{ + int i; + int j; +}; + dictionary<byte, bool> ByteBoolD; dictionary<short, int> ShortIntD; dictionary<long, float> LongFloatD; dictionary<string, string> StringStringD; dictionary<string, MyEnum> StringMyEnumD; +dictionary<MyStruct, MyEnum> MyStructMyEnumD; ["ami"] class MyClass { @@ -143,6 +150,9 @@ dictionary<string, MyEnum> StringMyEnumD; StringMyEnumD opStringMyEnumD(StringMyEnumD p1, StringMyEnumD p2, out StringMyEnumD p3); + MyStructMyEnumD opMyStructMyEnumD(MyStructMyEnumD p1, MyStructMyEnumD p2, + out MyStructMyEnumD p3); + IntS opIntS(IntS s); void opByteSOneway(ByteS s); diff --git a/py/test/Ice/operations/TestAMD.ice b/py/test/Ice/operations/TestAMD.ice index fcfd8e27c3b..528e8180fe7 100644 --- a/py/test/Ice/operations/TestAMD.ice +++ b/py/test/Ice/operations/TestAMD.ice @@ -58,11 +58,18 @@ sequence<MyClassS> MyClassSS; sequence<StringSS> StringSSS; +struct MyStruct +{ + int i; + int j; +}; + dictionary<byte, bool> ByteBoolD; dictionary<short, int> ShortIntD; dictionary<long, float> LongFloatD; dictionary<string, string> StringStringD; dictionary<string, MyEnum> StringMyEnumD; +dictionary<MyStruct, MyEnum> MyStructMyEnumD; ["ami", "amd"] class MyClass { @@ -141,6 +148,9 @@ dictionary<string, MyEnum> StringMyEnumD; StringMyEnumD opStringMyEnumD(StringMyEnumD p1, StringMyEnumD p2, out StringMyEnumD p3); + MyStructMyEnumD opMyStructMyEnumD(MyStructMyEnumD p1, MyStructMyEnumD p2, + out MyStructMyEnumD p3); + IntS opIntS(IntS s); void opByteSOneway(ByteS s); diff --git a/py/test/Ice/operations/TestI.py b/py/test/Ice/operations/TestI.py index ee595ba8532..5cf3a522b2b 100644 --- a/py/test/Ice/operations/TestI.py +++ b/py/test/Ice/operations/TestI.py @@ -154,6 +154,12 @@ class MyDerivedClassI(Test.MyDerivedClass): r.update(p2) return (r, p3) + def opMyStructMyEnumD(self, p1, p2, current=None): + p3 = p1.copy() + r = p1.copy() + r.update(p2) + return (r, p3) + def opIntS(self, s, current=None): return [-x for x in s] diff --git a/py/test/Ice/operations/Twoways.py b/py/test/Ice/operations/Twoways.py index 5ae6a98b5f8..d79bd05243e 100644 --- a/py/test/Ice/operations/Twoways.py +++ b/py/test/Ice/operations/Twoways.py @@ -524,6 +524,33 @@ def twoways(communicator, p): test(ro["Hello!!"] == Test.MyEnum.enum2) # + # opMyStructMyEnumD + # + s11 = Test.MyStruct() + s11.i = 1 + s11.j = 1 + s12 = Test.MyStruct() + s12.i = 1 + s12.j = 2 + s22 = Test.MyStruct() + s22.i = 2 + s22.j = 2 + s23 = Test.MyStruct() + s23.i = 2 + s23.j = 3 + di1 = {s11: Test.MyEnum.enum1, s12: Test.MyEnum.enum2} + di2 = {s11: Test.MyEnum.enum1, s22: Test.MyEnum.enum3, s23: Test.MyEnum.enum2} + + ro, do = p.opMyStructMyEnumD(di1, di2) + + test(do == di1) + test(len(ro) == 4) + test(ro[s11] == Test.MyEnum.enum1) + test(ro[s12] == Test.MyEnum.enum2) + test(ro[s22] == Test.MyEnum.enum3) + test(ro[s23] == Test.MyEnum.enum2) + + # # opIntS # lengths = ( 0, 1, 2, 126, 127, 128, 129, 253, 254, 255, 256, 257, 1000 ) diff --git a/py/test/Ice/operations/TwowaysAMI.py b/py/test/Ice/operations/TwowaysAMI.py index e0ceac2fddf..295a2051989 100644 --- a/py/test/Ice/operations/TwowaysAMI.py +++ b/py/test/Ice/operations/TwowaysAMI.py @@ -472,6 +472,35 @@ class AMI_MyClass_opStringMyEnumDI(CallbackBase): def ice_exception(self, ex): test(False) +class AMI_MyClass_opMyStructMyEnumDI(CallbackBase): + def __init__(self): + CallbackBase.__init__(self) + + def ice_response(self, ro, do): + s11 = Test.MyStruct() + s11.i = 1 + s11.j = 1 + s12 = Test.MyStruct() + s12.i = 1 + s12.j = 2 + s22 = Test.MyStruct() + s22.i = 2 + s22.j = 2 + s23 = Test.MyStruct() + s23.i = 2 + s23.j = 3 + di1 = {s11: Test.MyEnum.enum1, s12: Test.MyEnum.enum2} + test(do == di1) + test(len(ro) == 4) + test(ro[s11] == Test.MyEnum.enum1) + test(ro[s12] == Test.MyEnum.enum2) + test(ro[s22] == Test.MyEnum.enum3) + test(ro[s23] == Test.MyEnum.enum2) + self.called() + + def ice_exception(self, ex): + test(False) + class AMI_MyClass_opIntSI(CallbackBase): def __init__(self, l): CallbackBase.__init__(self) @@ -769,6 +798,28 @@ def twowaysAMI(communicator, p): test(cb.check()) # + # opMyStructMyEnumD + # + s11 = Test.MyStruct() + s11.i = 1 + s11.j = 1 + s12 = Test.MyStruct() + s12.i = 1 + s12.j = 2 + s22 = Test.MyStruct() + s22.i = 2 + s22.j = 2 + s23 = Test.MyStruct() + s23.i = 2 + s23.j = 3 + di1 = {s11: Test.MyEnum.enum1, s12: Test.MyEnum.enum2} + di2 = {s11: Test.MyEnum.enum1, s22: Test.MyEnum.enum3, s23: Test.MyEnum.enum2} + + cb = AMI_MyClass_opMyStructMyEnumDI() + p.opMyStructMyEnumD_async(cb, di1, di2) + test(cb.check()) + + # # opIntS # lengths = ( 0, 1, 2, 126, 127, 128, 129, 253, 254, 255, 256, 257, 1000 ) diff --git a/py/test/Ice/protobuf/AllTests.py b/py/test/Ice/protobuf/AllTests.py new file mode 100644 index 00000000000..566179a7db9 --- /dev/null +++ b/py/test/Ice/protobuf/AllTests.py @@ -0,0 +1,75 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import Ice, Test, threading +from Test_pb2 import Message + +def test(b): + if not b: + raise RuntimeError('test assertion failed') + +class CallbackBase: + def __init__(self): + self._called = False + self._cond = threading.Condition() + + def called(self): + self._cond.acquire() + self._called = True + self._cond.notify() + self._cond.release() + + def check(self): + self._cond.acquire() + while not self._called: + self._cond.wait(5.0) + self._called = False + return True + +class AMI_MyClass_opMessageI(CallbackBase): + def ice_response(self, r, o): + test(o.i == 99); + test(r.i == 99); + self.called() + + def ice_exception(self, ex): + test(False) + +def allTests(communicator, collocated): + sref = "test:default -p 12010 -t 10000" + obj = communicator.stringToProxy(sref) + test(obj != None) + + cl = Test.MyClassPrx.checkedCast(obj) + test(cl != None) + + print "testing twoway operations... ", + i = Message() + i.i = 99 + + r, o = cl.opMessage(i); + test(o.i == 99); + test(r.i == 99); + + r, o = cl.opMessageAMD(i); + test(o.i == 99); + test(r.i == 99); + print "ok" + + print "testing twoway AMI operations... ", + cb = AMI_MyClass_opMessageI() + cl.opMessage_async(cb, i) + cb.check() + + cb = AMI_MyClass_opMessageI() + cl.opMessageAMD_async(cb, i) + cb.check() + print "ok" + + return cl diff --git a/py/test/Ice/protobuf/Client.py b/py/test/Ice/protobuf/Client.py new file mode 100755 index 00000000000..070df3ac032 --- /dev/null +++ b/py/test/Ice/protobuf/Client.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys, traceback + +for toplevel in [".", "..", "../..", "../../..", "../../../.."]: + toplevel = os.path.normpath(toplevel) + if os.path.exists(os.path.join(toplevel, "python", "Ice.py")): + break +else: + raise "can't find toplevel directory!" + +# +# Get Slice directory. +# +slice_dir = os.path.join(os.path.join(toplevel, "..", "slice")) +if not os.path.exists(slice_dir): + print sys.argv[0] + ': Slice directory not found.' + sys.exit(1) + +import Ice +Ice.loadSlice('-I' + slice_dir + ' Test.ice') +import AllTests + +def test(b): + if not b: + raise RuntimeError('test assertion failed') + +def run(args, communicator): + myClass = AllTests.allTests(communicator, False) + myClass.shutdown() + + return True + +try: + initData = Ice.InitializationData() + initData.properties = Ice.createProperties(sys.argv) + communicator = Ice.initialize(sys.argv, initData) + status = run(sys.argv, communicator) +except: + traceback.print_exc() + status = False + +if communicator: + try: + communicator.destroy() + except: + traceback.print_exc() + status = False + +sys.exit(not status) diff --git a/py/test/Ice/protobuf/Server.py b/py/test/Ice/protobuf/Server.py new file mode 100755 index 00000000000..9caa59fd1f7 --- /dev/null +++ b/py/test/Ice/protobuf/Server.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys, traceback, time, threading + +for toplevel in [".", "..", "../..", "../../..", "../../../.."]: + toplevel = os.path.normpath(toplevel) + if os.path.exists(os.path.join(toplevel, "python", "Ice.py")): + break +else: + raise "can't find toplevel directory!" + +import Ice + +# +# Get Slice directory. +# +slice_dir = os.path.join(os.path.join(toplevel, "..", "slice")) +if not os.path.exists(slice_dir): + print sys.argv[0] + ': Slice directory not found.' + sys.exit(1) + +Ice.loadSlice('-I' + slice_dir + ' Test.ice') +import Test +from Test_pb2 import Message + +class MyClassI(Test.MyClass): + def opMessage(self, m, current=None): + return (m, m) + + def opMessageAMD_async(self, cb, m, current=None): + cb.ice_response(m, m); + + def shutdown(self, current=None): + current.adapter.getCommunicator().shutdown() + +def run(args, communicator): + communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010 -t 10000:udp") + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(MyClassI(), communicator.stringToIdentity("test")) + adapter.activate() + communicator.waitForShutdown() + return True + +try: + initData = Ice.InitializationData() + initData.properties = Ice.createProperties(sys.argv) + communicator = Ice.initialize(sys.argv, initData) + status = run(sys.argv, communicator) +except: + traceback.print_exc() + status = False + +if communicator: + try: + communicator.destroy() + except: + traceback.print_exc() + status = False + +sys.exit(not status) diff --git a/py/test/Ice/protobuf/Test.ice b/py/test/Ice/protobuf/Test.ice new file mode 100644 index 00000000000..bb234d349c8 --- /dev/null +++ b/py/test/Ice/protobuf/Test.ice @@ -0,0 +1,54 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef TEST_ICE +#define TEST_ICE + +module Test +{ + +["python:protobuf:Test_pb2.Message"] sequence<byte> Message; + +["ami"] class MyClass +{ + void shutdown(); + + Message opMessage(Message i, out Message o); + + ["amd"] Message opMessageAMD(Message i, out Message o); +}; + +// Remaining type definitions are there to verify that the generated +// code compiles correctly. + +sequence<Message> SLS; +sequence<SLS> SLSS; +dictionary<int, Message> SLD; +dictionary<int, SLS> SLSD; +struct Foo +{ + Message SLmem; + SLS SLSmem; +}; + +exception Bar +{ + Message SLmem; + SLS SLSmem; +}; + +class Baz +{ + Message SLmem; + SLS SLSmem; +}; + +}; + +#endif diff --git a/py/test/Ice/protobuf/Test.proto b/py/test/Ice/protobuf/Test.proto new file mode 100644 index 00000000000..fea4c801ddd --- /dev/null +++ b/py/test/Ice/protobuf/Test.proto @@ -0,0 +1,16 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package test; + +option java_outer_classname = "TestPB"; + +message Message { + required int32 i = 1; +} diff --git a/py/test/Ice/protobuf/run.py b/py/test/Ice/protobuf/run.py new file mode 100755 index 00000000000..cc2ad23e79d --- /dev/null +++ b/py/test/Ice/protobuf/run.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise "can't find toplevel directory!" +sys.path.append(os.path.join(path[0])) +from scripts import * + +if os.system("protoc --python_out=. Test.proto") != 0: + print "failed to compile Test.proto" + sys.exit(1) + +TestUtil.clientServerTest() + +# Remove generated protobuf files. +if os.path.exists("Test_pb2.py"): + os.unlink("Test_pb2.py") +if os.path.exists("Test_pb2.pyc"): + os.unlink("Test_pb2.pyc") diff --git a/py/test/Slice/keyword/Key.ice b/py/test/Slice/keyword/Key.ice index 74b2d51bbfe..e5d268cbffe 100644 --- a/py/test/Slice/keyword/Key.ice +++ b/py/test/Slice/keyword/Key.ice @@ -31,6 +31,7 @@ module and class for { + int lambda; ["ami"] void foo(exec* from, out int global); }; diff --git a/py/test/Slice/keyword/run.py b/py/test/Slice/keyword/run.py index f36d746e167..6722947e90c 100755 --- a/py/test/Slice/keyword/run.py +++ b/py/test/Slice/keyword/run.py @@ -21,6 +21,7 @@ sys.path.append(os.path.join(path[0])) from scripts import * print "starting client...", -clientProc = TestUtil.startClient("Client.py", "--Ice.Default.Host=127.0.0.1") +clientProc = TestUtil.startClient("Client.py", "--Ice.Default.Host=127.0.0.1", startReader = False) print "ok" +clientProc.startReader() clientProc.waitTestSuccess() |