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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 1x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 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 {
allTests() {
const communicator = this.communicator();
const out = this.getWriter();
out.write("testing primitive types... ");
{
const outS = new Ice.OutputStream(communicator);
outS.startEncapsulation();
outS.writeBool(true);
outS.endEncapsulation();
const data = outS.finished();
let inS = new Ice.InputStream(communicator, data);
inS.startEncapsulation();
test(inS.readBool());
inS.endEncapsulation();
inS = new Ice.InputStream(communicator, data);
inS.startEncapsulation();
test(inS.readBool());
inS.endEncapsulation();
}
{
const data = new Uint8Array();
const inS = new Ice.InputStream(communicator, data);
try {
inS.readBool();
test(false);
}
catch (ex) {
test(ex instanceof Ice.MarshalException);
}
}
{
// The InputStream accepts an ArrayBuffer holding the encoded data.
const outS = new Ice.OutputStream(communicator);
outS.writeInt(0x01020304);
const data = outS.finished();
const buffer = new ArrayBuffer(data.byteLength);
new Uint8Array(buffer).set(data);
const inS = new Ice.InputStream(communicator, buffer);
test(inS.readInt() === 0x01020304);
}
{
// The InputStream reads from the exact range of a Uint8Array view into a larger buffer.
const outS = new Ice.OutputStream(communicator);
outS.writeInt(0x01020304);
const data = outS.finished();
const padded = new Uint8Array(data.byteLength + 8);
padded.fill(0xff);
padded.set(data, 4);
const inS = new Ice.InputStream(communicator, padded.subarray(4, 4 + data.byteLength));
test(inS.readInt() === 0x01020304);
try {
inS.readByte(); // no data remains within the view's range
test(false);
}
catch (ex) {
test(ex instanceof Ice.MarshalException);
}
}
{
const outS = new Ice.OutputStream(communicator);
outS.writeBool(true);
const data = outS.finished();
const inS = new Ice.InputStream(communicator, data);
test(inS.readBool());
}
{
const outS = new Ice.OutputStream(communicator);
outS.writeByte(1);
const data = outS.finished();
const inS = new Ice.InputStream(communicator, data);
test(inS.readByte() == 1);
}
{
const outS = new Ice.OutputStream(communicator);
outS.writeShort(2);
const data = outS.finished();
const inS = new Ice.InputStream(communicator, data);
test(inS.readShort() == 2);
}
{
const outS = new Ice.OutputStream(communicator);
outS.writeInt(3);
const data = outS.finished();
const inS = new Ice.InputStream(communicator, data);
test(inS.readInt() == 3);
}
{
const outS = new Ice.OutputStream(communicator);
outS.writeLong(4n);
const data = outS.finished();
const inS = new Ice.InputStream(communicator, data);
test(inS.readLong() == 4n);
}
{
const outS = new Ice.OutputStream(communicator);
outS.writeFloat(5.0);
const data = outS.finished();
const inS = new Ice.InputStream(communicator, data);
test(inS.readFloat() == 5.0);
}
{
const outS = new Ice.OutputStream(communicator);
outS.writeDouble(6.0);
const data = outS.finished();
const inS = new Ice.InputStream(communicator, data);
test(inS.readDouble() == 6.0);
}
{
const outS = new Ice.OutputStream(communicator);
outS.writeString("hello world");
const data = outS.finished();
const inS = new Ice.InputStream(communicator, data);
test(inS.readString() == "hello world");
}
out.writeLine("ok");
out.write("testing constructed types... ");
{
const outS = new Ice.OutputStream(communicator);
outS.writeEnum(Test.MyEnum.enum3);
const data = outS.finished();
const inS = new Ice.InputStream(communicator, data);
const e = inS.readEnum(Test.MyEnum);
test(e == Test.MyEnum.enum3);
}
{
const outS = new Ice.OutputStream(communicator);
const s = new Test.LargeStruct();
s.bo = true;
s.by = 1;
s.sh = 2;
s.i = 3;
s.l = 4n;
s.f = 5.0;
s.d = 6.0;
s.str = "7";
s.e = Test.MyEnum.enum2;
s.p = new Test.MyInterfacePrx(communicator, "test:default");
Test.LargeStruct.write(outS, s);
const data = outS.finished();
const s2 = Test.LargeStruct.read(new Ice.InputStream(communicator, data));
test(s2.equals(s));
}
{
const outS = new Ice.OutputStream(communicator);
const o = new Test.OptionalClass();
o.bo = true;
o.by = 5;
o.sh = 4;
o.i = 3;
outS.writeValue(o);
outS.writePendingValues();
const data = outS.finished();
const inS = new Ice.InputStream(communicator, data);
let o2 = null;
inS.readValue((obj) => {
o2 = obj;
}, Test.OptionalClass);
inS.readPendingValues();
test(o2.bo == o.bo);
test(o2.by == o.by);
if (communicator.getProperties().getIceProperty("Ice.Default.EncodingVersion") == "1.0") {
test(o2.sh === undefined);
test(o2.i === undefined);
}
else {
test(o2.sh == o.sh);
test(o2.i == o.i);
}
}
{
const outS = new Ice.OutputStream(Ice.Encoding_1_0);
const o = new Test.OptionalClass();
o.bo = true;
o.by = 5;
o.sh = 4;
o.i = 3;
outS.writeValue(o);
outS.writePendingValues();
const data = outS.finished();
const inS = new Ice.InputStream(communicator, Ice.Encoding_1_0, data);
let o2 = null;
inS.readValue((obj) => {
o2 = obj;
}, Test.OptionalClass);
inS.readPendingValues();
test(o2.bo == o.bo);
test(o2.by == o.by);
test(o2.sh === undefined);
test(o2.i === undefined);
}
{
// The format argument of the OutputStream constructor selects the class format: the sliced format
// writes slice headers that the compact format omits.
const o = new Test.OptionalClass();
o.bo = true;
const outCompact = new Ice.OutputStream(Ice.Encoding_1_1, Ice.FormatType.CompactFormat);
outCompact.writeValue(o);
outCompact.writePendingValues();
const outSliced = new Ice.OutputStream(Ice.Encoding_1_1, Ice.FormatType.SlicedFormat);
outSliced.writeValue(o);
outSliced.writePendingValues();
test(outSliced.finished().length > outCompact.finished().length);
}
{
const arr = [true, false, true, false];
let outS = new Ice.OutputStream(communicator);
Ice.BoolSeqHelper.write(outS, arr);
let data = outS.finished();
let inS = new Ice.InputStream(communicator, data);
const arr2 = Ice.BoolSeqHelper.read(inS);
test(Ice.ArrayUtil.equals(arr, arr2));
const arrS = [arr, [], arr];
outS = new Ice.OutputStream(communicator);
Test.BoolSSHelper.write(outS, arrS);
data = outS.finished();
inS = new Ice.InputStream(communicator, data);
const arr2S = Test.BoolSSHelper.read(inS);
test(Ice.ArrayUtil.equals(arr2S, arrS));
}
{
const arr = new Uint8Array([0x01, 0x11, 0x12, 0x22]);
let outS = new Ice.OutputStream(communicator);
Ice.ByteSeqHelper.write(outS, arr);
let data = outS.finished();
let inS = new Ice.InputStream(communicator, data);
const arr2 = Ice.ByteSeqHelper.read(inS);
test(Ice.ArrayUtil.equals(arr2, arr));
const arrS = [arr, new Uint8Array(), arr];
outS = new Ice.OutputStream(communicator);
Test.ByteSSHelper.write(outS, arrS);
data = outS.finished();
inS = new Ice.InputStream(communicator, data);
const arr2S = Test.ByteSSHelper.read(inS);
test(Ice.ArrayUtil.equals(arr2S, arrS));
}
{
const arr = [0x01, 0x11, 0x12, 0x22];
let outS = new Ice.OutputStream(communicator);
Ice.ShortSeqHelper.write(outS, arr);
let data = outS.finished();
let inS = new Ice.InputStream(communicator, data);
const arr2 = Ice.ShortSeqHelper.read(inS);
test(Ice.ArrayUtil.equals(arr2, arr));
const arrS = [arr, [], arr];
outS = new Ice.OutputStream(communicator);
Test.ShortSSHelper.write(outS, arrS);
data = outS.finished();
inS = new Ice.InputStream(communicator, data);
const arr2S = Test.ShortSSHelper.read(inS);
test(Ice.ArrayUtil.equals(arr2S, arrS));
}
{
const arr = [0x01, 0x11, 0x12, 0x22];
let outS = new Ice.OutputStream(communicator);
Ice.IntSeqHelper.write(outS, arr);
let data = outS.finished();
let inS = new Ice.InputStream(communicator, data);
const arr2 = Ice.IntSeqHelper.read(inS);
test(Ice.ArrayUtil.equals(arr2, arr));
const arrS = [arr, [], arr];
outS = new Ice.OutputStream(communicator);
Test.IntSSHelper.write(outS, arrS);
data = outS.finished();
inS = new Ice.InputStream(communicator, data);
const arr2S = Test.IntSSHelper.read(inS);
test(Ice.ArrayUtil.equals(arr2S, arrS));
}
{
const arr = [1n, 17n, 18n, 34n];
let outS = new Ice.OutputStream(communicator);
Ice.LongSeqHelper.write(outS, arr);
let data = outS.finished();
let inS = new Ice.InputStream(communicator, data);
const arr2 = Ice.LongSeqHelper.read(inS);
test(Ice.ArrayUtil.equals(arr2, arr));
const arrS = [arr, [], arr];
outS = new Ice.OutputStream(communicator);
Test.LongSSHelper.write(outS, arrS);
data = outS.finished();
inS = new Ice.InputStream(communicator, data);
const arr2S = Test.LongSSHelper.read(inS);
test(Ice.ArrayUtil.equals(arr2S, arrS));
}
{
const arr = [1, 2, 3, 4];
let outS = new Ice.OutputStream(communicator);
Ice.FloatSeqHelper.write(outS, arr);
let data = outS.finished();
let inS = new Ice.InputStream(communicator, data);
const arr2 = Ice.FloatSeqHelper.read(inS);
test(Ice.ArrayUtil.equals(arr2, arr));
const arrS = [arr, [], arr];
outS = new Ice.OutputStream(communicator);
Test.FloatSSHelper.write(outS, arrS);
data = outS.finished();
inS = new Ice.InputStream(communicator, data);
const arr2S = Test.FloatSSHelper.read(inS);
test(Ice.ArrayUtil.equals(arr2S, arrS));
}
{
const arr = [1, 2, 3, 4];
let outS = new Ice.OutputStream(communicator);
Ice.DoubleSeqHelper.write(outS, arr);
let data = outS.finished();
let inS = new Ice.InputStream(communicator, data);
const arr2 = Ice.DoubleSeqHelper.read(inS);
test(Ice.ArrayUtil.equals(arr2, arr));
const arrS = [arr, [], arr];
outS = new Ice.OutputStream(communicator);
Test.DoubleSSHelper.write(outS, arrS);
data = outS.finished();
inS = new Ice.InputStream(communicator, data);
const arr2S = Test.DoubleSSHelper.read(inS);
test(Ice.ArrayUtil.equals(arr2S, arrS));
}
{
const arr = ["string1", "string2", "string3", "string4"];
let outS = new Ice.OutputStream(communicator);
Ice.StringSeqHelper.write(outS, arr);
let data = outS.finished();
let inS = new Ice.InputStream(communicator, data);
const arr2 = Ice.StringSeqHelper.read(inS);
test(Ice.ArrayUtil.equals(arr2, arr));
const arrS = [arr, [], arr];
outS = new Ice.OutputStream(communicator);
Test.StringSSHelper.write(outS, arrS);
data = outS.finished();
inS = new Ice.InputStream(communicator, data);
const arr2S = Test.StringSSHelper.read(inS);
test(Ice.ArrayUtil.equals(arr2S, arrS));
}
{
const arr = [Test.MyEnum.enum3, Test.MyEnum.enum2, Test.MyEnum.enum1, Test.MyEnum.enum2];
let outS = new Ice.OutputStream(communicator);
Test.MyEnumSHelper.write(outS, arr);
let data = outS.finished();
let inS = new Ice.InputStream(communicator, data);
const arr2 = Test.MyEnumSHelper.read(inS);
test(Ice.ArrayUtil.equals(arr2, arr));
const arrS = [arr, [], arr];
outS = new Ice.OutputStream(communicator);
Test.MyEnumSSHelper.write(outS, arrS);
data = outS.finished();
inS = new Ice.InputStream(communicator, data);
const arr2S = Test.MyEnumSSHelper.read(inS);
test(Ice.ArrayUtil.equals(arr2S, arrS));
}
const largeStructArray = [];
for (let i = 0; i < 3; ++i) {
const s = new Test.LargeStruct();
s.bo = true;
s.by = 1;
s.sh = 2;
s.i = 3;
s.l = 4n;
s.f = 5.0;
s.d = 6.0;
s.str = "7";
s.e = Test.MyEnum.enum2;
s.p = new Test.MyInterfacePrx(communicator, "test:default");
largeStructArray[i] = s;
}
const myClassArray = [];
for (let i = 0; i < 4; ++i) {
const c = new Test.MyClass();
myClassArray[i] = c;
c.c = myClassArray[i];
c.o = myClassArray[i];
c.s = new Test.LargeStruct();
c.s.e = Test.MyEnum.enum2;
c.seq1 = [true, false, true, false];
c.seq2 = new Uint8Array([1, 2, 3, 4]);
c.seq3 = [1, 2, 3, 4];
c.seq4 = [1, 2, 3, 4];
c.seq5 = [1n, 2n, 3n, 4n];
c.seq6 = [1, 2, 3, 4];
c.seq7 = [1, 2, 3, 4];
c.seq8 = ["string1", "string2", "string3", "string4"];
c.seq9 = [Test.MyEnum.enum3, Test.MyEnum.enum2, Test.MyEnum.enum1];
c.seq10 = [null, null, null, null]; // null elements.
c.d = new Test.StringMyClassD();
c.d.set("hi", myClassArray[i]);
}
{
let outS = new Ice.OutputStream(communicator);
Test.MyClassSHelper.write(outS, myClassArray);
outS.writePendingValues();
let data = outS.finished();
let inS = new Ice.InputStream(communicator, data);
const arr2 = Test.MyClassSHelper.read(inS);
inS.readPendingValues();
test(arr2.length == myClassArray.length);
for (let i = 0; i < arr2.length; ++i) {
test(arr2[i] !== null);
test(arr2[i].c == arr2[i]);
test(arr2[i].o == arr2[i]);
test(arr2[i].s.e == Test.MyEnum.enum2);
test(Ice.ArrayUtil.equals(arr2[i].seq1, myClassArray[i].seq1));
test(Ice.ArrayUtil.equals(arr2[i].seq2, myClassArray[i].seq2));
test(Ice.ArrayUtil.equals(arr2[i].seq3, myClassArray[i].seq3));
test(Ice.ArrayUtil.equals(arr2[i].seq4, myClassArray[i].seq4));
test(Ice.ArrayUtil.equals(arr2[i].seq5, myClassArray[i].seq5));
test(Ice.ArrayUtil.equals(arr2[i].seq6, myClassArray[i].seq6));
test(Ice.ArrayUtil.equals(arr2[i].seq7, myClassArray[i].seq7));
test(Ice.ArrayUtil.equals(arr2[i].seq8, myClassArray[i].seq8));
test(Ice.ArrayUtil.equals(arr2[i].seq9, myClassArray[i].seq9));
test(arr2[i].d.get("hi") == arr2[i]);
}
const arrS = [myClassArray, [], myClassArray];
outS = new Ice.OutputStream(communicator);
Test.MyClassSSHelper.write(outS, arrS);
data = outS.finished();
inS = new Ice.InputStream(communicator, data);
const arr2S = Test.MyClassSSHelper.read(inS);
test(arr2S.length == arrS.length);
test(arr2S[0].length == arrS[0].length);
test(arr2S[1].length == arrS[1].length);
test(arr2S[2].length == arrS[2].length);
}
{
const outS = new Ice.OutputStream(communicator);
const ex = new Test.MyException();
const c = new Test.MyClass();
c.c = c;
c.o = c;
c.s = new Test.LargeStruct();
c.s.e = Test.MyEnum.enum2;
c.seq1 = [true, false, true, false];
c.seq2 = new Uint8Array([1, 2, 3, 4]);
c.seq3 = [1, 2, 3, 4];
c.seq4 = [1, 2, 3, 4];
c.seq5 = [1n, 2n, 3n, 4n];
c.seq6 = [1, 2, 3, 4];
c.seq7 = [1, 2, 3, 4];
c.seq8 = ["string1", "string2", "string3", "string4"];
c.seq9 = [Test.MyEnum.enum3, Test.MyEnum.enum2, Test.MyEnum.enum1];
c.seq10 = [null, null, null, null]; // null elements.
c.d = new Test.StringMyClassD();
c.d.set("hi", c);
ex.c = c;
outS.writeException(ex);
const data = outS.finished();
const inS = new Ice.InputStream(communicator, data);
try {
inS.throwException();
test(false);
}
catch (ex1) {
if (ex1 instanceof Test.MyException) {
test(ex1.c.s.e == c.s.e);
test(Ice.ArrayUtil.equals(ex1.c.seq1, c.seq1));
test(Ice.ArrayUtil.equals(ex1.c.seq2, c.seq2));
test(Ice.ArrayUtil.equals(ex1.c.seq3, c.seq3));
test(Ice.ArrayUtil.equals(ex1.c.seq4, c.seq4));
test(Ice.ArrayUtil.equals(ex1.c.seq5, c.seq5));
test(Ice.ArrayUtil.equals(ex1.c.seq6, c.seq6));
test(Ice.ArrayUtil.equals(ex1.c.seq7, c.seq7));
test(Ice.ArrayUtil.equals(ex1.c.seq8, c.seq8));
test(Ice.ArrayUtil.equals(ex1.c.seq9, c.seq9));
}
else {
test(false, ex1);
}
}
}
{
// With the 1.0 encoding, a reader slices off the derived part of an exception it doesn't know, and then
// still reads the class instances the sender queued after it. Here the sliced-off slice holds the only
// reference to such an instance, so the reader has nothing to patch it into: it must discard the
// instance and deliver the base exception it does know.
//
// This exception is deliberately never registered with the Slice loader, and it must carry a non-null
// value: with a null one the sender queues no instance and the reader never exercises this path.
class UnknownDerived extends Test.MyException {
constructor(value) {
super();
this.value = value;
}
static get _parent() {
return Test.MyException;
}
static get _ice_id() {
return "::Test::UnknownDerived";
}
_mostDerivedType() {
return UnknownDerived;
}
_writeMemberImpl(ostr) {
ostr.writeValue(this.value);
}
}
const outS = new Ice.OutputStream(Ice.Encoding_1_0);
outS.writeException(new UnknownDerived(new Test.OptionalClass()));
const data = outS.finished();
const inS = new Ice.InputStream(communicator, Ice.Encoding_1_0, data);
try {
inS.throwException();
test(false);
}
catch (ex1) {
if (ex1 instanceof Test.MyException) {
// Not UnknownDerived: the most derived slice really was sliced off.
test(ex1.ice_id() === "::Test::MyException");
test(ex1.c === null);
}
else {
test(false, ex1);
}
}
}
{
const dict = new Test.ByteBoolD();
dict.set(4, true);
dict.set(1, false);
const outS = new Ice.OutputStream(communicator);
Test.ByteBoolDHelper.write(outS, dict);
const data = outS.finished();
const inS = new Ice.InputStream(communicator, data);
const dict2 = Test.ByteBoolDHelper.read(inS);
test(Ice.MapUtil.equals(dict2, dict));
}
{
const dict = new Test.ShortIntD();
dict.set(1, 9);
dict.set(4, 8);
const outS = new Ice.OutputStream(communicator);
Test.ShortIntDHelper.write(outS, dict);
const data = outS.finished();
const inS = new Ice.InputStream(communicator, data);
const dict2 = Test.ShortIntDHelper.read(inS);
test(Ice.MapUtil.equals(dict2, dict));
}
{
const dict = new Test.LongFloatD();
dict.set(123809828n, 0.5);
dict.set(123809829n, 0.6);
const outS = new Ice.OutputStream(communicator);
Test.LongFloatDHelper.write(outS, dict);
const data = outS.finished();
const inS = new Ice.InputStream(communicator, data);
const dict2 = Test.LongFloatDHelper.read(inS);
test(dict2.size == 2);
test(dict2.get(123809828n) == 0.5);
test(Math.abs(dict2.get(123809829n) - 0.6) <= 0.001);
}
{
const dict = new Test.StringStringD();
dict.set("key1", "value1");
dict.set("key2", "value2");
const outS = new Ice.OutputStream(communicator);
Test.StringStringDHelper.write(outS, dict);
const data = outS.finished();
const inS = new Ice.InputStream(communicator, data);
const dict2 = Test.StringStringDHelper.read(inS);
test(Ice.MapUtil.equals(dict2, dict));
}
{
const dict = new Test.StringMyClassD();
let c = new Test.MyClass();
c.s = new Test.LargeStruct();
c.s.e = Test.MyEnum.enum2;
dict.set("key1", c);
c = new Test.MyClass();
c.s = new Test.LargeStruct();
c.s.e = Test.MyEnum.enum3;
dict.set("key2", c);
const outS = new Ice.OutputStream(communicator);
Test.StringMyClassDHelper.write(outS, dict);
outS.writePendingValues();
const data = outS.finished();
const inS = new Ice.InputStream(communicator, data);
const dict2 = Test.StringMyClassDHelper.read(inS);
inS.readPendingValues();
test(dict2.size == dict.size);
test(dict2.get("key1").s.e == Test.MyEnum.enum2);
test(dict2.get("key2").s.e == Test.MyEnum.enum3);
}
out.writeLine("ok");
out.write("testing skipEncapsulation... ");
{
const outS = new Ice.OutputStream(communicator);
outS.startEncapsulation();
outS.writeInt(42);
outS.endEncapsulation();
const data = outS.finished();
// A well-formed encapsulation is skipped, advancing to its end and returning the encoding it was
// written with (the stream uses the communicator's default encoding, which varies across test runs).
const inS = new Ice.InputStream(communicator, data);
const encoding = inS.skipEncapsulation();
test(encoding.equals(outS.getEncoding()));
test(inS.pos === data.length);
// An encapsulation whose declared size exceeds the remaining buffer must be rejected, not silently
// accepted with the position left unchanged.
const bogus = data.slice();
const bogusSize = data.length + 100;
new DataView(bogus.buffer, bogus.byteOffset, bogus.byteLength).setInt32(0, bogusSize, true);
const inS2 = new Ice.InputStream(communicator, bogus);
try {
inS2.skipEncapsulation();
test(false);
}
catch (ex) {
test(ex instanceof Ice.MarshalException);
}
}
out.writeLine("ok");
out.write("testing buffer position bounds... ");
{
// Setting the stream position to an out-of-range or non-integer value must throw, not silently no-op.
const inS = new Ice.InputStream(communicator, new Uint8Array(4));
for (const badPos of [5, -1, 1.5, NaN]) {
try {
inS.pos = badPos;
test(false);
}
catch (ex) {
test(ex instanceof RangeError);
}
}
// Positions within [0, limit] are accepted (the limit itself is a valid position).
inS.pos = 4;
test(inS.pos === 4);
inS.pos = 0;
test(inS.pos === 0);
}
out.writeLine("ok");
}
async run(args) {
let communicator = null;
try {
[communicator] = this.initialize(args);
this.allTests();
}
finally {
if (communicator) {
await communicator.destroy();
}
}
}
}
|