A Discrete-Event Network Simulator
API
mobility-trace-test-suite.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2012 University of Washington
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Mitch Watrous (watrous@u.washington.edu)
19 */
20
21#include <string>
22
23#include "ns3/ascii-test.h"
24#include "ns3/trace-helper.h"
25#include "ns3/double.h"
26#include "ns3/uinteger.h"
27#include "ns3/string.h"
28#include "ns3/simulator.h"
29#include "ns3/rectangle.h"
30#include "ns3/mobility-model.h"
31#include "ns3/mobility-helper.h"
32#include "ns3/node-container.h"
33#include "ns3/test.h"
34
35using namespace ns3;
36
37
46{
47public:
49 virtual ~MobilityTraceTestCase ();
50
51private:
52 virtual void DoRun (void);
53};
54
56 :
57 TestCase ("Mobility Trace Test Case")
58{
59}
60
62{
63}
64
65void
67{
68 //***************************************************************************
69 // Create the new mobility trace.
70 //***************************************************************************
71
72 NodeContainer sta;
73 sta.Create (4);
75 mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
76 "MinX", DoubleValue (1.0),
77 "MinY", DoubleValue (1.0),
78 "DeltaX", DoubleValue (5.0),
79 "DeltaY", DoubleValue (5.0),
80 "GridWidth", UintegerValue (3),
81 "LayoutType", StringValue ("RowFirst"));
82 mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
83 "Mode", StringValue ("Time"),
84 "Time", StringValue ("2s"),
85 "Speed", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"),
86 "Bounds", RectangleValue (Rectangle (0.0, 20.0, 0.0, 20.0)));
87 mobility.Install (sta);
88 // Set mobility random number streams to fixed values
89 mobility.AssignStreams (sta, 0);
90
91 SetDataDir (NS_TEST_SOURCEDIR);
92 std::string referenceMobilityFilePath = CreateDataDirFilename ("mobility-trace-example.mob");
93 std::string testMobilityFilePath = CreateTempDirFilename ("mobility-trace-test.mob");
94
95 AsciiTraceHelper ascii;
96 MobilityHelper::EnableAsciiAll (ascii.CreateFileStream (testMobilityFilePath));
97 Simulator::Stop (Seconds (5.0));
99 Simulator::Destroy ();
100
101
102 //***************************************************************************
103 // Test the new mobility trace against the reference mobility trace.
104 //***************************************************************************
105
106 NS_ASCII_TEST_EXPECT_EQ (testMobilityFilePath, referenceMobilityFilePath);
107}
108
109
118{
119public:
121};
122
124 : TestSuite ("mobility-trace", UNIT)
125{
126 AddTestCase (new MobilityTraceTestCase, TestCase::QUICK);
127}
128
#define NS_ASCII_TEST_EXPECT_EQ(gotFilename, expectedFilename)
Test that a pair of new/reference ascii files are equal.
Definition: ascii-test.h:38
void Run(ObjectFactory &factory, uint32_t pop, uint32_t total, uint32_t runs, Ptr< RandomVariableStream > eventStream, bool calRev)
Perform the runs for a single scheduler type.
Mobility Trace Test Case.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Mobility Trace Test Suite.
Manage ASCII trace files for device models.
Definition: trace-helper.h:163
Ptr< OutputStreamWrapper > CreateFileStream(std::string filename, std::ios::openmode filemode=std::ios::out)
Create and initialize an output stream object we'll use to write the traced bits.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
Helper class used to assign positions and mobility models to nodes.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
a 2d rectangle
Definition: rectangle.h:35
AttributeValue implementation for Rectangle.
Hold variables of type string.
Definition: string.h:41
encapsulates test code
Definition: test.h:994
std::string CreateDataDirFilename(std::string filename)
Construct the full path to a file in the data directory.
Definition: test.cc:412
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
std::string CreateTempDirFilename(std::string filename)
Construct the full path to a file in a temporary directory.
Definition: test.cc:430
void SetDataDir(std::string directory)
Set the data directory where reference trace files can be found.
Definition: test.cc:467
A suite of tests to run.
Definition: test.h:1188
Hold an unsigned integer type.
Definition: uinteger.h:44
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1245
static MobilityTraceTestSuite mobilityTraceTestSuite
the test suite
Every class exported by the ns3 library is enclosed in the ns3 namespace.
mobility
Definition: third.py:98