A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
time-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) 2005,2006 INRIA
4
* Copyright (c) 2007 Emmanuelle Laprise
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License version 2 as
8
* published by the Free Software Foundation;
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
*
19
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20
* TimeStep support by Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
21
*/
22
#include "ns3/nstime.h"
23
#include "ns3/test.h"
24
25
using namespace
ns3;
26
27
class
TimeSimpleTestCase
:
public
TestCase
28
{
29
public
:
30
TimeSimpleTestCase
(
enum
Time::Unit
resolution);
31
private
:
32
virtual
void
DoSetup (
void
);
33
virtual
void
DoRun (
void
);
34
virtual
void
DoTeardown (
void
);
35
enum
Time::Unit
m_originalResolution
;
36
enum
Time::Unit
m_resolution
;
37
};
38
39
TimeSimpleTestCase::TimeSimpleTestCase
(
enum
Time::Unit
resolution)
40
:
TestCase
(
"Sanity check of common time operations"
),
41
m_resolution (resolution)
42
{
43
}
44
45
void
46
TimeSimpleTestCase::DoSetup
(
void
)
47
{
48
m_originalResolution
= Time::GetResolution ();
49
}
50
51
void
52
TimeSimpleTestCase::DoRun
(
void
)
53
{
54
Time::SetResolution (
m_resolution
);
55
NS_TEST_ASSERT_MSG_EQ_TOL
(
Seconds
(1.0).GetSeconds (), 1.0,
TimeStep
(1).GetSeconds (),
56
"is 1 really 1 ?"
);
57
NS_TEST_ASSERT_MSG_EQ_TOL
(
Seconds
(10.0).GetSeconds (), 10.0,
TimeStep
(1).GetSeconds (),
58
"is 10 really 10 ?"
);
59
NS_TEST_ASSERT_MSG_EQ
(
MilliSeconds
(1).GetMilliSeconds (), 1,
60
"is 1ms really 1ms ?"
);
61
NS_TEST_ASSERT_MSG_EQ
(
MicroSeconds
(1).GetMicroSeconds (), 1,
62
"is 1us really 1us ?"
);
63
#if 0
64
Time
ns =
NanoSeconds
(1);
65
ns.
GetNanoSeconds
();
66
NS_TEST_ASSERT_MSG_EQ
(
NanoSeconds
(1).GetNanoSeconds (), 1,
67
"is 1ns really 1ns ?"
);
68
NS_TEST_ASSERT_MSG_EQ
(
PicoSeconds
(1).GetPicoSeconds (), 1,
69
"is 1ps really 1ps ?"
);
70
NS_TEST_ASSERT_MSG_EQ
(
FemtoSeconds
(1).GetFemtoSeconds (), 1,
71
"is 1fs really 1fs ?"
);
72
#endif
73
}
74
75
void
76
TimeSimpleTestCase::DoTeardown
(
void
)
77
{
78
Time::SetResolution (
m_originalResolution
);
79
}
80
81
class
TimesWithSignsTestCase
:
public
TestCase
82
{
83
public
:
84
TimesWithSignsTestCase
();
85
private
:
86
virtual
void
DoSetup
(
void
);
87
virtual
void
DoRun
(
void
);
88
virtual
void
DoTeardown
(
void
);
89
};
90
91
TimesWithSignsTestCase::TimesWithSignsTestCase
()
92
:
TestCase
(
"Checks times that have plus or minus signs"
)
93
{
94
}
95
96
void
97
TimesWithSignsTestCase::DoSetup
(
void
)
98
{
99
}
100
101
void
102
TimesWithSignsTestCase::DoRun
(
void
)
103
{
104
Time
timePositive (
"+1000.0"
);
105
Time
timePositiveWithUnits (
"+1000.0ms"
);
106
107
Time
timeNegative (
"-1000.0"
);
108
Time
timeNegativeWithUnits (
"-1000.0ms"
);
109
110
NS_TEST_ASSERT_MSG_EQ_TOL
(timePositive.
GetSeconds
(),
111
+1000.0,
112
1.0e-8,
113
"Positive time not parsed correctly."
);
114
115
NS_TEST_ASSERT_MSG_EQ_TOL
(timePositiveWithUnits.
GetSeconds
(),
116
+1.0,
117
1.0e-8,
118
"Positive time with units not parsed correctly."
);
119
120
NS_TEST_ASSERT_MSG_EQ_TOL
(timeNegative.
GetSeconds
(),
121
-1000.0,
122
1.0e-8,
123
"Negative time not parsed correctly."
);
124
125
NS_TEST_ASSERT_MSG_EQ_TOL
(timeNegativeWithUnits.
GetSeconds
(),
126
-1.0,
127
1.0e-8,
128
"Negative time with units not parsed correctly."
);
129
}
130
131
void
132
TimesWithSignsTestCase::DoTeardown
(
void
)
133
{
134
}
135
136
static
class
TimeTestSuite
:
public
TestSuite
137
{
138
public
:
139
TimeTestSuite
()
140
:
TestSuite
(
"time"
,
UNIT
)
141
{
142
AddTestCase
(
new
TimeSimpleTestCase
(Time::US));
143
AddTestCase
(
new
TimesWithSignsTestCase
());
144
}
145
}
g_timeTestSuite
;
src
core
test
time-test-suite.cc
Generated on Fri Dec 21 2012 19:00:33 for ns-3 by
1.8.1.2