src/core/test/attribute-test-suite.cc
author Peter D. Barnes, Jr. <barnes26@llnl.gov>
Thu, 02 Oct 2014 21:17:48 -0700
changeset 10978 754c8256c35c
parent 10652 dc18deba4502
child 11036 1e03af4311bd
permissions -rw-r--r--
TracedValue callback function signatures.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2581
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2572
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2572
diff changeset
     2
/*
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
     3
 * Copyright (c) 2009 University of Washington
2581
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2572
diff changeset
     4
 *
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2572
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2572
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2572
diff changeset
     7
 * published by the Free Software Foundation;
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2572
diff changeset
     8
 *
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2572
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2572
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2572
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2572
diff changeset
    12
 * GNU General Public License for more details.
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2572
diff changeset
    13
 *
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2572
diff changeset
    14
 * You should have received a copy of the GNU General Public License
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2572
diff changeset
    15
 * along with this program; if not, write to the Free Software
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2572
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2572
diff changeset
    17
 */
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
    18
6821
203367ae7433 merge src/simulator into src/core; move src/core to new module layout
Tom Henderson <tomh@tomh.org>
parents: 6775
diff changeset
    19
#include "ns3/test.h"
203367ae7433 merge src/simulator into src/core; move src/core to new module layout
Tom Henderson <tomh@tomh.org>
parents: 6775
diff changeset
    20
#include "ns3/object.h"
203367ae7433 merge src/simulator into src/core; move src/core to new module layout
Tom Henderson <tomh@tomh.org>
parents: 6775
diff changeset
    21
#include "ns3/boolean.h"
203367ae7433 merge src/simulator into src/core; move src/core to new module layout
Tom Henderson <tomh@tomh.org>
parents: 6775
diff changeset
    22
#include "ns3/integer.h"
203367ae7433 merge src/simulator into src/core; move src/core to new module layout
Tom Henderson <tomh@tomh.org>
parents: 6775
diff changeset
    23
#include "ns3/uinteger.h"
7399
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7256
diff changeset
    24
#include "ns3/config.h"
6821
203367ae7433 merge src/simulator into src/core; move src/core to new module layout
Tom Henderson <tomh@tomh.org>
parents: 6775
diff changeset
    25
#include "ns3/enum.h"
203367ae7433 merge src/simulator into src/core; move src/core to new module layout
Tom Henderson <tomh@tomh.org>
parents: 6775
diff changeset
    26
#include "ns3/string.h"
8996
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
    27
#include "ns3/random-variable-stream.h"
6821
203367ae7433 merge src/simulator into src/core; move src/core to new module layout
Tom Henderson <tomh@tomh.org>
parents: 6775
diff changeset
    28
#include "ns3/double.h"
203367ae7433 merge src/simulator into src/core; move src/core to new module layout
Tom Henderson <tomh@tomh.org>
parents: 6775
diff changeset
    29
#include "ns3/object-vector.h"
7884
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
    30
#include "ns3/object-map.h"
6821
203367ae7433 merge src/simulator into src/core; move src/core to new module layout
Tom Henderson <tomh@tomh.org>
parents: 6775
diff changeset
    31
#include "ns3/traced-value.h"
203367ae7433 merge src/simulator into src/core; move src/core to new module layout
Tom Henderson <tomh@tomh.org>
parents: 6775
diff changeset
    32
#include "ns3/callback.h"
203367ae7433 merge src/simulator into src/core; move src/core to new module layout
Tom Henderson <tomh@tomh.org>
parents: 6775
diff changeset
    33
#include "ns3/trace-source-accessor.h"
203367ae7433 merge src/simulator into src/core; move src/core to new module layout
Tom Henderson <tomh@tomh.org>
parents: 6775
diff changeset
    34
#include "ns3/pointer.h"
7859
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
    35
#include "ns3/object-factory.h"
9891
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
    36
#include "ns3/nstime.h"
2405
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2385
diff changeset
    37
9079
1e5921e6507d Clean up core, network, internet, point-to-point tests that don't access private class attributes and methods in accordance to sample-test-suite.cc.
Vedran Miletić <rivanvx@gmail.com>
parents: 8996
diff changeset
    38
using namespace ns3;
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    39
2469
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    40
class ValueClassTest 
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    41
{
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    42
public:
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    43
  ValueClassTest () {}
10978
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10652
diff changeset
    44
  
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10652
diff changeset
    45
  /**
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10652
diff changeset
    46
   * TracedValue callback signature for ValueClassTest
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10652
diff changeset
    47
   *
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10652
diff changeset
    48
   * \param [in] oldValue original value of the traced variable
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10652
diff changeset
    49
   * \param [in] newValue new value of the traced variable
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10652
diff changeset
    50
   */
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10652
diff changeset
    51
  typedef void (* TracedValueCallback)(const ValueClassTest oldValue,
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10652
diff changeset
    52
                                       const ValueClassTest newValue);
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10652
diff changeset
    53
2469
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    54
private:
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    55
  int m_v;
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    56
};
10978
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10652
diff changeset
    57
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10652
diff changeset
    58
2469
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    59
bool operator != (const ValueClassTest &a, const ValueClassTest &b)
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    60
{
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    61
  return true;
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    62
}
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    63
std::ostream & operator << (std::ostream &os, ValueClassTest v)
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    64
{
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    65
  return os;
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    66
}
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    67
std::istream & operator >> (std::istream &is, ValueClassTest &v)
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    68
{
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    69
  return is;
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    70
}
3094
6e787ec9c8aa ATTRIBUTE_HELPER_HEADER_2 -> ATTRIBUTE_HELPER_HEADER
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2965
diff changeset
    71
ATTRIBUTE_HELPER_HEADER (ValueClassTest);
2582
3e28107b870f rename old VALUE leftovers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    72
ATTRIBUTE_HELPER_CPP (ValueClassTest);
2469
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    73
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    74
class Derived : public Object
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    75
{
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    76
public:
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    77
  static TypeId GetTypeId (void) {
6445
43d91786d268 simple doxygen fixes
Josh Pelkey <jpelkey@gatech.edu>
parents: 5246
diff changeset
    78
    static TypeId tid = TypeId ("ns3::Derived")
7859
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
    79
      .AddConstructor<Derived> ()
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    80
      .SetParent<Object> ()
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
    81
    ;
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    82
    return tid;
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    83
  }
7859
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
    84
  Derived () {}
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    85
};
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    86
10652
dc18deba4502 [doxygen] Revert r10410, r10411, r10412
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10410
diff changeset
    87
NS_OBJECT_ENSURE_REGISTERED (Derived);
7859
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
    88
2450
3ad8ebe70756 value-test.cc -> attribute-test.cc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2444
diff changeset
    89
