summaryrefslogtreecommitdiff
path: root/cesar/maximus/system/src/SystemSciMsgTest.cpp
blob: b8015ffee7d9668410e7b11068eeb0463362cd15 (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
#include "SystemSciMsgTest.h"

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

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

#include <iostream>
using namespace std;

CPPUNIT_TEST_SUITE_REGISTRATION (SystemSciMsgTest);


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

  mpSciServer = new SciServer();
  mpSystemManager = new SystemManager (mpSciServer);
  mpSystemSciMsg = new SystemSciMsg (mpSystemManager);
}


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

  if (NULL != mpSystemSciMsg)
  {
    delete mpSystemSciMsg;
    mpSystemSciMsg = NULL;
  }
  if (NULL != mpSystemManager)
  {
    delete (mpSystemManager);
    mpSystemManager = NULL;
  }
  if (NULL != mpSciServer)
  {
    delete (mpSciServer);
    mpSciServer = NULL;
  }
}


void SystemSciMsgTest::dispatchMsgTest (void)
{
  logTest();

  if (NULL != mpSystemSciMsg)
  {
    try
    {
      CPPUNIT_ASSERT_MESSAGE (  "setSpecializedSciMsgType failed",
                                mpSystemSciMsg->setSpecializedSciMsgType(SYSTEM_TYPE_IDLE)  );

      IFunctionCall * pFunctionCall = new FunctionCallManager (mpSciServer);
      IPhy * pPhy = new PhyProcessor (mpSciServer);
      IEthernet * pEthernet = new EthernetProcessor (mpSciServer);
      INetworkClock * pNetworkClock = new NetworkClockProcessor (mpSciServer, mpSystemManager, pFunctionCall, pPhy, pEthernet);
      mpSystemManager->setNetworkClock(pNetworkClock);
      Sci_Msg_Station_Id stationId = mpSystemManager->createStation(mpSystemManager->getDefaultStationExecutable());

      CPPUNIT_ASSERT_MESSAGE (  "setSciMsgStationId failed",
                                mpSystemSciMsg->setSciMsgStationId(stationId)  );

      CPPUNIT_ASSERT_MESSAGE (  "dispatchMsg failed",
                                mpSystemSciMsg->dispatchMsg() );

      if (NULL != pFunctionCall)
      {
        delete (pFunctionCall);
        pFunctionCall = NULL;
      }
      if (NULL != pPhy)
      {
        delete (pPhy);
        pPhy = NULL;
      }
      if (NULL != pEthernet)
      {
        delete (pEthernet);
        pEthernet = NULL;
      }
      if (NULL != pNetworkClock)
      {
        delete (pNetworkClock);
        pNetworkClock = NULL;
      }
    }
    catch ( Error &e ) 
    {
      e.display();
    }  
  }
  else
  {
    CPPUNIT_FAIL ( "Initialized SystemSciMsg pointer is NULL" );
  }
}