src/core/traced-callback.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Sat, 04 Jul 2009 08:15:48 +0200
changeset 4654 2eaebe77d66b
parent 2594 a8f89acd17a1
permissions -rw-r--r--
Added tag ns-3.5 for changeset c975274c9707
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     2 /*
     3  * Copyright (c) 2007 INRIA
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License version 2 as
     7  * published by the Free Software Foundation;
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program; if not, write to the Free Software
    16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    17  *
    18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
    19  */
    20 #include "traced-callback.h"
    21 
    22 #ifdef RUN_SELF_TESTS
    23 
    24 #include "test.h"
    25 
    26 namespace ns3 {
    27 
    28 class TracedCallbackTest : public Test 
    29 {
    30 public:
    31   TracedCallbackTest ();
    32   virtual ~TracedCallbackTest ();
    33   virtual bool RunTests (void);
    34 private:
    35   void CbOne (uint8_t a, double b);
    36   void CbTwo (uint8_t a, double b);
    37 
    38   bool m_one;
    39   bool m_two;
    40 };
    41 
    42 TracedCallbackTest::TracedCallbackTest ()
    43   : Test ("TracedCallback")
    44 {}
    45 TracedCallbackTest::~TracedCallbackTest ()
    46 {}
    47 void
    48 TracedCallbackTest::CbOne (uint8_t a, double b)
    49 {
    50   m_one = true;
    51 }
    52 void
    53 TracedCallbackTest::CbTwo (uint8_t a, double b)
    54 {
    55   m_two = true;
    56 }
    57 bool 
    58 TracedCallbackTest::RunTests (void)
    59 {
    60   bool result = true;
    61 
    62   TracedCallback<uint8_t,double> trace;
    63   trace.ConnectWithoutContext (MakeCallback (&TracedCallbackTest::CbOne, this));
    64   trace.ConnectWithoutContext (MakeCallback (&TracedCallbackTest::CbTwo, this));
    65   m_one = false;
    66   m_two = false;
    67   trace (1, 2);
    68   NS_TEST_ASSERT (m_one);
    69   NS_TEST_ASSERT (m_two);
    70 
    71   trace.DisconnectWithoutContext (MakeCallback (&TracedCallbackTest::CbOne, this));
    72   m_one = false;
    73   m_two = false;
    74   trace (1, 2);
    75   NS_TEST_ASSERT (!m_one);
    76   NS_TEST_ASSERT (m_two);
    77   trace.DisconnectWithoutContext (MakeCallback (&TracedCallbackTest::CbTwo, this));
    78   m_one = false;
    79   m_two = false;
    80   trace (1, 2);
    81   NS_TEST_ASSERT (!m_one);
    82   NS_TEST_ASSERT (!m_two);
    83 
    84   trace.ConnectWithoutContext (MakeCallback (&TracedCallbackTest::CbOne, this));
    85   trace.ConnectWithoutContext (MakeCallback (&TracedCallbackTest::CbTwo, this));
    86   m_one = false;
    87   m_two = false;
    88   trace (1, 2);
    89   NS_TEST_ASSERT (m_one);
    90   NS_TEST_ASSERT (m_two);
    91 
    92   return result;
    93 }
    94 
    95 static TracedCallbackTest g_eventTraceTest;
    96 
    97 }//namespace ns3
    98 
    99 #endif /* RUN_SELF_TESTS */