28 #include "ns3/nstime.h" 29 #include "ns3/int64x64.h" 40 virtual void DoSetup (
void);
41 virtual void DoRun (
void);
42 virtual void DoTeardown (
void);
46 :
TestCase (
"Sanity check of common time operations")
77 "is 1ms really 1ms ?");
79 "is 1us really 1us ?");
84 "is 1ns really 1ns ?");
86 "is 1ps really 1ps ?");
88 "is 1fs really 1fs ?");
93 Time::SetResolution (Time::PS);
96 "change resolution to PS");
110 virtual void DoRun (
void);
115 :
TestCase (
"Checks times that have plus or minus signs")
125 Time timePositive (
"+1000.0");
126 Time timePositiveWithUnits (
"+1000.0ms");
128 Time timeNegative (
"-1000.0");
129 Time timeNegativeWithUnits (
"-1000.0ms");
134 "Positive time not parsed correctly.");
139 "Positive time with units not parsed correctly.");
144 "Negative time not parsed correctly.");
149 "Negative time with units not parsed correctly.");
163 virtual void DoRun (
void);
164 void Check (
const std::string & str);
168 :
TestCase (
"Input,output from,to strings")
174 std::stringstream ss (str);
178 bool pass = (str == ss.str ());
181 << (pass ?
"pass " :
"FAIL ")
182 <<
"\"" << str <<
"\"";
185 std::cout <<
", got " << ss.str ();
187 std::cout << std::endl;
193 std::cout << std::endl;
206 Time t (3.141592654e9);
209 <<
"example: raw: " << t
213 << std::fixed << std::setprecision (9)
214 <<
"example: in s: " << t.
As (Time::S)
218 << std::setprecision (6)
219 <<
"example: in ms: " << t.
As (Time::MS)
226 std::cout << std::endl;
virtual void DoRun(void)
Implementation to actually run this TestCase.
Simulation virtual time values and global simulation resolution.
int64_t GetInteger(void) const
Get the raw time value, in the current resolution unit.
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
TimeTestSuite g_timeTestSuite
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
TimeWithUnit As(const enum Unit unit) const
Attach a unit to a Time, to facilitate output in a specific unit.
Time PicoSeconds(uint64_t value)
Construct a Time in the indicated unit.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Time Years(double value)
Construct a Time in the indicated unit.
virtual void DoSetup(void)
Implementation to do any local setup required for this TestCase.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
virtual void DoSetup(void)
Implementation to do any local setup required for this TestCase.
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
TestCase * GetParent() const
Get the parent of this TestCsse.
Time Hours(double value)
Construct a Time in the indicated unit.
Time TimeStep(uint64_t ts)
Time Minutes(double value)
Construct a Time in the indicated unit.
std::string GetName(void) const
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
Time Seconds(double value)
Construct a Time in the indicated unit.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time Days(double value)
Construct a Time in the indicated unit.
Time FemtoSeconds(uint64_t value)
Construct a Time in the indicated unit.
This test suite implements a Unit Test.