summaryrefslogtreecommitdiff
path: root/maximus/functioncall/src/IFunctionCallTest.cpp
blob: 5f60e7b435d223027c97b6ae95474e189d1ee78d (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
#include "IFunctionCallTest.h"

#include "IFunctionCall.h"
#include "FunctionCallManager.h"
#include "SciServer.h"
#include "FunctionSciMsg.h"
#include "FunctionCallParameter.h"
#include "SystemManager.h"
#include "PhyProcessor.h"
#include "NetworkClockProcessor.h"
#include "EthernetProcessor.h"

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

#include <iostream>
using namespace std;

CPPUNIT_TEST_SUITE_REGISTRATION (IFunctionCallTest);


void IFunctionCallTest::setUp (void)
{
  logTest();
}


void IFunctionCallTest::tearDown (void) 
{
  logTest();
}


void IFunctionCallTest::userTest (void)
{
  logTest();

  try
  {
    SciServer sciServer;
    FunctionCallManager functionCallManager(&sciServer);
    FunctionSciMsg * pFunctionSciMsg = functionCallManager.createMsg();

    CPPUNIT_ASSERT_MESSAGE ( "createMsg failed", (NULL != pFunctionSciMsg) );

    CPPUNIT_ASSERT_MESSAGE (  "registerCallback failed",
                              functionCallManager.registerCallback(pFunctionSciMsg->getSpecializedSciMsgId(), &userFunction) );

    CPPUNIT_ASSERT_MESSAGE (  "setFunctionName failed",
                              pFunctionSciMsg->setFunctionName("function_to_call") );

    FunctionCallParameter parameter ("parameter", 25, (unsigned char *)"1234567890123456789012345");

    CPPUNIT_ASSERT_MESSAGE (  "addParameter failed",
                              pFunctionSciMsg->addParameter (parameter)  );

    SystemManager systemManager(&sciServer);
    FunctionCallManager functionCall(&sciServer);
    PhyProcessor phy(&sciServer);
    EthernetProcessor ethernet(&sciServer);
    NetworkClockProcessor networkClock(&sciServer, &systemManager, &functionCall, &phy, &ethernet);
    systemManager.setNetworkClock(&networkClock);
    Sci_Msg_Station_Id stationId = 0;
    stationId = systemManager.createStation(systemManager.getDefaultStationExecutable());
    pFunctionSciMsg->setSciMsgStationId(stationId);
    systemManager.updateStationStatus ( stationId, MAXIMUS_STATION_STATUS_IDLE );

    CPPUNIT_ASSERT_MESSAGE (  "sendMsg failed",
                              functionCallManager.sendMsg(pFunctionSciMsg) );

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


void userFunction ( const FunctionSciMsg & function_sci_msg )
{
  logTest();
}