class AttributeObjectTest : public Object
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    90
{
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    91
public:
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
    92
  enum Test_e {
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    93
    TEST_A,
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    94
    TEST_B,
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    95
    TEST_C
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    96
  };
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    97
  static TypeId GetTypeId (void) {
2613
0e1267814e1c need to use ns3:: prefix for TypeId names now.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    98
    static TypeId tid = TypeId ("ns3::AttributeObjectTest")
7859
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
    99
      .AddConstructor<AttributeObjectTest> ()
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   100
      .SetParent<Object> ()
2602
d9262bff6df2 add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2599
diff changeset
   101
      .HideFromDocumentation ()
2458
e8f7c4960576 AddParameter -> AddAttribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2457
diff changeset
   102
      .AddAttribute ("TestBoolName", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   103
                     BooleanValue (false),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   104
                     MakeBooleanAccessor (&AttributeObjectTest::m_boolTest),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   105
                     MakeBooleanChecker ())
2458
e8f7c4960576 AddParameter -> AddAttribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2457
diff changeset
   106
      .AddAttribute ("TestBoolA", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   107
                     BooleanValue (false),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   108
                     MakeBooleanAccessor (&AttributeObjectTest::DoSetTestB,
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   109
                                          &AttributeObjectTest::DoGetTestB),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   110
                     MakeBooleanChecker ())
2458
e8f7c4960576 AddParameter -> AddAttribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2457
diff changeset
   111
      .AddAttribute ("TestInt16", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   112
                     IntegerValue (-2),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   113
                     MakeIntegerAccessor (&AttributeObjectTest::m_int16),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   114
                     MakeIntegerChecker<int16_t> ())
2458
e8f7c4960576 AddParameter -> AddAttribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2457
diff changeset
   115
      .AddAttribute ("TestInt16WithBounds", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   116
                     IntegerValue (-2),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   117
                     MakeIntegerAccessor (&AttributeObjectTest::m_int16WithBounds),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   118
                     MakeIntegerChecker<int16_t> (-5, 10))
2458
e8f7c4960576 AddParameter -> AddAttribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2457
diff changeset
   119
      .AddAttribute ("TestInt16SetGet", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   120
                     IntegerValue (6),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   121
                     MakeIntegerAccessor (&AttributeObjectTest::DoSetInt16,
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   122
                                          &AttributeObjectTest::DoGetInt16),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   123
                     MakeIntegerChecker<int16_t> ())
2458
e8f7c4960576 AddParameter -> AddAttribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2457
diff changeset
   124
      .AddAttribute ("TestUint8", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   125
                     UintegerValue (1),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   126
                     MakeUintegerAccessor (&AttributeObjectTest::m_uint8),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   127
                     MakeUintegerChecker<uint8_t> ())
2458
e8f7c4960576 AddParameter -> AddAttribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2457
diff changeset
   128
      .AddAttribute ("TestEnum", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   129
                     EnumValue (TEST_A),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   130
                     MakeEnumAccessor (&AttributeObjectTest::m_enum),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   131
                     MakeEnumChecker (TEST_A, "TestA",
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   132
                                      TEST_B, "TestB",
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   133
                                      TEST_C, "TestC"))
2458
e8f7c4960576 AddParameter -> AddAttribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2457
diff changeset
   134
      .AddAttribute ("TestRandom", "help text",
8996
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   135
                     StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"),
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   136
                     MakePointerAccessor (&AttributeObjectTest::m_random),
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   137
                     MakePointerChecker <RandomVariableStream>())
2458
e8f7c4960576 AddParameter -> AddAttribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2457
diff changeset
   138
      .AddAttribute ("TestFloat", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   139
                     DoubleValue (-1.1),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   140
                     MakeDoubleAccessor (&AttributeObjectTest::m_float),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   141
                     MakeDoubleChecker<float> ())
2458
e8f7c4960576 AddParameter -> AddAttribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2457
diff changeset
   142
      .AddAttribute ("TestVector1", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   143
                     ObjectVectorValue (),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   144
                     MakeObjectVectorAccessor (&AttributeObjectTest::m_vector1),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   145
                     MakeObjectVectorChecker<Derived> ())
2458
e8f7c4960576 AddParameter -> AddAttribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2457
diff changeset
   146
      .AddAttribute ("TestVector2", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   147
                     ObjectVectorValue (),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   148
                     MakeObjectVectorAccessor (&AttributeObjectTest::DoGetVectorN,
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   149
                                               &AttributeObjectTest::DoGetVector),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   150
                     MakeObjectVectorChecker<Derived> ())
7884
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   151
      .AddAttribute ("TestMap1", "help text",
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   152
                     ObjectMapValue (),
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   153
                     MakeObjectMapAccessor (&AttributeObjectTest::m_map1),
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   154
                     MakeObjectMapChecker<Derived> ())
2462
93028d4474ba add an IntegerTraceSource which behaves just like an Integer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2460
diff changeset
   155
      .AddAttribute ("IntegerTraceSource1", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   156
                     IntegerValue (-2),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   157
                     MakeIntegerAccessor (&AttributeObjectTest::m_intSrc1),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   158
                     MakeIntegerChecker<int8_t> ())
2462
93028d4474ba add an IntegerTraceSource which behaves just like an Integer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2460
diff changeset
   159
      .AddAttribute ("IntegerTraceSource2", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   160
                     IntegerValue (-2),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   161
                     MakeIntegerAccessor (&AttributeObjectTest::DoSetIntSrc,
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   162
                                          &AttributeObjectTest::DoGetIntSrc),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   163
                     MakeIntegerChecker<int8_t> ())
6490
34e72f4cdd87 bug 956: workaround compiler bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6445
diff changeset
   164
      .AddAttribute ("UIntegerTraceSource", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   165
                     UintegerValue (2),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   166
                     MakeUintegerAccessor (&AttributeObjectTest::m_uintSrc),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   167
                     MakeIntegerChecker<uint8_t> ())
6490
34e72f4cdd87 bug 956: workaround compiler bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6445
diff changeset
   168
      .AddAttribute ("DoubleTraceSource", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   169
                     DoubleValue (2),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   170
                     MakeDoubleAccessor (&AttributeObjectTest::m_doubleSrc),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   171
                     MakeDoubleChecker<double> ())
6490
34e72f4cdd87 bug 956: workaround compiler bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6445
diff changeset
   172
      .AddAttribute ("BoolTraceSource", "help text",
34e72f4cdd87 bug 956: workaround compiler bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6445
diff changeset
   173
                     BooleanValue (false),
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   174
                     MakeBooleanAccessor (&AttributeObjectTest::m_boolSrc),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   175
                     MakeBooleanChecker ())
6490
34e72f4cdd87 bug 956: workaround compiler bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6445
diff changeset
   176
      .AddAttribute ("EnumTraceSource", "help text",
34e72f4cdd87 bug 956: workaround compiler bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6445
diff changeset
   177
                     EnumValue (false),
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   178
                     MakeEnumAccessor (&AttributeObjectTest::m_enumSrc),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   179
                     MakeEnumChecker (TEST_A, "TestA"))
2469
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
   180
      .AddAttribute ("ValueClassSource", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   181
                     ValueClassTestValue (ValueClassTest ()),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   182
                     MakeValueClassTestAccessor (&AttributeObjectTest::m_valueSrc),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   183
                     MakeValueClassTestChecker ())
2463
c77e43117673 actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2462
diff changeset
   184
      .AddTraceSource ("Source1", "help test",
10978
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10652
diff changeset
   185
                       MakeTraceSourceAccessor (&AttributeObjectTest::m_intSrc1),
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10652
diff changeset
   186
                       "ns3::TracedValue::Int8Callback")
2466
8e4ee14cc574 make EventTraceSource acceptable to the MakeTraceSourceAccessor function
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2464
diff changeset
   187
      .AddTraceSource ("Source2", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   188
                       MakeTraceSourceAccessor (&AttributeObjectTest::m_cb))
2469
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
   189
      .AddTraceSource ("ValueSource", "help text",
10978
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10652
diff changeset
   190
                       MakeTraceSourceAccessor (&AttributeObjectTest::m_valueSrc),
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10652
diff changeset
   191
                       "ns3::ValueClassTest::TracedValueCallback")
3190
51fe9001a679 add some doxygen, remove a couple of XXX
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3094
diff changeset
   192
      .AddAttribute ("Pointer", "help text",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   193
                     PointerValue (),
2926
96d1fc816681 Pointer class for primitive type pointer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
   194
                     MakePointerAccessor (&AttributeObjectTest::m_ptr),
96d1fc816681 Pointer class for primitive type pointer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
   195
                     MakePointerChecker<Derived> ())
7859
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
   196
      .AddAttribute ("PointerInitialized", "help text",
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
   197
                     StringValue("ns3::Derived"),
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
   198
                     MakePointerAccessor (&AttributeObjectTest::m_ptrInitialized),
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
   199
                     MakePointerChecker<Derived> ())
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
   200
      .AddAttribute ("PointerInitialized2", "help text",
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
   201
                     StringValue("ns3::Derived[]"),
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
   202
                     MakePointerAccessor (&AttributeObjectTest::m_ptrInitialized2),
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
   203
                     MakePointerChecker<Derived> ())
3763
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3527
diff changeset
   204
      .AddAttribute ("Callback", "help text",
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3527
diff changeset
   205
                     CallbackValue (),
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3527
diff changeset
   206
                     MakeCallbackAccessor (&AttributeObjectTest::m_cbValue),
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3527
diff changeset
   207
                     MakeCallbackChecker ())
9891
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   208
      .AddAttribute ("TestTimeWithBounds", "help text",
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   209
                     TimeValue (Seconds (-2)),
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   210
                     MakeTimeAccessor (&AttributeObjectTest::m_timeWithBounds),
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   211
                     MakeTimeChecker (Seconds (-5), Seconds (10)))
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   212
    ;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   213
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   214
    return tid;
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   215
  }
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   216
10220
fd5b94ebc43f Bug 1779 - NS_UNUSED_GLOBAL not working in attribute test class declaration
Vedran Miletić <rivanvx@gmail.com>
parents: 10218
diff changeset
   217
  AttributeObjectTest (void)
fd5b94ebc43f Bug 1779 - NS_UNUSED_GLOBAL not working in attribute test class declaration
Vedran Miletić <rivanvx@gmail.com>
parents: 10218
diff changeset
   218
  {
fd5b94ebc43f Bug 1779 - NS_UNUSED_GLOBAL not working in attribute test class declaration
Vedran Miletić <rivanvx@gmail.com>
parents: 10218
diff changeset
   219
    NS_UNUSED (m_boolTest);
fd5b94ebc43f Bug 1779 - NS_UNUSED_GLOBAL not working in attribute test class declaration
Vedran Miletić <rivanvx@gmail.com>
parents: 10218
diff changeset
   220
    NS_UNUSED (m_int16);
fd5b94ebc43f Bug 1779 - NS_UNUSED_GLOBAL not working in attribute test class declaration
Vedran Miletić <rivanvx@gmail.com>
parents: 10218
diff changeset
   221
    NS_UNUSED (m_int16WithBounds);
fd5b94ebc43f Bug 1779 - NS_UNUSED_GLOBAL not working in attribute test class declaration
Vedran Miletić <rivanvx@gmail.com>
parents: 10218
diff changeset
   222
    NS_UNUSED (m_uint8);
fd5b94ebc43f Bug 1779 - NS_UNUSED_GLOBAL not working in attribute test class declaration
Vedran Miletić <rivanvx@gmail.com>
parents: 10218
diff changeset
   223
    NS_UNUSED (m_float);
fd5b94ebc43f Bug 1779 - NS_UNUSED_GLOBAL not working in attribute test class declaration
Vedran Miletić <rivanvx@gmail.com>
parents: 10218
diff changeset
   224
    NS_UNUSED (m_enum);
fd5b94ebc43f Bug 1779 - NS_UNUSED_GLOBAL not working in attribute test class declaration
Vedran Miletić <rivanvx@gmail.com>
parents: 10218
diff changeset
   225
  }
fd5b94ebc43f Bug 1779 - NS_UNUSED_GLOBAL not working in attribute test class declaration
Vedran Miletić <rivanvx@gmail.com>
parents: 10218
diff changeset
   226
fd5b94ebc43f Bug 1779 - NS_UNUSED_GLOBAL not working in attribute test class declaration
Vedran Miletić <rivanvx@gmail.com>
parents: 10218
diff changeset
   227
  virtual ~AttributeObjectTest (void) {};
fd5b94ebc43f Bug 1779 - NS_UNUSED_GLOBAL not working in attribute test class declaration
Vedran Miletić <rivanvx@gmail.com>
parents: 10218
diff changeset
   228
7252
c8200621e252 rerun check-style.py with uncrustify-0.58
Tom Henderson <tomh@tomh.org>
parents: 7169
diff changeset
   229
  void AddToVector1 (void) { m_vector1.push_back (CreateObject<Derived> ()); }
c8200621e252 rerun check-style.py with uncrustify-0.58
Tom Henderson <tomh@tomh.org>
parents: 7169
diff changeset
   230
  void AddToVector2 (void) { m_vector2.push_back (CreateObject<Derived> ()); }
7884
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   231
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   232
  void AddToMap1 (uint32_t i) { m_map1.insert (std::pair <uint32_t, Ptr<Derived> > (i, CreateObject<Derived> ())); }
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   233
7252
c8200621e252 rerun check-style.py with uncrustify-0.58
Tom Henderson <tomh@tomh.org>
parents: 7169
diff changeset
   234
  void InvokeCb (double a, int b, float c) { m_cb (a,b,c); }
2405
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2385
diff changeset
   235
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   236
  void InvokeCbValue (int8_t a)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   237
  {
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   238
    if (!m_cbValue.IsNull ()) {
3763
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3527
diff changeset
   239
        m_cbValue (a);
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3527
diff changeset
   240
      }
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3527
diff changeset
   241
  }
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3527
diff changeset
   242
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   243
private:
7252
c8200621e252 rerun check-style.py with uncrustify-0.58
Tom Henderson <tomh@tomh.org>
parents: 7169
diff changeset
   244
  void DoSetTestB (bool v) { m_boolTestA = v; }
c8200621e252 rerun check-style.py with uncrustify-0.58
Tom Henderson <tomh@tomh.org>
parents: 7169
diff changeset
   245
  bool DoGetTestB (void) const { return m_boolTestA; }
c8200621e252 rerun check-style.py with uncrustify-0.58
Tom Henderson <tomh@tomh.org>
parents: 7169
diff changeset
   246
  int16_t DoGetInt16 (void) const { return m_int16SetGet; }
c8200621e252 rerun check-style.py with uncrustify-0.58
Tom Henderson <tomh@tomh.org>
parents: 7169
diff changeset
   247
  void DoSetInt16 (int16_t v) { m_int16SetGet = v; }
c8200621e252 rerun check-style.py with uncrustify-0.58
Tom Henderson <tomh@tomh.org>
parents: 7169
diff changeset
   248
  uint32_t DoGetVectorN (void) const { return m_vector2.size (); }
c8200621e252 rerun check-style.py with uncrustify-0.58
Tom Henderson <tomh@tomh.org>
parents: 7169
diff changeset
   249
  Ptr<Derived> DoGetVector (uint32_t i) const { return m_vector2[i]; }
c8200621e252 rerun check-style.py with uncrustify-0.58
Tom Henderson <tomh@tomh.org>
parents: 7169
diff changeset
   250
  bool DoSetIntSrc (int8_t v) { m_intSrc2 = v; return true; }
c8200621e252 rerun check-style.py with uncrustify-0.58
Tom Henderson <tomh@tomh.org>
parents: 7169
diff changeset
   251
  int8_t DoGetIntSrc (void) const { return m_intSrc2; }
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   252
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   253
  bool m_boolTestA;
10220
fd5b94ebc43f Bug 1779 - NS_UNUSED_GLOBAL not working in attribute test class declaration
Vedran Miletić <rivanvx@gmail.com>
parents: 10218
diff changeset
   254
  bool m_boolTest;
fd5b94ebc43f Bug 1779 - NS_UNUSED_GLOBAL not working in attribute test class declaration
Vedran Miletić <rivanvx@gmail.com>
parents: 10218
diff changeset
   255
  int16_t m_int16;
fd5b94ebc43f Bug 1779 - NS_UNUSED_GLOBAL not working in attribute test class declaration
Vedran Miletić <rivanvx@gmail.com>
parents: 10218
diff changeset
   256
  int16_t m_int16WithBounds;
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   257
  int16_t m_int16SetGet;
10220
fd5b94ebc43f Bug 1779 - NS_UNUSED_GLOBAL not working in attribute test class declaration
Vedran Miletić <rivanvx@gmail.com>
parents: 10218
diff changeset
   258
  uint8_t m_uint8;
fd5b94ebc43f Bug 1779 - NS_UNUSED_GLOBAL not working in attribute test class declaration
Vedran Miletić <rivanvx@gmail.com>
parents: 10218
diff changeset
   259
  float m_float;
fd5b94ebc43f Bug 1779 - NS_UNUSED_GLOBAL not working in attribute test class declaration
Vedran Miletić <rivanvx@gmail.com>
parents: 10218
diff changeset
   260
  enum Test_e m_enum;
8996
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   261
  Ptr<RandomVariableStream> m_random;
2405
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2385
diff changeset
   262
  std::vector<Ptr<Derived> > m_vector1;
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2385
diff changeset
   263
  std::vector<Ptr<Derived> > m_vector2;
7884
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   264
  std::map <uint32_t, Ptr<Derived> > m_map1;
3763
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3527
diff changeset
   265
  Callback<void,int8_t> m_cbValue;
2482
adbc284a5849 EventTraceSource -> TracedCallback, ValueTraceSource -> TracedValue.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2469
diff changeset
   266
  TracedValue<int8_t> m_intSrc1;
adbc284a5849 EventTraceSource -> TracedCallback, ValueTraceSource -> TracedValue.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2469
diff changeset
   267
  TracedValue<int8_t> m_intSrc2;
adbc284a5849 EventTraceSource -> TracedCallback, ValueTraceSource -> TracedValue.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2469
diff changeset
   268
  TracedCallback<double, int, float> m_cb;
adbc284a5849 EventTraceSource -> TracedCallback, ValueTraceSource -> TracedValue.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2469
diff changeset
   269
  TracedValue<ValueClassTest> m_valueSrc;
2926
96d1fc816681 Pointer class for primitive type pointer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
   270
  Ptr<Derived> m_ptr;
7859
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
   271
  Ptr<Derived> m_ptrInitialized;
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
   272
  Ptr<Derived> m_ptrInitialized2;
6490
34e72f4cdd87 bug 956: workaround compiler bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6445
diff changeset
   273
  TracedValue<uint8_t> m_uintSrc;
34e72f4cdd87 bug 956: workaround compiler bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6445
diff changeset
   274
  TracedValue<enum Test_e> m_enumSrc;
34e72f4cdd87 bug 956: workaround compiler bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6445
diff changeset
   275
  TracedValue<double> m_doubleSrc;
34e72f4cdd87 bug 956: workaround compiler bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6445
diff changeset
   276
  TracedValue<bool> m_boolSrc;
9891
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   277
  Time m_timeWithBounds;
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   278
};
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   279
10652
dc18deba4502 [doxygen] Revert r10410, r10411, r10412
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10410
diff changeset
   280
