xpcom/tests/TestAutoPtr.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 // vim:cindent:ts=4:et:sw=4:
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "nsAutoPtr.h"
michael@0 8 #include <stdio.h>
michael@0 9 #include "nscore.h"
michael@0 10 #include "mozilla/Attributes.h"
michael@0 11
michael@0 12 class TestObjectBaseA {
michael@0 13 public:
michael@0 14 // Virtual dtor for deleting through base class pointer
michael@0 15 virtual ~TestObjectBaseA() { }
michael@0 16 int fooA;
michael@0 17 };
michael@0 18
michael@0 19 class TestObjectBaseB {
michael@0 20 public:
michael@0 21 // Virtual dtor for deleting through base class pointer
michael@0 22 virtual ~TestObjectBaseB() { }
michael@0 23 int fooB;
michael@0 24 };
michael@0 25
michael@0 26 class TestObject : public TestObjectBaseA, public TestObjectBaseB {
michael@0 27 public:
michael@0 28 TestObject()
michael@0 29 {
michael@0 30 printf(" Creating TestObject %p.\n",
michael@0 31 static_cast<void*>(this));
michael@0 32 }
michael@0 33
michael@0 34 // Virtual dtor for deleting through base class pointer
michael@0 35 virtual ~TestObject()
michael@0 36 {
michael@0 37 printf(" Destroying TestObject %p.\n",
michael@0 38 static_cast<void*>(this));
michael@0 39 }
michael@0 40 };
michael@0 41
michael@0 42 class TestRefObjectBaseA {
michael@0 43 public:
michael@0 44 int fooA;
michael@0 45 // Must return |nsrefcnt| to keep |nsDerivedSafe| happy.
michael@0 46 virtual nsrefcnt AddRef() = 0;
michael@0 47 virtual nsrefcnt Release() = 0;
michael@0 48 };
michael@0 49
michael@0 50 class TestRefObjectBaseB {
michael@0 51 public:
michael@0 52 int fooB;
michael@0 53 virtual nsrefcnt AddRef() = 0;
michael@0 54 virtual nsrefcnt Release() = 0;
michael@0 55 };
michael@0 56
michael@0 57 class TestRefObject MOZ_FINAL : public TestRefObjectBaseA, public TestRefObjectBaseB {
michael@0 58 public:
michael@0 59 TestRefObject()
michael@0 60 : mRefCount(0)
michael@0 61 {
michael@0 62 printf(" Creating TestRefObject %p.\n",
michael@0 63 static_cast<void*>(this));
michael@0 64 }
michael@0 65
michael@0 66 ~TestRefObject()
michael@0 67 {
michael@0 68 printf(" Destroying TestRefObject %p.\n",
michael@0 69 static_cast<void*>(this));
michael@0 70 }
michael@0 71
michael@0 72 nsrefcnt AddRef()
michael@0 73 {
michael@0 74 ++mRefCount;
michael@0 75 printf(" AddRef to %d on TestRefObject %p.\n",
michael@0 76 mRefCount, static_cast<void*>(this));
michael@0 77 return mRefCount;
michael@0 78 }
michael@0 79
michael@0 80 nsrefcnt Release()
michael@0 81 {
michael@0 82 --mRefCount;
michael@0 83 printf(" Release to %d on TestRefObject %p.\n",
michael@0 84 mRefCount, static_cast<void*>(this));
michael@0 85 if (mRefCount == 0) {
michael@0 86 delete const_cast<TestRefObject*>(this);
michael@0 87 return 0;
michael@0 88 }
michael@0 89 return mRefCount;
michael@0 90 }
michael@0 91
michael@0 92 protected:
michael@0 93 uint32_t mRefCount;
michael@0 94
michael@0 95 };
michael@0 96
michael@0 97 static void CreateTestObject(TestObject **aResult)
michael@0 98 {
michael@0 99 *aResult = new TestObject();
michael@0 100 }
michael@0 101
michael@0 102 static void CreateTestRefObject(TestRefObject **aResult)
michael@0 103 {
michael@0 104 (*aResult = new TestRefObject())->AddRef();
michael@0 105 }
michael@0 106
michael@0 107 static void DoSomethingWithTestObject(TestObject *aIn)
michael@0 108 {
michael@0 109 printf(" Doing something with |TestObject| %p.\n",
michael@0 110 static_cast<void*>(aIn));
michael@0 111 }
michael@0 112
michael@0 113 static void DoSomethingWithConstTestObject(const TestObject *aIn)
michael@0 114 {
michael@0 115 printf(" Doing something with |const TestObject| %p.\n",
michael@0 116 static_cast<const void*>(aIn));
michael@0 117 }
michael@0 118
michael@0 119 static void DoSomethingWithTestRefObject(TestRefObject *aIn)
michael@0 120 {
michael@0 121 printf(" Doing something with |TestRefObject| %p.\n",
michael@0 122 static_cast<void*>(aIn));
michael@0 123 }
michael@0 124
michael@0 125 static void DoSomethingWithConstTestRefObject(const TestRefObject *aIn)
michael@0 126 {
michael@0 127 printf(" Doing something with |const TestRefObject| %p.\n",
michael@0 128 static_cast<const void*>(aIn));
michael@0 129 }
michael@0 130
michael@0 131 static void DoSomethingWithTestObjectBaseB(TestObjectBaseB *aIn)
michael@0 132 {
michael@0 133 printf(" Doing something with |TestObjectBaseB| %p.\n",
michael@0 134 static_cast<void*>(aIn));
michael@0 135 }
michael@0 136
michael@0 137 static void DoSomethingWithConstTestObjectBaseB(const TestObjectBaseB *aIn)
michael@0 138 {
michael@0 139 printf(" Doing something with |const TestObjectBaseB| %p.\n",
michael@0 140 static_cast<const void*>(aIn));
michael@0 141 }
michael@0 142
michael@0 143 static void DoSomethingWithTestRefObjectBaseB(TestRefObjectBaseB *aIn)
michael@0 144 {
michael@0 145 printf(" Doing something with |TestRefObjectBaseB| %p.\n",
michael@0 146 static_cast<void*>(aIn));
michael@0 147 }
michael@0 148
michael@0 149 static void DoSomethingWithConstTestRefObjectBaseB(const TestRefObjectBaseB *aIn)
michael@0 150 {
michael@0 151 printf(" Doing something with |const TestRefObjectBaseB| %p.\n",
michael@0 152 static_cast<const void*>(aIn));
michael@0 153 }
michael@0 154
michael@0 155 int main()
michael@0 156 {
michael@0 157 {
michael@0 158 printf("Should create one |TestObject|:\n");
michael@0 159 nsAutoPtr<TestObject> pobj( new TestObject() );
michael@0 160 printf("Should destroy one |TestObject|:\n");
michael@0 161 }
michael@0 162
michael@0 163 {
michael@0 164 printf("Should create one |TestObject|:\n");
michael@0 165 nsAutoPtr<TestObject> pobj( new TestObject() );
michael@0 166 printf("Should create one |TestObject| and then destroy one:\n");
michael@0 167 pobj = new TestObject();
michael@0 168 printf("Should destroy one |TestObject|:\n");
michael@0 169 }
michael@0 170
michael@0 171 {
michael@0 172 printf("Should create 3 |TestObject|s:\n");
michael@0 173 nsAutoArrayPtr<TestObject> pobj( new TestObject[3] );
michael@0 174 printf("Should create 5 |TestObject|s and then destroy 3:\n");
michael@0 175 pobj = new TestObject[5];
michael@0 176 printf("Should destroy 5 |TestObject|s:\n");
michael@0 177 }
michael@0 178
michael@0 179 {
michael@0 180 printf("Should create and AddRef one |TestRefObject|:\n");
michael@0 181 nsRefPtr<TestRefObject> pobj( new TestRefObject() );
michael@0 182 printf("Should Release and destroy one |TestRefObject|:\n");
michael@0 183 }
michael@0 184
michael@0 185 {
michael@0 186 printf("Should create and AddRef one |TestRefObject|:\n");
michael@0 187 nsRefPtr<TestRefObject> pobj( new TestRefObject() );
michael@0 188 printf("Should create and AddRef one |TestRefObject| and then Release and destroy one:\n");
michael@0 189 pobj = new TestRefObject();
michael@0 190 printf("Should Release and destroy one |TestRefObject|:\n");
michael@0 191 }
michael@0 192
michael@0 193 {
michael@0 194 printf("Should create and AddRef one |TestRefObject|:\n");
michael@0 195 nsRefPtr<TestRefObject> p1( new TestRefObject() );
michael@0 196 printf("Should AddRef one |TestRefObject|:\n");
michael@0 197 nsRefPtr<TestRefObject> p2( p1 );
michael@0 198 printf("Should Release twice and destroy one |TestRefObject|:\n");
michael@0 199 }
michael@0 200
michael@0 201 printf("\nTesting equality (with all const-ness combinations):\n");
michael@0 202
michael@0 203 {
michael@0 204 nsRefPtr<TestRefObject> p1( new TestRefObject() );
michael@0 205 nsRefPtr<TestRefObject> p2( p1 );
michael@0 206 printf("equality %s.\n",
michael@0 207 ((p1 == p2) && !(p1 != p2)) ? "OK" : "broken");
michael@0 208 }
michael@0 209
michael@0 210 {
michael@0 211 const nsRefPtr<TestRefObject> p1( new TestRefObject() );
michael@0 212 nsRefPtr<TestRefObject> p2( p1 );
michael@0 213 printf("equality %s.\n",
michael@0 214 ((p1 == p2) && !(p1 != p2)) ? "OK" : "broken");
michael@0 215 }
michael@0 216
michael@0 217 {
michael@0 218 nsRefPtr<TestRefObject> p1( new TestRefObject() );
michael@0 219 const nsRefPtr<TestRefObject> p2( p1 );
michael@0 220 printf("equality %s.\n",
michael@0 221 ((p1 == p2) && !(p1 != p2)) ? "OK" : "broken");
michael@0 222 }
michael@0 223
michael@0 224 {
michael@0 225 const nsRefPtr<TestRefObject> p1( new TestRefObject() );
michael@0 226 const nsRefPtr<TestRefObject> p2( p1 );
michael@0 227 printf("equality %s.\n",
michael@0 228 ((p1 == p2) && !(p1 != p2)) ? "OK" : "broken");
michael@0 229 }
michael@0 230
michael@0 231 {
michael@0 232 nsRefPtr<TestRefObject> p1( new TestRefObject() );
michael@0 233 TestRefObject * p2 = p1;
michael@0 234 printf("equality %s.\n",
michael@0 235 ((p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken");
michael@0 236 }
michael@0 237
michael@0 238 {
michael@0 239 const nsRefPtr<TestRefObject> p1( new TestRefObject() );
michael@0 240 TestRefObject * p2 = p1;
michael@0 241 printf("equality %s.\n",
michael@0 242 ((p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken");
michael@0 243 }
michael@0 244
michael@0 245 #if 0 /* MSVC++ 6.0 can't be coaxed to accept this */
michael@0 246 {
michael@0 247 nsRefPtr<TestRefObject> p1( new TestRefObject() );
michael@0 248 TestRefObject * const p2 = p1;
michael@0 249 printf("equality %s.\n",
michael@0 250 ((p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken");
michael@0 251 }
michael@0 252
michael@0 253 {
michael@0 254 const nsRefPtr<TestRefObject> p1( new TestRefObject() );
michael@0 255 TestRefObject * const p2 = p1;
michael@0 256 printf("equality %s.\n",
michael@0 257 ((p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken");
michael@0 258 }
michael@0 259 #endif /* Things that MSVC++ 6.0 can't be coaxed to accept */
michael@0 260
michael@0 261 {
michael@0 262 nsRefPtr<TestRefObject> p1( new TestRefObject() );
michael@0 263 const TestRefObject * p2 = p1;
michael@0 264 printf("equality %s.\n",
michael@0 265 ((p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken");
michael@0 266 }
michael@0 267
michael@0 268 {
michael@0 269 const nsRefPtr<TestRefObject> p1( new TestRefObject() );
michael@0 270 const TestRefObject * p2 = p1;
michael@0 271 printf("equality %s.\n",
michael@0 272 ((p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken");
michael@0 273 }
michael@0 274
michael@0 275 {
michael@0 276 nsRefPtr<TestRefObject> p1( new TestRefObject() );
michael@0 277 const TestRefObject * const p2 = p1;
michael@0 278 printf("equality %s.\n",
michael@0 279 ((p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken");
michael@0 280 }
michael@0 281
michael@0 282 {
michael@0 283 const nsRefPtr<TestRefObject> p1( new TestRefObject() );
michael@0 284 const TestRefObject * const p2 = p1;
michael@0 285 printf("equality %s.\n",
michael@0 286 ((p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken");
michael@0 287 }
michael@0 288
michael@0 289 printf("\nTesting getter_Transfers and getter_AddRefs.\n");
michael@0 290
michael@0 291 {
michael@0 292 nsAutoPtr<TestObject> ptr;
michael@0 293 printf("Should create one |TestObject|:\n");
michael@0 294 CreateTestObject(getter_Transfers(ptr));
michael@0 295 printf("Should destroy one |TestObject|:\n");
michael@0 296 }
michael@0 297
michael@0 298 {
michael@0 299 nsRefPtr<TestRefObject> ptr;
michael@0 300 printf("Should create and AddRef one |TestRefObject|:\n");
michael@0 301 CreateTestRefObject(getter_AddRefs(ptr));
michael@0 302 printf("Should Release and destroy one |TestRefObject|:\n");
michael@0 303 }
michael@0 304
michael@0 305 printf("\nTesting casts and equality tests.\n");
michael@0 306
michael@0 307 if ((void*)(TestObject*)0x1000 ==
michael@0 308 (void*)(TestObjectBaseB*)(TestObject*)0x1000)
michael@0 309 printf("\n\nAll these tests are meaningless!\n\n\n");
michael@0 310
michael@0 311 {
michael@0 312 nsAutoPtr<TestObject> p1(new TestObject());
michael@0 313 TestObjectBaseB *p2 = p1;
michael@0 314 printf("equality %s.\n",
michael@0 315 ((static_cast<void*>(p1) != static_cast<void*>(p2)) &&
michael@0 316 (p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1))
michael@0 317 ? "OK" : "broken");
michael@0 318 }
michael@0 319
michael@0 320 {
michael@0 321 TestObject *p1 = new TestObject();
michael@0 322 nsAutoPtr<TestObjectBaseB> p2(p1);
michael@0 323 printf("equality %s.\n",
michael@0 324 ((static_cast<void*>(p1) != static_cast<void*>(p2)) &&
michael@0 325 (p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1))
michael@0 326 ? "OK" : "broken");
michael@0 327 }
michael@0 328
michael@0 329 {
michael@0 330 nsRefPtr<TestRefObject> p1 = new TestRefObject();
michael@0 331 // nsCOMPtr requires a |get| for something like this as well
michael@0 332 nsRefPtr<TestRefObjectBaseB> p2 = p1.get();
michael@0 333 printf("equality %s.\n",
michael@0 334 ((static_cast<void*>(p1) != static_cast<void*>(p2)) &&
michael@0 335 (p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1))
michael@0 336 ? "OK" : "broken");
michael@0 337 }
michael@0 338
michael@0 339 {
michael@0 340 nsRefPtr<TestRefObject> p1 = new TestRefObject();
michael@0 341 TestRefObjectBaseB *p2 = p1;
michael@0 342 printf("equality %s.\n",
michael@0 343 ((static_cast<void*>(p1) != static_cast<void*>(p2)) &&
michael@0 344 (p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1))
michael@0 345 ? "OK" : "broken");
michael@0 346 }
michael@0 347
michael@0 348 {
michael@0 349 TestRefObject *p1 = new TestRefObject();
michael@0 350 nsRefPtr<TestRefObjectBaseB> p2 = p1;
michael@0 351 printf("equality %s.\n",
michael@0 352 ((static_cast<void*>(p1) != static_cast<void*>(p2)) &&
michael@0 353 (p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1))
michael@0 354 ? "OK" : "broken");
michael@0 355 }
michael@0 356
michael@0 357 printf("\nTesting |forget()|.\n");
michael@0 358
michael@0 359 {
michael@0 360 printf("Should create one |TestObject|:\n");
michael@0 361 nsAutoPtr<TestObject> pobj( new TestObject() );
michael@0 362 printf("Should do nothing:\n");
michael@0 363 nsAutoPtr<TestObject> pobj2( pobj.forget() );
michael@0 364 printf("Should destroy one |TestObject|:\n");
michael@0 365 }
michael@0 366
michael@0 367 {
michael@0 368 printf("Should create 3 |TestObject|s:\n");
michael@0 369 nsAutoArrayPtr<TestObject> pobj( new TestObject[3] );
michael@0 370 printf("Should do nothing:\n");
michael@0 371 nsAutoArrayPtr<TestObject> pobj2( pobj.forget() );
michael@0 372 printf("Should destroy 3 |TestObject|s:\n");
michael@0 373 }
michael@0 374
michael@0 375 {
michael@0 376 printf("Should create one |TestRefObject|:\n");
michael@0 377 nsRefPtr<TestRefObject> pobj( new TestRefObject() );
michael@0 378 printf("Should do nothing:\n");
michael@0 379 nsRefPtr<TestRefObject> pobj2( pobj.forget() );
michael@0 380 printf("Should destroy one |TestRefObject|:\n");
michael@0 381 }
michael@0 382
michael@0 383
michael@0 384 printf("\nTesting construction.\n");
michael@0 385
michael@0 386 {
michael@0 387 printf("Should create one |TestObject|:\n");
michael@0 388 nsAutoPtr<TestObject> pobj(new TestObject());
michael@0 389 printf("Should destroy one |TestObject|:\n");
michael@0 390 }
michael@0 391
michael@0 392 {
michael@0 393 printf("Should create 3 |TestObject|s:\n");
michael@0 394 nsAutoArrayPtr<TestObject> pobj(new TestObject[3]);
michael@0 395 printf("Should destroy 3 |TestObject|s:\n");
michael@0 396 }
michael@0 397
michael@0 398 {
michael@0 399 printf("Should create and AddRef one |TestRefObject|:\n");
michael@0 400 nsRefPtr<TestRefObject> pobj = new TestRefObject();
michael@0 401 printf("Should Release and destroy one |TestRefObject|:\n");
michael@0 402 }
michael@0 403
michael@0 404 printf("\nTesting calling of functions (including array access and casts).\n");
michael@0 405
michael@0 406 {
michael@0 407 printf("Should create one |TestObject|:\n");
michael@0 408 nsAutoPtr<TestObject> pobj(new TestObject());
michael@0 409 printf("Should do something with one |TestObject|:\n");
michael@0 410 DoSomethingWithTestObject(pobj);
michael@0 411 printf("Should do something with one |TestObject|:\n");
michael@0 412 DoSomethingWithConstTestObject(pobj);
michael@0 413 printf("Should destroy one |TestObject|:\n");
michael@0 414 }
michael@0 415
michael@0 416 {
michael@0 417 printf("Should create 3 |TestObject|s:\n");
michael@0 418 nsAutoArrayPtr<TestObject> pobj(new TestObject[3]);
michael@0 419 printf("Should do something with one |TestObject|:\n");
michael@0 420 DoSomethingWithTestObject(&pobj[2]);
michael@0 421 printf("Should do something with one |TestObject|:\n");
michael@0 422 DoSomethingWithConstTestObject(&pobj[1]);
michael@0 423 printf("Should do something with one |TestObject|:\n");
michael@0 424 DoSomethingWithTestObject(pobj + 2);
michael@0 425 printf("Should do something with one |TestObject|:\n");
michael@0 426 DoSomethingWithConstTestObject(pobj + 1);
michael@0 427 printf("Should destroy 3 |TestObject|s:\n");
michael@0 428 }
michael@0 429
michael@0 430 {
michael@0 431 printf("Should create and AddRef one |TestRefObject|:\n");
michael@0 432 nsRefPtr<TestRefObject> pobj = new TestRefObject();
michael@0 433 printf("Should do something with one |TestRefObject|:\n");
michael@0 434 DoSomethingWithTestRefObject(pobj);
michael@0 435 printf("Should do something with one |TestRefObject|:\n");
michael@0 436 DoSomethingWithConstTestRefObject(pobj);
michael@0 437 printf("Should Release and destroy one |TestRefObject|:\n");
michael@0 438 }
michael@0 439
michael@0 440 {
michael@0 441 printf("Should create one |TestObject|:\n");
michael@0 442 nsAutoPtr<TestObject> pobj(new TestObject());
michael@0 443 printf("Should do something with one |TestObject|:\n");
michael@0 444 DoSomethingWithTestObjectBaseB(pobj);
michael@0 445 printf("Should do something with one |TestObject|:\n");
michael@0 446 DoSomethingWithConstTestObjectBaseB(pobj);
michael@0 447 printf("Should destroy one |TestObject|:\n");
michael@0 448 }
michael@0 449
michael@0 450 {
michael@0 451 printf("Should create 3 |TestObject|s:\n");
michael@0 452 nsAutoArrayPtr<TestObject> pobj(new TestObject[3]);
michael@0 453 printf("Should do something with one |TestObject|:\n");
michael@0 454 DoSomethingWithTestObjectBaseB(&pobj[2]);
michael@0 455 printf("Should do something with one |TestObject|:\n");
michael@0 456 DoSomethingWithConstTestObjectBaseB(&pobj[1]);
michael@0 457 printf("Should do something with one |TestObject|:\n");
michael@0 458 DoSomethingWithTestObjectBaseB(pobj + 2);
michael@0 459 printf("Should do something with one |TestObject|:\n");
michael@0 460 DoSomethingWithConstTestObjectBaseB(pobj + 1);
michael@0 461 printf("Should destroy 3 |TestObject|s:\n");
michael@0 462 }
michael@0 463
michael@0 464 {
michael@0 465 printf("Should create and AddRef one |TestRefObject|:\n");
michael@0 466 nsRefPtr<TestRefObject> pobj = new TestRefObject();
michael@0 467 printf("Should do something with one |TestRefObject|:\n");
michael@0 468 DoSomethingWithTestRefObjectBaseB(pobj);
michael@0 469 printf("Should do something with one |TestRefObject|:\n");
michael@0 470 DoSomethingWithConstTestRefObjectBaseB(pobj);
michael@0 471 printf("Should Release and destroy one |TestRefObject|:\n");
michael@0 472 }
michael@0 473
michael@0 474 {
michael@0 475 printf("Should create one |TestObject|:\n");
michael@0 476 const nsAutoPtr<TestObject> pobj(new TestObject());
michael@0 477 printf("Should do something with one |TestObject|:\n");
michael@0 478 DoSomethingWithTestObject(pobj);
michael@0 479 printf("Should do something with one |TestObject|:\n");
michael@0 480 DoSomethingWithConstTestObject(pobj);
michael@0 481 printf("Should destroy one |TestObject|:\n");
michael@0 482 }
michael@0 483
michael@0 484 {
michael@0 485 printf("Should create 3 |TestObject|s:\n");
michael@0 486 const nsAutoArrayPtr<TestObject> pobj(new TestObject[3]);
michael@0 487 printf("Should do something with one |TestObject|:\n");
michael@0 488 DoSomethingWithTestObject(&pobj[2]);
michael@0 489 printf("Should do something with one |TestObject|:\n");
michael@0 490 DoSomethingWithConstTestObject(&pobj[1]);
michael@0 491 printf("Should do something with one |TestObject|:\n");
michael@0 492 DoSomethingWithTestObject(pobj + 2);
michael@0 493 printf("Should do something with one |TestObject|:\n");
michael@0 494 DoSomethingWithConstTestObject(pobj + 1);
michael@0 495 printf("Should destroy 3 |TestObject|s:\n");
michael@0 496 }
michael@0 497
michael@0 498 {
michael@0 499 printf("Should create and AddRef one |TestRefObject|:\n");
michael@0 500 const nsRefPtr<TestRefObject> pobj = new TestRefObject();
michael@0 501 printf("Should do something with one |TestRefObject|:\n");
michael@0 502 DoSomethingWithTestRefObject(pobj);
michael@0 503 printf("Should do something with one |TestRefObject|:\n");
michael@0 504 DoSomethingWithConstTestRefObject(pobj);
michael@0 505 printf("Should Release and destroy one |TestRefObject|:\n");
michael@0 506 }
michael@0 507
michael@0 508 {
michael@0 509 printf("Should create one |TestObject|:\n");
michael@0 510 const nsAutoPtr<TestObject> pobj(new TestObject());
michael@0 511 printf("Should do something with one |TestObject|:\n");
michael@0 512 DoSomethingWithTestObjectBaseB(pobj);
michael@0 513 printf("Should do something with one |TestObject|:\n");
michael@0 514 DoSomethingWithConstTestObjectBaseB(pobj);
michael@0 515 printf("Should destroy one |TestObject|:\n");
michael@0 516 }
michael@0 517
michael@0 518 {
michael@0 519 printf("Should create 3 |TestObject|s:\n");
michael@0 520 const nsAutoArrayPtr<TestObject> pobj(new TestObject[3]);
michael@0 521 printf("Should do something with one |TestObject|:\n");
michael@0 522 DoSomethingWithTestObjectBaseB(&pobj[2]);
michael@0 523 printf("Should do something with one |TestObject|:\n");
michael@0 524 DoSomethingWithConstTestObjectBaseB(&pobj[1]);
michael@0 525 printf("Should do something with one |TestObject|:\n");
michael@0 526 DoSomethingWithTestObjectBaseB(pobj + 2);
michael@0 527 printf("Should do something with one |TestObject|:\n");
michael@0 528 DoSomethingWithConstTestObjectBaseB(pobj + 1);
michael@0 529 printf("Should destroy 3 |TestObject|s:\n");
michael@0 530 }
michael@0 531
michael@0 532 {
michael@0 533 printf("Should create and AddRef one |TestRefObject|:\n");
michael@0 534 const nsRefPtr<TestRefObject> pobj = new TestRefObject();
michael@0 535 printf("Should do something with one |TestRefObject|:\n");
michael@0 536 DoSomethingWithTestRefObjectBaseB(pobj);
michael@0 537 printf("Should do something with one |TestRefObject|:\n");
michael@0 538 DoSomethingWithConstTestRefObjectBaseB(pobj);
michael@0 539 printf("Should Release and destroy one |TestRefObject|:\n");
michael@0 540 }
michael@0 541
michael@0 542 return 0;
michael@0 543 }

mercurial