src/common/callback-trace-source.cc
changeset 1334 e8e07f44359f
parent 1333 c0d66de933e9
child 1335 d0e45d84f9c6
equal deleted inserted replaced
1333:c0d66de933e9 1334:e8e07f44359f
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
       
     2 /*
       
     3  * Copyright (c) 2007 INRIA
       
     4  * All rights reserved.
       
     5  *
       
     6  * This program is free software; you can redistribute it and/or modify
       
     7  * it under the terms of the GNU General Public License version 2 as
       
     8  * published by the Free Software Foundation;
       
     9  *
       
    10  * This program is distributed in the hope that it will be useful,
       
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    13  * GNU General Public License for more details.
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License
       
    16  * along with this program; if not, write to the Free Software
       
    17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
       
    18  *
       
    19  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
       
    20  */
       
    21 #include "callback-trace-source.h"
       
    22 #include "ns3/test.h"
       
    23 
       
    24 namespace ns3 {
       
    25 
       
    26 class CallbackTraceSourceTest : public Test 
       
    27 {
       
    28 public:
       
    29   CallbackTraceSourceTest ();
       
    30   virtual ~CallbackTraceSourceTest ();
       
    31   virtual bool RunTests (void);
       
    32 private:
       
    33   void CbOne (TraceContext const &context, uint8_t a, double b);
       
    34   void CbTwo (TraceContext const &context, uint8_t a, double b);
       
    35 
       
    36   bool m_one;
       
    37   bool m_two;
       
    38 };
       
    39 
       
    40 CallbackTraceSourceTest::CallbackTraceSourceTest ()
       
    41   : Test ("CallbackTraceSource")
       
    42 {}
       
    43 CallbackTraceSourceTest::~CallbackTraceSourceTest ()
       
    44 {}
       
    45 void
       
    46 CallbackTraceSourceTest::CbOne (TraceContext const &context, uint8_t a, double b)
       
    47 {
       
    48   m_one = true;
       
    49 }
       
    50 void
       
    51 CallbackTraceSourceTest::CbTwo (TraceContext const &context, uint8_t a, double b)
       
    52 {
       
    53   m_two = true;
       
    54 }
       
    55 bool 
       
    56 CallbackTraceSourceTest::RunTests (void)
       
    57 {
       
    58   bool ok = true;
       
    59   TraceContext ctx;
       
    60 
       
    61   CallbackTraceSource<uint8_t,double> trace;
       
    62   trace.AddCallback (MakeCallback (&CallbackTraceSourceTest::CbOne, this), ctx);
       
    63   trace.AddCallback (MakeCallback (&CallbackTraceSourceTest::CbTwo, this), ctx);
       
    64   m_one = false;
       
    65   m_two = false;
       
    66   trace (1, 2);
       
    67   if (!m_one || !m_two)
       
    68     {
       
    69       ok = false;
       
    70     }
       
    71   trace.RemoveCallback (MakeCallback (&CallbackTraceSourceTest::CbOne, this));
       
    72   m_one = false;
       
    73   m_two = false;
       
    74   trace (1, 2);
       
    75   if (m_one || !m_two)
       
    76     {
       
    77       ok = false;
       
    78     }
       
    79   trace.RemoveCallback (MakeCallback (&CallbackTraceSourceTest::CbTwo, this));
       
    80   m_one = false;
       
    81   m_two = false;
       
    82   trace (1, 2);
       
    83   if (m_one || m_two)
       
    84     {
       
    85       ok = false;
       
    86     }
       
    87 
       
    88   return ok;
       
    89 }
       
    90 
       
    91 CallbackTraceSourceTest g_callbackTraceTest;
       
    92 
       
    93 
       
    94 
       
    95 }//namespace ns3