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 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573
|
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
using System;
using System.Diagnostics;
using System.Collections.Generic;
namespace Ice
{
namespace objects
{
namespace Test
{
public partial class IBase
{
partial void ice_initialize()
{
id = "My id";
}
}
public partial class IDerived
{
partial void ice_initialize()
{
name = "My name";
}
}
public partial class I2
{
public bool called
{
get;
set;
}
partial void ice_initialize()
{
called = true;
}
}
public partial struct S1
{
partial void ice_initialize()
{
id = 1;
}
}
public partial class SC1
{
partial void ice_initialize()
{
id = "My id";
}
}
public class AllTests : global::Test.AllTests
{
public static Ice.Value 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.Value create(string type)
{
return null;
}
public void
destroy()
{
_destroyed = true;
}
private bool _destroyed;
}
public static Test.InitialPrx allTests(global::Test.TestHelper helper)
{
Ice.Communicator communicator = helper.communicator();
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
var output = helper.getWriter();
output.Write("testing stringToProxy... ");
output.Flush();
String @ref = "initial:" + helper.getTestEndpoint(0);
Ice.ObjectPrx @base = communicator.stringToProxy(@ref);
test(@base != null);
output.WriteLine("ok");
output.Write("testing checked cast... ");
output.Flush();
var initial = Test.InitialPrxHelper.checkedCast(@base);
test(initial != null);
test(initial.Equals(@base));
output.WriteLine("ok");
output.Write("getting B1... ");
output.Flush();
B b1 = initial.getB1();
test(b1 != null);
output.WriteLine("ok");
output.Write("getting B2... ");
output.Flush();
B b2 = initial.getB2();
test(b2 != null);
output.WriteLine("ok");
output.Write("getting C... ");
output.Flush();
C c = initial.getC();
test(c != null);
output.WriteLine("ok");
output.Write("getting D... ");
output.Flush();
D d = initial.getD();
test(d != null);
output.WriteLine("ok");
output.Write("checking consistency... ");
output.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);
output.WriteLine("ok");
output.Write("getting B1, B2, C, and D all at once... ");
output.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);
output.WriteLine("ok");
output.Write("checking consistency... ");
output.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);
output.WriteLine("ok");
output.Write("testing protected members... ");
output.Flush();
EI e =(EI)initial.getE();
test(e != null && 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);
FI f =(FI)initial.getF();
test(f.checkValues());
test(((EI)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);
output.WriteLine("ok");
output.Write("getting I, J and H... ");
output.Flush();
var i = initial.getI();
test(i != null);
var j = initial.getJ();
test(j != null);
var h = initial.getH();
test(h != null);
output.WriteLine("ok");
output.Write("getting K... ");
{
output.Flush();
var k = initial.getK();
var l = k.value as L;
test(l != null);
test(l.data.Equals("l"));
}
output.WriteLine("ok");
output.Write("testing Value as parameter... ");
output.Flush();
{
Ice.Value v1 = new L("l");
Ice.Value v2;
Ice.Value v3 = initial.opValue(v1, out v2);
test(((L)v2).data.Equals("l"));
test(((L)v3).data.Equals("l"));
}
{
L l = new L("l");
Ice.Value[] v1 = new Ice.Value[]{ l };
Ice.Value[] v2;
Ice.Value[] v3 = initial.opValueSeq(v1, out v2);
test(((L)v2[0]).data.Equals("l"));
test(((L)v3[0]).data.Equals("l"));
}
{
L l = new L("l");
Dictionary<string, Ice.Value> v1 = new Dictionary<string, Ice.Value>{ {"l", l} };
Dictionary<string, Ice.Value> v2;
Dictionary<string, Ice.Value> v3 = initial.opValueMap(v1, out v2);
test(((L)v2["l"]).data.Equals("l"));
test(((L)v3["l"]).data.Equals("l"));
}
output.WriteLine("ok");
output.Write("getting D1... ");
output.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"));
output.WriteLine("ok");
output.Write("throw EDerived... ");
output.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"));
}
output.WriteLine("ok");
output.Write("setting G... ");
output.Flush();
try
{
initial.setG(new G(new S("hello"), "g"));
}
catch(Ice.OperationNotExistException)
{
}
output.WriteLine("ok");
output.Write("setting I... ");
output.Flush();
initial.setI(i);
initial.setI(j);
initial.setI(h);
output.WriteLine("ok");
output.Write("testing sequences...");
output.Flush();
try
{
Base[] inS = new Test.Base[0];
Base[] outS;
Base[] retS;
retS = initial.opBaseSeq(inS, out outS);
inS = new Test.Base[1];
inS[0] = new Test.Base(new S(), "");
retS = initial.opBaseSeq(inS, out outS);
test(retS.Length == 1 && outS.Length == 1);
}
catch(Ice.OperationNotExistException)
{
}
output.WriteLine("ok");
output.Write("testing recursive type... ");
output.Flush();
var top = new Test.Recursive();
var p = top;
int depth = 0;
try
{
for(; depth <= 1000; ++depth)
{
p.v = new Test.Recursive();
p = p.v;
if((depth < 10 &&(depth % 10) == 0) ||
(depth < 1000 &&(depth % 100) == 0) ||
(depth < 10000 &&(depth % 1000) == 0) ||
(depth % 10000) == 0)
{
initial.setRecursive(top);
}
}
test(!initial.supportsClassGraphDepthMax());
}
catch(Ice.UnknownLocalException)
{
// Expected marshal exception from the server(max class graph depth reached)
}
catch(Ice.UnknownException)
{
// Expected stack overflow from the server(Java only)
}
initial.setRecursive(new Test.Recursive());
output.WriteLine("ok");
output.Write("testing compact ID...");
output.Flush();
try
{
test(initial.getCompact() != null);
}
catch(Ice.OperationNotExistException)
{
}
output.WriteLine("ok");
output.Write("testing marshaled results...");
output.Flush();
b1 = initial.getMB();
test(b1 != null && b1.theB == b1);
b1 = initial.getAMDMBAsync().Result;
test(b1 != null && b1.theB == b1);
output.WriteLine("ok");
output.Write("testing UnexpectedObjectException...");
output.Flush();
@ref = "uoet:" + helper.getTestEndpoint(0);
@base = communicator.stringToProxy(@ref);
test(@base != null);
var uoet = Test.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)
{
output.WriteLine(ex.ToString());
test(false);
}
output.WriteLine("ok");
// Disable Obsolete warning/error
#pragma warning disable 612, 618
output.Write("testing getting ObjectFactory...");
output.Flush();
test(communicator.findObjectFactory("TestOF") != null);
output.WriteLine("ok");
output.Write("testing getting ObjectFactory as ValueFactory...");
output.Flush();
test(communicator.getValueFactoryManager().find("TestOF") != null);
output.WriteLine("ok");
#pragma warning restore 612, 618
output.Write("testing partial ice_initialize...");
output.Flush();
var ib1 = new IBase();
test(ib1.id.Equals("My id"));
var id1 = new IDerived();
test(id1.id.Equals("My id"));
test(id1.name.Equals("My name"));
var id2 = new Test.IDerived2();
test(id2.id.Equals("My id"));
var i2 = new I2();
test(i2.called);
var s1 = new S1();
// The struct default constructor do not call ice_initialize
test(s1.id == 0);
s1 = new S1(2);
// The id should have the value set by ice_initialize and not 2
test(s1.id == 1);
var sc1 = new SC1();
test(sc1.id.Equals("My id"));
output.WriteLine("ok");
output.Write("testing class containing complex dictionary... ");
output.Flush();
{
var m = new Test.M();
m.v = new Dictionary<StructKey, L>();
var k1 = new StructKey(1, "1");
m.v[k1] = new L("one");
var k2 = new StructKey(2, "2");
m.v[k2] = new L("two");
Test.M m1;
var m2 = initial.opM(m, out m1);
test(m1.v.Count == 2);
test(m2.v.Count == 2);
test(m1.v[k1].data.Equals("one"));
test(m2.v[k1].data.Equals("one"));
test(m1.v[k2].data.Equals("two"));
test(m2.v[k2].data.Equals("two"));
}
output.WriteLine("ok");
output.Write("testing forward declared types... ");
output.Flush();
{
F1 f12;
F1 f11 = initial.opF1(new F1("F11"), out f12);
test(f11.name.Equals("F11"));
test(f12.name.Equals("F12"));
F2Prx f22;
F2Prx f21 = initial.opF2(
F2PrxHelper.uncheckedCast(communicator.stringToProxy("F21:" + helper.getTestEndpoint())),
out f22);
test(f21.ice_getIdentity().name.Equals("F21"));
f21.op();
test(f22.ice_getIdentity().name.Equals("F22"));
if(initial.hasF3())
{
F3 f32;
F3 f31 = initial.opF3(new F3(new F1("F11"),
F2PrxHelper.uncheckedCast(communicator.stringToProxy("F21"))),
out f32);
test(f31.f1.name.Equals("F11"));
test(f31.f2.ice_getIdentity().name.Equals("F21"));
test(f32.f1.name.Equals("F12"));
test(f32.f2.ice_getIdentity().name.Equals("F22"));
}
}
output.WriteLine("ok");
output.Write("testing sending class cycle... ");
output.Flush();
{
var rec = new Test.Recursive();
rec.v = rec;
var acceptsCycles = initial.acceptsClassCycles();
try
{
initial.setCycle(rec);
test(acceptsCycles);
}
catch(Ice.UnknownLocalException)
{
test(!acceptsCycles);
}
}
output.WriteLine("ok");
output.Write("testing class with interface by value member... ");
output.Flush();
{
var n = new Test.N(i);
n = initial.opN(n);
}
output.WriteLine("ok");
return initial;
}
}
}
}
}
|