src/core/callback-trace-source.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 06 Sep 2007 12:56:31 +0200
changeset 1419 ac2a81821ab5
parent 1350 7088f670a858
permissions -rw-r--r--
add support for NodeList::ConnectPrinterToAll
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     2
/*
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     3
 * Copyright (c) 2007 INRIA
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     4
 * All rights reserved.
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
 *
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     6
 * This program is free software; you can redistribute it and/or modify
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     7
 * it under the terms of the GNU General Public License version 2 as
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     8
 * published by the Free Software Foundation;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     9
 *
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    13
 * GNU General Public License for more details.
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    14
 *
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    16
 * along with this program; if not, write to the Free Software
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    18
 *
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    19
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    20
 */
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    21
#include "callback-trace-source.h"
1419
ac2a81821ab5 add support for NodeList::ConnectPrinterToAll
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1350
diff changeset
    22
ac2a81821ab5 add support for NodeList::ConnectPrinterToAll
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1350
diff changeset
    23
#ifdef RUN_SELF_TESTS
ac2a81821ab5 add support for NodeList::ConnectPrinterToAll
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1350
diff changeset
    24
1335
d0e45d84f9c6 fix includes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1334
diff changeset
    25
#include "test.h"
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    26
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    27
namespace ns3 {
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    28
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    29
class CallbackTraceSourceTest : public Test 
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    30
{
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    31
public:
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    32
  CallbackTraceSourceTest ();
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    33
  virtual ~CallbackTraceSourceTest ();
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    34
  virtual bool RunTests (void);
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    35
private:
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    36
  void CbOne (TraceContext const &context, uint8_t a, double b);
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    37
  void CbTwo (TraceContext const &context, uint8_t a, double b);
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    38
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    39
  bool m_one;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    40
  bool m_two;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    41
};
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    42
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    43
CallbackTraceSourceTest::CallbackTraceSourceTest ()
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    44
  : Test ("CallbackTraceSource")
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    45
{}
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    46
CallbackTraceSourceTest::~CallbackTraceSourceTest ()
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    47
{}
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    48
void
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    49
CallbackTraceSourceTest::CbOne (TraceContext const &context, uint8_t a, double b)
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    50
{
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    51
  m_one = true;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    52
}
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    53
void
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    54
CallbackTraceSourceTest::CbTwo (TraceContext const &context, uint8_t a, double b)
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    55
{
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    56
  m_two = true;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    57
}
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    58
bool 
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    59
CallbackTraceSourceTest::RunTests (void)
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    60
{
1350
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    61
  bool result = true;
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    62
  TraceContext ctx;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    63
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    64
  CallbackTraceSource<uint8_t,double> trace;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    65
  trace.AddCallback (MakeCallback (&CallbackTraceSourceTest::CbOne, this), ctx);
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    66
  trace.AddCallback (MakeCallback (&CallbackTraceSourceTest::CbTwo, this), ctx);
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    67
  m_one = false;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    68
  m_two = false;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    69
  trace (1, 2);
1350
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    70
  NS_TEST_ASSERT (m_one);
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    71
  NS_TEST_ASSERT (m_two);
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    72
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    73
  trace.RemoveCallback (MakeCallback (&CallbackTraceSourceTest::CbOne, this));
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    74
  m_one = false;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    75
  m_two = false;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    76
  trace (1, 2);
1350
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    77
  NS_TEST_ASSERT (!m_one);
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    78
  NS_TEST_ASSERT (m_two);
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    79
  trace.RemoveCallback (MakeCallback (&CallbackTraceSourceTest::CbTwo, this));
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    80
  m_one = false;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    81
  m_two = false;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    82
  trace (1, 2);
1350
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    83
  NS_TEST_ASSERT (!m_one);
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    84
  NS_TEST_ASSERT (!m_two);
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    85
1350
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    86
  trace.AddCallback (MakeCallback (&CallbackTraceSourceTest::CbOne, this), ctx);
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    87
  trace.AddCallback (MakeCallback (&CallbackTraceSourceTest::CbTwo, this), ctx);
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    88
  m_one = false;
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    89
  m_two = false;
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    90
  trace (1, 2);
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    91
  NS_TEST_ASSERT (m_one);
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    92
  NS_TEST_ASSERT (m_two);
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    93
7088f670a858 rewrite tests with test.h macros
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1335
diff changeset
    94
  return result;
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    95
}
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    96
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    97
CallbackTraceSourceTest g_callbackTraceTest;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    98
1419
ac2a81821ab5 add support for NodeList::ConnectPrinterToAll
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1350
diff changeset
    99
}//namespace ns3
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   100
1419
ac2a81821ab5 add support for NodeList::ConnectPrinterToAll
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1350
diff changeset
   101
#endif /* RUN_SELF_TESTS */