bug 675: convert unit tests to new test framework

This commit is contained in:
Mathieu Lacage
2009-09-30 14:24:04 +02:00
parent b63393d355
commit 2df88d723f

View File

@@ -151,31 +151,26 @@ DropTailQueue::DoPeek (void) const
} // namespace ns3
#ifdef RUN_SELF_TESTS
#include "ns3/test.h"
namespace ns3 {
class DropTailQueueTest: public Test {
class DropTailQueueTestCase : public TestCase
{
public:
virtual bool RunTests (void);
DropTailQueueTest ();
DropTailQueueTestCase ();
virtual bool DoRun (void);
};
DropTailQueueTest::DropTailQueueTest ()
: Test ("DropTailQueue") {}
bool
DropTailQueueTest::RunTests (void)
DropTailQueueTestCase::DropTailQueueTestCase ()
: TestCase ("Sanity check on the drop tail queue implementation")
{}
bool
DropTailQueueTestCase::DoRun (void)
{
bool result = true;
Ptr<DropTailQueue> queue = CreateObject<DropTailQueue> ();
NS_TEST_ASSERT (queue->SetAttributeFailSafe ("MaxPackets", UintegerValue (3)));
NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MaxPackets", UintegerValue (3)), true,
"Verify that we can actually set the attribute");
Ptr<Packet> p1, p2, p3, p4;
p1 = Create<Packet> ();
@@ -183,43 +178,47 @@ DropTailQueueTest::RunTests (void)
p3 = Create<Packet> ();
p4 = Create<Packet> ();
NS_TEST_ASSERT_EQUAL (queue->GetNPackets (), 0);
NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 0, "There should be no packets in there");
queue->Enqueue (p1);
NS_TEST_ASSERT_EQUAL (queue->GetNPackets (), 1);
NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 1, "There should be one packet in there");
queue->Enqueue (p2);
NS_TEST_ASSERT_EQUAL (queue->GetNPackets (), 2);
NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 2, "There should be two packets in there");
queue->Enqueue (p3);
NS_TEST_ASSERT_EQUAL (queue->GetNPackets (), 3);
NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 3, "There should be three packets in there");
queue->Enqueue (p4); // will be dropped
NS_TEST_ASSERT_EQUAL (queue->GetNPackets (), 3);
NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 3, "There should be still three packets in there");
Ptr<Packet> p;
p = queue->Dequeue ();
NS_TEST_ASSERT (p != 0);
NS_TEST_ASSERT_EQUAL (queue->GetNPackets (), 2);
NS_TEST_ASSERT_EQUAL (p->GetUid (), p1->GetUid ());
NS_TEST_EXPECT_MSG_EQ ((p != 0), true, "I want to remove the first packet");
NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 2, "There should be two packets in there");
NS_TEST_EXPECT_MSG_EQ (p->GetUid (), p1->GetUid (), "was this the first packet ?");
p = queue->Dequeue ();
NS_TEST_ASSERT (p != 0);
NS_TEST_ASSERT_EQUAL (queue->GetNPackets (), 1);
NS_TEST_ASSERT_EQUAL (p->GetUid (), p2->GetUid ());
NS_TEST_EXPECT_MSG_EQ ((p != 0), true, "I want to remove the second packet");
NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 1, "There should be one packet in there");
NS_TEST_EXPECT_MSG_EQ (p->GetUid (), p2->GetUid (), "Was this the second packet ?");
p = queue->Dequeue ();
NS_TEST_ASSERT (p != 0);
NS_TEST_ASSERT_EQUAL (queue->GetNPackets (), 0);
NS_TEST_ASSERT_EQUAL (p->GetUid (), p3->GetUid ());
NS_TEST_EXPECT_MSG_EQ ((p != 0), true, "I want to remove the third packet");
NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 0, "There should be no packets in there");
NS_TEST_EXPECT_MSG_EQ (p->GetUid (), p3->GetUid (), "Was this the third packet ?");
p = queue->Dequeue ();
NS_TEST_ASSERT (p == 0);
NS_TEST_EXPECT_MSG_EQ ((p == 0), true, "There are really no packets in there");
return result;
return false;
}
static class DropTailQueueTestSuite : public TestSuite
{
public:
DropTailQueueTestSuite ()
: TestSuite ("drop-tail-queue", UNIT)
{
AddTestCase (new DropTailQueueTestCase ());
}
} g_dropTailQueueTestSuite;
static DropTailQueueTest gDropTailQueueTest;
}; // namespace ns3
#endif /* RUN_SELF_TESTS */
} // namespace ns3