NS_OBJECT_ENSURE_REGISTERED (AttributeObjectTest);
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   281
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   282
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   283
// Test case template used for generic Attribute Value types -- used to make 
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   284
// sure that Attributes work as expected.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   285
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   286
template <typename T>
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   287
class AttributeTestCase : public TestCase
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   288
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   289
public:
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   290
  AttributeTestCase (std::string description);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   291
  virtual ~AttributeTestCase ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   292
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   293
private:
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
   294
  virtual void DoRun (void);
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   295
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   296
  bool CheckGetCodePaths (Ptr<Object> p, std::string attributeName, std::string expectedString, T expectedValue);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   297
};
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   298
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   299
template <typename T>
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   300
AttributeTestCase<T>::AttributeTestCase (std::string description)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   301
  : TestCase (description)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   302
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   303
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   304
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   305
template <typename T>
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   306
AttributeTestCase<T>::~AttributeTestCase ()
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   307
{
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   308
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   309
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   310
template <typename T> bool
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   311
AttributeTestCase<T>::CheckGetCodePaths (
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   312
  Ptr<Object> p, 
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   313
  std::string attributeName,
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   314
  std::string expectedString,
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   315
  T expectedValue)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   316
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   317
  StringValue stringValue;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   318
  T actualValue;
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   319
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   320
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   321
  // Get an Attribute value through its StringValue representation.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   322
  //
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   323
  bool ok1 = p->GetAttributeFailSafe (attributeName.c_str (), stringValue);
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   324
  bool ok2 = stringValue.Get () == expectedString;
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   325
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   326
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   327
  // Get the existing boolean value through its particular type representation.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   328
  //
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   329
  bool ok3 = p->GetAttributeFailSafe (attributeName.c_str (), actualValue);
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   330
  bool ok4 = expectedValue.Get () == actualValue.Get ();
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   331
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   332
  return ok1 && ok2 && ok3 && ok4;
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   333
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   334
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   335
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   336
// The actual Attribute type test cases are specialized for each Attribute type
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   337
// ===========================================================================
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
   338
template <> void
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   339
AttributeTestCase<BooleanValue>::DoRun (void)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   340
{
2450
3ad8ebe70756 value-test.cc -> attribute-test.cc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2444
diff changeset
   341
  Ptr<AttributeObjectTest> p;
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   342
  bool ok;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   343
7399
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7256
diff changeset
   344
  p = CreateObject<AttributeObjectTest> ();
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7256
diff changeset
   345
  NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   346
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   347
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   348
  // Set the default value of the BooleanValue and create an object.  The new
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   349
  // default value should stick.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   350
  //
7399
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7256
diff changeset
   351
  Config::SetDefault ("ns3::AttributeObjectTest::TestBoolName", StringValue ("true"));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   352
  p = CreateObject<AttributeObjectTest> ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   353
  NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   354
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   355
  ok = CheckGetCodePaths (p, "TestBoolName", "true", BooleanValue (true));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   356
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by default value");
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   357
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   358
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   359
  // Set the default value of the BooleanValue the other way and create an object.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   360
  // The new default value should stick.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   361
  //
7399
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7256
diff changeset
   362
  Config::SetDefaultFailSafe ("ns3::AttributeObjectTest::TestBoolName", StringValue ("false"));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   363
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   364
  p = CreateObject<AttributeObjectTest> ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   365
  NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   366
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   367
  ok = CheckGetCodePaths (p, "TestBoolName", "false", BooleanValue (false));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   368
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not et properly by default value");
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   369
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   370
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   371
  // Set the BooleanValue Attribute to true via SetAttributeFailSafe path.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   372
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   373
  ok = p->SetAttributeFailSafe ("TestBoolName", StringValue ("true"));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   374
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() \"TestBoolName\" to true");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   375
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   376
  ok = CheckGetCodePaths (p, "TestBoolName", "true", BooleanValue (true));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   377
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by SetAttributeFailSafe() via StringValue");
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   378
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   379
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   380
  // Set the BooleanValue to false via SetAttributeFailSafe path.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   381
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   382
  ok = p->SetAttributeFailSafe ("TestBoolName", StringValue ("false"));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   383
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() \"TestBoolName\" to false");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   384
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   385
  ok = CheckGetCodePaths (p, "TestBoolName", "false", BooleanValue (false));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   386
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by SetAttributeFailSafe() via StringValue");
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   387
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   388
  //
