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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
// **********************************************************************
//
// Copyright (c) 2003-2016 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.
//
// **********************************************************************
using System;
using System.Diagnostics;
using Test;
#if SILVERLIGHT
using System.Windows.Controls;
#endif
public class AllTests : TestCommon.TestApp
{
public static Ice.Object MyValueFactory(string type)
{
if (type.Equals("::Test::B"))
{
return new BI();
}
else if (type.Equals("::Test::C"))
{
return new CI();
}
else if (type.Equals("::Test::D"))
{
return new DI();
}
else if (type.Equals("::Test::E"))
{
return new EI();
}
else if (type.Equals("::Test::F"))
{
return new FI();
}
else if (type.Equals("::Test::I"))
{
return new II();
}
else if (type.Equals("::Test::J"))
{
return new JI();
}
else if (type.Equals("::Test::H"))
{
return new HI();
}
Debug.Assert(false); // Should never be reached
return null;
}
private class MyObjectFactory : Ice.ObjectFactory
{
public MyObjectFactory()
{
_destroyed = false;
}
~MyObjectFactory()
{
Debug.Assert(_destroyed);
}
public Ice.Object create(string type)
{
return null;
}
public void
destroy()
{
_destroyed = true;
}
private bool _destroyed;
}
#if SILVERLIGHT
public override Ice.InitializationData initData()
{
Ice.InitializationData initData = new Ice.InitializationData();
initData.properties = Ice.Util.createProperties();
initData.properties.setProperty("Ice.FactoryAssemblies", "objects,version=1.0.0.0");
return initData;
}
override
public void run(Ice.Communicator communicator)
#else
public static InitialPrx allTests(Ice.Communicator communicator)
#endif
{
communicator.getValueFactoryManager().add(MyValueFactory, "::Test::B");
communicator.getValueFactoryManager().add(MyValueFactory, "::Test::C");
communicator.getValueFactoryManager().add(MyValueFactory, "::Test::D");
communicator.getValueFactoryManager().add(MyValueFactory, "::Test::E");
communicator.getValueFactoryManager().add(MyValueFactory, "::Test::F");
communicator.getValueFactoryManager().add(MyValueFactory, "::Test::I");
communicator.getValueFactoryManager().add(MyValueFactory, "::Test::J");
communicator.getValueFactoryManager().add(MyValueFactory, "::Test::H");
// Disable Obsolete warning/error
#pragma warning disable 612, 618
communicator.addObjectFactory(new MyObjectFactory(), "TestOF");
#pragma warning restore 612, 618
Write("testing stringToProxy... ");
Flush();
String @ref = "initial:default -p 12010";
Ice.ObjectPrx @base = communicator.stringToProxy(@ref);
test(@base != null);
WriteLine("ok");
Write("testing checked cast... ");
Flush();
InitialPrx initial = InitialPrxHelper.checkedCast(@base);
test(initial != null);
test(initial.Equals(@base));
WriteLine("ok");
Write("getting B1... ");
Flush();
B b1 = initial.getB1();
test(b1 != null);
WriteLine("ok");
Write("getting B2... ");
Flush();
B b2 = initial.getB2();
test(b2 != null);
WriteLine("ok");
Write("getting C... ");
Flush();
C c = initial.getC();
test(c != null);
WriteLine("ok");
Write("getting D... ");
Flush();
D d = initial.getD();
test(d != null);
WriteLine("ok");
Write("checking consistency... ");
Flush();
test(b1 != b2);
//test(b1 != c);
//test(b1 != d);
//test(b2 != c);
//test(b2 != d);
//test(c != d);
test(b1.theB == b1);
test(b1.theC == null);
test(b1.theA is B);
test(((B) b1.theA).theA == b1.theA);
test(((B) b1.theA).theB == b1);
//test(((B)b1.theA).theC is C); // Redundant -- theC is always of type C
test(((C) (((B) b1.theA).theC)).theB == b1.theA);
test(b1.preMarshalInvoked);
test(b1.postUnmarshalInvoked());
test(b1.theA.preMarshalInvoked);
test(b1.theA.postUnmarshalInvoked());
test(((B)b1.theA).theC.preMarshalInvoked);
test(((B)b1.theA).theC.postUnmarshalInvoked());
// More tests possible for b2 and d, but I think this is already
// sufficient.
test(b2.theA == b2);
test(d.theC == null);
WriteLine("ok");
Write("getting B1, B2, C, and D all at once... ");
Flush();
B b1out;
B b2out;
C cout;
D dout;
initial.getAll(out b1out, out b2out, out cout, out dout);
test(b1out != null);
test(b2out != null);
test(cout != null);
test(dout != null);
WriteLine("ok");
Write("checking consistency... ");
Flush();
test(b1out != b2out);
test(b1out.theA == b2out);
test(b1out.theB == b1out);
test(b1out.theC == null);
test(b2out.theA == b2out);
test(b2out.theB == b1out);
test(b2out.theC == cout);
test(cout.theB == b2out);
test(dout.theA == b1out);
test(dout.theB == b2out);
test(dout.theC == null);
test(dout.preMarshalInvoked);
test(dout.postUnmarshalInvoked());
test(dout.theA.preMarshalInvoked);
test(dout.theA.postUnmarshalInvoked());
test(dout.theB.preMarshalInvoked);
test(dout.theB.postUnmarshalInvoked());
test(dout.theB.theC.preMarshalInvoked);
test(dout.theB.theC.postUnmarshalInvoked());
WriteLine("ok");
Write("testing protected members... ");
Flush();
E e = initial.getE();
test(e.checkValues());
System.Reflection.BindingFlags flags = System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Public |
System.Reflection.BindingFlags.Instance;
test(!typeof(E).GetField("i", flags).IsPublic && !typeof(E).GetField("i", flags).IsPrivate);
test(!typeof(E).GetField("s", flags).IsPublic && !typeof(E).GetField("s", flags).IsPrivate);
F f = initial.getF();
test(f.checkValues());
test(f.e2.checkValues());
test(!typeof(F).GetField("e1", flags).IsPublic && !typeof(F).GetField("e1", flags).IsPrivate);
test(typeof(F).GetField("e2", flags).IsPublic && !typeof(F).GetField("e2", flags).IsPrivate);
WriteLine("ok");
Write("getting I, J and H... ");
Flush();
I i = initial.getI();
test(i != null);
I j = initial.getJ();
test(j != null && ((J)j) != null);
I h = initial.getH();
test(h != null && ((H)h) != null);
WriteLine("ok");
Write("getting D1... ");
Flush();
D1 d1 = new D1(new A1("a1"), new A1("a2"), new A1("a3"), new A1("a4"));
d1 = initial.getD1(d1);
test(d1.a1.name.Equals("a1"));
test(d1.a2.name.Equals("a2"));
test(d1.a3.name.Equals("a3"));
test(d1.a4.name.Equals("a4"));
WriteLine("ok");
Write("throw EDerived... ");
Flush();
try
{
initial.throwEDerived();
test(false);
}
catch(EDerived ederived)
{
test(ederived.a1.name.Equals("a1"));
test(ederived.a2.name.Equals("a2"));
test(ederived.a3.name.Equals("a3"));
test(ederived.a4.name.Equals("a4"));
}
WriteLine("ok");
Write("setting I... ");
Flush();
initial.setI(i);
initial.setI(j);
initial.setI(h);
WriteLine("ok");
Write("testing sequences...");
Flush();
try
{
Base[] inS = new Base[0];
Base[] outS;
Base[] retS;
retS = initial.opBaseSeq(inS, out outS);
inS = new Base[1];
inS[0] = new Base(new S(), "");
retS = initial.opBaseSeq(inS, out outS);
test(retS.Length == 1 && outS.Length == 1);
}
catch(Ice.OperationNotExistException)
{
}
WriteLine("ok");
Write("testing compact ID...");
Flush();
try
{
test(initial.getCompact() != null);
}
catch(Ice.OperationNotExistException)
{
}
WriteLine("ok");
Write("testing UnexpectedObjectException...");
Flush();
@ref = "uoet:default -p 12010";
@base = communicator.stringToProxy(@ref);
test(@base != null);
UnexpectedObjectExceptionTestPrx uoet = UnexpectedObjectExceptionTestPrxHelper.uncheckedCast(@base);
test(uoet != null);
try
{
uoet.op();
test(false);
}
catch(Ice.UnexpectedObjectException ex)
{
test(ex.type.Equals("::Test::AlsoEmpty"));
test(ex.expectedType.Equals("::Test::Empty"));
}
catch(System.Exception ex)
{
WriteLine(ex.ToString());
test(false);
}
WriteLine("ok");
// Disable Obsolete warning/error
#pragma warning disable 612, 618
Write("testing getting ObjectFactory...");
Flush();
test(communicator.findObjectFactory("TestOF") != null);
WriteLine("ok");
Write("testing getting ObjectFactory as ValueFactory...");
Flush();
test(communicator.getValueFactoryManager().find("TestOF") != null);
WriteLine("ok");
#pragma warning restore 612, 618
#if SILVERLIGHT
initial.shutdown();
#else
return initial;
#endif
}
}
|