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
|
// **********************************************************************
//
// 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.
//
// **********************************************************************
using System;
using System.Collections.Generic;
using Test;
#if SILVERLIGHT
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
#endif
public class AllTests : TestCommon.TestApp
{
#if SILVERLIGHT
override
public void run(Ice.Communicator communicator)
#else
public static GPrx allTests(Ice.Communicator communicator)
#endif
{
Write("testing Ice.Admin.Facets property... ");
test(communicator.getProperties().getPropertyAsList("Ice.Admin.Facets").Length == 0);
communicator.getProperties().setProperty("Ice.Admin.Facets", "foobar");
String[] facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets");
test(facetFilter.Length == 1 && facetFilter[0].Equals("foobar"));
communicator.getProperties().setProperty("Ice.Admin.Facets", "foo\\'bar");
facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets");
test(facetFilter.Length == 1 && facetFilter[0].Equals("foo'bar"));
communicator.getProperties().setProperty("Ice.Admin.Facets", "'foo bar' toto 'titi'");
facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets");
test(facetFilter.Length == 3 && facetFilter[0].Equals("foo bar") && facetFilter[1].Equals("toto")
&& facetFilter[2].Equals("titi"));
communicator.getProperties().setProperty("Ice.Admin.Facets", "'foo bar\\' toto' 'titi'");
facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets");
test(facetFilter.Length == 2 && facetFilter[0].Equals("foo bar' toto") && facetFilter[1].Equals("titi"));
// communicator.getProperties().setProperty("Ice.Admin.Facets", "'foo bar' 'toto titi");
// facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets");
// test(facetFilter.Length == 0);
communicator.getProperties().setProperty("Ice.Admin.Facets", "");
WriteLine("ok");
#if !SILVERLIGHT
Write("testing facet registration exceptions... ");
communicator.getProperties().setProperty("FacetExceptionTestAdapter.Endpoints", "default");
Ice.ObjectAdapter adapter = communicator.createObjectAdapter("FacetExceptionTestAdapter");
Ice.Object obj = new EmptyI();
adapter.add(obj, communicator.stringToIdentity("d"));
adapter.addFacet(obj, communicator.stringToIdentity("d"), "facetABCD");
try
{
adapter.addFacet(obj, communicator.stringToIdentity("d"), "facetABCD");
test(false);
}
catch(Ice.AlreadyRegisteredException)
{
}
adapter.removeFacet(communicator.stringToIdentity("d"), "facetABCD");
try
{
adapter.removeFacet(communicator.stringToIdentity("d"), "facetABCD");
test(false);
}
catch(Ice.NotRegisteredException)
{
}
WriteLine("ok");
Write("testing removeAllFacets... ");
Ice.Object obj1 = new EmptyI();
Ice.Object obj2 = new EmptyI();
adapter.addFacet(obj1, communicator.stringToIdentity("id1"), "f1");
adapter.addFacet(obj2, communicator.stringToIdentity("id1"), "f2");
Ice.Object obj3 = new EmptyI();
adapter.addFacet(obj1, communicator.stringToIdentity("id2"), "f1");
adapter.addFacet(obj2, communicator.stringToIdentity("id2"), "f2");
adapter.addFacet(obj3, communicator.stringToIdentity("id2"), "");
Dictionary<string, Ice.Object> fm
= adapter.removeAllFacets(communicator.stringToIdentity("id1"));
test(fm.Count == 2);
test(fm["f1"] == obj1);
test(fm["f2"] == obj2);
try
{
adapter.removeAllFacets(communicator.stringToIdentity("id1"));
test(false);
}
catch(Ice.NotRegisteredException)
{
}
fm = adapter.removeAllFacets(communicator.stringToIdentity("id2"));
test(fm.Count == 3);
test(fm["f1"] == obj1);
test(fm["f2"] == obj2);
test(fm[""] == obj3);
WriteLine("ok");
adapter.deactivate();
#endif
Write("testing stringToProxy... ");
Flush();
string @ref = "d:default -p 12010";
Ice.ObjectPrx db = communicator.stringToProxy(@ref);
test(db != null);
WriteLine("ok");
Write("testing unchecked cast... ");
Flush();
Ice.ObjectPrx prx = Ice.ObjectPrxHelper.uncheckedCast(db);
test(prx.ice_getFacet().Length == 0);
prx = Ice.ObjectPrxHelper.uncheckedCast(db, "facetABCD");
test(prx.ice_getFacet() == "facetABCD");
Ice.ObjectPrx prx2 = Ice.ObjectPrxHelper.uncheckedCast(prx);
test(prx2.ice_getFacet() == "facetABCD");
Ice.ObjectPrx prx3 = Ice.ObjectPrxHelper.uncheckedCast(prx, "");
test(prx3.ice_getFacet().Length == 0);
DPrx d = Test.DPrxHelper.uncheckedCast(db);
test(d.ice_getFacet().Length == 0);
DPrx df = Test.DPrxHelper.uncheckedCast(db, "facetABCD");
test(df.ice_getFacet() == "facetABCD");
DPrx df2 = Test.DPrxHelper.uncheckedCast(df);
test(df2.ice_getFacet() == "facetABCD");
DPrx df3 = Test.DPrxHelper.uncheckedCast(df, "");
test(df3.ice_getFacet().Length == 0);
WriteLine("ok");
Write("testing checked cast... ");
Flush();
prx = Ice.ObjectPrxHelper.checkedCast(db);
test(prx.ice_getFacet().Length == 0);
prx = Ice.ObjectPrxHelper.checkedCast(db, "facetABCD");
test(prx.ice_getFacet() == "facetABCD");
prx2 = Ice.ObjectPrxHelper.checkedCast(prx);
test(prx2.ice_getFacet() == "facetABCD");
prx3 = Ice.ObjectPrxHelper.checkedCast(prx, "");
test(prx3.ice_getFacet().Length == 0);
d = Test.DPrxHelper.checkedCast(db);
test(d.ice_getFacet().Length == 0);
df = Test.DPrxHelper.checkedCast(db, "facetABCD");
test(df.ice_getFacet() == "facetABCD");
df2 = Test.DPrxHelper.checkedCast(df);
test(df2.ice_getFacet() == "facetABCD");
df3 = Test.DPrxHelper.checkedCast(df, "");
test(df3.ice_getFacet().Length == 0);
WriteLine("ok");
Write("testing non-facets A, B, C, and D... ");
Flush();
d = DPrxHelper.checkedCast(db);
test(d != null);
test(d.Equals(db));
test(d.callA().Equals("A"));
test(d.callB().Equals("B"));
test(d.callC().Equals("C"));
test(d.callD().Equals("D"));
WriteLine("ok");
Write("testing facets A, B, C, and D... ");
Flush();
df = DPrxHelper.checkedCast(d, "facetABCD");
test(df != null);
test(df.callA().Equals("A"));
test(df.callB().Equals("B"));
test(df.callC().Equals("C"));
test(df.callD().Equals("D"));
WriteLine("ok");
Write("testing facets E and F... ");
Flush();
FPrx ff = FPrxHelper.checkedCast(d, "facetEF");
test(ff != null);
test(ff.callE().Equals("E"));
test(ff.callF().Equals("F"));
WriteLine("ok");
Write("testing facet G... ");
Flush();
GPrx gf = GPrxHelper.checkedCast(ff, "facetGH");
test(gf != null);
test(gf.callG().Equals("G"));
WriteLine("ok");
Write("testing whether casting preserves the facet... ");
Flush();
HPrx hf = HPrxHelper.checkedCast(gf);
test(hf != null);
test(hf.callG().Equals("G"));
test(hf.callH().Equals("H"));
WriteLine("ok");
#if SILVERLIGHT
gf.shutdown();
#else
return gf;
#endif
}
}
|