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