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
|
// **********************************************************************
//
// Copyright (c) 2003-2017 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.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using Test;
#if SILVERLIGHT
using System.Windows.Controls;
#endif
public class AllTests : TestCommon.TestApp
{
//
// There does not appear to be any way to compare collections
// in either C# or with the .NET framework. Something like
// C++ STL EqualRange would be nice...
//
private static bool Compare(ICollection c1, ICollection c2)
{
if (c1 == null)
{
return c2 == null;
}
if (c2 == null)
{
return false;
}
if (!c1.GetType().Equals(c2.GetType()))
{
return false;
}
if (c1.Count != c2.Count)
{
return false;
}
IEnumerator i1 = c1.GetEnumerator();
IEnumerator i2 = c2.GetEnumerator();
while (i1.MoveNext())
{
i2.MoveNext();
if (i1.Current is ICollection)
{
Debug.Assert(i2.Current is ICollection);
if (!Compare((ICollection)i1.Current, (ICollection)i2.Current))
{
return false;
}
}
else if (!i1.Current.Equals(i2.Current))
{
return false;
}
}
return true;
}
#if SILVERLIGHT
public override Ice.InitializationData initData()
{
Ice.InitializationData initData = new Ice.InitializationData();
initData.properties = Ice.Util.createProperties();
initData.properties.setProperty("Ice.FactoryAssemblies", "serialize,version=1.0.0.0");
return initData;
}
override
public void run(Ice.Communicator communicator)
#else
static public int run(Ice.Communicator communicator)
#endif
{
Write("testing serialization... ");
Flush();
MyClassPrx proxy = MyClassPrxHelper.uncheckedCast(communicator.stringToProxy("test"));
MyException ex, ex2;
ex = new MyException();
ex.name = "";
ex.vss = new ValStruct[0];
ex.vsl = new List<ValStruct>();
ex.vsll = new LinkedList<ValStruct>();
ex.vssk = new Stack<ValStruct>();
ex.vsq = new Queue<ValStruct>();
ex.vsc = new ValStructCollection();
ex.isd = new Dictionary<int, string>();
ex.ivd = new Dictionary<int, ValStruct>();
ex.ipd = null;
ex.issd = new SortedDictionary<int, string>();
ex.isdc = new IntStringDC();
ex.optName = new Ice.Optional<string>();
ex.optInt = new Ice.Optional<int>();
ex.optValStruct = new Ice.Optional<ValStruct>();
ex.optRefStruct = new Ice.Optional<RefStruct>();
ex.optEnum = new Ice.Optional<MyEnum>();
ex.optProxy = new Ice.Optional<MyClassPrx>();
ex2 = inOut(ex);
test(ex.Equals(ex2));
ex.name = "MyException";
ex.b = 1;
ex.s = 2;
ex.i = 3;
ex.l = 4;
ex.vs = new ValStruct(true, 1, 2, 3, 4, MyEnum.enum2);
ex.rs = new RefStruct("RefStruct", "prop", null, null);
ex.vss = new ValStruct[1];
ex.vss[0] = ex.vs;
ex.vsl = new List<ValStruct>();
ex.vsl.Add(ex.vs);
ex.vsll = new LinkedList<ValStruct>();
ex.vsll.AddLast(ex.vs);
ex.vssk = new Stack<ValStruct>();
ex.vssk.Push(ex.vs);
ex.vsq = new Queue<ValStruct>();
ex.vsq.Enqueue(ex.vs);
ex.vsc = new ValStructCollection();
ex.vsc.Add(ex.vs);
ex.isd = new Dictionary<int, string>();
ex.isd[5] = "five";
ex.ivd = new Dictionary<int, ValStruct>();
ex.ivd[1] = ex.vs;
ex.ipd = new Dictionary<int, MyClassPrx>();
ex.issd = new SortedDictionary<int, string>();
ex.issd[3] = "three";
ex.isdc = new IntStringDC();
ex.isdc[4] = "four";
ex.optName = new Ice.Optional<string>("MyException");
ex.optInt = new Ice.Optional<int>(99);
ex.optValStruct = new Ice.Optional<ValStruct>(ex.vs);
ex.optRefStruct = new Ice.Optional<RefStruct>(ex.rs);
ex.optEnum = new Ice.Optional<MyEnum>(MyEnum.enum3);
ex.optProxy = new Ice.Optional<MyClassPrx>(proxy);
ex2 = inOut(ex);
test(!ex.Equals(ex2));
ex.ipd = null; // Not serialized
ex.optProxy = Ice.Util.None; // Not serialized
test(ex.optName.Equals(ex2.optName));
test(ex.optInt.Equals(ex2.optInt));
test(ex.optValStruct.Equals(ex2.optValStruct));
test(ex.optRefStruct.Equals(ex2.optRefStruct));
test(ex.optEnum.Equals(ex2.optEnum));
test(ex.optProxy.Equals(ex2.optProxy));
test(ex.Equals(ex2));
RefStruct rs, rs2;
rs = new RefStruct();
rs.s = "RefStruct";
rs.sp = "prop";
rs.p = MyClassPrxHelper.uncheckedCast(communicator.stringToProxy("test"));
rs.seq = new MyClassPrx[] { rs.p };
rs2 = inOut(rs);
test(rs2.s.Equals(rs.s));
test(rs2.sp.Equals(rs.sp));
test(rs2.p == null);
test(rs2.seq == null);
Base b, b2;
b = new Base(true, 1, 2, 3, 4, MyEnum.enum2);
b2 = inOut(b);
test(b2.bo == b.bo);
test(b2.by == b.by);
test(b2.sh == b.sh);
test(b2.i == b.i);
test(b2.l == b.l);
test(b2.e == b.e);
MyClass c, c2;
c = new MyClass(true, 1, 2, 3, 4, MyEnum.enum1, null, null, new ValStruct(true, 1, 2, 3, 4, MyEnum.enum2));
c.c = c;
c.o = c;
c2 = inOut(c);
test(c2.bo == c.bo);
test(c2.by == c.by);
test(c2.sh == c.sh);
test(c2.i == c.i);
test(c2.l == c.l);
test(c2.e == c.e);
test(c2.c == c2);
test(c2.o == c2);
test(c2.s.Equals(c.s));
WriteLine("ok");
#if !SILVERLIGHT
return 0;
#endif
}
private static T inOut<T>(T o)
{
BinaryFormatter bin = new BinaryFormatter();
using (MemoryStream mem = new MemoryStream())
{
bin.Serialize(mem, o);
mem.Seek(0, 0);
return (T)bin.Deserialize(mem);
}
}
}
|