All files / test/Ice/slicing/objects Client.js

85.92% Statements 586/682
31.03% Branches 9/29
100% Functions 2/2
85.92% Lines 586/682

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 6831x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                   1x 1x 1x 1x             1x 1x 1x 1x       1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x             1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x             1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x         1x 1x 1x 1x 1x 1x 10x 10x 10x 10x 10x 10x 10x 1x 1x 1x 10x 10x 10x 10x 10x 10x 10x 10x 10x 1x 1x 10x 10x 10x 10x 10x 10x 10x 10x 10x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x       1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x       1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x       1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x       1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x           1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x           1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x           1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 300x 300x 300x 300x 300x 300x 1x 1x 1x 1x 1x 1x 1x 1x                           1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x             1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
// Copyright (c) ZeroC, Inc.
import { Ice } from "@zeroc/ice";
import { Test } from "./Test.js";
import { TestHelper, test } from "../../../Common/TestHelper.js";
export class Client extends TestHelper {
    async allTests() {
        const out = this.getWriter();
        const communicator = this.communicator();
        const prx = new Test.TestIntfPrx(communicator, `Test:${this.getTestEndpoint()} -t 10000`);
        out.write("base as Object... ");
        {
            const sb = (await prx.SBaseAsObject());
            test(sb !== null);
            test(sb.ice_id() == "::Test::SBase");
            test(sb.sb == "SBase.sb");
        }
        out.writeLine("ok");
        out.write("base as base... ");
        {
            const sb = await prx.SBaseAsSBase();
            test(sb !== null);
            test(sb.sb == "SBase.sb");
        }
        out.writeLine("ok");
        out.write("base with known derived as base... ");
        {
            const sb = (await prx.SBSKnownDerivedAsSBase());
            test(sb !== null);
            test(sb.sb == "SBSKnownDerived.sb");
            test(sb.sbskd == "SBSKnownDerived.sbskd");
        }
        out.writeLine("ok");
        out.write("base with known derived as known derived... ");
        {
            const sb = await prx.SBSKnownDerivedAsSBSKnownDerived();
            test(sb !== null);
            test(sb.sbskd == "SBSKnownDerived.sbskd");
        }
        out.writeLine("ok");
        out.write("base with unknown derived as base... ");
        {
            const sb = await prx.SBSUnknownDerivedAsSBase();
            test(sb !== null);
            test(sb.sb == "SBSUnknownDerived.sb");
        }
        if (prx.ice_getEncodingVersion().equals(Ice.Encoding_1_0)) {
            const sb = await prx.SBSUnknownDerivedAsSBaseCompact();
            test(sb !== null);
            test(sb.sb == "SBSUnknownDerived.sb");
        }
        else {
            try {
                await prx.SBSUnknownDerivedAsSBaseCompact();
                test(false);
            }
            catch (ex) {
                test(ex instanceof Ice.MarshalException, ex);
            }
        }
        out.writeLine("ok");
        out.write("unknown with Object as Object... ");
        try {
            const obj = await prx.SUnknownAsObject();
            test(!prx.ice_getEncodingVersion().equals(Ice.Encoding_1_0));
            test(obj instanceof Ice.UnknownSlicedValue);
            test(obj.ice_id() == "::Test::SUnknown");
            test(obj.ice_getSlicedData() !== null);
            await prx.checkSUnknown(obj);
        }
        catch (ex) {
            if (ex instanceof Ice.MarshalException) {
                test(prx.ice_getEncodingVersion().equals(Ice.Encoding_1_0));
            }
            else {
                test(false, ex);
            }
        }
        out.writeLine("ok");
        out.write("one-element cycle... ");
        {
            const b = await prx.oneElementCycle();
            test(b !== null);
            test(b.ice_id() == "::Test::B");
            test(b.sb == "B1.sb");
            test(b.pb === b);
        }
        out.writeLine("ok");
        out.write("two-element cycle... ");
        {
            const b1 = await prx.twoElementCycle();
            test(b1 !== null);
            test(b1.ice_id() == "::Test::B");
            test(b1.sb == "B1.sb");
            const b2 = b1.pb;
            test(b2 !== null);
            test(b2.ice_id() == "::Test::B");
            test(b2.sb == "B2.sb");
            test(b2.pb == b1);
        }
        out.writeLine("ok");
        out.write("known derived pointer slicing as derived... ");
        {
            const d1 = await prx.D1AsD1();
            test(d1 !== null);
            test(d1.ice_id() == "::Test::D1");
            test(d1.sb == "D1.sb");
            test(d1.pb !== null);
            test(d1.pb !== d1);
            const b2 = d1.pb;
            test(b2 !== null);
            test(b2.ice_id() == "::Test::B");
            test(b2.sb == "D2.sb");
            test(b2.pb === d1);
        }
        out.writeLine("ok");
        out.write("unknown derived pointer slicing as base... ");
        {
            const b2 = (await prx.D2AsB());
            test(b2 !== null);
            test(b2.ice_id() == "::Test::B");
            test(b2.sb == "D2.sb");
            test(b2.pb !== null);
            test(b2.pb !== b2);
            const b1 = b2.pb;
            test(b1 !== null);
            test(b1.ice_id() == "::Test::D1");
            test(b1.sb == "D1.sb");
            test(b1.pb == b2);
            const d1 = b1;
            test(d1.sd1 == "D1.sd1");
            test(d1.pd1 === b2);
        }
        out.writeLine("ok");
        out.write("param ptr slicing with known first... ");
        {
            const [b1, b2] = (await prx.paramTest1());
            test(b1 !== null);
            test(b1.ice_id() == "::Test::D1");
            test(b1.sb == "D1.sb");
            test(b1.pb == b2);
            const d1 = b1;
            test(d1 !== null);
            test(d1.sd1 == "D1.sd1");
            test(d1.pd1 === b2);
            test(b2 !== null);
            test(b2.ice_id() == "::Test::B"); // No factory, must be sliced
            test(b2.sb == "D2.sb");
            test(b2.pb === b1);
        }
        out.writeLine("ok");
        out.write("param ptr slicing with unknown first... ");
        {
            const [b2, b1] = (await prx.paramTest2());
            test(b1 !== null);
            test(b1.ice_id() == "::Test::D1");
            test(b1.sb == "D1.sb");
            test(b1.pb === b2);
            test(b1 !== null);
            const d1 = b1;
            test(d1.sd1 == "D1.sd1");
            test(d1.pd1 == b2);
            test(b2 !== null);
            test(b2.ice_id() == "::Test::B"); // No factory, must be sliced
            test(b2.sb == "D2.sb");
            test(b2.pb == b1);
        }
        out.writeLine("ok");
        out.write("return value identity with known first... ");
        {
            const [ret, p1] = await prx.returnTest1();
            test(ret === p1);
        }
        out.writeLine("ok");
        out.write("return value identity with unknown first... ");
        {
            const [ret, p1] = await prx.returnTest2();
            test(ret == p1);
        }
        out.writeLine("ok");
        out.write("return value identity for input params known first... ");
        {
            const d1 = new Test.D1();
            d1.sb = "D1.sb";
            d1.sd1 = "D1.sd1";
            const d3 = new Test.D3();
            d3.pb = d1;
            d3.sb = "D3.sb";
            d3.sd3 = "D3.sd3";
            d3.pd3 = d1;
            d1.pb = d3;
            d1.pd1 = d3;
            const b1 = await prx.returnTest3(d1, d3);
            test(b1 !== null);
            test(b1.sb == "D1.sb");
            test(b1.ice_id() == "::Test::D1");
            const p1 = b1;
            test(p1 !== null);
            test(p1.sd1 == "D1.sd1");
            test(p1.pd1 == b1.pb);
            const b2 = b1.pb;
            test(b2 !== null);
            test(b2.sb == "D3.sb");
            test(b2.pb == b1);
            if (prx.ice_getEncodingVersion().equals(Ice.Encoding_1_0)) {
                test(!(b2 instanceof Test.D3));
            }
            else {
                const d3 = b2;
                test(d3 !== null);
                test(d3.pd3 === p1);
                test(d3.sd3 == "D3.sd3");
            }
            test(b1 !== d1);
            test(b1 !== d3);
            test(b2 !== d1);
            test(b2 !== d3);
        }
        out.writeLine("ok");
        out.write("return value identity for input params unknown first... ");
        {
            const d1 = new Test.D1();
            d1.sb = "D1.sb";
            d1.sd1 = "D1.sd1";
            const d3 = new Test.D3();
            d3.pb = d1;
            d3.sb = "D3.sb";
            d3.sd3 = "D3.sd3";
            d3.pd3 = d1;
            d1.pb = d3;
            d1.pd1 = d3;
            const b1 = await prx.returnTest3(d3, d1);
            test(b1 !== null);
            test(b1.sb == "D3.sb");
            const b2 = b1.pb;
            test(b2 !== null);
            test(b2.sb == "D1.sb");
            test(b2.ice_id() == "::Test::D1");
            test(b2.pb == b1);
            const p3 = b2;
            test(p3 !== null);
            test(p3.sd1 == "D1.sd1");
            test(p3.pd1 === b1);
            if (prx.ice_getEncodingVersion().equals(Ice.Encoding_1_0)) {
                test(!(b1 instanceof Test.D3));
            }
            else {
                const p1 = b1;
                test(p1 !== null);
                test(p1.pd3 === b2);
                test(p1.sd3 == "D3.sd3");
            }
            test(b1 !== d1);
            test(b1 !== d3);
            test(b2 !== d1);
            test(b2 !== d3);
        }
        out.writeLine("ok");
        out.write("remainder unmarshaling (3 instances)... ");
        {
            const [ret, p1, p2] = await prx.paramTest3();
            test(p1 !== null);
            test(p1.sb == "D2.sb (p1 1)");
            test(p1.pb === null);
            test(p1.ice_id() == "::Test::B");
            test(p2 !== null);
            test(p2.sb == "D2.sb (p2 1)");
            test(p2.pb === null);
            test(p2.ice_id() == "::Test::B");
            test(ret !== null);
            test(ret.sb == "D1.sb (p2 2)");
            test(ret.pb === null);
            test(ret.ice_id() == "::Test::D1");
        }
        out.writeLine("ok");
        out.write("remainder unmarshaling (4 instances)... ");
        {
            const [ret, b] = await prx.paramTest4();
            test(b !== null);
            test(b.sb == "D4.sb (1)");
            test(b.pb === null);
            test(b.ice_id() == "::Test::B");
            test(ret !== null);
            test(ret.sb == "B.sb (2)");
            test(ret.pb === null);
            test(ret.ice_id() == "::Test::B");
        }
        out.writeLine("ok");
        out.write("param ptr slicing, instance marshaled in unknown derived as base... ");
        {
            const b1 = new Test.B();
            b1.sb = "B.sb(1)";
            b1.pb = b1;
            const d3 = new Test.D3();
            d3.sb = "D3.sb";
            d3.pb = d3;
            d3.sd3 = "D3.sd3";
            d3.pd3 = b1;
            const b2 = new Test.B();
            b2.sb = "B.sb(2)";
            b2.pb = b1;
            const ret = await prx.returnTest3(d3, b2);
            test(ret !== null);
            test(ret.sb == "D3.sb");
            test(ret.pb === ret);
            if (prx.ice_getEncodingVersion().equals(Ice.Encoding_1_0)) {
                test(!(ret instanceof Test.D3));
            }
            else {
                const p3 = ret;
                test(p3 !== null);
                test(p3.sd3 == "D3.sd3");
                test(p3.pd3.ice_id() == "::Test::B");
                test(p3.pd3.sb == "B.sb(1)");
                test(p3.pd3.pb === p3.pd3);
            }
        }
        out.writeLine("ok");
        out.write("param ptr slicing, instance marshaled in unknown derived as derived... ");
        {
            const d11 = new Test.D1();
            d11.sb = "D1.sb(1)";
            d11.pb = d11;
            d11.sd1 = "D1.sd1(1)";
            const d3 = new Test.D3();
            d3.sb = "D3.sb";
            d3.pb = d3;
            d3.sd3 = "D3.sd3";
            d3.pd3 = d11;
            const d12 = new Test.D1();
            d12.sb = "D1.sb(2)";
            d12.pb = d12;
            d12.sd1 = "D1.sd1(2)";
            d12.pd1 = d11;
            const ret = await prx.returnTest3(d3, d12);
            test(ret !== null);
            test(ret.sb == "D3.sb");
            test(ret.pb === ret);
        }
        out.writeLine("ok");
        out.write("sequence slicing... ");
        {
            let ss1b = new Test.B();
            ss1b.sb = "B.sb";
            ss1b.pb = ss1b;
            let ss1d1 = new Test.D1();
            ss1d1.sb = "D1.sb";
            ss1d1.sd1 = "D1.sd1";
            ss1d1.pb = ss1b;
            let ss1d3 = new Test.D3();
            ss1d3.sb = "D3.sb";
            ss1d3.sd3 = "D3.sd3";
            ss1d3.pb = ss1b;
            let ss2b = new Test.B();
            ss2b.sb = "B.sb";
            ss2b.pb = ss1b;
            let ss2d1 = new Test.D1();
            ss2d1.sb = "D1.sb";
            ss2d1.sd1 = "D1.sd1";
            ss2d1.pb = ss2b;
            let ss2d3 = new Test.D3();
            ss2d3.sb = "D3.sb";
            ss2d3.sd3 = "D3.sd3";
            ss2d3.pb = ss2b;
            ss1d1.pd1 = ss2b;
            ss1d3.pd3 = ss2d1;
            ss2d1.pd1 = ss1d3;
            ss2d3.pd3 = ss1d1;
            const ss1 = new Test.SS1();
            ss1.s = [];
            ss1.s[0] = ss1b;
            ss1.s[1] = ss1d1;
            ss1.s[2] = ss1d3;
            const ss2 = new Test.SS2();
            ss2.s = [];
            ss2.s[0] = ss2b;
            ss2.s[1] = ss2d1;
            ss2.s[2] = ss2d3;
            const ss = await prx.sequenceTest(ss1, ss2);
            test(ss.c1 !== null);
            ss1b = ss.c1.s[0];
            ss1d1 = ss.c1.s[1];
            test(ss.c2 !== null);
            ss1d3 = ss.c1.s[2];
            test(ss.c2 !== null);
            ss2b = ss.c2.s[0];
            ss2d1 = ss.c2.s[1];
            ss2d3 = ss.c2.s[2];
            test(ss1b.pb === ss1b);
            test(ss1d1.pb === ss1b);
            test(ss1d3.pb === ss1b);
            test(ss2b.pb === ss1b);
            test(ss2d1.pb === ss2b);
            test(ss2d3.pb === ss2b);
            test(ss1b.ice_id() == "::Test::B");
            test(ss1d1.ice_id() == "::Test::D1");
            test(ss2b.ice_id() == "::Test::B");
            test(ss2d1.ice_id() == "::Test::D1");
            if (prx.ice_getEncodingVersion().equals(Ice.Encoding_1_0)) {
                test(ss1d3 instanceof Test.B);
                test(ss2d3 instanceof Test.B);
            }
            else {
                test(ss1d3 instanceof Test.D3);
                test(ss2d3 instanceof Test.D3);
            }
        }
        out.writeLine("ok");
        out.write("dictionary slicing... ");
        {
            const bin = new Map();
            for (let i = 0; i < 10; ++i) {
                const s = `D1.${i}`;
                const d1 = new Test.D1();
                d1.sb = s;
                d1.pb = d1;
                d1.sd1 = s;
                bin.set(i, d1);
            }
            const [ret, boutH] = await prx.dictionaryTest(bin);
            test(boutH.size === 10);
            for (let i = 0; i < 10; ++i) {
                const b = boutH.get(i * 10);
                test(b instanceof Test.B);
                const s = `D1.${i}`;
                test(b.sb == s);
                test(b.pb !== null);
                test(b.pb !== b);
                test(b.pb.sb == s);
                test(b.pb.pb == b.pb);
            }
            test(ret.size === 10);
            for (let i = 0; i < 10; ++i) {
                const b = ret.get(i * 20);
                test(b instanceof Test.B);
                const s = "D1." + i * 20;
                test(b.sb == s);
                test(b.pb === (i === 0 ? null : ret.get((i - 1) * 20)));
                const d1 = b;
                test(d1.sd1 == s);
                test(d1.pd1 === b);
            }
        }
        out.writeLine("ok");
        out.write("base exception thrown as base exception... ");
        try {
            await prx.throwBaseAsBase();
            test(false);
        }
        catch (ex) {
            if (ex instanceof Test.BaseException) {
                test(ex.ice_id() == "::Test::BaseException");
                test(ex.sbe == "sbe");
                test(ex.pb !== null);
                test(ex.pb.sb == "sb");
                test(ex.pb.pb == ex.pb);
            }
            else {
                test(false, ex);
            }
        }
        out.writeLine("ok");
        out.write("derived exception thrown as base exception... ");
        try {
            await prx.throwDerivedAsBase();
            test(false);
        }
        catch (ex) {
            if (ex instanceof Test.DerivedException) {
                test(ex.ice_id() == "::Test::DerivedException");
                test(ex.sbe == "sbe");
                test(ex.pb !== null);
                test(ex.pb.sb == "sb1");
                test(ex.pb.pb === ex.pb);
                test(ex.sde == "sde1");
                test(ex.pd1 !== null);
                test(ex.pd1.sb == "sb2");
                test(ex.pd1.pb === ex.pd1);
                test(ex.pd1.sd1 == "sd2");
                test(ex.pd1.pd1 === ex.pd1);
            }
            else {
                test(false, ex);
            }
        }
        out.writeLine("ok");
        out.write("derived exception thrown as derived exception... ");
        try {
            await prx.throwDerivedAsDerived();
            test(false);
        }
        catch (ex) {
            if (ex instanceof Test.DerivedException) {
                test(ex.ice_id() == "::Test::DerivedException");
                test(ex.sbe == "sbe");
                test(ex.pb !== null);
                test(ex.pb.sb == "sb1");
                test(ex.pb.pb == ex.pb);
                test(ex.sde == "sde1");
                test(ex.pd1 !== null);
                test(ex.pd1.sb == "sb2");
                test(ex.pd1.pb === ex.pd1);
                test(ex.pd1.sd1 == "sd2");
                test(ex.pd1.pd1 === ex.pd1);
            }
            else {
                test(false, ex);
            }
        }
        out.writeLine("ok");
        out.write("unknown derived exception thrown as base exception... ");
        try {
            await prx.throwUnknownDerivedAsBase();
            test(false);
        }
        catch (ex) {
            if (ex instanceof Test.BaseException) {
                test(ex.ice_id() == "::Test::BaseException");
                test(ex.sbe == "sbe");
                test(ex.pb !== null);
                test(ex.pb.sb == "sb d2");
                test(ex.pb.pb == ex.pb);
            }
            else {
                test(false, ex);
            }
        }
        out.writeLine("ok");
        out.write("forward-declared class... ");
        {
            const f = await prx.useForward();
            test(f !== null);
        }
        out.writeLine("ok");
        out.write("preserved classes... ");
        {
            //
            // Server knows the most-derived class PDerived.
            //
            const pd = new Test.PDerived();
            pd.pi = 3;
            pd.ps = "preserved";
            pd.pb = pd;
            const p2 = (await prx.exchangePBase(pd));
            test(p2.pi === 3);
            test(p2.ps == "preserved");
            test(p2.pb === p2);
        }
        {
            //
            // Server only knows the base (non-preserved) type, so the object is sliced.
            //
            const pu = new Test.PCUnknown();
            pu.pi = 3;
            pu.pu = "preserved";
            const r = await prx.exchangePBase(pu);
            test(r !== null);
            test(r.pi == 3);
            if (prx.ice_getEncodingVersion().equals(Ice.Encoding_1_0)) {
                test(!(r instanceof Test.PCUnknown));
            }
            else {
                const p2 = r;
                test(p2 !== null);
                test(p2.pu == "preserved");
            }
        }
        {
            //
            // Server only knows the intermediate type Preserved. The object will be sliced to
            // Preserved for the 1.0 encoding; otherwise it should be returned intact.
            //
            const pcd = new Test.PCDerived();
            pcd.pi = 3;
            pcd.pbs = [pcd];
            const r = await prx.exchangePBase(pcd);
            if (prx.ice_getEncodingVersion().equals(Ice.Encoding_1_0)) {
                test(r !== null);
                test(!(r instanceof Test.PCDerived));
                test(r.pi === 3);
            }
            else {
                const p2 = r;
                test(p2.pi === 3);
                test(p2.pbs[0] === r);
            }
        }
        {
            //
            // Server only knows the intermediate type Preserved. The object will be sliced to
            // Preserved for the 1.0 encoding; otherwise it should be returned intact.
            //
            const pcd = new Test.CompactPCDerived();
            pcd.pi = 3;
            pcd.pbs = [pcd];
            const r = await prx.exchangePBase(pcd);
            if (prx.ice_getEncodingVersion().equals(Ice.Encoding_1_0)) {
                test(r !== null);
                test(!(r instanceof Test.CompactPCDerived));
                test(r.pi === 3);
            }
            else {
                const p2 = r;
                test(p2.pi === 3);
                test(p2.pbs[0] === p2);
            }
        }
        {
            //
            // Send an object that will have multiple preserved slices in the server.
            // The object will be sliced to Preserved for the 1.0 encoding.
            //
            const pcd = new Test.PCDerived3();
            pcd.pi = 3;
            //
            // Sending more than 254 objects exercises the encoding for object ids.
            //
            pcd.pbs = new Array(300);
            for (let i = 0; i < 300; ++i) {
                const p2 = new Test.PCDerived2();
                p2.pi = i;
                p2.pbs = [null]; // Nil reference. This slice should not have an indirection table.
                p2.pcd2 = i;
                pcd.pbs[i] = p2;
            }
            pcd.pcd2 = pcd.pi;
            pcd.pcd3 = pcd.pbs[10];
            const r = await prx.exchangePBase(pcd);
            if (prx.ice_getEncodingVersion().equals(Ice.Encoding_1_0)) {
                test(!(r instanceof Test.PCDerived3));
                test(r instanceof Test.Preserved);
                test(r.pi === 3);
            }
            else {
                const p3 = r;
                test(p3.pi === 3);
                for (let i = 0; i < 300; ++i) {
                    const p2 = p3.pbs[i];
                    test(p2.pi === i);
                    test(p2.pbs.length === 1);
                    test(p2.pbs[0] === null);
                    test(p2.pcd2 === i);
                }
                test(p3.pcd2 === p3.pi);
                test(p3.pcd3 === p3.pbs[10]);
            }
        }
        {
            //
            // Obtain an object with preserved slices and send it back to the server.
            // The preserved slices should be excluded for the 1.0 encoding, otherwise
            // they should be included.
            //
            const p = await prx.PBSUnknownAsPreserved();
            test(p !== null);
            await prx.checkPBSUnknown(p);
            if (!prx.ice_getEncodingVersion().equals(Ice.Encoding_1_0)) {
                const slicedData = p.ice_getSlicedData();
                test(slicedData !== null);
                test(slicedData.slices.length === 1);
                test(slicedData.slices[0].typeId == "::Test::PSUnknown");
                await prx.ice_encodingVersion(Ice.Encoding_1_0).checkPBSUnknown(p);
            }
            else {
                test(p.ice_getSlicedData() === null);
            }
        }
        out.writeLine("ok");
        await prx.shutdown();
    }
    async run(args) {
        let communicator = null;
        try {
            [communicator] = this.initialize(args);
            await this.allTests();
        }
        finally {
            if (communicator) {
                await communicator.destroy();
            }
        }
    }
}