#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); } }