|
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
|
2 /* |
|
3 * Copyright (c) 2010 Andrea Sacco |
|
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: Andrea Sacco <andrea.sacco85@gmail.com> |
|
19 */ |
|
20 |
|
21 #include "ns3/log.h" |
|
22 #include "ns3/test.h" |
|
23 #include "ns3/simple-device-energy-model.h" |
|
24 #include "ns3/li-ion-energy-source.h" |
|
25 #include "ns3/node.h" |
|
26 #include "ns3/simulator.h" |
|
27 |
|
28 namespace ns3 { |
|
29 |
|
30 NS_LOG_COMPONENT_DEFINE ("LiIonEnergySourceTestSuite"); |
|
31 |
|
32 class LiIonEnergyTestCase : public TestCase |
|
33 { |
|
34 public: |
|
35 LiIonEnergyTestCase (); |
|
36 ~LiIonEnergyTestCase (); |
|
37 |
|
38 bool DoRun (void); |
|
39 |
|
40 double m_simTime; |
|
41 Ptr<Node> m_node; |
|
42 }; |
|
43 |
|
44 LiIonEnergyTestCase::LiIonEnergyTestCase () |
|
45 : TestCase ("Li-Ion energy source test case") |
|
46 { |
|
47 } |
|
48 |
|
49 LiIonEnergyTestCase::~LiIonEnergyTestCase () |
|
50 { |
|
51 m_node = 0; |
|
52 } |
|
53 |
|
54 bool |
|
55 LiIonEnergyTestCase::DoRun () |
|
56 { |
|
57 m_node = CreateObject<Node> (); |
|
58 |
|
59 Ptr<SimpleDeviceEnergyModel> sem = CreateObject<SimpleDeviceEnergyModel> (); |
|
60 Ptr<LiIonEnergySource> es = CreateObject<LiIonEnergySource> (); |
|
61 |
|
62 es->SetNode (m_node); |
|
63 sem->SetEnergySource (es); |
|
64 es->AppendDeviceEnergyModel (sem); |
|
65 m_node->AggregateObject (es); |
|
66 |
|
67 Time now = Simulator::Now (); |
|
68 |
|
69 // discharge at 2.33 A for 1700 seconds |
|
70 sem->SetCurrentA (2.33); |
|
71 now += Seconds (1701); |
|
72 |
|
73 Simulator::Stop (now); |
|
74 Simulator::Run (); |
|
75 Simulator::Destroy (); |
|
76 |
|
77 NS_TEST_ASSERT_MSG_EQ_TOL (es->GetSupplyVoltage (), 3.6, 1.0e-3, |
|
78 "Incorrect consumed energy!"); |
|
79 |
|
80 return false; |
|
81 } |
|
82 |
|
83 class LiIonEnergySourceTestSuite : public TestSuite |
|
84 { |
|
85 public: |
|
86 LiIonEnergySourceTestSuite (); |
|
87 }; |
|
88 |
|
89 LiIonEnergySourceTestSuite::LiIonEnergySourceTestSuite () |
|
90 : TestSuite ("li-ion-energy-source", UNIT) |
|
91 { |
|
92 AddTestCase (new LiIonEnergyTestCase); |
|
93 } |
|
94 |
|
95 // create an instance of the test suite |
|
96 LiIonEnergySourceTestSuite g_liIonEnergySourceTestSuite; |
|
97 |
|
98 } // namespace ns3 |