7399
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7256
diff changeset
   389
  // Create an object using
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   390
  //
7399
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7256
diff changeset
   391
  p = CreateObject<AttributeObjectTest> ();
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7256
diff changeset
   392
  NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   393
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   394
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   395
  // The previous object-based tests checked access directly.  Now check through
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   396
  // setter and getter.  The code here looks the same, but the underlying
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   397
  // attribute is declared differently in the object.  First make sure we can set
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   398
  // to true.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   399
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   400
  ok = p->SetAttributeFailSafe ("TestBoolA", StringValue ("true"));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   401
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a boolean value to true");
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   402
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   403
  ok = CheckGetCodePaths (p, "TestBoolA", "true", BooleanValue (true));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   404
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by SetAttributeFailSafe() (getter/setter) via StringValue");
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   405
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   406
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   407
  // Now Set the BooleanValue to false via the setter.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   408
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   409
  ok = p->SetAttributeFailSafe ("TestBoolA", StringValue ("false"));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   410
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a boolean value to false");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   411
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   412
  ok = CheckGetCodePaths (p, "TestBoolA", "false", BooleanValue (false));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   413
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by SetAttributeFailSafe() (getter/setter) via StringValue");
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   414
}
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   415
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
   416
template <> void
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   417
AttributeTestCase<IntegerValue>::DoRun (void)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   418
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   419
  Ptr<AttributeObjectTest> p;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   420
  bool ok;
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   421
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   422
  p = CreateObject<AttributeObjectTest> ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   423
  NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   424
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   425
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   426
  // When the object is first created, the Attribute should have the default 
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   427
  // value.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   428
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   429
  ok = CheckGetCodePaths (p, "TestInt16", "-2", IntegerValue (-2));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   430
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by default value");
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   431
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   432
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   433
  // Set the Attribute to a negative value through a StringValue.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   434
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   435
  ok = p->SetAttributeFailSafe ("TestInt16", StringValue ("-5"));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   436
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via StringValue to -5");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   437
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   438
  ok = CheckGetCodePaths (p, "TestInt16", "-5", IntegerValue (-5));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   439
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by SetAttributeFailSafe() via StringValue");
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   440
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   441
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   442
  // Set the Attribute to a positive value through a StringValue.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   443
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   444
  ok = p->SetAttributeFailSafe ("TestInt16", StringValue ("+2"));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   445
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via StringValue to +2");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   446
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   447
  ok = CheckGetCodePaths (p, "TestInt16", "2", IntegerValue (2));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   448
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by SetAttributeFailSafe() via StringValue");
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   449
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   450
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   451
  // Set the Attribute to the most negative value of the signed 16-bit range.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   452
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   453
  ok = p->SetAttributeFailSafe ("TestInt16", StringValue ("-32768"));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   454
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via StringValue to -32768");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   455
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   456
  ok = CheckGetCodePaths (p, "TestInt16", "-32768", IntegerValue (-32768));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   457
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by SetAttributeFailSafe() (most negative) via StringValue");
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   458
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   459
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   460
  // Try to set the Attribute past the most negative value of the signed 16-bit
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   461
  // range and make sure the underlying attribute is unchanged.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   462
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   463
  ok = p->SetAttributeFailSafe ("TestInt16", StringValue ("-32769"));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   464
  NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via StringValue to -32769");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   465
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   466
  ok = CheckGetCodePaths (p, "TestInt16", "-32768", IntegerValue (-32768));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   467
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Error in SetAttributeFailSafe() but value changes");
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   468
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   469
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   470
  // Set the Attribute to the most positive value of the signed 16-bit range.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   471
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   472
  ok = p->SetAttributeFailSafe ("TestInt16", StringValue ("32767"));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   473
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via StringValue to 32767");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   474
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   475
  ok = CheckGetCodePaths (p, "TestInt16", "32767", IntegerValue (32767));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   476
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by SetAttributeFailSafe() (most positive) via StringValue");
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   477
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   478
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   479
  // Try to set the Attribute past the most positive value of the signed 16-bit
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   480
  // range and make sure the underlying attribute is unchanged.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   481
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   482
  ok = p->SetAttributeFailSafe ("TestInt16", StringValue ("32768"));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   483
  NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via StringValue to 32768");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   484
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   485
  ok = CheckGetCodePaths (p, "TestInt16", "32767", IntegerValue (32767));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   486
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Error in SetAttributeFailSafe() but value changes");
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   487
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   488
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   489
  // Attributes can have limits other than the intrinsic limits of the
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   490
  // underlying data types.  These limits are specified in the Object.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   491
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   492
  ok = p->SetAttributeFailSafe ("TestInt16WithBounds", IntegerValue (10));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   493
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to 10");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   494
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   495
  ok = CheckGetCodePaths (p, "TestInt16WithBounds", "10", IntegerValue (10));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   496
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by SetAttributeFailSafe() (positive limit) via StringValue");
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   497
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   498
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   499
  // Set the Attribute past the positive limit.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   500
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   501
  ok = p->SetAttributeFailSafe ("TestInt16WithBounds", IntegerValue (11));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   502
  NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via IntegerValue to 11");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   503
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   504
  ok = CheckGetCodePaths (p, "TestInt16WithBounds", "10", IntegerValue (10));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   505
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Error in SetAttributeFailSafe() but value changes");
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   506
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   507
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   508
  // Set the Attribute at the negative limit.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   509
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   510
  ok = p->SetAttributeFailSafe ("TestInt16WithBounds", IntegerValue (-5));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   511
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to -5");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   512
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   513
  ok = CheckGetCodePaths (p, "TestInt16WithBounds", "-5", IntegerValue (-5));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   514
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by SetAttributeFailSafe() (negative limit) via StringValue");
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   515
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   516
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   517
  // Set the Attribute past the negative limit.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   518
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   519
  ok = p->SetAttributeFailSafe ("TestInt16WithBounds", IntegerValue (-6));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   520
  NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via IntegerValue to -6");
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   521
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   522
  ok = CheckGetCodePaths (p, "TestInt16WithBounds", "-5", IntegerValue (-5));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   523
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Error in SetAttributeFailSafe() but value changes");
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   524
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   525
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
   526
template <> void
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   527
AttributeTestCase<UintegerValue>::DoRun (void)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   528
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   529
  Ptr<AttributeObjectTest> p;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   530
  bool ok;
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   531
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   532
  p = CreateObject<AttributeObjectTest> ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   533
  NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   534
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   535
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   536
  // When the object is first created, the Attribute should have the default 
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   537
  // value.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   538
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   539
  ok = CheckGetCodePaths (p, "TestUint8", "1", UintegerValue (1));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   540
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by default value");;
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   541
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   542
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   543
  // Set the Attribute to zero.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   544
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   545
  ok = p->SetAttributeFailSafe ("TestUint8", UintegerValue (0));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   546
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() to 0");
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   547
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   548
  ok = CheckGetCodePaths (p, "TestUint8", "0", UintegerValue (0));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   549
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by SetAttributeFailSafe() via StringValue");
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   550
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   551
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   552
  // Set the Attribute to the most positive value of the unsigned 8-bit range.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   553
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   554
  ok = p->SetAttributeFailSafe ("TestUint8", UintegerValue (255));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   555
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() to 255");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   556
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   557
  ok = CheckGetCodePaths (p, "TestUint8", "255", UintegerValue (255));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   558
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by SetAttributeFailSafe() (positive limit) via UintegerValue");
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   559
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   560
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   561
  // Try and set the Attribute past the most positive value of the unsigned 
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   562
  // 8-bit range.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   563
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   564
  ok = p->SetAttributeFailSafe ("TestUint8", UintegerValue (256));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   565
  NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() to 256");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   566
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   567
  ok = CheckGetCodePaths (p, "TestUint8", "255", UintegerValue (255));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   568
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Error in SetAttributeFailSafe() but value changes");
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   569
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   570
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   571
  // Set the Attribute to the most positive value of the unsigned 8-bit range
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   572
  // through a StringValue.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   573
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   574
  ok = p->SetAttributeFailSafe ("TestUint8", StringValue ("255"));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   575
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via StringValue to 255");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   576
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   577
  ok = CheckGetCodePaths (p, "TestUint8", "255", UintegerValue (255));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   578
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by SetAttributeFailSafe() via StringValue");
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   579
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   580
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   581
  // Try and set the Attribute past the most positive value of the unsigned
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   582
  // 8-bit range through a StringValue.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   583
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   584
  ok = p->SetAttributeFailSafe ("TestUint8", StringValue ("256"));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   585
  NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via StringValue to 256");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   586
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   587
  ok = CheckGetCodePaths (p, "TestUint8", "255", UintegerValue (255));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   588
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Error in SetAttributeFailSafe() but value changes");
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   589
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   590
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   591
  // Try to set the Attribute to a negative StringValue.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   592
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   593
  ok = p->SetAttributeFailSafe ("TestUint8", StringValue ("-1"));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   594
  NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via StringValue to -1");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   595
}
2375
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
   596
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
   597
