src/core/test/attribute-test-suite.cc
author Josh Pelkey <jpelkey@gatech.edu>
Fri, 13 May 2011 14:52:27 -0400
changeset 7169 358f71a624d8
parent 7120 95b46556cbac
child 7252 c8200621e252
permissions -rw-r--r--
core coding style changes
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"
203367ae7433 merge src/simulator into src/core; move src/core to new module layout
Tom Henderson <tomh@tomh.org>
parents: 6775
diff changeset
    24
#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
    25
#include "ns3/string.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/random-variable.h"
203367ae7433 merge src/simulator into src/core; move src/core to new module layout
Tom Henderson <tomh@tomh.org>
parents: 6775
diff changeset
    27
#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
    28
#include "ns3/object-vector.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/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
    30
#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
    31
#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
    32
#include "ns3/pointer.h"
2405
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2385
diff changeset
    33
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    34
namespace ns3 {
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    35
2469
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    36
class ValueClassTest 
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    37
{
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    38
public:
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    39
  ValueClassTest () {}
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    40
private:
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    41
  int m_v;
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    42
};
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    43
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
    44
{
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    45
  return true;
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    46
}
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    47
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
    48
{
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    49
  return os;
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    50
}
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    51
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
    52
{
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    53
  return is;
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    54
}
3094
6e787ec9c8aa ATTRIBUTE_HELPER_HEADER_2 -> ATTRIBUTE_HELPER_HEADER
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2965
diff changeset
    55
ATTRIBUTE_HELPER_HEADER (ValueClassTest);
2582
3e28107b870f rename old VALUE leftovers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    56
ATTRIBUTE_HELPER_CPP (ValueClassTest);
2469
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
    57
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    58
class Derived : public Object
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    59
{
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    60
public:
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    61
  static TypeId GetTypeId (void) {
6445
43d91786d268 simple doxygen fixes
Josh Pelkey <jpelkey@gatech.edu>
parents: 5246
diff changeset
    62
    static TypeId tid = TypeId ("ns3::Derived")
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    63
      .SetParent<Object> ()
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
    64
    ;
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    65
    return tid;
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    66
  }
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    67
};
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    68
2450
3ad8ebe70756 value-test.cc -> attribute-test.cc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2444
diff changeset
    69
class AttributeObjectTest : public Object
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    70
{
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    71
public:
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
    72
  enum Test_e {
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    73
    TEST_A,
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    74
    TEST_B,
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    75
    TEST_C
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    76
  };
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    77
  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
    78
    static TypeId tid = TypeId ("ns3::AttributeObjectTest")
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    79
      .SetParent<Object> ()
2602
d9262bff6df2 add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2599
diff changeset
    80
      .HideFromDocumentation ()
2458
e8f7c4960576 AddParameter -> AddAttribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2457
diff changeset
    81
      .AddAttribute ("TestBoolName", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
    82
                     BooleanValue (false),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
    83
                     MakeBooleanAccessor (&AttributeObjectTest::m_boolTest),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
    84
                     MakeBooleanChecker ())
2458
e8f7c4960576 AddParameter -> AddAttribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2457
diff changeset
    85
      .AddAttribute ("TestBoolA", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
    86
                     BooleanValue (false),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
    87
                     MakeBooleanAccessor (&AttributeObjectTest::DoSetTestB,
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
    88
                                          &AttributeObjectTest::DoGetTestB),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
    89
                     MakeBooleanChecker ())
2458
e8f7c4960576 AddParameter -> AddAttribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2457
diff changeset
    90
      .AddAttribute ("TestInt16", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
    91
                     IntegerValue (-2),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
    92
                     MakeIntegerAccessor (&AttributeObjectTest::m_int16),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
    93
                     MakeIntegerChecker<int16_t> ())
2458
e8f7c4960576 AddParameter -> AddAttribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2457
diff changeset
    94
      .AddAttribute ("TestInt16WithBounds", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
    95
                     IntegerValue (-2),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
    96
                     MakeIntegerAccessor (&AttributeObjectTest::m_int16WithBounds),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
    97
                     MakeIntegerChecker<int16_t> (-5, 10))
2458
e8f7c4960576 AddParameter -> AddAttribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2457
diff changeset
    98
      .AddAttribute ("TestInt16SetGet", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
    99
                     IntegerValue (6),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   100
                     MakeIntegerAccessor (&AttributeObjectTest::DoSetInt16,
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   101
                                          &AttributeObjectTest::DoGetInt16),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   102
                     MakeIntegerChecker<int16_t> ())
2458
e8f7c4960576 AddParameter -> AddAttribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2457
diff changeset
   103
      .AddAttribute ("TestUint8", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   104
                     UintegerValue (1),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   105
                     MakeUintegerAccessor (&AttributeObjectTest::m_uint8),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   106
                     MakeUintegerChecker<uint8_t> ())
2458
e8f7c4960576 AddParameter -> AddAttribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2457
diff changeset
   107
      .AddAttribute ("TestEnum", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   108
                     EnumValue (TEST_A),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   109
                     MakeEnumAccessor (&AttributeObjectTest::m_enum),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   110
                     MakeEnumChecker (TEST_A, "TestA",
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   111
                                      TEST_B, "TestB",
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   112
                                      TEST_C, "TestC"))
2458
e8f7c4960576 AddParameter -> AddAttribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2457
diff changeset
   113
      .AddAttribute ("TestRandom", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   114
                     RandomVariableValue (ConstantVariable (1.0)),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   115
                     MakeRandomVariableAccessor (&AttributeObjectTest::m_random),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   116
                     MakeRandomVariableChecker ())
2458
e8f7c4960576 AddParameter -> AddAttribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2457
diff changeset
   117
      .AddAttribute ("TestFloat", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   118
                     DoubleValue (-1.1),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   119
                     MakeDoubleAccessor (&AttributeObjectTest::m_float),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   120
                     MakeDoubleChecker<float> ())
2458
e8f7c4960576 AddParameter -> AddAttribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2457
diff changeset
   121
      .AddAttribute ("TestVector1", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   122
                     ObjectVectorValue (),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   123
                     MakeObjectVectorAccessor (&AttributeObjectTest::m_vector1),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   124
                     MakeObjectVectorChecker<Derived> ())
2458
e8f7c4960576 AddParameter -> AddAttribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2457
diff changeset
   125
      .AddAttribute ("TestVector2", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   126
                     ObjectVectorValue (),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   127
                     MakeObjectVectorAccessor (&AttributeObjectTest::DoGetVectorN,
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   128
                                               &AttributeObjectTest::DoGetVector),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   129
                     MakeObjectVectorChecker<Derived> ())
2462
93028d4474ba add an IntegerTraceSource which behaves just like an Integer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2460
diff changeset
   130
      .AddAttribute ("IntegerTraceSource1", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   131
                     IntegerValue (-2),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   132
                     MakeIntegerAccessor (&AttributeObjectTest::m_intSrc1),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   133
                     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
   134
      .AddAttribute ("IntegerTraceSource2", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   135
                     IntegerValue (-2),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   136
                     MakeIntegerAccessor (&AttributeObjectTest::DoSetIntSrc,
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   137
                                          &AttributeObjectTest::DoGetIntSrc),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   138
                     MakeIntegerChecker<int8_t> ())
6490
34e72f4cdd87 bug 956: workaround compiler bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6445
diff changeset
   139
      .AddAttribute ("UIntegerTraceSource", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   140
                     UintegerValue (2),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   141
                     MakeUintegerAccessor (&AttributeObjectTest::m_uintSrc),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   142
                     MakeIntegerChecker<uint8_t> ())
6490
34e72f4cdd87 bug 956: workaround compiler bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6445
diff changeset
   143
      .AddAttribute ("DoubleTraceSource", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   144
                     DoubleValue (2),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   145
                     MakeDoubleAccessor (&AttributeObjectTest::m_doubleSrc),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   146
                     MakeDoubleChecker<double> ())
6490
34e72f4cdd87 bug 956: workaround compiler bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6445
diff changeset
   147
      .AddAttribute ("BoolTraceSource", "help text",
34e72f4cdd87 bug 956: workaround compiler bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6445
diff changeset
   148
                     BooleanValue (false),
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   149
                     MakeBooleanAccessor (&AttributeObjectTest::m_boolSrc),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   150
                     MakeBooleanChecker ())
6490
34e72f4cdd87 bug 956: workaround compiler bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6445
diff changeset
   151
      .AddAttribute ("EnumTraceSource", "help text",
34e72f4cdd87 bug 956: workaround compiler bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6445
diff changeset
   152
                     EnumValue (false),
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   153
                     MakeEnumAccessor (&AttributeObjectTest::m_enumSrc),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   154
                     MakeEnumChecker (TEST_A, "TestA"))
2469
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
   155
      .AddAttribute ("ValueClassSource", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   156
                     ValueClassTestValue (ValueClassTest ()),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   157
                     MakeValueClassTestAccessor (&AttributeObjectTest::m_valueSrc),
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   158
                     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
   159
      .AddTraceSource ("Source1", "help test",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   160
                       MakeTraceSourceAccessor (&AttributeObjectTest::m_intSrc1))
2466
8e4ee14cc574 make EventTraceSource acceptable to the MakeTraceSourceAccessor function
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2464
diff changeset
   161
      .AddTraceSource ("Source2", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   162
                       MakeTraceSourceAccessor (&AttributeObjectTest::m_cb))
2469
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
   163
      .AddTraceSource ("ValueSource", "help text",
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   164
                       MakeTraceSourceAccessor (&AttributeObjectTest::m_valueSrc))
3190
51fe9001a679 add some doxygen, remove a couple of XXX
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3094
diff changeset
   165
      .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
   166
                     PointerValue (),
2926
96d1fc816681 Pointer class for primitive type pointer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
   167
                     MakePointerAccessor (&AttributeObjectTest::m_ptr),
96d1fc816681 Pointer class for primitive type pointer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
   168
                     MakePointerChecker<Derived> ())
3763
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3527
diff changeset
   169
      .AddAttribute ("Callback", "help text",
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3527
diff changeset
   170
                     CallbackValue (),
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3527
diff changeset
   171
                     MakeCallbackAccessor (&AttributeObjectTest::m_cbValue),
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3527
diff changeset
   172
                     MakeCallbackChecker ())
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   173
    ;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   174
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   175
    return tid;
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   176
  }
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   177
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   178
  void AddToVector1 (void) { m_vector1.push_back (CreateObject<Derived> ());}
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   179
  void AddToVector2 (void) { m_vector2.push_back (CreateObject<Derived> ());}
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   180
  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
   181
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   182
  void InvokeCbValue (int8_t a)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   183
  {
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   184
    if (!m_cbValue.IsNull ()) {
3763
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3527
diff changeset
   185
        m_cbValue (a);
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3527
diff changeset
   186
      }
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3527
diff changeset
   187
  }
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3527
diff changeset
   188
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   189
private:
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   190
  void DoSetTestB (bool v) { m_boolTestA = v;}
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   191
  bool DoGetTestB (void) const { return m_boolTestA;}
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   192
  int16_t DoGetInt16 (void) const { return m_int16SetGet;}
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   193
  void DoSetInt16 (int16_t v) { m_int16SetGet = v;}
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   194
  uint32_t DoGetVectorN (void) const { return m_vector2.size ();}
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   195
  Ptr<Derived> DoGetVector (uint32_t i) const { return m_vector2[i];}
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   196
  bool DoSetIntSrc (int8_t v) { m_intSrc2 = v; return true;}
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   197
  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
   198
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   199
  bool m_boolTestA;
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   200
  bool m_boolTest;
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   201
  int16_t m_int16;
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   202
  int16_t m_int16WithBounds;
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   203
  int16_t m_int16SetGet;
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   204
  uint8_t m_uint8;
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   205
  float m_float;
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   206
  enum Test_e m_enum;
2384
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2381
diff changeset
   207
  RandomVariable m_random;
2405
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2385
diff changeset
   208
  std::vector<Ptr<Derived> > m_vector1;
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2385
diff changeset
   209
  std::vector<Ptr<Derived> > m_vector2;
3763
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3527
diff changeset
   210
  Callback<void,int8_t> m_cbValue;
2482
adbc284a5849 EventTraceSource -> TracedCallback, ValueTraceSource -> TracedValue.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2469
diff changeset
   211
  TracedValue<int8_t> m_intSrc1;
adbc284a5849 EventTraceSource -> TracedCallback, ValueTraceSource -> TracedValue.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2469
diff changeset
   212
  TracedValue<int8_t> m_intSrc2;
adbc284a5849 EventTraceSource -> TracedCallback, ValueTraceSource -> TracedValue.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2469
diff changeset
   213
  TracedCallback<double, int, float> m_cb;
adbc284a5849 EventTraceSource -> TracedCallback, ValueTraceSource -> TracedValue.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2469
diff changeset
   214
  TracedValue<ValueClassTest> m_valueSrc;
2926
96d1fc816681 Pointer class for primitive type pointer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
   215
  Ptr<Derived> m_ptr;
6490
34e72f4cdd87 bug 956: workaround compiler bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6445
diff changeset
   216
  TracedValue<uint8_t> m_uintSrc;
34e72f4cdd87 bug 956: workaround compiler bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6445
diff changeset
   217
  TracedValue<enum Test_e> m_enumSrc;
34e72f4cdd87 bug 956: workaround compiler bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6445
diff changeset
   218
  TracedValue<double> m_doubleSrc;
34e72f4cdd87 bug 956: workaround compiler bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6445
diff changeset
   219
  TracedValue<bool> m_boolSrc;
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   220
};
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   221
2450
3ad8ebe70756 value-test.cc -> attribute-test.cc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2444
diff changeset
   222
NS_OBJECT_ENSURE_REGISTERED (AttributeObjectTest);
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   223
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   224
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   225
// 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
   226
// 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
   227
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   228
template <typename T>
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   229
class AttributeTestCase : public TestCase
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   230
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   231
public:
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   232
  AttributeTestCase (std::string description);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   233
  virtual ~AttributeTestCase ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   234
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   235
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
   236
  virtual void DoRun (void);
5239
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
  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
   239
};
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   240
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   241
template <typename T>
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   242
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
   243
  : TestCase (description)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   244
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   245
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   246
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   247
template <typename T>
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   248
AttributeTestCase<T>::~AttributeTestCase ()
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   249
{
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   250
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   251
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   252
template <typename T> bool
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   253
AttributeTestCase<T>::CheckGetCodePaths (
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   254
  Ptr<Object> p, 
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   255
  std::string attributeName,
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   256
  std::string expectedString,
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   257
  T expectedValue)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   258
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   259
  StringValue stringValue;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   260
  T actualValue;
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   261
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   262
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   263
  // 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
   264
  //
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   265
  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
   266
  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
   267
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   268
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   269
  // 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
   270
  //
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   271
  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
   272
  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
   273
7120
95b46556cbac avoid the use of nested NS_TEST_ calls
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6821
diff changeset
   274
  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
   275
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   276
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   277
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   278
// 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
   279
// ===========================================================================
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
   280
template <> void
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   281
AttributeTestCase<BooleanValue>::DoRun (void)
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
  AttributeList attrs;
2450
3ad8ebe70756 value-test.cc -> attribute-test.cc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2444
diff changeset
   284
  Ptr<AttributeObjectTest> p;
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   285
  bool ok;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   286
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   287
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   288
  // Test setting a boolean via string representation using AttributeList.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   289
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   290
  ok = attrs.SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", StringValue ("false"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   291
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetFailSafe() \"ns3::AttributeObjectTest::TestBoolName\" into AttributeList");
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
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   294
  // Create an object using that attribute list (which should therefore have the
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   295
  // boolean from above set to false.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   296
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   297
  p = CreateObjectWithAttributes<AttributeObjectTest> (attrs);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   298
  NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObjectWithAttributes");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   299
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   300
  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
   301
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly from CreateObjectWithAttributes");
5239
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
  // 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
   305
  // default value should stick.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   306
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   307
  AttributeList::GetGlobal ()->SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", StringValue ("true"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   308
  p = CreateObject<AttributeObjectTest> ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   309
  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
   310
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   311
  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
   312
  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
   313
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   314
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   315
  // 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
   316
  // 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
   317
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   318
  AttributeList::GetGlobal ()->SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", StringValue ("false"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   319
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   320
  p = CreateObject<AttributeObjectTest> ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   321
  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
   322
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   323
  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
   324
  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
   325
