A Discrete-Event Network Simulator
API
li-ion-energy-source-test.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 Andrea Sacco
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Andrea Sacco <andrea.sacco85@gmail.com>
18  */
19 
20 #include "ns3/li-ion-energy-source.h"
21 #include "ns3/log.h"
22 #include "ns3/node.h"
23 #include "ns3/simple-device-energy-model.h"
24 #include "ns3/simulator.h"
25 #include "ns3/test.h"
26 
27 using namespace ns3;
28 
29 NS_LOG_COMPONENT_DEFINE("LiIonEnergySourceTestSuite");
30 
37 {
38  public:
40  ~LiIonEnergyTestCase() override;
41 
42  void DoRun() override;
43 
45 };
46 
48  : TestCase("Li-Ion energy source test case")
49 {
50 }
51 
53 {
54  m_node = nullptr;
55 }
56 
57 void
59 {
60  m_node = CreateObject<Node>();
61 
62  Ptr<SimpleDeviceEnergyModel> sem = CreateObject<SimpleDeviceEnergyModel>();
63  Ptr<LiIonEnergySource> es = CreateObject<LiIonEnergySource>();
64 
65  es->SetNode(m_node);
66  sem->SetEnergySource(es);
67  es->AppendDeviceEnergyModel(sem);
69 
70  Time now = Simulator::Now();
71 
72  // discharge at 2.33 A for 1700 seconds
73  sem->SetCurrentA(2.33);
74  now += Seconds(1701);
75 
76  Simulator::Stop(now);
77  Simulator::Run();
78  Simulator::Destroy();
79 
80  NS_TEST_ASSERT_MSG_EQ_TOL(es->GetSupplyVoltage(), 3.6, 1.0e-3, "Incorrect consumed energy!");
81 }
82 
89 {
90  public:
92 };
93 
95  : TestSuite("li-ion-energy-source", UNIT)
96 {
97  AddTestCase(new LiIonEnergyTestCase, TestCase::QUICK);
98 }
99 
void DoRun() override
Implementation to actually run this TestCase.
Ptr< Node > m_node
Node to aggreagte the source to.
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:259
void SetEnergySource(Ptr< EnergySource > source) override
Sets pointer to EnergySource installed on node.
encapsulates test code
Definition: test.h:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1256
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:305
#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...
Definition: test.h:337
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
static LiIonEnergySourceTestSuite g_liIonEnergySourceTestSuite
create an instance of the test suite
Every class exported by the ns3 library is enclosed in the ns3 namespace.