template <> void
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   598
AttributeTestCase<DoubleValue>::DoRun (void)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   599
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   600
  Ptr<AttributeObjectTest> p;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   601
  bool ok;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   602
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   603
  p = CreateObject<AttributeObjectTest> ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   604
  NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   605
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   606
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   607
  // When the object is first created, the Attribute should have the default 
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   608
  // value.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   609
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   610
  ok = CheckGetCodePaths (p, "TestFloat", "-1.1", DoubleValue ((float)-1.1));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   611
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by default value");
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   612
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   613
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   614
  // Set the Attribute.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   615
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   616
  ok = p->SetAttributeFailSafe ("TestFloat", DoubleValue ((float)2.3));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   617
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() to 2.3");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   618
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   619
  ok = CheckGetCodePaths (p, "TestFloat", "2.3", DoubleValue ((float)2.3));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   620
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by SetAttributeFailSafe() via DoubleValue");
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   621
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   622
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
   623
template <> void
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   624
AttributeTestCase<EnumValue>::DoRun (void)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   625
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   626
  Ptr<AttributeObjectTest> p;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   627
  bool ok;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   628
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   629
  p = CreateObject<AttributeObjectTest> ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   630
  NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   631
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   632
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   633
  // When the object is first created, the Attribute should have the default 
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   634
  // value.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   635
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   636
  ok = CheckGetCodePaths (p, "TestEnum", "TestA", EnumValue (AttributeObjectTest::TEST_A));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   637
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by default value");
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   638
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   639
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   640
  // Set the Attribute using the EnumValue type.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   641
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   642
  ok = p->SetAttributeFailSafe ("TestEnum", EnumValue (AttributeObjectTest::TEST_C));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   643
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() to TEST_C");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   644
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   645
  ok = CheckGetCodePaths (p, "TestEnum", "TestC", EnumValue (AttributeObjectTest::TEST_C));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   646
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by SetAttributeFailSafe() via EnumValue");
2385
ae4d6740d5a0 add back FpValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2384
diff changeset
   647
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   648
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   649
  // Set the Attribute using the StringValue type.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   650
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   651
  ok = p->SetAttributeFailSafe ("TestEnum", StringValue ("TestB"));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   652
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() to TEST_B");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   653
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   654
  ok = CheckGetCodePaths (p, "TestEnum", "TestB", EnumValue (AttributeObjectTest::TEST_B));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   655
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by SetAttributeFailSafe() via StringValue");
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   656
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   657
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   658
  // Try to set the Attribute to a bogus enum using the StringValue type and 
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   659
  // make sure the underlying value doesn't change.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   660
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   661
  ok = p->SetAttributeFailSafe ("TestEnum", StringValue ("TestD"));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   662
  NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() to TEST_D"); // 
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   663
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   664
  ok = CheckGetCodePaths (p, "TestEnum", "TestB", EnumValue (AttributeObjectTest::TEST_B));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   665
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Error in SetAttributeFailSafe() but value changes");
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   666
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   667
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   668
  // Try to set the Attribute to a bogus enum using an integer implicit conversion
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   669
  // and make sure the underlying value doesn't change.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   670
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   671
  ok = p->SetAttributeFailSafe ("TestEnum", EnumValue (5));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   672
  NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() to 5");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   673
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   674
  ok = CheckGetCodePaths (p, "TestEnum", "TestB", EnumValue (AttributeObjectTest::TEST_B));
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   675
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Error in SetAttributeFailSafe() but value changes");
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   676
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   677
9891
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   678
template <> void
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   679
AttributeTestCase<TimeValue>::DoRun (void)
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   680
{
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   681
  Ptr<AttributeObjectTest> p;
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   682
  bool ok;
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   683
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   684
  p = CreateObject<AttributeObjectTest> ();
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   685
  NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   686
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   687
  //
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   688
  // Set value
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   689
  //
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   690
  ok = p->SetAttributeFailSafe ("TestTimeWithBounds", TimeValue (Seconds (5)));
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   691
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via TimeValue to 5s");
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   692
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   693
  ok = CheckGetCodePaths (p, "TestTimeWithBounds", "+5000000000.0ns", TimeValue (Seconds (5)));
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   694
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by SetAttributeFailSafe() (5s) via TimeValue");
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   695
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   696
  ok = p->SetAttributeFailSafe ("TestTimeWithBounds", StringValue ("3s"));
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   697
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via TimeValue to 5s");
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   698
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   699
  ok = CheckGetCodePaths (p, "TestTimeWithBounds", "+3000000000.0ns", TimeValue (Seconds (3)));
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   700
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by SetAttributeFailSafe() (3s) via StringValue");
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   701
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   702
  
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   703
  //
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   704
  // Attributes can have limits other than the intrinsic limits of the
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   705
  // underlying data types.  These limits are specified in the Object.
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   706
  //
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   707
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   708
  //
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   709
  // Set the Attribute at the positive limit
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   710
  //
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   711
  ok = p->SetAttributeFailSafe ("TestTimeWithBounds", TimeValue (Seconds (10)));
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   712
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via TimeValue to 10");
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   713
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   714
  ok = CheckGetCodePaths (p, "TestTimeWithBounds", "+10000000000.0ns", TimeValue (Seconds (10)));
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   715
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by SetAttributeFailSafe() (positive limit) via StringValue");
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   716
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   717
  //
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   718
  // Set the Attribute past the positive limit.
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   719
  //
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   720
  ok = p->SetAttributeFailSafe ("TestTimeWithBounds", TimeValue (Seconds (11)));
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   721
  NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via TimeValue to 11");
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   722
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   723
  ok = CheckGetCodePaths (p, "TestTimeWithBounds", "+10000000000.0ns", TimeValue (Seconds (10)));
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   724
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Error in SetAttributeFailSafe() but value changes");
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   725
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   726
  //
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   727
  // Set the Attribute at the negative limit.
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   728
  //
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   729
  ok = p->SetAttributeFailSafe ("TestTimeWithBounds", TimeValue (Seconds (-5)));
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   730
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via TimeValue to -5");
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   731
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   732
  ok = CheckGetCodePaths (p, "TestTimeWithBounds", "-5000000000.0ns", TimeValue (Seconds (-5)));
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   733
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by SetAttributeFailSafe() (negative limit) via StringValue");
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   734
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   735
  //
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   736
  // Set the Attribute past the negative limit.
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   737
  //
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   738
  ok = p->SetAttributeFailSafe ("TestTimeWithBounds", TimeValue (Seconds (-6)));
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   739
  NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via TimeValue to -6");
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   740
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   741
  ok = CheckGetCodePaths (p, "TestTimeWithBounds", "-5000000000.0ns", TimeValue (Seconds (-5)));
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   742
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Error in SetAttributeFailSafe() but value changes");
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   743
}
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
   744
8996
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   745
// ===========================================================================
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   746
// Test the Attributes of type RandomVariableStream.
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   747
// ===========================================================================
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   748
class RandomVariableStreamAttributeTestCase : public TestCase
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   749
{
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   750
public:
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   751
  RandomVariableStreamAttributeTestCase (std::string description);
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   752
  virtual ~RandomVariableStreamAttributeTestCase () {}
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   753
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   754
  void InvokeCbValue (int8_t a)
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   755
  {
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   756
    if (!m_cbValue.IsNull ()) {
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   757
        m_cbValue (a);
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   758
      }
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   759
  }
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   760
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   761
private:
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   762
  virtual void DoRun (void);
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   763
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   764
  Callback<void,int8_t> m_cbValue;
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   765
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   766
  void NotifyCallbackValue (int8_t a) { m_gotCbValue = a; }
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   767
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   768
  int16_t m_gotCbValue;
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   769
};
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   770
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   771
RandomVariableStreamAttributeTestCase::RandomVariableStreamAttributeTestCase (std::string description)
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   772
  : TestCase (description)
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   773
{
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   774
}
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   775
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   776
void
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   777
RandomVariableStreamAttributeTestCase::DoRun (void)
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   778
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   779
  Ptr<AttributeObjectTest> p;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   780
  bool ok;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   781
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   782
  p = CreateObject<AttributeObjectTest> ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   783
  NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   784
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   785
  //
8996
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   786
  // Try to set a UniformRandomVariable
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   787
  //
8996
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   788
  ok = p->SetAttributeFailSafe ("TestRandom", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]"));
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   789
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a UniformRandomVariable");
2385
ae4d6740d5a0 add back FpValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2384
diff changeset
   790
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   791
  //
8996
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   792
  // Try to set a <snicker> ConstantRandomVariable
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   793
  //
8996
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   794
  //  ok = p->SetAttributeFailSafe ("TestRandom", StringValue ("ns3::ConstantRandomVariable[Constant=10.0]"));
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   795
  //ok = p->SetAttributeFailSafe ("TestRandom", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]"));
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   796
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   797
  ok = p->SetAttributeFailSafe ("TestRandom", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"));
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   798
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
   799
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a ConstantRandomVariable");
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   800
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   801
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   802
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   803
// Test case for Object Vector Attributes.  Generic nature is pretty much lost
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   804
// here, so we just break the class out.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   805
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   806
class ObjectVectorAttributeTestCase : public TestCase
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   807
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   808
public:
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   809
  ObjectVectorAttributeTestCase (std::string description);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   810
  virtual ~ObjectVectorAttributeTestCase () {}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   811
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   812
private:
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
   813
  virtual void DoRun (void);
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   814
};
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   815
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   816
ObjectVectorAttributeTestCase::ObjectVectorAttributeTestCase (std::string description)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   817
  : TestCase (description)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   818
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   819
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   820
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
   821
