summaryrefslogtreecommitdiff
path: root/maximus/networkclock/src/NetworkClockEvtListTest.cpp
blob: 2b64a4d4095b98e955ab6bd542d1a6e73042903f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#include "NetworkClockEvtListTest.h"
#include "NetworkClockEvt.h"

#include <string>
#include <iostream>
using namespace std;

CPPUNIT_TEST_SUITE_REGISTRATION (NetworkClockEvtListTest);


void NetworkClockEvtListTest::setUp (void)
{
  clog << "NetworkClockEvtListTest::setUp" << endl;
  
  clog << "\tNetworkClockEvtListTest -> NetworkClockEvtList()" << endl;
	mpNetworkClockEvtList = new NetworkClockEvtList ();
}


void NetworkClockEvtListTest::tearDown (void) 
{
  clog << "NetworkClockEvtListTest::tearDown" << endl;
  
  if (NULL != mpNetworkClockEvtList)
  {
    clog << "\tNetworkClockEvtListTest -> ~NetworkClockEvtList" << endl;
  	delete (mpNetworkClockEvtList);
    mpNetworkClockEvtList = NULL;
  }
}


void NetworkClockEvtListTest::insertElementTest (void)
{
  clog << endl;
  clog << "-------------------------------------------------------------------------------------" << endl;
	clog << "*** UNITARY TEST OF NetworkClockEvtList::insertElement ***" << endl;
  
  clog << "\tNetworkClockEvtListTest -> NetworkClockEvt()" << endl;
  NetworkClockEvt evt;
  
  clog << "\tNetworkClockEvtListTest -> NetworkClockEvtList::setId" << endl;
  CPPUNIT_ASSERT_MESSAGE (  "setNetworkClockId failed",
                            evt.setNetworkClockId(123) );
    
  clog << "\tNetworkClockEvtListTest -> NetworkClockEvtList::insertElement" << endl;
  CPPUNIT_ASSERT_MESSAGE (  "insertElement failed",
                            mpNetworkClockEvtList->insertElement (1, evt) );
                            
  mpNetworkClockEvtList->displayListOfEvts();
 
  clog << "-------------------------------------------------------------------------------------" << endl;
  clog << endl;
}


void NetworkClockEvtListTest::removeElementTest (void)
{
  clog << endl;
  clog << "-------------------------------------------------------------------------------------" << endl;
  clog << "*** UNITARY TEST OF NetworkClockEvtList::removeElement ***" << endl;

  // Insert Event 1
  //
  clog << "\tNetworkClockEvtListTest -> NetworkClockEvt()" << endl;
  NetworkClockEvt evt1;
  clog << "\tNetworkClockEvtListTest -> NetworkClockEvtList::setId" << endl;
  CPPUNIT_ASSERT_MESSAGE (  "setNetworkClockId failed",
                            evt1.setNetworkClockId(1)  );
  clog << "\tNetworkClockEvtListTest -> NetworkClockEvtList::insertElement" << endl;
  CPPUNIT_ASSERT_MESSAGE (  "insertElement failed",
                            mpNetworkClockEvtList->insertElement (2, evt1)  );

  // Insert Event 2
  //
  NetworkClockEvt evt2;
  evt2.setNetworkClockId(2);
  mpNetworkClockEvtList->insertElement (3, evt2);

  // Insert Event 3
  //
  NetworkClockEvt evt3;
  evt3.setNetworkClockId(3);
  mpNetworkClockEvtList->insertElement (65, evt3);

  // Insert Event 4
  //
  NetworkClockEvt evt4;
  evt4.setNetworkClockId(4);
  mpNetworkClockEvtList->insertElement (5, evt4);

  // Insert Event 5
  //
  NetworkClockEvt evt5;
  evt5.setNetworkClockId(5);
  mpNetworkClockEvtList->insertElement (687, evt5);

  // Insert Event 6
  //
  NetworkClockEvt evt6;
  evt6.setNetworkClockId(6);
  mpNetworkClockEvtList->insertElement (98726, evt6);

  // Insert Event 7
  //
  NetworkClockEvt evt7;
  evt7.setNetworkClockId(7);
  mpNetworkClockEvtList->insertElement (0, evt7);

  // Insert Event 8
  //
  NetworkClockEvt evt8;
  evt8.setNetworkClockId(8);
  mpNetworkClockEvtList->insertElement (1, evt8);

  // Insert Event 9
  //
  NetworkClockEvt evt9;
  evt9.setNetworkClockId(9);
  mpNetworkClockEvtList->insertElement (68, evt9);
  
  // Insert Event 10
  //
  NetworkClockEvt evt10;
  evt10.setNetworkClockId(10);
  mpNetworkClockEvtList->insertElement (2, evt10);
  
  // Update Event 7
  //
  NetworkClockEvt evt7bis (evt7);
  mpNetworkClockEvtList->insertElement (7, evt7bis);
    
  clog << "\tNetworkClockEvtListTest -> NetworkClockEvtList::removeElement" << endl;
  CPPUNIT_ASSERT_MESSAGE (  "removeElement failed",
                            mpNetworkClockEvtList->removeElement (2, evt1)  );
  
  mpNetworkClockEvtList->displayListOfEvts();                        

  clog << "-------------------------------------------------------------------------------------" << endl;
  clog << endl;
}


void NetworkClockEvtListTest::getNextElementTest (void)
{
  clog << endl;
  clog << "-------------------------------------------------------------------------------------" << endl;
  clog << "*** UNITARY TEST OF NetworkClockEvtList::getNextElement ***" << endl;

  // Insert Event 1
  //
  clog << "\tNetworkClockEvtListTest -> NetworkClockEvt()" << endl;
  NetworkClockEvt evt1;
  clog << "\tNetworkClockEvtListTest -> NetworkClockEvtList::setName" << endl;
  evt1.setNetworkClockId(1);
  clog << "\tNetworkClockEvtListTest -> NetworkClockEvtList::insertElement" << endl;
  CPPUNIT_ASSERT_MESSAGE (  "insertElement failed",
                            mpNetworkClockEvtList->insertElement (0, evt1)  );
  
  // Insert Event 2
  //                     
  NetworkClockEvt evt2;
  evt2.setNetworkClockId(2);
  mpNetworkClockEvtList->insertElement (3524, evt2);
  
  // Insert Event 3
  //  
  NetworkClockEvt evt3;
  evt3.setNetworkClockId(3);
  mpNetworkClockEvtList->insertElement (6457, evt3);
  
  // Insert Event 4
  //  
  NetworkClockEvt evt4;
  evt4.setNetworkClockId(4);
  mpNetworkClockEvtList->insertElement (111, evt4);

  mpNetworkClockEvtList->displayListOfEvts();

  clog << "\tNetworkClockEvtListTest -> NetworkClockEvt()" << endl;
  Network_Clock_Tick tickValue = 0;
  NetworkClockEvt evt (0, NETWORK_CLOCK_TYPE_STATION, 0);
  clog << "\tNetworkClockEvtListTest -> NetworkClockEvtList::getNextElement" << endl;
  CPPUNIT_ASSERT_MESSAGE (  "getNextElement failed",
                            mpNetworkClockEvtList->getNextElement (tickValue, evt) );

  clog << "\tget element is ";
  evt.displayEvt();
  clog << endl;

  clog << "-------------------------------------------------------------------------------------" << endl;
  clog << endl;
}