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

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is TestCOMPtrEq.cpp.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * L. David Baron.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2001
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   L. David Baron <dbaron@dbaron.org> (original author)
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      27                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 :  /**
      40                 :   * This attempts to test all the possible variations of |operator==|
      41                 :   * used with |nsCOMPtr|s.  Currently only the tests where pointers
      42                 :   * are to the same class are enabled.  It's not clear whether we
      43                 :   * should be supporting other tests, and some of them won't work
      44                 :   * on at least some platforms.  If we add separate comparisons
      45                 :   * for nsCOMPtr<nsISupports> we'll need to add more tests for
      46                 :   * those cases.
      47                 :   */
      48                 : 
      49                 : #include "nsCOMPtr.h"
      50                 : 
      51                 :   // Don't test these now, since some of them won't work and it's
      52                 :   // not clear whether they should (see above).
      53                 : #undef NSCAP_EQTEST_TEST_ACROSS_TYPES
      54                 : 
      55                 : #define NS_ICOMPTREQTESTFOO_IID \
      56                 :   {0x8eb5bbef, 0xd1a3, 0x4659, \
      57                 :     {0x9c, 0xf6, 0xfd, 0xf3, 0xe4, 0xd2, 0x00, 0x0e}}
      58                 : 
      59                 : class nsICOMPtrEqTestFoo : public nsISupports {
      60                 :   public:
      61                 :     NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICOMPTREQTESTFOO_IID)
      62                 : };
      63                 : 
      64                 : NS_DEFINE_STATIC_IID_ACCESSOR(nsICOMPtrEqTestFoo, NS_ICOMPTREQTESTFOO_IID)
      65                 : 
      66                 : #ifdef NSCAP_EQTEST_TEST_ACROSS_TYPES
      67                 : 
      68                 : #define NS_ICOMPTREQTESTFOO2_IID \
      69                 :   {0x6516387b, 0x36c5, 0x4036, \
      70                 :     {0x82, 0xc9, 0xa7, 0x4d, 0xd9, 0xe5, 0x92, 0x2f}}
      71                 : 
      72                 : class nsICOMPtrEqTestFoo2 : public nsISupports {
      73                 :   public:
      74                 :     NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICOMPTREQTESTFOO2_IID)
      75                 : };
      76                 : 
      77                 : NS_DEFINE_STATIC_IID_ACCESSOR(nsICOMPtrEqTestFoo2, NS_ICOMPTREQTESTFOO2_IID)
      78                 : 
      79                 : #endif
      80                 : 
      81                 : int
      82               1 : main()
      83                 :   {
      84               2 :     nsCOMPtr<nsICOMPtrEqTestFoo> s;
      85               1 :     nsICOMPtrEqTestFoo* r = 0;
      86               2 :     const nsCOMPtr<nsICOMPtrEqTestFoo> sc;
      87               1 :     const nsICOMPtrEqTestFoo* rc = 0;
      88               1 :     nsICOMPtrEqTestFoo* const rk = 0;
      89               1 :     const nsICOMPtrEqTestFoo* const rkc = 0;
      90               1 :     nsICOMPtrEqTestFoo* d = s;
      91                 :     
      92                 : #ifdef NSCAP_EQTEST_TEST_ACROSS_TYPES
      93                 :     nsCOMPtr<nsICOMPtrEqTestFoo2> s2;
      94                 :     nsICOMPtrEqTestFoo2* r2 = 0;
      95                 :     const nsCOMPtr<nsICOMPtrEqTestFoo2> sc2;
      96                 :     const nsICOMPtrEqTestFoo2* rc2 = 0;
      97                 :     nsICOMPtrEqTestFoo2* const rk2 = 0;
      98                 :     const nsICOMPtrEqTestFoo2* const rkc2 = 0;
      99                 :     nsICOMPtrEqTestFoo2* d2 = s2;
     100                 : #endif
     101                 : 
     102                 :     return (!(true &&
     103               1 :               (s == s) &&
     104               1 :               (s == r) &&
     105               1 :               (s == sc) &&
     106               1 :               (s == rc) &&
     107               1 :               (s == rk) &&
     108               1 :               (s == rkc) &&
     109               1 :               (s == d) &&
     110               1 :               (r == s) &&
     111                 :               (r == r) &&
     112               1 :               (r == sc) &&
     113                 :               (r == rc) &&
     114                 :               (r == rk) &&
     115                 :               (r == rkc) &&
     116                 :               (r == d) &&
     117               1 :               (sc == s) &&
     118               1 :               (sc == r) &&
     119               1 :               (sc == sc) &&
     120               1 :               (sc == rc) &&
     121               1 :               (sc == rk) &&
     122               1 :               (sc == rkc) &&
     123               1 :               (sc == d) &&
     124               1 :               (rc == s) &&
     125                 :               (rc == r) &&
     126               1 :               (rc == sc) &&
     127                 :               (rc == rc) &&
     128                 :               (rc == rk) &&
     129                 :               (rc == rkc) &&
     130                 :               (rc == d) &&
     131               1 :               (rk == s) &&
     132                 :               (rk == r) &&
     133               1 :               (rk == sc) &&
     134                 :               (rk == rc) &&
     135                 :               (rk == rk) &&
     136                 :               (rk == rkc) &&
     137                 :               (rk == d) &&
     138               1 :               (rkc == s) &&
     139                 :               (rkc == r) &&
     140               1 :               (rkc == sc) &&
     141                 :               (rkc == rc) &&
     142                 :               (rkc == rk) &&
     143                 :               (rkc == rkc) &&
     144                 :               (rkc == d) &&
     145               1 :               (d == s) &&
     146                 :               (d == r) &&
     147               1 :               (d == sc) &&
     148                 :               (d == rc) &&
     149                 :               (d == rk) &&
     150                 :               (d == rkc) &&
     151                 :               (d == d) &&
     152                 : #ifdef NSCAP_EQTEST_TEST_ACROSS_TYPES
     153                 :               (s == s2) &&
     154                 :               (s == r2) &&
     155                 :               (s == sc2) &&
     156                 :               (s == rc2) &&
     157                 :               (s == rk2) &&
     158                 :               (s == rkc2) &&
     159                 :               (s == d2) &&
     160                 :               (r == s2) &&
     161                 :               (r == r2) &&
     162                 :               (r == sc2) &&
     163                 :               (r == rc2) &&
     164                 :               (r == rk2) &&
     165                 :               (r == rkc2) &&
     166                 :               (r == d2) &&
     167                 :               (sc == s2) &&
     168                 :               (sc == r2) &&
     169                 :               (sc == sc2) &&
     170                 :               (sc == rc2) &&
     171                 :               (sc == rk2) &&
     172                 :               (sc == rkc2) &&
     173                 :               (sc == d2) &&
     174                 :               (rc == s2) &&
     175                 :               (rc == r2) &&
     176                 :               (rc == sc2) &&
     177                 :               (rc == rc2) &&
     178                 :               (rc == rk2) &&
     179                 :               (rc == rkc2) &&
     180                 :               (rc == d2) &&
     181                 :               (rk == s2) &&
     182                 :               (rk == r2) &&
     183                 :               (rk == sc2) &&
     184                 :               (rk == rc2) &&
     185                 :               (rk == rk2) &&
     186                 :               (rk == rkc2) &&
     187                 :               (rk == d2) &&
     188                 :               (rkc == s2) &&
     189                 :               (rkc == r2) &&
     190                 :               (rkc == sc2) &&
     191                 :               (rkc == rc2) &&
     192                 :               (rkc == rk2) &&
     193                 :               (rkc == rkc2) &&
     194                 :               (rkc == d2) &&
     195                 :               (d == s2) &&
     196                 :               (d == r2) &&
     197                 :               (d == sc2) &&
     198                 :               (d == rc2) &&
     199                 :               (d == rk2) &&
     200                 :               (d == rkc2) &&
     201                 :               (d == d2) &&
     202                 : #endif
     203              24 :               true));
     204                 :   }

Generated by: LCOV version 1.7