void
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   822
ObjectVectorAttributeTestCase::DoRun (void)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   823
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   824
  Ptr<AttributeObjectTest> p;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   825
  ObjectVectorValue vector;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   826
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   827
  p = CreateObject<AttributeObjectTest> ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   828
  NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   829
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   830
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   831
  // When the object is first created, the Attribute should have no items in
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   832
  // the vector.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   833
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   834
  p->GetAttribute ("TestVector1", vector);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   835
  NS_TEST_ASSERT_MSG_EQ (vector.GetN (), 0, "Initial count of ObjectVectorValue \"TestVector1\" should be zero");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   836
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   837
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   838
  // Adding to the attribute shouldn't affect the value we already have.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   839
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   840
  p->AddToVector1 ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   841
  NS_TEST_ASSERT_MSG_EQ (vector.GetN (), 0, "Initial count of ObjectVectorValue \"TestVector1\" should still be zero");
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   842
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   843
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   844
  // Getting the attribute again should update the value.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   845
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   846
  p->GetAttribute ("TestVector1", vector);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   847
  NS_TEST_ASSERT_MSG_EQ (vector.GetN (), 1, "ObjectVectorValue \"TestVector1\" should be incremented");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   848
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   849
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   850
  // Get the Object pointer from the value.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   851
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   852
  Ptr<Object> a = vector.Get (0);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   853
  NS_TEST_ASSERT_MSG_NE (a, 0, "Ptr<Object> from VectorValue \"TestVector1\" is zero");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   854
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   855
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   856
  // Adding to the attribute shouldn't affect the value we already have.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   857
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   858
  p->AddToVector1 ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   859
  NS_TEST_ASSERT_MSG_EQ (vector.GetN (), 1, "Count of ObjectVectorValue \"TestVector1\" should still be one");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   860
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   861
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   862
  // Getting the attribute again should update the value.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   863
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   864
  p->GetAttribute ("TestVector1", vector);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   865
  NS_TEST_ASSERT_MSG_EQ (vector.GetN (), 2, "ObjectVectorValue \"TestVector1\" should be incremented");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   866
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   867
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   868
// ===========================================================================
7884
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   869
// Test case for Object Map Attributes.
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   870
// ===========================================================================
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   871
class ObjectMapAttributeTestCase : public TestCase
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   872
{
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   873
public:
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   874
  ObjectMapAttributeTestCase (std::string description);
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   875
  virtual ~ObjectMapAttributeTestCase () {}
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   876
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   877
private:
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   878
  virtual void DoRun (void);
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   879
};
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   880
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   881
ObjectMapAttributeTestCase::ObjectMapAttributeTestCase (std::string description)
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   882
  : TestCase (description)
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   883
{
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   884
}
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   885
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   886
void
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   887
ObjectMapAttributeTestCase::DoRun (void)
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   888
{
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   889
  Ptr<AttributeObjectTest> p;
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   890
  ObjectMapValue map;
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   891
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   892
  p = CreateObject<AttributeObjectTest> ();
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   893
  NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   894
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   895
  //
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   896
  // When the object is first created, the Attribute should have no items in
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   897
  // the vector.
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   898
  //
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   899
  p->GetAttribute ("TestMap1", map);
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   900
  NS_TEST_ASSERT_MSG_EQ (map.GetN (), 0, "Initial count of ObjectVectorValue \"TestMap1\" should be zero");
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   901
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   902
  //
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   903
  // Adding to the attribute shouldn't affect the value we already have.
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   904
  //
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   905
  p->AddToMap1 (1);
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   906
  NS_TEST_ASSERT_MSG_EQ (map.GetN (), 0, "Initial count of ObjectVectorValue \"TestMap1\" should still be zero");
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   907
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   908
  //
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   909
  // Getting the attribute again should update the value.
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   910
  //
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   911
  p->GetAttribute ("TestMap1", map);
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   912
  NS_TEST_ASSERT_MSG_EQ (map.GetN (), 1, "ObjectVectorValue \"TestMap1\" should be incremented");
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   913
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   914
  //
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   915
  // Get the Object pointer from the value.
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   916
  //
8765
b89660102b63 Fixed valgrind errors in attribute system. Fixed typo in AttributeMap test. Fixed Get() method for elements not present in the map
Jaume Nin
parents: 7884
diff changeset
   917
  Ptr<Object> a = map.Get (1);
7884
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   918
  NS_TEST_ASSERT_MSG_NE (a, 0, "Ptr<Object> from VectorValue \"TestMap1\" is zero");
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   919
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   920
  //
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   921
  // Adding to the attribute shouldn't affect the value we already have.
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   922
  //
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   923
  p->AddToMap1 (2);
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   924
  NS_TEST_ASSERT_MSG_EQ (map.GetN (), 1, "Count of ObjectVectorValue \"TestMap1\" should still be one");
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   925
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   926
  //
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   927
  // Getting the attribute again should update the value.
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   928
  //
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   929
  p->GetAttribute ("TestMap1", map);
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   930
  NS_TEST_ASSERT_MSG_EQ (map.GetN (), 2, "ObjectVectorValue \"TestMap1\" should be incremented");
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   931
}
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   932
963d5bfe9c52 Fixed bug 1352 (Object attribute map / vector issue)
Jaume Nin <jnin@cttc.cat>
parents: 7859
diff changeset
   933
// ===========================================================================
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   934
// Trace sources with value semantics can be used like Attributes.  Make sure
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   935
// we can use them that way.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   936
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   937
class IntegerTraceSourceAttributeTestCase : public TestCase
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   938
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   939
public:
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   940
  IntegerTraceSourceAttributeTestCase (std::string description);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   941
  virtual ~IntegerTraceSourceAttributeTestCase () {}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   942
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   943
private:
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
   944
  virtual void DoRun (void);
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   945
};
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   946
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   947
IntegerTraceSourceAttributeTestCase::IntegerTraceSourceAttributeTestCase (std::string description)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   948
  : TestCase (description)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   949
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   950
}
2405
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2385
diff changeset
   951
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
   952
void
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   953
IntegerTraceSourceAttributeTestCase::DoRun (void)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   954
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   955
  Ptr<AttributeObjectTest> p;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   956
  IntegerValue iv;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   957
  bool ok;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   958
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   959
  p = CreateObject<AttributeObjectTest> ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   960
  NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   961
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   962
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   963
  // When the object is first created, the Attribute should have the default 
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   964
  // value.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   965
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   966
  p->GetAttribute ("IntegerTraceSource1", iv);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   967
  NS_TEST_ASSERT_MSG_EQ (iv.Get (), -2, "Attribute not set properly by default value");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   968
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   969
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   970
  // Set the Attribute to a positive value through an IntegerValue.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   971
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   972
  ok = p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (5));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   973
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to 5");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   974
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   975
  p->GetAttribute ("IntegerTraceSource1", iv);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   976
  NS_TEST_ASSERT_MSG_EQ (iv.Get (), 5, "Attribute not set properly by SetAttributeFailSafe() via IntegerValue");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   977
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   978
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   979
  // Limits should work.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   980
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   981
  ok = p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (127));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   982
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to 127");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   983
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   984
  ok = p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (128));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   985
  NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via IntegerValue to 128");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   986
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   987
  ok = p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (-128));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   988
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to -128");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   989
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   990
  ok = p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (-129));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   991
  NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via IntegerValue to -129");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   992
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   993
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   994
  // When the object is first created, the Attribute should have the default 
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   995
  // value.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   996
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   997
  p->GetAttribute ("IntegerTraceSource2", iv);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   998
  NS_TEST_ASSERT_MSG_EQ (iv.Get (), -2, "Attribute not set properly by default value");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   999
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1000
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1001
  // Set the Attribute to a positive value through an IntegerValue.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1002
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
  1003
  ok = p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (5));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1004
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to 5");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1005
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1006
  p->GetAttribute ("IntegerTraceSource2", iv);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1007
  NS_TEST_ASSERT_MSG_EQ (iv.Get (), 5, "Attribute not set properly by SetAttributeFailSafe() via IntegerValue");
2405
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2385
diff changeset
  1008
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1009
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1010
  // Limits should work.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1011
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
  1012
  ok = p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (127));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1013
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to 127");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1014
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
  1015
  ok = p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (128));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1016
  NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via IntegerValue to 128");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1017
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
  1018
  ok = p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (-128));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1019
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to -128");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1020
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
  1021
  ok = p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (-129));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1022
  NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via IntegerValue to -129");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1023
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1024
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1025
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1026
// Trace sources used like Attributes must also work as trace sources.  Make 
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1027
// sure we can use them that way.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1028
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1029
class IntegerTraceSourceTestCase : public TestCase
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1030
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1031
public:
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1032
  IntegerTraceSourceTestCase (std::string description);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1033
  virtual ~IntegerTraceSourceTestCase () {}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1034
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1035
private:
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
  1036
  virtual void DoRun (void);
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1037
7252
c8200621e252 rerun check-style.py with uncrustify-0.58
Tom Henderson <tomh@tomh.org>
parents: 7169
diff changeset
  1038
  void NotifySource1 (int8_t old, int8_t n) { m_got1 = n; }
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1039
  int64_t m_got1;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1040
};
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1041
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1042
IntegerTraceSourceTestCase::IntegerTraceSourceTestCase (std::string description)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1043
  : TestCase (description)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1044
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1045
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1046
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
  1047
void
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1048
IntegerTraceSourceTestCase::DoRun (void)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1049
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1050
  Ptr<AttributeObjectTest> p;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1051
  bool ok;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1052
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1053
  p = CreateObject<AttributeObjectTest> ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1054
  NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
