~ubuntu-branches/ubuntu/quantal/zeroc-ice/quantal

« back to all changes in this revision

Viewing changes to py/test/Slice/structure/Client.py

  • Committer: Bazaar Package Importer
  • Author(s): Cleto Martin Angelina
  • Date: 2011-04-25 18:44:24 UTC
  • mfrom: (6.1.14 sid)
  • Revision ID: james.westby@ubuntu.com-20110425184424-sep9i9euu434vq4c
Tags: 3.4.1-7
* Bug fix: "libdb5.1-java.jar was renamed to db.jar", thanks to Ondřej
  Surý (Closes: #623555).
* Bug fix: "causes noise in php5", thanks to Jayen Ashar (Closes:
  #623533).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# **********************************************************************
 
3
#
 
4
# Copyright (c) 2003-2010 ZeroC, Inc. All rights reserved.
 
5
#
 
6
# This copy of Ice is licensed to you under the terms described in the
 
7
# ICE_LICENSE file included in this distribution.
 
8
#
 
9
# **********************************************************************
 
10
 
 
11
import os, sys, traceback
 
12
 
 
13
for toplevel in [".", "..", "../..", "../../..", "../../../.."]:
 
14
    toplevel = os.path.normpath(toplevel)
 
15
    if os.path.exists(os.path.join(toplevel, "python", "Ice.py")):
 
16
        break
 
17
else:
 
18
    raise "can't find toplevel directory!"
 
19
 
 
20
import Ice
 
21
 
 
22
Ice.loadSlice('Test.ice')
 
23
import Test, copy
 
24
 
 
25
def test(b):
 
26
    if not b:
 
27
        raise RuntimeError('test assertion failed')
 
28
 
 
29
def allTests(communicator):
 
30
    print("testing equals() for Slice structures..."),
 
31
 
 
32
    #
 
33
    # Define some default values.
 
34
    #
 
35
    def_s2 = Test.S2(True, 98, 99, 100, 101, 1.0, 2.0, "string", ("one", "two", "three"), {"abc":"def"}, \
 
36
                     Test.S1("name"), Test.C(5), communicator.stringToProxy("test"))
 
37
 
 
38
    #
 
39
    # Compare default-constructed structures.
 
40
    #
 
41
    test(Test.S2() == Test.S2())
 
42
 
 
43
    #
 
44
    # Change one primitive member at a time.
 
45
    #
 
46
    v = copy.copy(def_s2)
 
47
    test(v == def_s2)
 
48
 
 
49
    v = copy.copy(def_s2)
 
50
    v.bo = False
 
51
    test(v != def_s2)
 
52
 
 
53
    v = copy.copy(def_s2)
 
54
    v.by = v.by - 1
 
55
    test(v != def_s2)
 
56
 
 
57
    v = copy.copy(def_s2)
 
58
    v.sh = v.sh - 1
 
59
    test(v != def_s2)
 
60
 
 
61
    v = copy.copy(def_s2)
 
62
    v.i = v.i - 1
 
63
    test(v != def_s2)
 
64
 
 
65
    v = copy.copy(def_s2)
 
66
    v.l = v.l - 1
 
67
    test(v != def_s2)
 
68
 
 
69
    v = copy.copy(def_s2)
 
70
    v.f = v.f - 1
 
71
    test(v != def_s2)
 
72
 
 
73
    v = copy.copy(def_s2)
 
74
    v.d = v.d - 1
 
75
    test(v != def_s2)
 
76
 
 
77
    v = copy.copy(def_s2)
 
78
    v.str = ""
 
79
    test(v != def_s2)
 
80
 
 
81
    #
 
82
    # String member
 
83
    #
 
84
    v1 = copy.copy(def_s2)
 
85
    v1.str = "string"
 
86
    test(v1 == def_s2)
 
87
 
 
88
    v1 = copy.copy(def_s2)
 
89
    v2 = copy.copy(def_s2)
 
90
    v1.str = None
 
91
    test(v1 != v2)
 
92
 
 
93
    v1 = copy.copy(def_s2)
 
94
    v2 = copy.copy(def_s2)
 
95
    v2.str = None
 
96
    test(v1 != v2)
 
97
 
 
98
    v1 = copy.copy(def_s2)
 
99
    v2 = copy.copy(def_s2)
 
100
    v1.str = None
 
101
    v2.str = None
 
102
    test(v1 == v2)
 
103
 
 
104
    #
 
105
    # Sequence member
 
106
    #
 
107
    v1 = copy.copy(def_s2)
 
108
    v1.ss = copy.copy(def_s2.ss)
 
109
    test(v1 == def_s2)
 
110
 
 
111
    v1 = copy.copy(def_s2)
 
112
    v1.ss = []
 
113
    test(v1 != def_s2)
 
114
 
 
115
    v1 = copy.copy(def_s2)
 
116
    v1.ss = ("one", "two", "three")
 
117
    test(v1 == def_s2)
 
118
 
 
119
    v1 = copy.copy(def_s2)
 
120
    v2 = copy.copy(def_s2)
 
121
    v1.ss = None
 
122
    test(v1 != v2)
 
123
 
 
124
    v1 = copy.copy(def_s2)
 
125
    v2 = copy.copy(def_s2)
 
126
    v2.ss = None
 
127
    test(v1 != v2)
 
128
 
 
129
    #
 
130
    # Dictionary member
 
131
    #
 
132
    v1 = copy.copy(def_s2)
 
133
    v1.sd = {"abc":"def"}
 
134
    test(v1 == def_s2)
 
135
 
 
136
    v1 = copy.copy(def_s2)
 
137
    v1.sd = {}
 
138
    test(v1 != def_s2)
 
139
 
 
140
    v1 = copy.copy(def_s2)
 
141
    v2 = copy.copy(def_s2)
 
142
    v1.sd = None
 
143
    test(v1 != v2)
 
144
 
 
145
    v1 = copy.copy(def_s2)
 
146
    v2 = copy.copy(def_s2)
 
147
    v2.sd = None
 
148
    test(v1 != v2)
 
149
 
 
150
    #
 
151
    # Struct member
 
152
    #
 
153
    v1 = copy.copy(def_s2)
 
154
    v1.s = copy.copy(def_s2.s)
 
155
    test(v1 == def_s2)
 
156
 
 
157
    v1 = copy.copy(def_s2)
 
158
    v1.s = Test.S1("name")
 
159
    test(v1 == def_s2)
 
160
 
 
161
    v1 = copy.copy(def_s2)
 
162
    v1.s = Test.S1("noname")
 
163
    test(v1 != def_s2)
 
164
 
 
165
    v1 = copy.copy(def_s2)
 
166
    v2 = copy.copy(def_s2)
 
167
    v1.s = None
 
168
    test(v1 != v2)
 
169
 
 
170
    v1 = copy.copy(def_s2)
 
171
    v2 = copy.copy(def_s2)
 
172
    v2.s = None
 
173
    test(v1 != v2)
 
174
 
 
175
    #
 
176
    # Class member
 
177
    #
 
178
    v1 = copy.copy(def_s2)
 
179
    v1.cls = copy.copy(def_s2.cls)
 
180
    test(v1 != def_s2)
 
181
 
 
182
    v1 = copy.copy(def_s2)
 
183
    v2 = copy.copy(def_s2)
 
184
    v1.cls = None
 
185
    test(v1 != v2)
 
186
 
 
187
    v1 = copy.copy(def_s2)
 
188
    v2 = copy.copy(def_s2)
 
189
    v2.cls = None
 
190
    test(v1 != v2)
 
191
 
 
192
    #
 
193
    # Proxy member
 
194
    #
 
195
    v1 = copy.copy(def_s2)
 
196
    v1.prx = communicator.stringToProxy("test")
 
197
    test(v1 == def_s2)
 
198
 
 
199
    v1 = copy.copy(def_s2)
 
200
    v1.prx = communicator.stringToProxy("test2")
 
201
    test(v1 != def_s2)
 
202
 
 
203
    v1 = copy.copy(def_s2)
 
204
    v2 = copy.copy(def_s2)
 
205
    v1.prx = None
 
206
    test(v1 != v2)
 
207
 
 
208
    v1 = copy.copy(def_s2)
 
209
    v2 = copy.copy(def_s2)
 
210
    v2.prx = None
 
211
    test(v1 != v2)
 
212
 
 
213
    print "ok"
 
214
 
 
215
def run(args, communicator):
 
216
    allTests(communicator)
 
217
 
 
218
    return True
 
219
 
 
220
try:
 
221
    initData = Ice.InitializationData()
 
222
    initData.properties = Ice.createProperties(sys.argv)
 
223
    communicator = Ice.initialize(sys.argv, initData)
 
224
    status = run(sys.argv, communicator)
 
225
except:
 
226
    traceback.print_exc()
 
227
    status = False
 
228
 
 
229
if communicator:
 
230
    try:
 
231
        communicator.destroy()
 
232
    except:
 
233
        traceback.print_exc()
 
234
        status = False
 
235
 
 
236
sys.exit(not status)