5239
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
  // 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
   328
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   329
  ok = p->SetAttributeFailSafe("TestBoolName", StringValue ("true"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   330
  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
   331
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   332
  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
   333
  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
   334
5239
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
  // 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
   337
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   338
  ok = p->SetAttributeFailSafe("TestBoolName", StringValue ("false"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   339
  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
   340
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   341
  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
   342
  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
   343
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   344
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   345
  // Create an object using individually provided StringValue Attribute.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   346
  //
4554
b1940a738981 make CreateObject<> behave like Create<>: use positional constructor arguments rather than attribute lists.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3763
diff changeset
   347
  p = CreateObjectWithAttributes<AttributeObjectTest> ("TestBoolName", StringValue ("true"));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   348
  NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObjectWithAttributes");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   349
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   350
  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
   351
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by CreateObjectWithAttributes() with StringValue");
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   352
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   353
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   354
  // Create an object using individually provided BooleanValue Attribute.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   355
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   356
  p = CreateObjectWithAttributes<AttributeObjectTest> ("TestBoolName", BooleanValue (false));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   357
  NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObjectWithAttributes");
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
  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
   360
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by CreateObjectWithAttributes() with BooleanValue");
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   361
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   362
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   363
  // 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
   364
  // 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
   365
  // 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
   366
  // to true.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   367
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   368
  ok = p->SetAttributeFailSafe("TestBoolA", StringValue ("true"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   369
  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
   370
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   371
  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
   372
  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
   373
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   374
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   375
  // 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
   376
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   377
  ok = p->SetAttributeFailSafe("TestBoolA", StringValue ("false"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   378
  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
   379
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   380
  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
   381
  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
   382
}
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   383
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
   384
template <> void
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   385
AttributeTestCase<IntegerValue>::DoRun (void)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   386
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   387
  Ptr<AttributeObjectTest> p;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   388
  bool ok;
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   389
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   390
  p = CreateObject<AttributeObjectTest> ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   391
  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
   392
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   393
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   394
  // 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
   395
  // value.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   396
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   397
  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
   398
  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
   399
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   400
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   401
  // 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
   402
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   403
  ok = p->SetAttributeFailSafe("TestInt16", StringValue ("-5"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   404
  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
   405
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   406
  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
   407
  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
   408
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   409
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   410
  // 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
   411
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   412
  ok = p->SetAttributeFailSafe("TestInt16", StringValue ("+2"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   413
  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
   414
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   415
  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
   416
  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
   417
5239
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
  // 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
   420
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   421
  ok = p->SetAttributeFailSafe("TestInt16", StringValue ("-32768"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   422
  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
   423
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   424
  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
   425
  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
   426
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   427
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   428
  // 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
   429
  // 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
   430
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   431
  ok = p->SetAttributeFailSafe("TestInt16", StringValue ("-32769"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   432
  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
   433
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   434
  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
   435
  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
   436
5239
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
  // 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
   439
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   440
  ok = p->SetAttributeFailSafe("TestInt16", StringValue ("32767"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   441
  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
   442
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   443
  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
   444
  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
   445
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
  // 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
   448
  // 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
   449
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   450
  ok = p->SetAttributeFailSafe("TestInt16", StringValue ("32768"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   451
  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
   452
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   453
  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
   454
  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
   455
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   456
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   457
  // 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
   458
  // 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
   459
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   460
  ok = p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (10));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   461
  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
   462
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   463
  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
   464
  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
   465
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   466
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   467
  // 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
   468
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   469
  ok = p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (11));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   470
  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
   471
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   472
  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
   473
  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
   474
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   475
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   476
  // 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
   477
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   478
  ok = p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (-5));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   479
  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
   480
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   481
  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
   482
  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
   483
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
  // 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
   486
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   487
  ok = p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (-6));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   488
  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
   489
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   490
  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
   491
  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
   492
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   493
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
   494
template <> void
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   495
AttributeTestCase<UintegerValue>::DoRun (void)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   496
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   497
  Ptr<AttributeObjectTest> p;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   498
  bool ok;
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   499
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   500
  p = CreateObject<AttributeObjectTest> ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   501
  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
   502
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
  // 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
   505
  // value.
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
  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
   508
  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
   509
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   510
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   511
  // Set the Attribute to zero.
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 = p->SetAttributeFailSafe("TestUint8", UintegerValue (0));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   514
  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
   515
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   516
  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
   517
  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
   518
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   519
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   520
  // 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
   521
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   522
  ok = p->SetAttributeFailSafe("TestUint8", UintegerValue (255));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   523
  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
   524
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   525
  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
   526
  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
   527
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
  // 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
   530
  // 8-bit range.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   531
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   532
  ok = p->SetAttributeFailSafe("TestUint8", UintegerValue (256));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   533
  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
   534
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   535
  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
   536
  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
   537
5239
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
  // 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
   540
  // through a StringValue.
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
  ok = p->SetAttributeFailSafe("TestUint8", StringValue ("255"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   543
  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
   544
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   545
  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
   546
  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
   547
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   548
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   549
  // 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
   550
  // 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
   551
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   552
  ok = p->SetAttributeFailSafe("TestUint8", StringValue ("256"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   553
  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
   554
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   555
  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
   556
  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
   557
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   558
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   559
  // 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
   560
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   561
  ok = p->SetAttributeFailSafe("TestUint8", StringValue ("-1"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   562
  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
   563
}
2375
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
   564
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
   565
template <> void
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   566
AttributeTestCase<DoubleValue>::DoRun (void)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   567
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   568
  Ptr<AttributeObjectTest> p;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   569
  bool ok;
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
  p = CreateObject<AttributeObjectTest> ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   572
  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
   573
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   574
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   575
  // 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
   576
  // value.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   577
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   578
  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
   579
  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
   580
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   581
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   582
  // Set the Attribute.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   583
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   584
  ok = p->SetAttributeFailSafe("TestFloat", DoubleValue ((float)2.3));
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, 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
   586
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   587
  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
   588
  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
   589
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   590
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
   591
template <> void
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   592
AttributeTestCase<EnumValue>::DoRun (void)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   593
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   594
  Ptr<AttributeObjectTest> p;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   595
  bool ok;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   596
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   597
  p = CreateObject<AttributeObjectTest> ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   598
  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
   599
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   600
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   601
  // 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
   602
  // value.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   603
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   604
  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
   605
  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
   606
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   607
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   608
  // 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
   609
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   610
  ok = p->SetAttributeFailSafe("TestEnum", EnumValue (AttributeObjectTest::TEST_C));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   611
  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
   612
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   613
  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
   614
  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
   615
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   616
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   617
  // 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
   618
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   619
  ok = p->SetAttributeFailSafe("TestEnum", StringValue ("TestB"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   620
  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
   621
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   622
  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
   623
  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
   624
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
  // 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
   627
  // 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
   628
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   629
  ok = p->SetAttributeFailSafe("TestEnum", StringValue ("TestD"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   630
  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
   631
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   632
  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
   633
  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
   634
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
  // 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
   637
  // 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
   638
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   639
  ok = p->SetAttributeFailSafe("TestEnum", EnumValue (5));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   640
  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
   641
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   642
  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
   643
  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
   644
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   645
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
   646
template <> void
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   647
AttributeTestCase<RandomVariableValue>::DoRun (void)
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
  Ptr<AttributeObjectTest> p;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   650
  bool ok;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   651
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   652
  p = CreateObject<AttributeObjectTest> ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   653
  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
   654
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   655
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   656
  // Try to set a UniformVariable
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
  ok = p->SetAttributeFailSafe("TestRandom", RandomVariableValue (UniformVariable (0., 1.)));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   659
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a UniformVariable");
2385
ae4d6740d5a0 add back FpValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2384
diff changeset
   660
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   661
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   662
  // Try to set a <snicker> ConstantVariable
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 = p->SetAttributeFailSafe("TestRandom", RandomVariableValue (ConstantVariable (10.)));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   665
  NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a UniformVariable");
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
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   669
// 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
   670
// 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
   671
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   672
class ObjectVectorAttributeTestCase : public TestCase
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
public:
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   675
  ObjectVectorAttributeTestCase (std::string description);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   676
  virtual ~ObjectVectorAttributeTestCase () {}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   677
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   678
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
   679
  virtual void DoRun (void);
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   680
};
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   681
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   682
ObjectVectorAttributeTestCase::ObjectVectorAttributeTestCase (std::string description)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   683
  : TestCase (description)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   684
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   685
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   686
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
   687
void
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   688
ObjectVectorAttributeTestCase::DoRun (void)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   689
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   690
  Ptr<AttributeObjectTest> p;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   691
  ObjectVectorValue vector;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   692
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   693
  p = CreateObject<AttributeObjectTest> ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   694
  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
   695
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   696
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   697
  // 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
   698
  // the vector.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   699
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   700
  p->GetAttribute ("TestVector1", vector);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   701
  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
   702
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   703
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   704
  // 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
   705
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   706
  p->AddToVector1 ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   707
  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
   708
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   709
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   710
  // 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
   711
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   712
  p->GetAttribute ("TestVector1", vector);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   713
  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
   714
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   715
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   716
  // 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
   717
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   718
  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
   719
  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
   720
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   721
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   722
  // 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
   723
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   724
  p->AddToVector1 ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   725
  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
   726
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   727
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   728
  // 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
   729
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   730
  p->GetAttribute ("TestVector1", vector);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   731
  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
   732
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   733
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   734
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   735
// 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
   736
// 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
   737
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   738
class IntegerTraceSourceAttributeTestCase : public TestCase
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   739
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   740
public:
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   741
  IntegerTraceSourceAttributeTestCase (std::string description);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   742
  virtual ~IntegerTraceSourceAttributeTestCase () {}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   743
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   744
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
   745
  virtual void DoRun (void);
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   746
};
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   747
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   748
IntegerTraceSourceAttributeTestCase::IntegerTraceSourceAttributeTestCase (std::string description)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   749
  : TestCase (description)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   750
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   751
}
2405
17f406c71505 add ObjectVector value support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2385
diff changeset
   752
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
   753
void
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   754
IntegerTraceSourceAttributeTestCase::DoRun (void)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   755
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   756
  Ptr<AttributeObjectTest> p;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   757
  IntegerValue iv;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   758
  bool ok;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   759
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   760
  p = CreateObject<AttributeObjectTest> ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   761
  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
   762
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   763
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   764
  // 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
   765
  // value.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   766
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   767
  p->GetAttribute ("IntegerTraceSource1", iv);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   768
  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
   769
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   770
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   771
  // 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
   772
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   773
  ok = p->SetAttributeFailSafe("IntegerTraceSource1", IntegerValue (5));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   774
  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
   775
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   776
  p->GetAttribute ("IntegerTraceSource1", iv);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   777
  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
   778
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   779
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   780
  // Limits should work.
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
  ok = p->SetAttributeFailSafe("IntegerTraceSource1", IntegerValue (127));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   783
  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
   784
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   785
  ok = p->SetAttributeFailSafe("IntegerTraceSource1", IntegerValue (128));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   786
  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
   787
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   788
  ok = p->SetAttributeFailSafe("IntegerTraceSource1", IntegerValue (-128));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   789
  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
   790
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   791
  ok = p->SetAttributeFailSafe("IntegerTraceSource1", IntegerValue (-129));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   792
  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
   793
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   794
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   795
  // 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
   796
  // value.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   797
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   798
  p->GetAttribute ("IntegerTraceSource2", iv);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   799
  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
   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
  // 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
   803
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   804
  ok = p->SetAttributeFailSafe("IntegerTraceSource2", IntegerValue (5));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   805
  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
   806
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   807
  p->GetAttribute ("IntegerTraceSource2", iv);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   808
  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
   809
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   810
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   811
  // Limits should work.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   812
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   813
  ok = p->SetAttributeFailSafe("IntegerTraceSource2", IntegerValue (127));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   814
  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
   815
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   816
  ok = p->SetAttributeFailSafe("IntegerTraceSource2", IntegerValue (128));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   817
  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
   818
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   819
  ok = p->SetAttributeFailSafe("IntegerTraceSource2", IntegerValue (-128));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   820
  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
   821
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   822
  ok = p->SetAttributeFailSafe("IntegerTraceSource2", IntegerValue (-129));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   823
  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
   824
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   825
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
// 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
   828
// 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
   829
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   830
class IntegerTraceSourceTestCase : public TestCase
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   831
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   832
public:
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   833
  IntegerTraceSourceTestCase (std::string description);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   834
  virtual ~IntegerTraceSourceTestCase () {}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   835
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   836
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
   837
  virtual void DoRun (void);
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   838
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   839
  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
   840
  int64_t m_got1;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   841
};
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   842
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   843
IntegerTraceSourceTestCase::IntegerTraceSourceTestCase (std::string description)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   844
  : TestCase (description)
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
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   847
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
   848
void
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   849
IntegerTraceSourceTestCase::DoRun (void)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   850
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   851
  Ptr<AttributeObjectTest> p;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   852
  bool ok;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   853
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   854
  p = CreateObject<AttributeObjectTest> ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   855
  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
   856
5239
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
  // 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
   859
  // that sets a member variable.
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
  m_got1 = 1234;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   862
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   863
  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
   864
  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
   865
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
  // 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
   868
  // 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
   869
  // 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
   870
  // 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
   871
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   872
  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
   873
  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
   874
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   875
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   876
  // 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
   877
  // 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
   878
  // 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
   879
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   880
  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
   881
  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
   882
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   883
  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
   884
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   885
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   886
  // 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
   887
  // 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
   888
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   889
  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
   890
  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
   891
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   892
  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
   893
  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
   894
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   895
  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
   896
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   897
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   898
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   899
// 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
   900
// 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
   901
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   902
class TracedCallbackTestCase : public TestCase
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   903
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   904
public:
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   905
  TracedCallbackTestCase (std::string description);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   906
  virtual ~TracedCallbackTestCase () {}
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   907
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   908
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
   909
  virtual void DoRun (void);
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   910
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   911
  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
   912
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   913
  double m_got2;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   914
};
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   915
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   916
TracedCallbackTestCase::TracedCallbackTestCase (std::string description)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   917
  : TestCase (description)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   918
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   919
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   920
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
   921
void
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   922
TracedCallbackTestCase::DoRun (void)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   923
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   924
  Ptr<AttributeObjectTest> p;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   925
  bool ok;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   926
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   927
  p = CreateObject<AttributeObjectTest> ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   928
  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
   929
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   930
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   931
  // Initialize the 
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   932
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   933
  m_got2 = 4.3;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   934
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   935
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   936
  // 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
   937
  // 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
   938
  // 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
   939
  // 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
   940
  // 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
   941
  // have changed.
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
  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
   944
  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
   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
  // 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
   948
  // 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
   949
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   950
  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
   951
  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
   952
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   953
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   954
  // 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
   955
  // 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
   956
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   957
  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
   958
  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
   959
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   960
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   961
  // 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
   962
  // 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
   963
  // should remain unchanged.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   964
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   965
  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
   966
  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
   967
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   968
  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
   969
  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
   970
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   971
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   972
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   973
// 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
   974
// attributes.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   975
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   976
class PointerAttributeTestCase : public TestCase
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
public:
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   979
  PointerAttributeTestCase (std::string description);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   980
  virtual ~PointerAttributeTestCase () {}
2466
8e4ee14cc574 make EventTraceSource acceptable to the MakeTraceSourceAccessor function
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2464
diff changeset
   981
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   982
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
   983
  virtual void DoRun (void);
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   984
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
   985
  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
   986
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   987
  double m_got2;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   988
};
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   989
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   990
PointerAttributeTestCase::PointerAttributeTestCase (std::string description)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   991
  : TestCase (description)
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
}
2469
181c6a5b14c1 test the ValueTraceSource with an arbitrary class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2468
diff changeset
   994
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
   995
void
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   996
PointerAttributeTestCase::DoRun (void)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   997
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   998
  Ptr<AttributeObjectTest> p;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
   999
  bool ok;
2926
96d1fc816681 Pointer class for primitive type pointer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
  1000
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1001
  p = CreateObject<AttributeObjectTest> ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1002
  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
  1003
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1004
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1005
  // 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
  1006
  // 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
  1007
  // 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
  1008
  //
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
  1009
  PointerValue ptr;
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
  1010
  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
  1011
  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
  1012
  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
  1013
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1014
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1015
  // 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
  1016
  // 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
  1017
  //
2926
96d1fc816681 Pointer class for primitive type pointer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
  1018
  derived = Create<Derived> ();
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1019
  ok = p->SetAttributeFailSafe("Pointer", PointerValue (derived));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1020
  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
  1021
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1022
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1023
  // 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
  1024
  // correct object.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1025
  //
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
  1026
  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
  1027
  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
  1028
  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
  1029
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
  // 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
  1032
  // 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
  1033
  // 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
  1034
  // same object.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1035
  //
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
  1036
  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
  1037
  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
  1038
  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
  1039
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
  // 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
  1042
  // retrieve a 0.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1043
  //
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
  1044
  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
  1045
  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
  1046
  NS_TEST_ASSERT_MSG_EQ (x, 0, "Unexpectedly retreived unrelated Ptr<type> from stored Ptr<Derived>");
2926
96d1fc816681 Pointer class for primitive type pointer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
  1047
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1048
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1049
  // We should be able to create the object From a list of attributes.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1050
  //
4554
b1940a738981 make CreateObject<> behave like Create<>: use positional constructor arguments rather than attribute lists.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3763
diff changeset
  1051
  p = CreateObjectWithAttributes<AttributeObjectTest> ("Pointer", PointerValue (Create<Derived> ()));
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1052
  NS_TEST_ASSERT_MSG_NE (p, 0, "Could not create Object with PointerValue Attribute in Attribute List");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1053
2926
96d1fc816681 Pointer class for primitive type pointer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
  1054
  derived = 0;
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
  1055
  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
  1056
  derived = ptr.Get<Derived> ();
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1057
  NS_TEST_ASSERT_MSG_NE (p, 0, "Retrieved zero PointerValue Attribute after initializing to non-zero Ptr");
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1058
}
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
// ===========================================================================
5246
0974f3a8f379 Remove and replace CommandLine BVT (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
  1061
// Test the Attributes of type CallbackVale.
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1062
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1063
class CallbackValueTestCase : public TestCase
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
public:
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1066
  CallbackValueTestCase (std::string description);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1067
  virtual ~CallbackValueTestCase () {}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1068
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1069
  void InvokeCbValue (int8_t a)
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
    if (!m_cbValue.IsNull ()) {
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1072
        m_cbValue (a);
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
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1076
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
  1077
  virtual void DoRun (void);
5239
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
  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
  1080
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7120
diff changeset
  1081
  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
  1082
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1083
  int16_t m_gotCbValue;
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
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1086
CallbackValueTestCase::CallbackValueTestCase (std::string description)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1087
  : TestCase (description)
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1088
{
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1089
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1090
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6490
diff changeset
  1091
void
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1092
CallbackValueTestCase::DoRun (void)
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
  Ptr<AttributeObjectTest> p;
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1095
  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
  1096
3763
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3527
diff changeset
  1097
  p = CreateObject<AttributeObjectTest> ();
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1098
  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
  1099
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
  // 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
  1102
  // 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
  1103
  // callback using that Attribute.
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1104
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1105
  // 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
  1106
  // 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
  1107
  // 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
  1108
  // 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
  1109
  //
3763
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3527
diff changeset
  1110
  m_gotCbValue = 1;
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
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1113
  // 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
  1114
  // 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
  1115
  // accidentally fire).
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1116
  //
3763
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3527
diff changeset
  1117
  p->InvokeCbValue (2);
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1118
  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
  1119
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1120
  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
  1121
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1122
  ok = p->SetAttributeFailSafe ("Callback", cbValue);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1123
  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
  1124
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
  // 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
  1127
  //
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1128
  p->InvokeCbValue (2);
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1129
  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
  1130
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1131
  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
  1132
  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
  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
  // 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
  1136
  //
3763
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3527
diff changeset
  1137
  p->InvokeCbValue (3);
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1138
  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
  1139
}
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1140
5239
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
// 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
  1143
// ===========================================================================
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1144
class AttributesTestSuite : public TestSuite
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
public:
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1147
  AttributesTestSuite ();
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1148
};
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1149
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1150
AttributesTestSuite::AttributesTestSuite ()
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1151
  : TestSuite ("attributes", UNIT)
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
  AddTestCase (new AttributeTestCase<BooleanValue> ("Check Attributes of type BooleanValue"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1154
  AddTestCase (new AttributeTestCase<IntegerValue> ("Check Attributes of type IntegerValue"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1155
  AddTestCase (new AttributeTestCase<UintegerValue> ("Check Attributes of type UintegerValue"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1156
  AddTestCase (new AttributeTestCase<DoubleValue> ("Check Attributes of type DoubleValue"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1157
  AddTestCase (new AttributeTestCase<EnumValue> ("Check Attributes of type EnumValue"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1158
  AddTestCase (new AttributeTestCase<RandomVariableValue> ("Check Attributes of type RandomVariableValue"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1159
  AddTestCase (new ObjectVectorAttributeTestCase ("Check Attributes of type ObjectVectorValue"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1160
  AddTestCase (new IntegerTraceSourceAttributeTestCase ("Ensure TracedValue<uint8_t> can be set like IntegerValue"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1161
  AddTestCase (new IntegerTraceSourceTestCase ("Ensure TracedValue<uint8_t> also works as trace source"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1162
  AddTestCase (new TracedCallbackTestCase ("Ensure TracedCallback<double, int, float> works as trace source"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1163
  AddTestCase (new PointerAttributeTestCase ("Check Attributes of type PointerValue"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1164
  AddTestCase (new CallbackValueTestCase ("Check Attributes of type CallbackValue"));
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1165
}
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4554
diff changeset
  1166
6490
34e72f4cdd87 bug 956: workaround compiler bug
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6445
diff changeset
  1167
static AttributesTestSuite attributesTestSuite;
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1168
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1169
} // namespace ns3