ipc/ipdl/test/cxx/TestDataStructures.cpp

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 #include "TestDataStructures.h"
michael@0 2
michael@0 3 #include "mozilla/unused.h"
michael@0 4
michael@0 5 #include "IPDLUnitTests.h" // fail etc.
michael@0 6
michael@0 7 typedef InfallibleTArray<nsIntRegion> RegionArray;
michael@0 8
michael@0 9 namespace mozilla {
michael@0 10 namespace _ipdltest {
michael@0 11
michael@0 12 static const uint32_t nactors = 10;
michael@0 13
michael@0 14 #define test_assert(_cond, _msg) \
michael@0 15 if (!(_cond)) fail(_msg)
michael@0 16
michael@0 17 template<typename T>
michael@0 18 static void
michael@0 19 assert_arrays_equal(const InfallibleTArray<T>& a, const InfallibleTArray<T>& b)
michael@0 20 {
michael@0 21 test_assert(a == b, "arrays equal");
michael@0 22 }
michael@0 23
michael@0 24 inline static TestDataStructuresSub&
michael@0 25 Cast(PTestDataStructuresSubParent* a)
michael@0 26 {
michael@0 27 return *static_cast<TestDataStructuresSub*>(a);
michael@0 28 }
michael@0 29
michael@0 30 inline static TestDataStructuresSub&
michael@0 31 Cast(PTestDataStructuresSubChild* a)
michael@0 32 {
michael@0 33 return *static_cast<TestDataStructuresSub*>(a);
michael@0 34 }
michael@0 35
michael@0 36 //-----------------------------------------------------------------------------
michael@0 37 // parent
michael@0 38
michael@0 39 TestDataStructuresParent::TestDataStructuresParent()
michael@0 40 {
michael@0 41 MOZ_COUNT_CTOR(TestDataStructuresParent);
michael@0 42 }
michael@0 43
michael@0 44 TestDataStructuresParent::~TestDataStructuresParent()
michael@0 45 {
michael@0 46 MOZ_COUNT_DTOR(TestDataStructuresParent);
michael@0 47 }
michael@0 48
michael@0 49 void
michael@0 50 TestDataStructuresParent::Main()
michael@0 51 {
michael@0 52 for (uint32_t i = 0; i < nactors; ++i)
michael@0 53 if (!SendPTestDataStructuresSubConstructor(i))
michael@0 54 fail("can't alloc actor");
michael@0 55
michael@0 56 if (!SendStart())
michael@0 57 fail("can't send Start()");
michael@0 58 }
michael@0 59
michael@0 60 bool
michael@0 61 TestDataStructuresParent::DeallocPTestDataStructuresSubParent(PTestDataStructuresSubParent* actor)
michael@0 62 {
michael@0 63 test_assert(Cast(actor).mI == Cast(mKids[0]).mI,
michael@0 64 "dtor sent to wrong actor");
michael@0 65 mKids.RemoveElementAt(0);
michael@0 66 delete actor;
michael@0 67 if (mKids.Length() > 0)
michael@0 68 return true;
michael@0 69
michael@0 70 return true;
michael@0 71 }
michael@0 72
michael@0 73 bool TestDataStructuresParent::RecvTest1(
michael@0 74 const InfallibleTArray<int>& ia,
michael@0 75 InfallibleTArray<int>* oa)
michael@0 76 {
michael@0 77 test_assert(5 == ia.Length(), "wrong length");
michael@0 78 for (int i = 0; i < 5; ++i)
michael@0 79 test_assert(i == ia[i], "wrong value");
michael@0 80
michael@0 81 *oa = ia;
michael@0 82
michael@0 83 return true;
michael@0 84 }
michael@0 85
michael@0 86 bool TestDataStructuresParent::RecvTest2(
michael@0 87 const InfallibleTArray<PTestDataStructuresSubParent*>& i1,
michael@0 88 InfallibleTArray<PTestDataStructuresSubParent*>* o1)
michael@0 89 {
michael@0 90 test_assert(nactors == i1.Length(), "wrong #actors");
michael@0 91 for (uint32_t i = 0; i < i1.Length(); ++i)
michael@0 92 test_assert(i == Cast(i1[i]).mI, "wrong mI value");
michael@0 93 *o1 = i1;
michael@0 94 return true;
michael@0 95 }
michael@0 96
michael@0 97 bool TestDataStructuresParent::RecvTest3(
michael@0 98 const IntDouble& i1,
michael@0 99 const IntDouble& i2,
michael@0 100 IntDouble* o1,
michael@0 101 IntDouble* o2)
michael@0 102 {
michael@0 103 test_assert(42 == i1.get_int(), "wrong value");
michael@0 104 test_assert(4.0 == i2.get_double(), "wrong value");
michael@0 105
michael@0 106 *o1 = i1;
michael@0 107 *o2 = i2;
michael@0 108
michael@0 109 return true;
michael@0 110 }
michael@0 111
michael@0 112 bool TestDataStructuresParent::RecvTest4(
michael@0 113 const InfallibleTArray<IntDouble>& i1,
michael@0 114 InfallibleTArray<IntDouble>* o1)
michael@0 115 {
michael@0 116 test_assert(4 == i1.Length(), "wrong length");
michael@0 117 test_assert(1 == i1[0].get_int(), "wrong value");
michael@0 118 test_assert(2.0 == i1[1].get_double(), "wrong value");
michael@0 119 test_assert(3 == i1[2].get_int(), "wrong value");
michael@0 120 test_assert(4.0 == i1[3].get_double(), "wrong value");
michael@0 121
michael@0 122 *o1 = i1;
michael@0 123
michael@0 124 return true;
michael@0 125 }
michael@0 126
michael@0 127 bool TestDataStructuresParent::RecvTest5(
michael@0 128 const IntDoubleArrays& i1,
michael@0 129 const IntDoubleArrays& i2,
michael@0 130 const IntDoubleArrays& i3,
michael@0 131 IntDoubleArrays* o1,
michael@0 132 IntDoubleArrays* o2,
michael@0 133 IntDoubleArrays* o3)
michael@0 134 {
michael@0 135 test_assert(42 == i1.get_int(), "wrong value");
michael@0 136
michael@0 137 const InfallibleTArray<int>& i2a = i2.get_ArrayOfint();
michael@0 138 test_assert(3 == i2a.Length(), "wrong length");
michael@0 139 test_assert(1 == i2a[0], "wrong value");
michael@0 140 test_assert(2 == i2a[1], "wrong value");
michael@0 141 test_assert(3 == i2a[2], "wrong value");
michael@0 142
michael@0 143 const InfallibleTArray<double>& i3a = i3.get_ArrayOfdouble();
michael@0 144 test_assert(3 == i3a.Length(), "wrong length");
michael@0 145 test_assert(1.0 == i3a[0], "wrong value");
michael@0 146 test_assert(2.0 == i3a[1], "wrong value");
michael@0 147 test_assert(3.0 == i3a[2], "wrong value");
michael@0 148
michael@0 149 *o1 = i1;
michael@0 150 *o2 = i2a;
michael@0 151 *o3 = i3a;
michael@0 152
michael@0 153 return true;
michael@0 154 }
michael@0 155
michael@0 156 bool
michael@0 157 TestDataStructuresParent::RecvTest7_0(const ActorWrapper& i1,
michael@0 158 ActorWrapper* o1)
michael@0 159 {
michael@0 160 if (i1.actorChild() != nullptr)
michael@0 161 fail("child side actor should always be null");
michael@0 162
michael@0 163 if (i1.actorParent() != mKids[0])
michael@0 164 fail("should have got back same actor on parent side");
michael@0 165
michael@0 166 o1->actorParent() = mKids[0];
michael@0 167 // malicious behavior
michael@0 168 o1->actorChild() =
michael@0 169 reinterpret_cast<PTestDataStructuresSubChild*>(0xdeadbeef);
michael@0 170 return true;
michael@0 171 }
michael@0 172
michael@0 173 bool TestDataStructuresParent::RecvTest6(
michael@0 174 const InfallibleTArray<IntDoubleArrays>& i1,
michael@0 175 InfallibleTArray<IntDoubleArrays>* o1)
michael@0 176 {
michael@0 177 test_assert(3 == i1.Length(), "wrong length");
michael@0 178
michael@0 179 IntDoubleArrays id1(i1[0]);
michael@0 180 test_assert(42 == id1.get_int(), "wrong value");
michael@0 181
michael@0 182 InfallibleTArray<int> i2a(i1[1].get_ArrayOfint());
michael@0 183 test_assert(3 == i2a.Length(), "wrong length");
michael@0 184 test_assert(1 == i2a[0], "wrong value");
michael@0 185 test_assert(2 == i2a[1], "wrong value");
michael@0 186 test_assert(3 == i2a[2], "wrong value");
michael@0 187
michael@0 188 InfallibleTArray<double> i3a(i1[2].get_ArrayOfdouble());
michael@0 189 test_assert(3 == i3a.Length(), "wrong length");
michael@0 190 test_assert(1.0 == i3a[0], "wrong value");
michael@0 191 test_assert(2.0 == i3a[1], "wrong value");
michael@0 192 test_assert(3.0 == i3a[2], "wrong value");
michael@0 193
michael@0 194 o1->AppendElement(id1);
michael@0 195 o1->AppendElement(IntDoubleArrays(i2a));
michael@0 196 o1->AppendElement(IntDoubleArrays(i3a));
michael@0 197
michael@0 198 return true;
michael@0 199 }
michael@0 200
michael@0 201 bool TestDataStructuresParent::RecvTest7(
michael@0 202 const Actors& i1,
michael@0 203 const Actors& i2,
michael@0 204 const Actors& i3,
michael@0 205 Actors* o1,
michael@0 206 Actors* o2,
michael@0 207 Actors* o3)
michael@0 208 {
michael@0 209 test_assert(42 == i1.get_int(), "wrong value");
michael@0 210
michael@0 211 InfallibleTArray<int> i2a(i2.get_ArrayOfint());
michael@0 212 test_assert(3 == i2a.Length(), "wrong length");
michael@0 213 test_assert(1 == i2a[0], "wrong value");
michael@0 214 test_assert(2 == i2a[1], "wrong value");
michael@0 215 test_assert(3 == i2a[2], "wrong value");
michael@0 216
michael@0 217 assert_arrays_equal(mKids, i3.get_ArrayOfPTestDataStructuresSubParent());
michael@0 218
michael@0 219 *o1 = 42;
michael@0 220 *o2 = i2a;
michael@0 221 *o3 = mKids;
michael@0 222
michael@0 223 return true;
michael@0 224 }
michael@0 225
michael@0 226 bool TestDataStructuresParent::RecvTest8(
michael@0 227 const InfallibleTArray<Actors>& i1,
michael@0 228 InfallibleTArray<Actors>* o1)
michael@0 229 {
michael@0 230 test_assert(3 == i1.Length(), "wrong length");
michael@0 231 test_assert(42 == i1[0].get_int(), "wrong value");
michael@0 232
michael@0 233 const InfallibleTArray<int>& i2a = i1[1].get_ArrayOfint();
michael@0 234 test_assert(3 == i2a.Length(), "wrong length");
michael@0 235 test_assert(1 == i2a[0], "wrong value");
michael@0 236 test_assert(2 == i2a[1], "wrong value");
michael@0 237 test_assert(3 == i2a[2], "wrong value");
michael@0 238
michael@0 239 assert_arrays_equal(mKids, i1[2].get_ArrayOfPTestDataStructuresSubParent());
michael@0 240
michael@0 241 *o1 = i1;
michael@0 242
michael@0 243 return true;
michael@0 244 }
michael@0 245
michael@0 246 bool TestDataStructuresParent::RecvTest9(
michael@0 247 const Unions& i1,
michael@0 248 const Unions& i2,
michael@0 249 const Unions& i3,
michael@0 250 const Unions& i4,
michael@0 251 Unions* o1,
michael@0 252 Unions* o2,
michael@0 253 Unions* o3,
michael@0 254 Unions* o4)
michael@0 255 {
michael@0 256 test_assert(42 == i1.get_int(), "wrong value");
michael@0 257
michael@0 258 const InfallibleTArray<int>& i2a = i2.get_ArrayOfint();
michael@0 259 test_assert(3 == i2a.Length(), "wrong length");
michael@0 260 test_assert(1 == i2a[0], "wrong value");
michael@0 261 test_assert(2 == i2a[1], "wrong value");
michael@0 262 test_assert(3 == i2a[2], "wrong value");
michael@0 263
michael@0 264 assert_arrays_equal(mKids, i3.get_ArrayOfPTestDataStructuresSubParent());
michael@0 265
michael@0 266 const InfallibleTArray<PTestDataStructuresSubParent*>& i4a =
michael@0 267 i4.get_ArrayOfActors()[0].get_ArrayOfPTestDataStructuresSubParent();
michael@0 268 assert_arrays_equal(mKids, i4a);
michael@0 269
michael@0 270 *o1 = i1;
michael@0 271 *o2 = i2;
michael@0 272 *o3 = i3;
michael@0 273 *o4 = i4;
michael@0 274
michael@0 275 return true;
michael@0 276 }
michael@0 277
michael@0 278 bool TestDataStructuresParent::RecvTest10(
michael@0 279 const InfallibleTArray<Unions>& i1,
michael@0 280 InfallibleTArray<Unions>* o1)
michael@0 281 {
michael@0 282 test_assert(42 == i1[0].get_int(), "wrong value");
michael@0 283
michael@0 284 const InfallibleTArray<int>& i2a = i1[1].get_ArrayOfint();
michael@0 285 test_assert(3 == i2a.Length(), "wrong length");
michael@0 286 test_assert(1 == i2a[0], "wrong value");
michael@0 287 test_assert(2 == i2a[1], "wrong value");
michael@0 288 test_assert(3 == i2a[2], "wrong value");
michael@0 289
michael@0 290 assert_arrays_equal(mKids, i1[2].get_ArrayOfPTestDataStructuresSubParent());
michael@0 291
michael@0 292 const InfallibleTArray<PTestDataStructuresSubParent*>& i4a =
michael@0 293 i1[3].get_ArrayOfActors()[0].get_ArrayOfPTestDataStructuresSubParent();
michael@0 294 assert_arrays_equal(mKids, i4a);
michael@0 295
michael@0 296 *o1 = i1;
michael@0 297
michael@0 298 return true;
michael@0 299 }
michael@0 300
michael@0 301 bool TestDataStructuresParent::RecvTest11(
michael@0 302 const SIntDouble& i,
michael@0 303 SIntDouble* o)
michael@0 304 {
michael@0 305 test_assert(1 == i.i(), "wrong value");
michael@0 306 test_assert(2.0 == i.d(), "wrong value");
michael@0 307 *o = i;
michael@0 308 return true;
michael@0 309 }
michael@0 310
michael@0 311 bool TestDataStructuresParent::RecvTest12(
michael@0 312 const SIntDoubleArrays& i,
michael@0 313 SIntDoubleArrays* o)
michael@0 314 {
michael@0 315 InfallibleTArray<int> ai;
michael@0 316 ai.AppendElement(1);
michael@0 317 ai.AppendElement(2);
michael@0 318 ai.AppendElement(3);
michael@0 319
michael@0 320 InfallibleTArray<double> ad;
michael@0 321 ad.AppendElement(.5);
michael@0 322 ad.AppendElement(1.0);
michael@0 323 ad.AppendElement(2.0);
michael@0 324
michael@0 325 test_assert(42 == i.i(), "wrong value");
michael@0 326 assert_arrays_equal(ai, i.ai());
michael@0 327 assert_arrays_equal(ad, i.ad());
michael@0 328
michael@0 329 *o = i;
michael@0 330
michael@0 331 return true;
michael@0 332 }
michael@0 333
michael@0 334 bool TestDataStructuresParent::RecvTest13(
michael@0 335 const SActors& i,
michael@0 336 SActors* o)
michael@0 337 {
michael@0 338 InfallibleTArray<int> ai;
michael@0 339 ai.AppendElement(1); ai.AppendElement(2); ai.AppendElement(3);
michael@0 340
michael@0 341 test_assert(42 == i.i(), "wrong value");
michael@0 342 assert_arrays_equal(ai, i.ai());
michael@0 343 assert_arrays_equal(mKids, i.apParent());
michael@0 344
michael@0 345 *o = i;
michael@0 346
michael@0 347 return true;
michael@0 348 }
michael@0 349
michael@0 350 bool TestDataStructuresParent::RecvTest14(
michael@0 351 const Structs& i,
michael@0 352 Structs* o)
michael@0 353 {
michael@0 354 InfallibleTArray<int> ai;
michael@0 355 ai.AppendElement(1); ai.AppendElement(2); ai.AppendElement(3);
michael@0 356
michael@0 357 test_assert(42 == i.i(), "wrong value");
michael@0 358 assert_arrays_equal(ai, i.ai());
michael@0 359 assert_arrays_equal(mKids, i.apParent());
michael@0 360
michael@0 361 const SActors& ia = i.aa()[0];
michael@0 362 test_assert(42 == ia.i(), "wrong value");
michael@0 363 assert_arrays_equal(ai, ia.ai());
michael@0 364 assert_arrays_equal(mKids, ia.apParent());
michael@0 365
michael@0 366 *o = i;
michael@0 367
michael@0 368 return true;
michael@0 369 }
michael@0 370
michael@0 371 bool TestDataStructuresParent::RecvTest15(
michael@0 372 const WithStructs& i1,
michael@0 373 const WithStructs& i2,
michael@0 374 const WithStructs& i3,
michael@0 375 const WithStructs& i4,
michael@0 376 const WithStructs& i5,
michael@0 377 WithStructs* o1,
michael@0 378 WithStructs* o2,
michael@0 379 WithStructs* o3,
michael@0 380 WithStructs* o4,
michael@0 381 WithStructs* o5)
michael@0 382 {
michael@0 383 InfallibleTArray<int> ai;
michael@0 384 ai.AppendElement(1); ai.AppendElement(2); ai.AppendElement(3);
michael@0 385
michael@0 386 test_assert(i1 == int(42), "wrong value");
michael@0 387 assert_arrays_equal(i2.get_ArrayOfint(), ai);
michael@0 388 assert_arrays_equal(i3.get_ArrayOfPTestDataStructuresSubParent(), mKids);
michael@0 389
michael@0 390 const SActors& ia = i4.get_ArrayOfSActors()[0];
michael@0 391 test_assert(42 == ia.i(), "wrong value");
michael@0 392 assert_arrays_equal(ai, ia.ai());
michael@0 393 assert_arrays_equal(mKids, ia.apParent());
michael@0 394
michael@0 395 const Structs& is = i5.get_ArrayOfStructs()[0];
michael@0 396 test_assert(42 == is.i(), "wrong value");
michael@0 397 assert_arrays_equal(ai, is.ai());
michael@0 398 assert_arrays_equal(mKids, is.apParent());
michael@0 399
michael@0 400 const SActors& isa = is.aa()[0];
michael@0 401 test_assert(42 == isa.i(), "wrong value");
michael@0 402 assert_arrays_equal(ai, isa.ai());
michael@0 403 assert_arrays_equal(mKids, isa.apParent());
michael@0 404
michael@0 405 *o1 = i1;
michael@0 406 *o2 = i2;
michael@0 407 *o3 = i3;
michael@0 408 *o4 = i4;
michael@0 409 *o5 = i5;
michael@0 410
michael@0 411 return true;
michael@0 412 }
michael@0 413
michael@0 414 bool TestDataStructuresParent::RecvTest16(
michael@0 415 const WithUnions& i,
michael@0 416 WithUnions* o)
michael@0 417 {
michael@0 418 test_assert(i.i() == 42, "wrong value");
michael@0 419
michael@0 420 InfallibleTArray<int> ai;
michael@0 421 ai.AppendElement(1); ai.AppendElement(2); ai.AppendElement(3);
michael@0 422 assert_arrays_equal(ai, i.ai());
michael@0 423
michael@0 424 assert_arrays_equal(i.apParent(), mKids);
michael@0 425
michael@0 426 assert_arrays_equal(mKids, i.aa()[0].get_ArrayOfPTestDataStructuresSubParent());
michael@0 427
michael@0 428 const InfallibleTArray<Unions>& iau = i.au();
michael@0 429 test_assert(iau[0] == 42, "wrong value");
michael@0 430 assert_arrays_equal(ai, iau[1].get_ArrayOfint());
michael@0 431 assert_arrays_equal(mKids, iau[2].get_ArrayOfPTestDataStructuresSubParent());
michael@0 432 assert_arrays_equal(mKids,
michael@0 433 iau[3].get_ArrayOfActors()[0]
michael@0 434 .get_ArrayOfPTestDataStructuresSubParent());
michael@0 435
michael@0 436 *o = i;
michael@0 437
michael@0 438 return true;
michael@0 439 }
michael@0 440
michael@0 441 bool TestDataStructuresParent::RecvTest17(const InfallibleTArray<Op>& sa)
michael@0 442 {
michael@0 443 test_assert(sa.Length() == 1 && Op::TSetAttrs == sa[0].type(),
michael@0 444 "wrong value");
michael@0 445 return true;
michael@0 446 }
michael@0 447
michael@0 448 bool TestDataStructuresParent::RecvTest18(const RegionArray& ra)
michael@0 449 {
michael@0 450 for (RegionArray::index_type i = 0; i < ra.Length(); ++i) {
michael@0 451 nsIntRegionRectIterator it(ra[i]);
michael@0 452 // if |ra| has been realloc()d and given a different allocator
michael@0 453 // chunk, this next line will nondeterministically crash or
michael@0 454 // iloop
michael@0 455 while (const nsIntRect* sr = it.Next()) unused << sr;
michael@0 456 }
michael@0 457
michael@0 458 return true;
michael@0 459 }
michael@0 460
michael@0 461 //-----------------------------------------------------------------------------
michael@0 462 // child
michael@0 463
michael@0 464 TestDataStructuresChild::TestDataStructuresChild()
michael@0 465 {
michael@0 466 MOZ_COUNT_CTOR(TestDataStructuresChild);
michael@0 467 }
michael@0 468
michael@0 469 TestDataStructuresChild::~TestDataStructuresChild()
michael@0 470 {
michael@0 471 MOZ_COUNT_DTOR(TestDataStructuresChild);
michael@0 472 }
michael@0 473
michael@0 474 bool
michael@0 475 TestDataStructuresChild::RecvStart()
michael@0 476 {
michael@0 477 puts("[TestDataStructuresChild] starting");
michael@0 478
michael@0 479 Test1();
michael@0 480 Test2();
michael@0 481 Test3();
michael@0 482 Test4();
michael@0 483 Test5();
michael@0 484 Test6();
michael@0 485 Test7_0();
michael@0 486 Test7();
michael@0 487 Test8();
michael@0 488 Test9();
michael@0 489 Test10();
michael@0 490 Test11();
michael@0 491 Test12();
michael@0 492 Test13();
michael@0 493 Test14();
michael@0 494 Test15();
michael@0 495 Test16();
michael@0 496 Test17();
michael@0 497 if (OtherProcess() != 0) {
michael@0 498 //FIXME/bug 703317 allocation of nsIntRegion uses a global
michael@0 499 //region pool which breaks threads
michael@0 500 Test18();
michael@0 501 }
michael@0 502
michael@0 503 for (uint32_t i = 0; i < nactors; ++i)
michael@0 504 if (!PTestDataStructuresSubChild::Send__delete__(mKids[i]))
michael@0 505 fail("can't send dtor");
michael@0 506
michael@0 507 Close();
michael@0 508
michael@0 509 return true;
michael@0 510 }
michael@0 511
michael@0 512 void
michael@0 513 TestDataStructuresChild::Test1()
michael@0 514 {
michael@0 515 InfallibleTArray<int> ia;
michael@0 516
michael@0 517 for (int i = 0; i < 5; ++i)
michael@0 518 ia.AppendElement(i);
michael@0 519
michael@0 520 InfallibleTArray<int> oa;
michael@0 521 if (!SendTest1(ia, &oa))
michael@0 522 fail("can't send Test1");
michael@0 523
michael@0 524 assert_arrays_equal(ia, oa);
michael@0 525
michael@0 526 printf(" passed %s\n", __FUNCTION__);
michael@0 527 }
michael@0 528
michael@0 529 void
michael@0 530 TestDataStructuresChild::Test2()
michael@0 531 {
michael@0 532 InfallibleTArray<PTestDataStructuresSubChild*> oa;
michael@0 533 if (!SendTest2(mKids, &oa))
michael@0 534 fail("can't send Test2");
michael@0 535 assert_arrays_equal(mKids, oa);
michael@0 536
michael@0 537 printf(" passed %s\n", __FUNCTION__);
michael@0 538 }
michael@0 539
michael@0 540 void
michael@0 541 TestDataStructuresChild::Test3()
michael@0 542 {
michael@0 543 int i1i = 42;
michael@0 544 double i2d = 4.0;
michael@0 545 IntDouble i1(i1i);
michael@0 546 IntDouble i2(i2d);
michael@0 547 IntDouble o1, o2;
michael@0 548
michael@0 549 SendTest3(i1, i2, &o1, &o2);
michael@0 550
michael@0 551 test_assert(i1i == o1.get_int(), "wrong value");
michael@0 552 test_assert(i2d == o2.get_double(), "wrong value");
michael@0 553
michael@0 554 printf(" passed %s\n", __FUNCTION__);
michael@0 555 }
michael@0 556
michael@0 557 void
michael@0 558 TestDataStructuresChild::Test4()
michael@0 559 {
michael@0 560 InfallibleTArray<IntDouble> i1;
michael@0 561 i1.AppendElement(IntDouble(int(1)));
michael@0 562 i1.AppendElement(IntDouble(2.0));
michael@0 563 i1.AppendElement(IntDouble(int(3)));
michael@0 564 i1.AppendElement(IntDouble(4.0));
michael@0 565
michael@0 566 InfallibleTArray<IntDouble> o1;
michael@0 567 if (!SendTest4(i1, &o1))
michael@0 568 fail("can't send Test4");
michael@0 569
michael@0 570 // TODO Union::operator==()
michael@0 571 test_assert(i1.Length() == o1.Length(), "wrong length");
michael@0 572 test_assert(1 == o1[0].get_int(), "wrong value");
michael@0 573 test_assert(2.0 == o1[1].get_double(), "wrong value");
michael@0 574 test_assert(3 == o1[2].get_int(), "wrong value");
michael@0 575 test_assert(4.0 == o1[3].get_double(), "wrong value");
michael@0 576
michael@0 577 printf(" passed %s\n", __FUNCTION__);
michael@0 578 }
michael@0 579
michael@0 580 void
michael@0 581 TestDataStructuresChild::Test5()
michael@0 582 {
michael@0 583 IntDoubleArrays i1(int(42));
michael@0 584 InfallibleTArray<int> i2;
michael@0 585 i2.AppendElement(1); i2.AppendElement(2); i2.AppendElement(3);
michael@0 586 InfallibleTArray<double> i3;
michael@0 587 i3.AppendElement(1.0); i3.AppendElement(2.0); i3.AppendElement(3.0);
michael@0 588
michael@0 589 IntDoubleArrays o1, o2, o3;
michael@0 590 if (!SendTest5(i1, IntDoubleArrays(i2), IntDoubleArrays(i3),
michael@0 591 &o1, &o2, &o3))
michael@0 592 fail("can't send Test5");
michael@0 593
michael@0 594 test_assert(42 == o1.get_int(), "wrong value");
michael@0 595 assert_arrays_equal(i2, o2.get_ArrayOfint());
michael@0 596 assert_arrays_equal(i3, o3.get_ArrayOfdouble());
michael@0 597
michael@0 598 printf(" passed %s\n", __FUNCTION__);
michael@0 599 }
michael@0 600
michael@0 601 void
michael@0 602 TestDataStructuresChild::Test6()
michael@0 603 {
michael@0 604 IntDoubleArrays id1(int(42));
michael@0 605 InfallibleTArray<int> id2;
michael@0 606 id2.AppendElement(1); id2.AppendElement(2); id2.AppendElement(3);
michael@0 607 InfallibleTArray<double> id3;
michael@0 608 id3.AppendElement(1.0); id3.AppendElement(2.0); id3.AppendElement(3.0);
michael@0 609
michael@0 610 InfallibleTArray<IntDoubleArrays> i1;
michael@0 611 i1.AppendElement(id1);
michael@0 612 i1.AppendElement(IntDoubleArrays(id2));
michael@0 613 i1.AppendElement(IntDoubleArrays(id3));
michael@0 614
michael@0 615 InfallibleTArray<IntDoubleArrays> o1;
michael@0 616 if (!SendTest6(i1, &o1))
michael@0 617 fail("can't send Test6");
michael@0 618
michael@0 619 test_assert(3 == o1.Length(), "wrong length");
michael@0 620 IntDoubleArrays od1(o1[0]);
michael@0 621 InfallibleTArray<int> od2(o1[1].get_ArrayOfint());
michael@0 622 InfallibleTArray<double> od3(o1[2].get_ArrayOfdouble());
michael@0 623
michael@0 624 test_assert(42 == od1.get_int(), "wrong value");
michael@0 625 assert_arrays_equal(id2, od2);
michael@0 626 assert_arrays_equal(id3, od3);
michael@0 627
michael@0 628 printf(" passed %s\n", __FUNCTION__);
michael@0 629 }
michael@0 630
michael@0 631 void
michael@0 632 TestDataStructuresChild::Test7_0()
michael@0 633 {
michael@0 634 ActorWrapper iaw;
michael@0 635 if (iaw.actorChild() != nullptr || iaw.actorParent() != nullptr)
michael@0 636 fail("actor members should be null initially");
michael@0 637
michael@0 638 iaw.actorChild() = mKids[0];
michael@0 639 if (iaw.actorParent() != nullptr)
michael@0 640 fail("parent should be null on child side after set");
michael@0 641
michael@0 642 ActorWrapper oaw;
michael@0 643 if (!SendTest7_0(iaw, &oaw))
michael@0 644 fail("sending Test7_0");
michael@0 645
michael@0 646 if (oaw.actorParent() != nullptr)
michael@0 647 fail("parent accessor on actor-struct members should always be null in child");
michael@0 648
michael@0 649 if (oaw.actorChild() != mKids[0])
michael@0 650 fail("should have got back same child-side actor");
michael@0 651 }
michael@0 652
michael@0 653 void
michael@0 654 TestDataStructuresChild::Test7()
michael@0 655 {
michael@0 656 Actors i1(42);
michael@0 657 InfallibleTArray<int> i2a;
michael@0 658 i2a.AppendElement(1); i2a.AppendElement(2); i2a.AppendElement(3);
michael@0 659
michael@0 660 Actors o1, o2, o3;
michael@0 661 if (!SendTest7(i1, Actors(i2a), Actors(mKids), &o1, &o2, &o3))
michael@0 662 fail("can't send Test7");
michael@0 663
michael@0 664 test_assert(42 == o1.get_int(), "wrong value");
michael@0 665 assert_arrays_equal(i2a, o2.get_ArrayOfint());
michael@0 666 assert_arrays_equal(mKids, o3.get_ArrayOfPTestDataStructuresSubChild());
michael@0 667
michael@0 668 printf(" passed %s\n", __FUNCTION__);
michael@0 669 }
michael@0 670
michael@0 671 void
michael@0 672 TestDataStructuresChild::Test8()
michael@0 673 {
michael@0 674 Actors i1e(42);
michael@0 675 InfallibleTArray<int> i2a;
michael@0 676 i2a.AppendElement(1); i2a.AppendElement(2); i2a.AppendElement(3);
michael@0 677
michael@0 678 InfallibleTArray<Actors> i1;
michael@0 679 i1.AppendElement(i1e);
michael@0 680 i1.AppendElement(i2a);
michael@0 681 i1.AppendElement(mKids);
michael@0 682
michael@0 683 InfallibleTArray<Actors> o1;
michael@0 684 if (!SendTest8(i1, &o1))
michael@0 685 fail("can't send Test8");
michael@0 686
michael@0 687 test_assert(3 == o1.Length(), "wrong length");
michael@0 688 test_assert(42 == o1[0].get_int(), "wrong value");
michael@0 689 assert_arrays_equal(i2a, o1[1].get_ArrayOfint());
michael@0 690 assert_arrays_equal(mKids, o1[2].get_ArrayOfPTestDataStructuresSubChild());
michael@0 691
michael@0 692 printf(" passed %s\n", __FUNCTION__);
michael@0 693 }
michael@0 694
michael@0 695 void
michael@0 696 TestDataStructuresChild::Test9()
michael@0 697 {
michael@0 698 Unions i1(int(42));
michael@0 699
michael@0 700 InfallibleTArray<int> i2a;
michael@0 701 i2a.AppendElement(1);
michael@0 702 i2a.AppendElement(2);
michael@0 703 i2a.AppendElement(3);
michael@0 704
michael@0 705 InfallibleTArray<Actors> i4a;
michael@0 706 i4a.AppendElement(mKids);
michael@0 707
michael@0 708 Unions o1, o2, o3, o4;
michael@0 709 if (!SendTest9(i1, Unions(i2a), Unions(mKids), Unions(i4a),
michael@0 710 &o1, &o2, &o3, &o4))
michael@0 711 fail("can't send Test9");
michael@0 712
michael@0 713 test_assert(42 == o1.get_int(), "wrong value");
michael@0 714 assert_arrays_equal(i2a, o2.get_ArrayOfint());
michael@0 715 assert_arrays_equal(mKids, o3.get_ArrayOfPTestDataStructuresSubChild());
michael@0 716 assert_arrays_equal(
michael@0 717 mKids,
michael@0 718 o4.get_ArrayOfActors()[0].get_ArrayOfPTestDataStructuresSubChild());
michael@0 719
michael@0 720 printf(" passed %s\n", __FUNCTION__);
michael@0 721 }
michael@0 722
michael@0 723 void
michael@0 724 TestDataStructuresChild::Test10()
michael@0 725 {
michael@0 726 Unions i1a(int(42));
michael@0 727
michael@0 728 InfallibleTArray<int> i2a;
michael@0 729 i2a.AppendElement(1);
michael@0 730 i2a.AppendElement(2);
michael@0 731 i2a.AppendElement(3);
michael@0 732
michael@0 733 InfallibleTArray<Actors> i4a;
michael@0 734 i4a.AppendElement(mKids);
michael@0 735
michael@0 736 InfallibleTArray<Unions> i1;
michael@0 737 i1.AppendElement(i1a);
michael@0 738 i1.AppendElement(Unions(i2a));
michael@0 739 i1.AppendElement(Unions(mKids));
michael@0 740 i1.AppendElement(Unions(i4a));
michael@0 741
michael@0 742 InfallibleTArray<Unions> o1;
michael@0 743 if (!SendTest10(i1, &o1))
michael@0 744 fail("can't send Test10");
michael@0 745
michael@0 746 test_assert(4 == o1.Length(), "wrong length");
michael@0 747 test_assert(42 == o1[0].get_int(), "wrong value");
michael@0 748 assert_arrays_equal(i2a, o1[1].get_ArrayOfint());
michael@0 749 assert_arrays_equal(mKids, o1[2].get_ArrayOfPTestDataStructuresSubChild());
michael@0 750 assert_arrays_equal(
michael@0 751 mKids,
michael@0 752 o1[3].get_ArrayOfActors()[0].get_ArrayOfPTestDataStructuresSubChild());
michael@0 753
michael@0 754 printf(" passed %s\n", __FUNCTION__);
michael@0 755 }
michael@0 756
michael@0 757 void
michael@0 758 TestDataStructuresChild::Test11()
michael@0 759 {
michael@0 760 SIntDouble i(1, 2.0);
michael@0 761 SIntDouble o;
michael@0 762
michael@0 763 if (!SendTest11(i, &o))
michael@0 764 fail("sending Test11");
michael@0 765
michael@0 766 test_assert(1 == o.i() && 2.0 == o.d(), "wrong values");
michael@0 767
michael@0 768 printf(" passed %s\n", __FUNCTION__);
michael@0 769 }
michael@0 770
michael@0 771 void
michael@0 772 TestDataStructuresChild::Test12()
michael@0 773 {
michael@0 774 InfallibleTArray<int> ai;
michael@0 775 ai.AppendElement(1); ai.AppendElement(2); ai.AppendElement(3);
michael@0 776
michael@0 777 InfallibleTArray<double> ad;
michael@0 778 ad.AppendElement(.5); ad.AppendElement(1.0); ad.AppendElement(2.0);
michael@0 779
michael@0 780 SIntDoubleArrays i(42, ai, ad);
michael@0 781 SIntDoubleArrays o;
michael@0 782
michael@0 783 if (!SendTest12(i, &o))
michael@0 784 fail("sending Test12");
michael@0 785
michael@0 786 test_assert(42 == o.i(), "wrong value");
michael@0 787 assert_arrays_equal(ai, o.ai());
michael@0 788 assert_arrays_equal(ad, o.ad());
michael@0 789
michael@0 790 printf(" passed %s\n", __FUNCTION__);
michael@0 791 }
michael@0 792
michael@0 793 void
michael@0 794 TestDataStructuresChild::Test13()
michael@0 795 {
michael@0 796 InfallibleTArray<int> ai;
michael@0 797 ai.AppendElement(1); ai.AppendElement(2); ai.AppendElement(3);
michael@0 798
michael@0 799 SActors i;
michael@0 800 i.i() = 42;
michael@0 801 i.ai() = ai;
michael@0 802 i.apChild() = mKids;
michael@0 803
michael@0 804 SActors o;
michael@0 805 if (!SendTest13(i, &o))
michael@0 806 fail("can't send Test13");
michael@0 807
michael@0 808 test_assert(42 == o.i(), "wrong value");
michael@0 809 assert_arrays_equal(ai, o.ai());
michael@0 810 assert_arrays_equal(mKids, o.apChild());
michael@0 811
michael@0 812 printf(" passed %s\n", __FUNCTION__);
michael@0 813 }
michael@0 814
michael@0 815 void
michael@0 816 TestDataStructuresChild::Test14()
michael@0 817 {
michael@0 818 InfallibleTArray<int> ai;
michael@0 819 ai.AppendElement(1); ai.AppendElement(2); ai.AppendElement(3);
michael@0 820
michael@0 821 SActors ia;
michael@0 822 ia.i() = 42;
michael@0 823 ia.ai() = ai;
michael@0 824 ia.apChild() = mKids;
michael@0 825 InfallibleTArray<SActors> aa; aa.AppendElement(ia);
michael@0 826
michael@0 827 Structs i;
michael@0 828 i.i() = 42;
michael@0 829 i.ai() = ai;
michael@0 830 i.apChild() = mKids;
michael@0 831 i.aa() = aa;
michael@0 832
michael@0 833 Structs o;
michael@0 834 if (!SendTest14(i, &o))
michael@0 835 fail("can't send Test14");
michael@0 836
michael@0 837 test_assert(42 == o.i(), "wrong value");
michael@0 838 assert_arrays_equal(ai, o.ai());
michael@0 839 assert_arrays_equal(mKids, o.apChild());
michael@0 840
michael@0 841 const SActors& os = o.aa()[0];
michael@0 842 test_assert(42 == os.i(), "wrong value");
michael@0 843 assert_arrays_equal(ai, os.ai());
michael@0 844 assert_arrays_equal(mKids, os.apChild());
michael@0 845
michael@0 846 printf(" passed %s\n", __FUNCTION__);
michael@0 847 }
michael@0 848
michael@0 849 void
michael@0 850 TestDataStructuresChild::Test15()
michael@0 851 {
michael@0 852 InfallibleTArray<int> ai;
michael@0 853 ai.AppendElement(1); ai.AppendElement(2); ai.AppendElement(3);
michael@0 854
michael@0 855 SActors ia;
michael@0 856 ia.i() = 42;
michael@0 857 ia.ai() = ai;
michael@0 858 ia.apChild() = mKids;
michael@0 859 InfallibleTArray<SActors> iaa; iaa.AppendElement(ia);
michael@0 860
michael@0 861 Structs is;
michael@0 862 is.i() = 42;
michael@0 863 is.ai() = ai;
michael@0 864 is.apChild() = mKids;
michael@0 865 is.aa() = iaa;
michael@0 866 InfallibleTArray<Structs> isa; isa.AppendElement(is);
michael@0 867
michael@0 868 WithStructs o1, o2, o3, o4, o5;
michael@0 869 if (!SendTest15(WithStructs(42),
michael@0 870 WithStructs(ai),
michael@0 871 WithStructs(mKids),
michael@0 872 WithStructs(iaa),
michael@0 873 WithStructs(isa),
michael@0 874 &o1, &o2, &o3, &o4, &o5))
michael@0 875 fail("sending Test15");
michael@0 876
michael@0 877 test_assert(o1 == int(42), "wrong value");
michael@0 878 assert_arrays_equal(o2.get_ArrayOfint(), ai);
michael@0 879 assert_arrays_equal(o3.get_ArrayOfPTestDataStructuresSubChild(), mKids);
michael@0 880
michael@0 881 const SActors& oa = o4.get_ArrayOfSActors()[0];
michael@0 882 test_assert(42 == oa.i(), "wrong value");
michael@0 883 assert_arrays_equal(ai, oa.ai());
michael@0 884 assert_arrays_equal(mKids, oa.apChild());
michael@0 885
michael@0 886 const Structs& os = o5.get_ArrayOfStructs()[0];
michael@0 887 test_assert(42 == os.i(), "wrong value");
michael@0 888 assert_arrays_equal(ai, os.ai());
michael@0 889 assert_arrays_equal(mKids, os.apChild());
michael@0 890
michael@0 891 const SActors& osa = os.aa()[0];
michael@0 892 test_assert(42 == osa.i(), "wrong value");
michael@0 893 assert_arrays_equal(ai, osa.ai());
michael@0 894 assert_arrays_equal(mKids, osa.apChild());
michael@0 895
michael@0 896 printf(" passed %s\n", __FUNCTION__);
michael@0 897 }
michael@0 898
michael@0 899 void
michael@0 900 TestDataStructuresChild::Test16()
michael@0 901 {
michael@0 902 WithUnions i;
michael@0 903
michael@0 904 i.i() = 42;
michael@0 905
michael@0 906 InfallibleTArray<int> ai;
michael@0 907 ai.AppendElement(1); ai.AppendElement(2); ai.AppendElement(3);
michael@0 908 i.ai() = ai;
michael@0 909
michael@0 910 i.apChild() = mKids;
michael@0 911
michael@0 912 InfallibleTArray<Actors> iaa;
michael@0 913 iaa.AppendElement(mKids);
michael@0 914 i.aa() = iaa;
michael@0 915
michael@0 916 InfallibleTArray<Unions> iau;
michael@0 917 iau.AppendElement(int(42));
michael@0 918 iau.AppendElement(ai);
michael@0 919 iau.AppendElement(mKids);
michael@0 920 iau.AppendElement(iaa);
michael@0 921 i.au() = iau;
michael@0 922
michael@0 923 WithUnions o;
michael@0 924 if (!SendTest16(i, &o))
michael@0 925 fail("sending Test16");
michael@0 926
michael@0 927 test_assert(42 == o.i(), "wrong value");
michael@0 928 assert_arrays_equal(o.ai(), ai);
michael@0 929 assert_arrays_equal(o.apChild(), mKids);
michael@0 930
michael@0 931 const Actors& oaa = o.aa()[0];
michael@0 932 assert_arrays_equal(oaa.get_ArrayOfPTestDataStructuresSubChild(), mKids);
michael@0 933
michael@0 934 const InfallibleTArray<Unions>& oau = o.au();
michael@0 935 test_assert(oau[0] == 42, "wrong value");
michael@0 936 assert_arrays_equal(oau[1].get_ArrayOfint(), ai);
michael@0 937 assert_arrays_equal(oau[2].get_ArrayOfPTestDataStructuresSubChild(),
michael@0 938 mKids);
michael@0 939 assert_arrays_equal(oau[3].get_ArrayOfActors()[0]
michael@0 940 .get_ArrayOfPTestDataStructuresSubChild(),
michael@0 941 mKids);
michael@0 942
michael@0 943 printf(" passed %s\n", __FUNCTION__);
michael@0 944 }
michael@0 945
michael@0 946 void
michael@0 947 TestDataStructuresChild::Test17()
michael@0 948 {
michael@0 949 Attrs attrs;
michael@0 950 attrs.common() = CommonAttrs(true);
michael@0 951 attrs.specific() = BarAttrs(1.0f);
michael@0 952
michael@0 953 InfallibleTArray<Op> ops;
michael@0 954 ops.AppendElement(SetAttrs(nullptr, mKids[0], attrs));
michael@0 955
michael@0 956 if (!SendTest17(ops))
michael@0 957 fail("sending Test17");
michael@0 958
michael@0 959 printf(" passed %s\n", __FUNCTION__);
michael@0 960 }
michael@0 961
michael@0 962 void
michael@0 963 TestDataStructuresChild::Test18()
michael@0 964 {
michael@0 965 const int nelements = 1000;
michael@0 966 RegionArray ra;
michael@0 967 // big enough to hopefully force a realloc to a different chunk of
michael@0 968 // memory on the receiving side, if the workaround isn't working
michael@0 969 // correctly. But SetCapacity() here because we don't want to
michael@0 970 // crash on the sending side.
michael@0 971 ra.SetCapacity(nelements);
michael@0 972 for (int i = 0; i < nelements; ++i) {
michael@0 973 nsIntRegion r;
michael@0 974 r = r.Or(nsIntRect(0, 0, 10, 10), nsIntRect(10, 10, 10, 10));
michael@0 975 ra.AppendElement(r);
michael@0 976 }
michael@0 977
michael@0 978 if (!SendTest18(ra))
michael@0 979 fail("sending Test18");
michael@0 980
michael@0 981 printf(" passed %s\n", __FUNCTION__);
michael@0 982 }
michael@0 983
michael@0 984 } // namespace _ipdltest
michael@0 985 } // namespace mozilla

mercurial