2384
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2381
diff changeset
  1055
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1056
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1057
  // Check to make sure changing an Attibute value triggers a trace callback
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1058
  // that sets a member variable.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1059
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1060
  m_got1 = 1234;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1061
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1062
  ok = p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (-1));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1063
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to -1");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1064
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1065
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1066
  // Source1 is declared as a TraceSourceAccessor to m_intSrc1.  This m_intSrc1
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1067
  // is also declared as an Integer Attribute.  We just checked to make sure we
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1068
  // could set it using an IntegerValue through its IntegerTraceSource1 "persona."
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1069
  // We should also be able to hook a trace source to the underlying variable.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1070
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1071
  ok = p->TraceConnectWithoutContext ("Source1", MakeCallback (&IntegerTraceSourceTestCase::NotifySource1, this));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1072
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not TraceConnectWithoutContext() \"Source1\" to NodifySource1()");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1073
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1074
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1075
  // When we set the IntegerValue that now underlies both the Integer Attribute
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1076
  // and the trace source, the trace should fire and call NotifySource1 which
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1077
  // will set m_got1 to the new value.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1078
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1079
  ok = p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (0));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1080
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to 0");
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1081
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1082
  NS_TEST_ASSERT_MSG_EQ (m_got1, 0, "Hitting a TracedValue does not cause trace callback to be called");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1083
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1084
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1085
  // Now disconnect from the trace source and ensure that the trace callback
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1086
  // is not called if the trace source is hit.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1087
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1088
  ok = p->TraceDisconnectWithoutContext ("Source1", MakeCallback (&IntegerTraceSourceTestCase::NotifySource1, this));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1089
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not TraceConnectWithoutContext() \"Source1\" to NodifySource1()");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1090
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1091
  ok = p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (1));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1092
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to 1");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1093
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1094
  NS_TEST_ASSERT_MSG_EQ (m_got1, 0, "Hitting a TracedValue after disconnect still causes callback");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1095
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1096
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1097
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1098
// Trace sources used like Attributes must also work as trace sources.  Make 
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1099
// sure we can use them that way.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1100
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1101
class TracedCallbackTestCase : public TestCase
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1102
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1103
public:
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1104
  TracedCallbackTestCase (std::string description);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1105
  virtual ~TracedCallbackTestCase () {}
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1106
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1107
private:
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
  1108
  virtual void DoRun (void);
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1109
7252
c8200621e252 rerun check-style.py with uncrustify-0.58
Tom Henderson <tomh@tomh.org>
parents: 7169
diff changeset
  1110
  void NotifySource2 (double a, int b, float c) { m_got2 = a; }
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1111
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1112
  double m_got2;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1113
};
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1114
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1115
TracedCallbackTestCase::TracedCallbackTestCase (std::string description)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1116
  : TestCase (description)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1117
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1118
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1119
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
  1120
void
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1121
TracedCallbackTestCase::DoRun (void)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1122
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1123
  Ptr<AttributeObjectTest> p;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1124
  bool ok;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1125
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1126
  p = CreateObject<AttributeObjectTest> ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1127
  NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
2462
93028d4474ba add an IntegerTraceSource which behaves just like an Integer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2460
diff changeset
  1128
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1129
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1130
  // Initialize the 
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1131
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1132
  m_got2 = 4.3;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1133
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1134
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1135
  // Invoke the callback that lies at the heart of this test.  We have a
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1136
  // method InvokeCb() that just executes m_cb().  The variable m_cb is 
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1137
  // declared as a TracedCallback<double, int, float>.  This kind of beast
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1138
  // is like a callback but can call a list of targets.  This list should
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1139
  // be empty so nothing should happen now.  Specifically, m_got2 shouldn't
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1140
  // have changed.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1141
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1142
  p->InvokeCb (1.0, -5, 0.0);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1143
  NS_TEST_ASSERT_MSG_EQ (m_got2, 4.3, "Invoking a newly created TracedCallback results in an unexpected callback");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1144
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1145
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1146
  // Now, wire the TracedCallback up to a trace sink.  This sink will just set
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1147
  // m_got2 to the first argument.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1148
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1149
  ok = p->TraceConnectWithoutContext ("Source2", MakeCallback (&TracedCallbackTestCase::NotifySource2, this));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1150
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not TraceConnectWithoutContext() to NotifySource2");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1151
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1152
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1153
  // Now if we invoke the callback, the trace source should fire and m_got2
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1154
  // should be set in the trace sink.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1155
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1156
  p->InvokeCb (1.0, -5, 0.0);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1157
  NS_TEST_ASSERT_MSG_EQ (m_got2, 1.0, "Invoking TracedCallback does not result in trace callback");
2462
93028d4474ba add an IntegerTraceSource which behaves just like an Integer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2460
diff changeset
  1158
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1159
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1160
  // Now, disconnect the trace sink and see what happens when we invoke the
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1161
  // callback again.  Of course, the trace should not happen and m_got2 
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1162
  // should remain unchanged.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1163
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1164
  ok = p->TraceDisconnectWithoutContext ("Source2", MakeCallback (&TracedCallbackTestCase::NotifySource2, this));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1165
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not TraceDisconnectWithoutContext() from NotifySource2");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1166
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1167
  p->InvokeCb (-1.0, -5, 0.0);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1168
  NS_TEST_ASSERT_MSG_EQ (m_got2, 1.0, "Invoking disconnected TracedCallback unexpectedly results in trace callback");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1169
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1170
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1171
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1172
// Smart pointers (Ptr) are central to our architecture, so they must work as
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1173
// attributes.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1174
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1175
class PointerAttributeTestCase : public TestCase
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1176
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1177
public:
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1178
  PointerAttributeTestCase (std::string description);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1179
  virtual ~PointerAttributeTestCase () {}
2466
8e4ee14cc574 make EventTraceSource acceptable to the MakeTraceSourceAccessor function
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2464
diff changeset
  1180
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1181
private:
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
  1182
  virtual void DoRun (void);
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1183
7252
c8200621e252 rerun check-style.py with uncrustify-0.58
Tom Henderson <tomh@tomh.org>
parents: 7169
diff changeset
  1184
  void NotifySource2 (double a, int b, float c) { m_got2 = a; }
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1185
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1186
  double m_got2;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1187
};
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1188
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1189
PointerAttributeTestCase::PointerAttributeTestCase (std::string description)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1190
  : TestCase (description)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1191
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1192
}
2469
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
  1193
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
  1194
void
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1195
PointerAttributeTestCase::DoRun (void)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1196
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1197
  Ptr<AttributeObjectTest> p;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1198
  bool ok;
2926
96d1fc816681 Pointer class for primitive type pointer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
  1199
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1200
  p = CreateObject<AttributeObjectTest> ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1201
  NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1202
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1203
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1204
  // We have declared a PointerValue Attribute named "Pointer" with a pointer
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1205
  // checker of type Derived.  This means that we should be able to pull out
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1206
  // a Ptr<Derived> with the initial value (which is 0).
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1207
  //
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
  1208
  PointerValue ptr;
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
  1209
  p->GetAttribute ("Pointer", ptr);
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
  1210
  Ptr<Derived> derived = ptr.Get<Derived> ();
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1211
  NS_TEST_ASSERT_MSG_EQ (derived, 0, "Unexpectedly found non-null pointer in newly initialized PointerValue Attribute");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1212
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1213
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1214
  // Now, lets create an Object of type Derived and set the local Ptr to point
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1215
  // to that object.  We can then set the PointerValue Attribute to that Ptr.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1216
  //
2926
96d1fc816681 Pointer class for primitive type pointer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
  1217
  derived = Create<Derived> ();
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
  1218
  ok = p->SetAttributeFailSafe ("Pointer", PointerValue (derived));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1219
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a PointerValue of the correct type");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1220
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1221
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1222
  // Pull the value back out of the Attribute and make sure it points to the
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1223
  // correct object.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1224
  //
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
  1225
  p->GetAttribute ("Pointer", ptr);
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
  1226
  Ptr<Derived> stored = ptr.Get<Derived> ();
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1227
  NS_TEST_ASSERT_MSG_EQ (stored, derived, "Retreived Attribute does not match stored PointerValue");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1228
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1229
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1230
  // We should be able to use the Attribute Get() just like GetObject<type>,
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1231
  // So see if we can get a Ptr<Object> out of the Ptr<Derived> we stored.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1232
  // This should be a pointer to the same physical memory since its the 
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1233
  // same object.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1234
  //
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
  1235
  p->GetAttribute ("Pointer", ptr);
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
  1236
  Ptr<Object> storedBase = ptr.Get<Object> ();
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1237
  NS_TEST_ASSERT_MSG_EQ (storedBase, stored, "Retreived Ptr<Object> does not match stored Ptr<Derived>");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1238
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1239
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1240
  // If we try to Get() something that is unrelated to what we stored, we should
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1241
  // retrieve a 0.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1242
  //
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
  1243
  p->GetAttribute ("Pointer", ptr);
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
  1244
  Ptr<AttributeObjectTest> x = ptr.Get<AttributeObjectTest> ();
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1245
  NS_TEST_ASSERT_MSG_EQ (x, 0, "Unexpectedly retreived unrelated Ptr<type> from stored Ptr<Derived>");
