summaryrefslogtreecommitdiff
path: root/python/test/Slice/structure/Client.py
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2015-03-21 15:35:40 -0230
committerMatthew Newhook <matthew@zeroc.com>2015-03-21 15:35:40 -0230
commit630a37d2fe66f24518299e705f958b571803c522 (patch)
tree969723791bdc4d73bb099c19d45554d0ca241ad9 /python/test/Slice/structure/Client.py
parentFix some README.md markdown formatting (diff)
downloadice-630a37d2fe66f24518299e705f958b571803c522.tar.bz2
ice-630a37d2fe66f24518299e705f958b571803c522.tar.xz
ice-630a37d2fe66f24518299e705f958b571803c522.zip
py -> python
rb -> ruby objc -> objective-c cs -> csharp
Diffstat (limited to 'python/test/Slice/structure/Client.py')
-rwxr-xr-xpython/test/Slice/structure/Client.py211
1 files changed, 211 insertions, 0 deletions
diff --git a/python/test/Slice/structure/Client.py b/python/test/Slice/structure/Client.py
new file mode 100755
index 00000000000..036ce2121d1
--- /dev/null
+++ b/python/test/Slice/structure/Client.py
@@ -0,0 +1,211 @@
+#!/usr/bin/env python
+# **********************************************************************
+#
+# Copyright (c) 2003-2015 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 RuntimeError("can't find toplevel directory!")
+
+import Ice
+
+Ice.loadSlice('Test.ice')
+import Test, copy
+
+def test(b):
+ if not b:
+ raise RuntimeError('test assertion failed')
+
+def allTests(communicator):
+ sys.stdout.write("testing equals() for Slice structures... ")
+ sys.stdout.flush()
+
+ #
+ # Define some default values.
+ #
+ def_s2 = Test.S2(True, 98, 99, 100, 101, "string", (1, 2, 3), Test.S1("name"))
+
+ #
+ # Compare default-constructed structures.
+ #
+ test(Test.S2() == Test.S2())
+
+ #
+ # Change one member at a time.
+ #
+ v = copy.copy(def_s2)
+ test(v == def_s2)
+
+ v = copy.copy(def_s2)
+ v.bo = False
+ test(v != def_s2)
+
+ v = copy.copy(def_s2)
+ v.by = v.by - 1
+ test(v != def_s2)
+
+ v = copy.copy(def_s2)
+ v.sh = v.sh - 1
+ test(v != def_s2)
+
+ v = copy.copy(def_s2)
+ v.i = v.i - 1
+ test(v != def_s2)
+
+ v = copy.copy(def_s2)
+ v.l = v.l - 1
+ test(v != def_s2)
+
+ v = copy.copy(def_s2)
+ v.str = ""
+ test(v != def_s2)
+
+ #
+ # String member
+ #
+ v1 = copy.copy(def_s2)
+ v1.str = "string"
+ test(v1 == def_s2)
+
+ v1 = copy.copy(def_s2)
+ v2 = copy.copy(def_s2)
+ v1.str = None
+ test(v1 != v2)
+
+ v1 = copy.copy(def_s2)
+ v2 = copy.copy(def_s2)
+ v2.str = None
+ test(v1 != v2)
+
+ v1 = copy.copy(def_s2)
+ v2 = copy.copy(def_s2)
+ v1.str = None
+ v2.str = None
+ test(v1 == v2)
+
+ #
+ # Sequence member
+ #
+ v1 = copy.copy(def_s2)
+ v1.seq = copy.copy(def_s2.seq)
+ test(v1 == def_s2)
+
+ v1 = copy.copy(def_s2)
+ v1.seq = ()
+ test(v1 != def_s2)
+
+ v1 = copy.copy(def_s2)
+ v1.seq = (1, 2, 3)
+ test(v1 == def_s2)
+
+ v1 = copy.copy(def_s2)
+ v2 = copy.copy(def_s2)
+ v1.seq = None
+ test(v1 != v2)
+
+ v1 = copy.copy(def_s2)
+ v2 = copy.copy(def_s2)
+ v2.seq = None
+ test(v1 != v2)
+
+ #
+ # Struct member
+ #
+ v1 = copy.copy(def_s2)
+ v1.s = copy.copy(def_s2.s)
+ test(v1 == def_s2)
+
+ v1 = copy.copy(def_s2)
+ v1.s = Test.S1("name")
+ test(v1 == def_s2)
+
+ v1 = copy.copy(def_s2)
+ v1.s = Test.S1("noname")
+ test(v1 != def_s2)
+
+ v1 = copy.copy(def_s2)
+ v2 = copy.copy(def_s2)
+ v1.s = None
+ test(v1 != v2)
+
+ v1 = copy.copy(def_s2)
+ v2 = copy.copy(def_s2)
+ v2.s = None
+ test(v1 != v2)
+
+ #
+ # Define some default values.
+ #
+ def_s3 = Test.S3(Test.C("name"), {"1":"2"}, communicator.stringToProxy("test"))
+
+ #
+ # Compare default-constructed structures.
+ #
+ test(Test.S3() == Test.S3())
+
+ #
+ # Change one member at a time.
+ #
+ v1 = copy.copy(def_s3)
+ test(v1 == def_s3)
+
+ v1.obj = None
+ test(v1 != def_s3)
+
+ v1.obj = Test.C("name")
+ test(v1 != def_s3)
+
+ v1 = copy.copy(def_s3)
+ v1.sd = copy.copy(def_s3.sd)
+ test(v1 == def_s3)
+
+ v1.sd = None
+ test(v1 != def_s3)
+
+ v1.sd = {"1":"3"}
+ test(v1 != def_s3)
+
+ v1 = copy.copy(def_s3)
+ v1.prx = None
+ test(v1 != def_s3)
+
+ v1.prx = communicator.stringToProxy("test")
+ test(v1 == def_s3)
+
+ v1.prx = communicator.stringToProxy("test2")
+ test(v1 != def_s3)
+
+ print("ok")
+
+def run(args, communicator):
+ allTests(communicator)
+
+ 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)