1.1 --- a/src/common/buffer.cc Thu Oct 01 11:22:26 2009 +0200
1.2 +++ b/src/common/buffer.cc Thu Oct 01 11:24:55 2009 +0200
1.3 @@ -21,6 +21,9 @@
1.4 #include "ns3/assert.h"
1.5 #include "ns3/log.h"
1.6 #include "ns3/fatal-error.h"
1.7 +#include "ns3/test.h"
1.8 +#include "ns3/random-variable.h"
1.9 +#include <iomanip>
1.10 #include <iostream>
1.11
1.12 NS_LOG_COMPONENT_DEFINE ("Buffer");
1.13 @@ -1197,29 +1200,20 @@
1.14 return m_dataEnd - m_dataStart;
1.15 }
1.16
1.17 -} // namespace ns3
1.18 -
1.19 -
1.20 -#ifdef RUN_SELF_TESTS
1.21 -
1.22 -#include "ns3/test.h"
1.23 -#include "ns3/random-variable.h"
1.24 -#include <iomanip>
1.25 -
1.26 -
1.27 -namespace ns3 {
1.28 -
1.29 -class BufferTest: public Test {
1.30 +//-----------------------------------------------------------------------------
1.31 +// Unit tests
1.32 +//-----------------------------------------------------------------------------
1.33 +class BufferTest: public TestCase {
1.34 private:
1.35 bool EnsureWrittenBytes (Buffer b, uint32_t n, uint8_t array[]);
1.36 public:
1.37 - virtual bool RunTests (void);
1.38 + virtual bool DoRun (void);
1.39 BufferTest ();
1.40 };
1.41
1.42
1.43 BufferTest::BufferTest ()
1.44 - : Test ("Buffer") {}
1.45 + : TestCase ("Buffer") {}
1.46
1.47 bool
1.48 BufferTest::EnsureWrittenBytes (Buffer b, uint32_t n, uint8_t array[])
1.49 @@ -1237,22 +1231,24 @@
1.50 }
1.51 if (!success)
1.52 {
1.53 - Failure () << "Buffer -- ";
1.54 - Failure () << "expected: n=";
1.55 - Failure () << n << ", ";
1.56 - Failure ().setf (std::ios::hex, std::ios::basefield);
1.57 + std::ostringstream failure;
1.58 + failure << "Buffer -- ";
1.59 + failure << "expected: n=";
1.60 + failure << n << ", ";
1.61 + failure.setf (std::ios::hex, std::ios::basefield);
1.62 for (uint32_t j = 0; j < n; j++)
1.63 {
1.64 - Failure () << (uint16_t)expected[j] << " ";
1.65 + failure << (uint16_t)expected[j] << " ";
1.66 }
1.67 - Failure ().setf (std::ios::dec, std::ios::basefield);
1.68 - Failure () << "got: ";
1.69 - Failure ().setf (std::ios::hex, std::ios::basefield);
1.70 + failure.setf (std::ios::dec, std::ios::basefield);
1.71 + failure << "got: ";
1.72 + failure.setf (std::ios::hex, std::ios::basefield);
1.73 for (uint32_t j = 0; j < n; j++)
1.74 {
1.75 - Failure () << (uint16_t)got[j] << " ";
1.76 + failure << (uint16_t)got[j] << " ";
1.77 }
1.78 - Failure () << std::endl;
1.79 + failure << std::endl;
1.80 + ReportTestFailure ("", "", "", failure.str(), __FILE__, __LINE__);
1.81 }
1.82 return success;
1.83 }
1.84 @@ -1266,14 +1262,13 @@
1.85 uint8_t bytes[] = {__VA_ARGS__}; \
1.86 if (!EnsureWrittenBytes (buffer, n , bytes)) \
1.87 { \
1.88 - result = false; \
1.89 + SetErrorStatus (false); \
1.90 } \
1.91 }
1.92
1.93 bool
1.94 -BufferTest::RunTests (void)
1.95 +BufferTest::DoRun (void)
1.96 {
1.97 - bool result = true;
1.98 Buffer buffer;
1.99 Buffer::Iterator i;
1.100 buffer.AddAtStart (6);
1.101 @@ -1320,7 +1315,7 @@
1.102 i.Prev (2);
1.103 if (i.ReadNtohU16 () != 0xff00)
1.104 {
1.105 - result = false;
1.106 + SetErrorStatus (false);
1.107 }
1.108 i.Prev (2);
1.109 i.WriteU16 (saved);
1.110 @@ -1347,7 +1342,7 @@
1.111 i = buff64.Begin();
1.112 if (i.ReadLsbtohU64() != 0x0123456789abcdefllu)
1.113 {
1.114 - result = false;
1.115 + SetErrorStatus (false);
1.116 }
1.117 i = buff64.Begin();
1.118 i.WriteHtolsbU64 (0x0123456789ABCDEFllu);
1.119 @@ -1355,7 +1350,7 @@
1.120 i = buff64.Begin();
1.121 if (i.ReadLsbtohU64() != 0x0123456789abcdefllu)
1.122 {
1.123 - result = false;
1.124 + SetErrorStatus (false);
1.125 }
1.126 i = buff64.Begin();
1.127 i.WriteHtonU64 (0x0123456789ABCDEFllu);
1.128 @@ -1363,7 +1358,7 @@
1.129 i = buff64.Begin();
1.130 if (i.ReadNtohU64() != 0x0123456789abcdefllu)
1.131 {
1.132 - result = false;
1.133 + SetErrorStatus (false);
1.134 }
1.135
1.136 // test self-assignment
1.137 @@ -1438,7 +1433,7 @@
1.138 buffer.RemoveAtEnd (8);
1.139 if (buffer.GetSize () != 0)
1.140 {
1.141 - result = false;
1.142 + SetErrorStatus (false);
1.143 }
1.144
1.145 buffer = Buffer (6);
1.146 @@ -1462,13 +1457,6 @@
1.147 i.Prev (100);
1.148 i.WriteU8 (1, 100);
1.149
1.150 -#if 0
1.151 - buffer = Buffer (10);
1.152 - ENSURE_WRITTEN_BYTES (buffer, 10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
1.153 - buffer.Begin ().WriteU8 (1);
1.154 - ENSURE_WRITTEN_BYTES (buffer, 10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
1.155 -#endif
1.156 -
1.157 // Bug #54
1.158 {
1.159 const uint32_t actualSize = 72602;
1.160 @@ -1490,7 +1478,7 @@
1.161 iter.Prev (chunkSize);
1.162 iter.Write (inputBuffer.PeekData (), chunkSize);
1.163
1.164 - NS_TEST_ASSERT (memcmp (inputBuffer.PeekData (), outputBuffer.PeekData (), chunkSize) == 0);
1.165 + NS_TEST_EXPECT_MSG_EQ (memcmp (inputBuffer.PeekData (), outputBuffer.PeekData (), chunkSize), 0, "memcp works");
1.166 }
1.167
1.168 buffer = Buffer (5);
1.169 @@ -1508,15 +1496,23 @@
1.170 ENSURE_WRITTEN_BYTES (buffer, 7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66);
1.171 ENSURE_WRITTEN_BYTES (frag0, 7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66);
1.172
1.173 - return result;
1.174 + return GetErrorStatus ();
1.175 +}
1.176 +//-----------------------------------------------------------------------------
1.177 +class BufferTestSuite : public TestSuite
1.178 +{
1.179 +public:
1.180 + BufferTestSuite ();
1.181 +};
1.182 +
1.183 +BufferTestSuite::BufferTestSuite ()
1.184 + : TestSuite ("buffer", UNIT)
1.185 +{
1.186 + AddTestCase (new BufferTest);
1.187 }
1.188
1.189 -
1.190 -
1.191 -static BufferTest gBufferTest;
1.192 +BufferTestSuite g_bufferTestSuite;
1.193
1.194 } // namespace ns3
1.195
1.196 -#endif /* RUN_SELF_TESTS */
1.197
1.198 -
2.1 --- a/src/devices/point-to-point/point-to-point-test.cc Thu Oct 01 11:22:26 2009 +0200
2.2 +++ b/src/devices/point-to-point/point-to-point-test.cc Thu Oct 01 11:24:55 2009 +0200
2.3 @@ -1,5 +1,3 @@
2.4 -#ifdef RUN_SELF_TESTS
2.5 -
2.6 #include "ns3/test.h"
2.7 #include "ns3/drop-tail-queue.h"
2.8 #include "ns3/simulator.h"
2.9 @@ -8,19 +6,19 @@
2.10
2.11 namespace ns3 {
2.12
2.13 -class PointToPointTest : public Test
2.14 +class PointToPointTest : public TestCase
2.15 {
2.16 public:
2.17 PointToPointTest ();
2.18
2.19 - virtual bool RunTests (void);
2.20 + virtual bool DoRun (void);
2.21
2.22 private:
2.23 void SendOnePacket (Ptr<PointToPointNetDevice> device);
2.24 };
2.25
2.26 PointToPointTest::PointToPointTest ()
2.27 - : Test ("PointToPoint")
2.28 + : TestCase ("PointToPoint")
2.29 {}
2.30
2.31 void
2.32 @@ -32,10 +30,8 @@
2.33
2.34
2.35 bool
2.36 -PointToPointTest::RunTests (void)
2.37 +PointToPointTest::DoRun (void)
2.38 {
2.39 - bool result = true;
2.40 -
2.41 Ptr<Node> a = CreateObject<Node> ();
2.42 Ptr<Node> b = CreateObject<Node> ();
2.43 Ptr<PointToPointNetDevice> devA = CreateObject<PointToPointNetDevice> ();
2.44 @@ -58,11 +54,21 @@
2.45
2.46 Simulator::Destroy ();
2.47
2.48 - return result;
2.49 + return GetErrorStatus ();
2.50 +}
2.51 +//-----------------------------------------------------------------------------
2.52 +class PointToPointTestSuite : public TestSuite
2.53 +{
2.54 +public:
2.55 + PointToPointTestSuite ();
2.56 +};
2.57 +
2.58 +PointToPointTestSuite::PointToPointTestSuite ()
2.59 + : TestSuite ("devices-point-to-point", UNIT)
2.60 +{
2.61 + AddTestCase (new PointToPointTest);
2.62 }
2.63
2.64 -static PointToPointTest g_pointToPointTest;
2.65 +PointToPointTestSuite g_pointToPointTestSuite;
2.66
2.67 } // namespace ns3
2.68 -
2.69 -#endif /* RUN_SELF_TESTS */