1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
#!/usr/bin/env python
# **********************************************************************
#
# Copyright (c) 2003-2018 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.
#
# **********************************************************************
from TestHelper import TestHelper
TestHelper.loadSlice('Test.ice')
import sys
import copy
import Test
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")
class Client(TestHelper):
def run(self, args):
with self.initialize(args=args) as communicator:
allTests(communicator)
|