7859
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1246
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1247
  //
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1248
  // Test whether the initialized pointers from two different objects
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1249
  // point to different Derived objects
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1250
  //
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1251
  p->GetAttribute ("PointerInitialized", ptr);
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1252
  Ptr<Derived> storedPtr = ptr.Get<Derived> ();
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1253
  Ptr<AttributeObjectTest> p2 = CreateObject<AttributeObjectTest> ();
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1254
  PointerValue ptr2;
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1255
  p2->GetAttribute ("PointerInitialized", ptr2);
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1256
  Ptr<Derived> storedPtr2 = ptr2.Get<Derived> ();
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1257
  NS_TEST_ASSERT_MSG_NE (storedPtr, storedPtr2, "ptr and ptr2 both have PointerInitialized pointing to the same object");
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1258
  PointerValue ptr3;
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1259
  p2->GetAttribute ("PointerInitialized", ptr3);
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1260
  Ptr<Derived> storedPtr3 = ptr3.Get<Derived> ();
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1261
  NS_TEST_ASSERT_MSG_NE (storedPtr, storedPtr3, "ptr and ptr3 both have PointerInitialized pointing to the same object");
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1262
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1263
  // 
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1264
  // Test whether object factory creates the objects properly
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1265
  //
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1266
  ObjectFactory factory;
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1267
  factory.SetTypeId ("ns3::AttributeObjectTest");
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1268
  factory.Set ("PointerInitialized", StringValue ("ns3::Derived"));
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1269
  Ptr<AttributeObjectTest> aotPtr = factory.Create ()->GetObject<AttributeObjectTest> ();
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1270
  NS_TEST_ASSERT_MSG_NE (aotPtr, 0, "Unable to factory.Create() a AttributeObjectTest");
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1271
  Ptr<AttributeObjectTest> aotPtr2 = factory.Create ()->GetObject<AttributeObjectTest> ();
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1272
  NS_TEST_ASSERT_MSG_NE (aotPtr2, 0, "Unable to factory.Create() a AttributeObjectTest");
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1273
  NS_TEST_ASSERT_MSG_NE (aotPtr, aotPtr2, "factory object not creating unique objects");
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1274
  PointerValue ptr4;
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1275
  aotPtr->GetAttribute ("PointerInitialized", ptr4);
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1276
  Ptr<Derived> storedPtr4 = ptr4.Get<Derived> ();
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1277
  PointerValue ptr5;
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1278
  aotPtr2->GetAttribute ("PointerInitialized", ptr5);
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1279
  Ptr<Derived> storedPtr5 = ptr5.Get<Derived> ();
ad7dbee94ba6 test code to support previous three commits
Tom Henderson <tomh@tomh.org>
parents: 7399
diff changeset
  1280
  NS_TEST_ASSERT_MSG_NE (storedPtr4, storedPtr5, "aotPtr and aotPtr2 are unique, but their Derived member is not");
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1281
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1282
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1283
// ===========================================================================
8996
d0e0a162a990 Replace various instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8765
diff changeset
  1284
// Test the Attributes of type CallbackValue.
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1285
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1286
class CallbackValueTestCase : public TestCase
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1287
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1288
public:
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1289
  CallbackValueTestCase (std::string description);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1290
  virtual ~CallbackValueTestCase () {}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1291
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1292
  void InvokeCbValue (int8_t a)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1293
  {
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1294
    if (!m_cbValue.IsNull ()) {
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1295
        m_cbValue (a);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1296
      }
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1297
  }
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1298
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1299
private:
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
  1300
  virtual void DoRun (void);
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1301
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1302
  Callback<void,int8_t> m_cbValue;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1303
7252
c8200621e252 rerun check-style.py with uncrustify-0.58
Tom Henderson <tomh@tomh.org>
parents: 7169
diff changeset
  1304
  void NotifyCallbackValue (int8_t a) { m_gotCbValue = a; }
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1305
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1306
  int16_t m_gotCbValue;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1307
};
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1308
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1309
CallbackValueTestCase::CallbackValueTestCase (std::string description)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1310
  : TestCase (description)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1311
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1312
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1313
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
  1314
void
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1315
CallbackValueTestCase::DoRun (void)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1316
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1317
  Ptr<AttributeObjectTest> p;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1318
  bool ok;
2463
c77e43117673 actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2462
diff changeset
  1319
3763
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3527
diff changeset
  1320
  p = CreateObject<AttributeObjectTest> ();
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1321
  NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1322
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1323
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1324
  // The member variable m_cbValue is declared as a Callback<void, int8_t>.  The
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1325
  // Attibute named "Callback" also points to m_cbValue and allows us to set the
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1326
  // callback using that Attribute.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1327
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1328
  // NotifyCallbackValue is going to be the target of the callback and will just set
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1329
  // m_gotCbValue to its single parameter.  This will be the parameter from the
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1330
  // callback invocation.  The method InvokeCbValue() just invokes the m_cbValue 
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1331
  // callback if it is non-null.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1332
  //
3763
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3527
diff changeset
  1333
  m_gotCbValue = 1;
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1334
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1335
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1336
  // If we invoke the callback (which has not been set) nothing should happen.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1337
  // Further, nothing should happen when we initialize the callback (it shouldn't
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1338
  // accidentally fire).
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1339
  //
3763
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3527
diff changeset
  1340
  p->InvokeCbValue (2);
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1341
  CallbackValue cbValue = MakeCallback (&CallbackValueTestCase::NotifyCallbackValue, this);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1342
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1343
  NS_TEST_ASSERT_MSG_EQ (m_gotCbValue, 1, "Callback unexpectedly fired");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1344
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1345
  ok = p->SetAttributeFailSafe ("Callback", cbValue);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1346
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a CallbackValue");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1347
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1348
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1349
  // Now that the callback has been set, invoking it should set m_gotCbValue.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1350
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1351
  p->InvokeCbValue (2);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1352
  NS_TEST_ASSERT_MSG_EQ (m_gotCbValue, 2, "Callback Attribute set by CallbackValue did not fire");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1353
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1354
  ok = p->SetAttributeFailSafe ("Callback", CallbackValue (MakeNullCallback<void,int8_t> ()));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1355
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a null CallbackValue");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1356
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1357
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1358
  // If the callback has been set to a null callback, it should no longer fire.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1359
  //
3763
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3527
diff changeset
  1360
  p->InvokeCbValue (3);
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1361
  NS_TEST_ASSERT_MSG_EQ (m_gotCbValue, 2, "Callback Attribute set to null callback unexpectedly fired");
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
  1362
}
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1363
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1364
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1365
// The Test Suite that glues all of the Test Cases together.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1366
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1367
class AttributesTestSuite : public TestSuite
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1368
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1369
public:
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1370
  AttributesTestSuite ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1371
};
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1372
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1373
AttributesTestSuite::AttributesTestSuite ()
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1374
  : TestSuite ("attributes", UNIT)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1375
{
9266
d26408b17360 bug 1563: get rid of default argument value in AddTestCase
Nicola Baldo <nbaldo@cttc.es>
parents: 9079
diff changeset
  1376
  AddTestCase (new AttributeTestCase<BooleanValue> ("Check Attributes of type BooleanValue"), TestCase::QUICK);
d26408b17360 bug 1563: get rid of default argument value in AddTestCase
Nicola Baldo <nbaldo@cttc.es>
parents: 9079
diff changeset
  1377
  AddTestCase (new AttributeTestCase<IntegerValue> ("Check Attributes of type IntegerValue"), TestCase::QUICK);
d26408b17360 bug 1563: get rid of default argument value in AddTestCase
Nicola Baldo <nbaldo@cttc.es>
parents: 9079
diff changeset
  1378
  AddTestCase (new AttributeTestCase<UintegerValue> ("Check Attributes of type UintegerValue"), TestCase::QUICK);
d26408b17360 bug 1563: get rid of default argument value in AddTestCase
Nicola Baldo <nbaldo@cttc.es>
parents: 9079
diff changeset
  1379
  AddTestCase (new AttributeTestCase<DoubleValue> ("Check Attributes of type DoubleValue"), TestCase::QUICK);
d26408b17360 bug 1563: get rid of default argument value in AddTestCase
Nicola Baldo <nbaldo@cttc.es>
parents: 9079
diff changeset
  1380
  AddTestCase (new AttributeTestCase<EnumValue> ("Check Attributes of type EnumValue"), TestCase::QUICK);
9891
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
  1381
  AddTestCase (new AttributeTestCase<TimeValue> ("Check Attributes of type TimeValue"), TestCase::QUICK);
9266
d26408b17360 bug 1563: get rid of default argument value in AddTestCase
Nicola Baldo <nbaldo@cttc.es>
parents: 9079
diff changeset
  1382
  AddTestCase (new RandomVariableStreamAttributeTestCase ("Check Attributes of type RandomVariableStream"), TestCase::QUICK);
d26408b17360 bug 1563: get rid of default argument value in AddTestCase
Nicola Baldo <nbaldo@cttc.es>
parents: 9079
diff changeset
  1383
  AddTestCase (new ObjectVectorAttributeTestCase ("Check Attributes of type ObjectVectorValue"), TestCase::QUICK);
d26408b17360 bug 1563: get rid of default argument value in AddTestCase
Nicola Baldo <nbaldo@cttc.es>
parents: 9079
diff changeset
  1384
  AddTestCase (new ObjectMapAttributeTestCase ("Check Attributes of type ObjectMapValue"), TestCase::QUICK);
9891
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
  1385
  AddTestCase (new PointerAttributeTestCase ("Check Attributes of type PointerValue"), TestCase::QUICK);
e12094c8b31b Time attributes with enforced bounds.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9266
diff changeset
  1386
  AddTestCase (new CallbackValueTestCase ("Check Attributes of type CallbackValue"), TestCase::QUICK);
9266
d26408b17360 bug 1563: get rid of default argument value in AddTestCase
Nicola Baldo <nbaldo@cttc.es>
parents: 9079
diff changeset
  1387
  AddTestCase (new IntegerTraceSourceAttributeTestCase ("Ensure TracedValue<uint8_t> can be set like IntegerValue"), TestCase::QUICK);
d26408b17360 bug 1563: get rid of default argument value in AddTestCase
Nicola Baldo <nbaldo@cttc.es>
parents: 9079
diff changeset
  1388
  AddTestCase (new IntegerTraceSourceTestCase ("Ensure TracedValue<uint8_t> also works as trace source"), TestCase::QUICK);
d26408b17360 bug 1563: get rid of default argument value in AddTestCase
Nicola Baldo <nbaldo@cttc.es>
parents: 9079
diff changeset
  1389
  AddTestCase (new TracedCallbackTestCase ("Ensure TracedCallback<double, int, float> works as trace source"), TestCase::QUICK);
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1390
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1391
6490
34e72f4cdd87 bug 956: workaround compiler bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6445
diff changeset
  1392
static AttributesTestSuite attributesTestSuite;