src/core/traced-callback-test-suite.cc
author Nicola Baldo <nbaldo@cttc.es>
Tue, 24 Nov 2009 13:59:14 +0100
changeset 5774 0fad665ff307
parent 5298 00703d57e767
child 6774 034f362af24d
permissions -rw-r--r--
fixed bug 668
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5298
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     2
/*
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     3
 * Copyright (c) 2009 University of Washington
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     4
 *
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     8
 *
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    12
 * GNU General Public License for more details.
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    13
 *
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    17
 */
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    18
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    19
#include "test.h"
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    20
#include "traced-callback.h"
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    21
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    22
using namespace ns3;
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    23
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    24
class BasicTracedCallbackTestCase : public TestCase
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
{
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
public:
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
  BasicTracedCallbackTestCase ();
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    28
  virtual ~BasicTracedCallbackTestCase () {}
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    29
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    30
private:
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    31
  virtual bool DoRun (void);
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
  void CbOne (uint8_t a, double b);
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    34
  void CbTwo (uint8_t a, double b);
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    35
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    36
  bool m_one;
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    37
  bool m_two;
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    38
};
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    39
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
BasicTracedCallbackTestCase::BasicTracedCallbackTestCase ()
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
  : TestCase ("Check basic TracedCallback operation")
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    42
{
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    43
}
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    45
void
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    46
BasicTracedCallbackTestCase::CbOne (uint8_t a, double b)
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    47
{
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    48
  m_one = true;
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    49
}
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    50
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
void
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    52
BasicTracedCallbackTestCase::CbTwo (uint8_t a, double b)
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    53
{
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    54
  m_two = true;
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    55
}
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    56
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    57
bool
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    58
BasicTracedCallbackTestCase::DoRun (void)
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    59
{
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    60
  //
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
  // Create a traced callback and connect it up to our target methods.  All that
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    62
  // these methods do is to set corresponding member variables m_one and m_two.
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    63
  //
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    64
  TracedCallback<uint8_t, double> trace;
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    65
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    66
  //
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
  // Connect both callbacks to their respective test methods.  If we hit the 
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    68
  // trace, both callbacks should be called and the two variables  should be set
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    69
  // to true.
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    70
  //
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    71
  trace.ConnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbOne, this));
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    72
  trace.ConnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbTwo, this));
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    73
  m_one = false;
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    74
  m_two = false;
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    75
  trace (1, 2);
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    76
  NS_TEST_ASSERT_MSG_EQ (m_one, true, "Callback CbOne not called");
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    77
  NS_TEST_ASSERT_MSG_EQ (m_two, true, "Callback CbTwo not called");
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    78
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    79
  //
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    80
  // If we now disconnect callback one then only callback two should be called.
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    81
  //
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    82
  trace.DisconnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbOne, this));
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    83
  m_one = false;
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    84
  m_two = false;
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    85
  trace (1, 2);
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    86
  NS_TEST_ASSERT_MSG_EQ (m_one, false, "Callback CbOne unexpectedly called");
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    87
  NS_TEST_ASSERT_MSG_EQ (m_two, true, "Callback CbTwo not called");
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    88
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    89
  //
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    90
  // If we now disconnect callback two then neither callback should be called.
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    91
  //
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    92
  trace.DisconnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbTwo, this));
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    93
  m_one = false;
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    94
  m_two = false;
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    95
  trace (1, 2);
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    96
  NS_TEST_ASSERT_MSG_EQ (m_one, false, "Callback CbOne unexpectedly called");
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    97
  NS_TEST_ASSERT_MSG_EQ (m_two, false, "Callback CbTwo unexpectedly called");
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    98
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    99
  //
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   100
  // If we connect them back up, then both callbacks should be called.
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   101
  //
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   102
  trace.ConnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbOne, this));
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   103
  trace.ConnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbTwo, this));
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   104
  m_one = false;
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   105
  m_two = false;
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   106
  trace (1, 2);
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   107
  NS_TEST_ASSERT_MSG_EQ (m_one, true, "Callback CbOne not called");
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   108
  NS_TEST_ASSERT_MSG_EQ (m_two, true, "Callback CbTwo not called");
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   109
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   110
  return GetErrorStatus ();
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   111
}
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   112
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   113
class TracedCallbackTestSuite : public TestSuite
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   114
{
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   115
public:
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   116
  TracedCallbackTestSuite ();
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   117
};
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   118
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   119
TracedCallbackTestSuite::TracedCallbackTestSuite ()
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   120
  : TestSuite ("traced-callback", UNIT)
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   121
{
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   122
  AddTestCase (new BasicTracedCallbackTestCase);
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   123
}
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   124
00703d57e767 Remove and replace traced-callback unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   125
TracedCallbackTestSuite tracedCallbackTestSuite;