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
();
31
private
:
32
virtual
void
DoSetup (
void
);
33
virtual
void
DoRun (
void
);
34
virtual
void
DoTeardown (
void
);
35
};
36
37
TimeSimpleTestCase::TimeSimpleTestCase
()
38
:
TestCase
(
"Sanity check of common time operations"
)
39
{
40
}
41
42
void
43
TimeSimpleTestCase::DoSetup
(
void
)
44
{
45
}
46
47
void
48
TimeSimpleTestCase::DoRun
(
void
)
49
{
50
NS_TEST_ASSERT_MSG_EQ_TOL
(Seconds (1.0).GetSeconds (), 1.0,
TimeStep
(1).GetSeconds (),
51
"is 1 really 1 ?"
);
52
NS_TEST_ASSERT_MSG_EQ_TOL
(Seconds (10.0).GetSeconds (), 10.0,
TimeStep
(1).GetSeconds (),
53
"is 10 really 10 ?"
);
54
NS_TEST_ASSERT_MSG_EQ
(MilliSeconds (1).GetMilliSeconds (), 1,
55
"is 1ms really 1ms ?"
);
56
NS_TEST_ASSERT_MSG_EQ
(MicroSeconds (1).GetMicroSeconds (), 1,
57
"is 1us really 1us ?"
);
58
#if 0
59
Time
ns = NanoSeconds (1);
60
ns.
GetNanoSeconds
();
61
NS_TEST_ASSERT_MSG_EQ
(NanoSeconds (1).GetNanoSeconds (), 1,
62
"is 1ns really 1ns ?"
);
63
NS_TEST_ASSERT_MSG_EQ
(PicoSeconds (1).GetPicoSeconds (), 1,
64
"is 1ps really 1ps ?"
);
65
NS_TEST_ASSERT_MSG_EQ
(FemtoSeconds (1).GetFemtoSeconds (), 1,
66
"is 1fs really 1fs ?"
);
67
#endif
68
69
Time
ten = NanoSeconds (10);
70
int64_t tenValue = ten.
GetInteger
();
71
Time::SetResolution (Time::PS);
72
int64_t tenKValue = ten.
GetInteger
();
73
NS_TEST_ASSERT_MSG_EQ
(tenValue * 1000, tenKValue,
74
"change resolution to PS"
);
75
}
76
77
void
78
TimeSimpleTestCase::DoTeardown
(
void
)
79
{
80
}
81
82
class
TimesWithSignsTestCase
:
public
TestCase
83
{
84
public
:
85
TimesWithSignsTestCase
();
86
private
:
87
virtual
void
DoSetup
(
void
);
88
virtual
void
DoRun
(
void
);
89
virtual
void
DoTeardown
(
void
);
90
};
91
92
TimesWithSignsTestCase::TimesWithSignsTestCase
()
93
:
TestCase
(
"Checks times that have plus or minus signs"
)
94
{
95
}
96
97
void
98
TimesWithSignsTestCase::DoSetup
(
void
)
99
{
100
}
101
102
void
103
TimesWithSignsTestCase::DoRun
(
void
)
104
{
105
Time
timePositive (
"+1000.0"
);
106
Time
timePositiveWithUnits (
"+1000.0ms"
);
107
108
Time
timeNegative (
"-1000.0"
);
109
Time
timeNegativeWithUnits (
"-1000.0ms"
);
110
111
NS_TEST_ASSERT_MSG_EQ_TOL
(timePositive.
GetSeconds
(),
112
+1000.0,
113
1.0e-8,
114
"Positive time not parsed correctly."
);
115
116
NS_TEST_ASSERT_MSG_EQ_TOL
(timePositiveWithUnits.
GetSeconds
(),
117
+1.0,
118
1.0e-8,
119
"Positive time with units not parsed correctly."
);
120
121
NS_TEST_ASSERT_MSG_EQ_TOL
(timeNegative.
GetSeconds
(),
122
-1000.0,
123
1.0e-8,
124
"Negative time not parsed correctly."
);
125
126
NS_TEST_ASSERT_MSG_EQ_TOL
(timeNegativeWithUnits.
GetSeconds
(),
127
-1.0,
128
1.0e-8,
129
"Negative time with units not parsed correctly."
);
130
}
131
132
void
133
TimesWithSignsTestCase::DoTeardown
(
void
)
134
{
135
}
136
137
static
class
TimeTestSuite
:
public
TestSuite
138
{
139
public
:
140
TimeTestSuite
()
141
:
TestSuite
(
"time"
,
UNIT
)
142
{
143
AddTestCase
(
new
TimeSimpleTestCase
(), TestCase::QUICK);
144
AddTestCase
(
new
TimesWithSignsTestCase
(), TestCase::QUICK);
145
}
146
}
g_timeTestSuite
;
src
core
test
time-test-suite.cc
Generated on Fri Aug 30 2013 01:42:48 for ns-3 by
1.8.1.2