LCOV - code coverage report
Current view: directory - xpcom/tests - TestAutoPtr.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 284 284 100.0 %
Date: 2012-06-02 Functions: 26 24 92.3 %

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

Generated by: LCOV version 1.7