summaryrefslogtreecommitdiff
path: root/maximus/system/src/SystemManagerTest.cpp
blob: 6b71009730242b1e603f572f0cedf509f961fb2c (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
196
197
198
199
200
201
202
#include "SystemManagerTest.h"

#include "SystemManager.h"
#include "SciServer.h"
#include "PhyProcessor.h"
#include "NetworkClockProcessor.h"
#include "FunctionCallManager.h"
#include "EthernetProcessor.h"

#include "Error.h"
#include "Logger.h"

using namespace std;

CPPUNIT_TEST_SUITE_REGISTRATION (SystemManagerTest);


void SystemManagerTest::setUp (void)
{
  logTest();

  mpSciServer = new SciServer ();
  mpSystemManager = new SystemManager (mpSciServer);

  mpFunctionCall = new FunctionCallManager (mpSciServer);
  mpPhy = new PhyProcessor (mpSciServer);
  mpEthernet = new EthernetProcessor (mpSciServer);
  mpNetworkClock = new NetworkClockProcessor (mpSciServer, mpSystemManager, mpFunctionCall, mpPhy, mpEthernet);
  mpSystemManager->setNetworkClock(mpNetworkClock);
}


void SystemManagerTest::tearDown (void) 
{
  logTest();

  if (NULL != mpSystemManager)
  {
    delete mpSystemManager;
    mpSystemManager = NULL;
  }
  if (NULL != mpSciServer)
  {
    delete mpSciServer;
    mpSciServer = NULL;
  }
  if (NULL != mpFunctionCall)
  {
    delete mpFunctionCall;
    mpFunctionCall = NULL;
  }
  if (NULL != mpPhy)
  {
    delete mpPhy;
    mpPhy = NULL;
  }
  if (NULL != mpEthernet)
  {
    delete mpEthernet;
    mpEthernet = NULL;
  }
  if (NULL != mpNetworkClock)
  {
    delete mpNetworkClock;
    mpNetworkClock = NULL;
  }
}


void SystemManagerTest::createStationTest (void)
{
  logTest();

  try
  {
    Sci_Msg_Station_Id stationId = mpSystemManager->createStation(mpSystemManager->getDefaultStationExecutable()); // will be deleted in 'tearDown()'
    CPPUNIT_ASSERT_MESSAGE ( "createStation failed",
                             0 != stationId );
  }
  catch ( Error &e ) 
  {
    e.display();
  }
}


void SystemManagerTest::removeStationTest (void)
{
  logTest();

  try
  {
    // Create Station 1
    //
    Sci_Msg_Station_Id stationId1 = mpSystemManager->createStation(mpSystemManager->getDefaultStationExecutable());

    // Create Station 2
    //
    Sci_Msg_Station_Id stationId2 = mpSystemManager->createStation(mpSystemManager->getDefaultStationExecutable());

    // Create Station 3
    //
    Sci_Msg_Station_Id stationId3 = mpSystemManager->createStation(mpSystemManager->getDefaultStationExecutable());

    INetworkClock * pNetworkClock = new NetworkClockProcessor();
    mpSystemManager->setNetworkClock(pNetworkClock);

    CPPUNIT_ASSERT_MESSAGE (  "removeStation failed",
                              mpSystemManager->removeStation (stationId2)  );

    CPPUNIT_ASSERT_MESSAGE (  "removeStation failed",
                              mpSystemManager->removeStation (stationId1)  );

    CPPUNIT_ASSERT_MESSAGE (  "removeStation failed",
                              mpSystemManager->removeStation (stationId3)  );

    if (NULL != pNetworkClock)
    {
      delete (pNetworkClock);
      pNetworkClock = NULL;
    }
  }
  catch ( Error &e ) 
  {
    e.display();
  }
}


void SystemManagerTest::areAllActiveStationsIdleTest (void)
{
  logTest();

  try
  {
    // Create Station 1
    //
    mpSystemManager->createStation(mpSystemManager->getDefaultStationExecutable());

    // Create Station 2
    //
    mpSystemManager->createStation(mpSystemManager->getDefaultStationExecutable());

    // Create Station 3
    //
    mpSystemManager->createStation(mpSystemManager->getDefaultStationExecutable());

    CPPUNIT_ASSERT_MESSAGE (  "areAllActiveStationsIdle failed",
                              !mpSystemManager->areAllActiveStationsIdle() );

    CPPUNIT_ASSERT_MESSAGE (  "removeAllStations failed",
                              mpSystemManager->removeAllStations() );
  }
  catch ( Error &e ) 
  {
    e.display();
  }
}


void SystemManagerTest::setNetworkClockTest (void)
{
  logTest();

  INetworkClock * pNetworkClock = new NetworkClockProcessor();

  CPPUNIT_ASSERT_MESSAGE ( "setNetworkClock failed",
                           mpSystemManager->setNetworkClock(pNetworkClock) );

  if (NULL != pNetworkClock)
  {
    delete (pNetworkClock);
    pNetworkClock = NULL;
  }
}


void SystemManagerTest::setStationNameTest (void)
{
  logTest();

  if (NULL == mpSystemManager)
  {
    CPPUNIT_FAIL ( "The initialized System Manager pointer is NULL" );
  }
  else
  {
    string stationName = "This is my station name";

    Sci_Msg_Station_Id stationId = mpSystemManager->createStation(mpSystemManager->getDefaultStationExecutable());
    mpSystemManager->updateStationStatus(stationId, MAXIMUS_STATION_STATUS_IDLE);
    NetworkClockProcessor networkClock;
    mpSystemManager->setNetworkClock((INetworkClock *)&networkClock);

    CPPUNIT_ASSERT_MESSAGE ( "setStationName failed",
                             mpSystemManager->setStationName(stationId, stationName) );

    mpSystemManager->removeStation(stationId);
  }
}