LCOV - code coverage report
Current view: directory - toolkit/components/places/tests/cpp - mock_Link.h (source / functions) Found Hit Coverage
Test: app.info Lines: 35 18 51.4 %
Date: 2012-06-02 Functions: 16 8 50.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2                 :  * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
       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 places test code.
      17                 :  *
      18                 :  * The Initial Developer of the Original Code is
      19                 :  * Mozilla Foundation.
      20                 :  * Portions created by the Initial Developer are Copyright (C) 2009
      21                 :  * the Initial Developer. All Rights Reserved.
      22                 :  *
      23                 :  * Contributor(s):
      24                 :  *   Shawn Wilsher <me@shawnwilsher.com> (Original Author)
      25                 :  *
      26                 :  * Alternatively, the contents of this file may be used under the terms of
      27                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      28                 :  * 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                 : /**
      41                 :  * This is a mock Link object which can be used in tests.
      42                 :  */
      43                 : 
      44                 : #ifndef mock_Link_h__
      45                 : #define mock_Link_h__
      46                 : 
      47                 : #include "mozilla/dom/Link.h"
      48                 : 
      49                 : class mock_Link : public mozilla::dom::Link
      50                 : {
      51                 : public:
      52                 :   NS_DECL_ISUPPORTS
      53                 : 
      54               9 :   mock_Link(void (*aHandlerFunction)(nsLinkState),
      55                 :             bool aRunNextTest = true)
      56                 :   : mozilla::dom::Link(nsnull)
      57                 :   , mHandler(aHandlerFunction)
      58               9 :   , mRunNextTest(aRunNextTest)
      59                 :   {
      60                 :     // Create a cyclic ownership, so that the link will be released only
      61                 :     // after its status has been updated.  This will ensure that, when it should
      62                 :     // run the next test, it will happen at the end of the test function, if
      63                 :     // the link status has already been set before.  Indeed the link status is
      64                 :     // updated on a separate connection, thus may happen at any time.
      65               9 :     mDeathGrip = this;
      66               9 :   }
      67                 : 
      68               5 :   virtual void SetLinkState(nsLinkState aState)
      69                 :   {
      70                 :     // Notify our callback function.
      71               5 :     mHandler(aState);
      72                 : 
      73                 :     // Break the cycle so the object can be destroyed.
      74               5 :     mDeathGrip = 0;
      75               5 :   }
      76                 : 
      77               0 :   virtual size_t SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
      78                 :   {
      79               0 :     return 0;   // the value shouldn't matter
      80                 :   }
      81                 : 
      82              15 :   ~mock_Link() {
      83                 :     // Run the next test if we are supposed to.
      84               5 :     if (mRunNextTest) {
      85               3 :       run_next_test();
      86                 :     }
      87              20 :   }
      88                 : 
      89                 : private:
      90                 :   void (*mHandler)(nsLinkState);
      91                 :   bool mRunNextTest;
      92                 :   nsRefPtr<Link> mDeathGrip;
      93                 : };
      94                 : 
      95              34 : NS_IMPL_ISUPPORTS1(
      96                 :   mock_Link,
      97                 :   mozilla::dom::Link
      98                 : )
      99                 : 
     100                 : ////////////////////////////////////////////////////////////////////////////////
     101                 : //// Needed Link Methods
     102                 : 
     103                 : namespace mozilla {
     104                 : namespace dom {
     105                 : 
     106               9 : Link::Link(Element* aElement)
     107                 : : mLinkState(mozilla::dom::Link::defaultState)
     108                 : , mRegistered(false)
     109               9 : , mElement(aElement)
     110                 : {
     111               9 : }
     112                 : 
     113               5 : Link::~Link()
     114                 : {
     115              10 : }
     116                 : 
     117                 : nsLinkState
     118               0 : Link::GetLinkState() const
     119                 : {
     120               0 :   NS_NOTREACHED("Unexpected call to Link::GetLinkState");
     121               0 :   return eLinkState_Unknown; // suppress compiler warning
     122                 : }
     123                 : 
     124                 : void
     125               0 : Link::SetLinkState(nsLinkState aState)
     126                 : {
     127               0 :   NS_NOTREACHED("Unexpected call to Link::SetLinkState");
     128               0 : }
     129                 : 
     130                 : void
     131               0 : Link::ResetLinkState(bool aNotify)
     132                 : {
     133               0 :   NS_NOTREACHED("Unexpected call to Link::ResetLinkState");
     134               0 : }
     135                 : 
     136                 : already_AddRefed<nsIURI>
     137               0 : Link::GetURI() const 
     138                 : {
     139               0 :   NS_NOTREACHED("Unexpected call to Link::GetURI");
     140               0 :   return nsnull; // suppress compiler warning
     141                 : }
     142                 : 
     143                 : size_t
     144               0 : Link::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
     145                 : {
     146               0 :   NS_NOTREACHED("Unexpected call to Link::SizeOfExcludingThis");
     147               0 :   return 0;
     148                 : }
     149                 : 
     150                 : } // namespace dom
     151                 : } // namespace mozilla
     152                 : 
     153                 : #endif // mock_Link_h__

Generated by: LCOV version 1.7