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

#include <iostream>
using namespace std;

CPPUNIT_TEST_SUITE_REGISTRATION (IFunctionCallTest);


void IFunctionCallTest::setUp (void)
{
  clog << "IFunctionCallTest::setUp" << endl;
}


void IFunctionCallTest::tearDown (void) 
{
  clog << "IFunctionCallTest::tearDown" << endl;
}


void IFunctionCallTest::userTest (void)
{
  clog << endl;
  clog << "-------------------------------------------------------------------------------------" << endl; 
  clog << "*** UNITARY TEST OF IFunctionCall ***" << endl;

  try
  {
    clog << "IFunctionCallTest -> SciServer()" << endl;
    SciServer sciServer;
    clog << "IFunctionCallTest -> FunctionCallManager(SciServer)" << endl;
    FunctionCallManager functionCallManager(&sciServer);
  
    clog << "IFunctionCallTest -> FunctionCallManager::createMsg" << endl;
    FunctionSciMsg * functionSciMsg = functionCallManager.createMsg();
    CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("createMsg failed"), (NULL != functionSciMsg) );
    
    clog << "IFunctionCallTest -> FunctionCallManager::registerCallback" << endl;
    CPPUNIT_ASSERT_MESSAGE (  CPPUNIT_NS::Message("registerCallback failed"),
                              functionCallManager.registerCallback("userFunction", &userFunction) );
   
   // Following test has to return 'false' because function name has not been set before sending the message
   //
    clog << "IFunctionCallTest -> FunctionCallManager::sendMsg" << endl;
    CPPUNIT_ASSERT_MESSAGE (  CPPUNIT_NS::Message("sendMsg failed"),
                              !functionCallManager.sendMsg(functionSciMsg)  );
                              
    clog << "IFunctionCallTest -> FunctionCallManager::setFunctionName" << endl;
    CPPUNIT_ASSERT_MESSAGE (  CPPUNIT_NS::Message("setFunctionName failed"),
                              functionSciMsg->setFunctionName("function_to_call") );
    
    Function_Call_Parameter parameter = {"parameter", 25, (unsigned char *)"1234567890123456789012345"};
    clog << "IFunctionCallTest -> FunctionSciMsg::addParameter" << endl;
    CPPUNIT_ASSERT_MESSAGE (  CPPUNIT_NS::Message("addParameter failed"),
                              functionSciMsg->addParameter (parameter)  );
                              
    CPPUNIT_ASSERT_MESSAGE (  CPPUNIT_NS::Message("sendMsg failed"),
                              functionCallManager.sendMsg(functionSciMsg) );
  }
  catch ( Error &e ) 
  {
    clog << "\tIFunctionCallTest -> Error::display" << endl;
    e.display();
  }
  
  clog << "-------------------------------------------------------------------------------------" << endl; 
  clog << endl; 
}


void userFunction ( FunctionSciMsg & function_sci_msg )
{
  clog << "=> userFunction" << endl;
}