summaryrefslogtreecommitdiff
path: root/maximus/functioncall/src/FunctionSciMsgTest.cpp
blob: 68ceb480d2986f1105b30f0391af76b086213acd (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
#include "FunctionSciMsgTest.h"
#include "SciServer.h"
#include "FunctionCallManager.h"
#include "FunctionCallParameter.h"

#include <iostream>
using namespace std;

CPPUNIT_TEST_SUITE_REGISTRATION (FunctionSciMsgTest);


void FunctionSciMsgTest::setUp (void)
{
  clog << "FunctionSciMsgTest::setUp" << endl;
  
  clog << "\tFunctionSciMsgTest -> SciServer()" << endl;
  mpSciServer = new SciServer();
  clog << "\tFunctionSciMsgTest -> FunctionCallManager(SciServer*)" << endl;
  mpFunctionCallManager = new FunctionCallManager (mpSciServer);  
  clog << "\tFunctionSciMsgTest -> FunctionSciMsg(FunctionCallManager*)" << endl;
  mpFunctionSciMsg = new FunctionSciMsg (mpFunctionCallManager);
}


void FunctionSciMsgTest::tearDown (void) 
{
  clog << "FunctionSciMsgTest::tearDown" << endl;
  
  if (NULL != mpSciServer)
  {
    clog << "\tFunctionSciMsgTest -> ~SciServer" << endl;
    delete (mpSciServer);
    mpSciServer = NULL;
  }
  if (NULL != mpFunctionCallManager)
  {
    clog << "\tFunctionSciMsgTest -> ~FunctionCallManager" << endl;
    delete (mpFunctionCallManager);
    mpFunctionCallManager = NULL;
  }
  if (NULL != mpFunctionSciMsg)
  {
    clog << "\tFunctionSciMsgTest -> ~FunctionSciMsg" << endl;
    delete mpFunctionSciMsg;
    mpFunctionSciMsg = NULL;
  }
}


void FunctionSciMsgTest::addParameterTest (void)
{
  clog << endl; 
  clog << "-------------------------------------------------------------------------------------" << endl;
	clog << "*** UNITARY TEST OF FunctionSciMsg::addParameter ***" << endl;
  
  if (NULL != mpFunctionSciMsg)
  {
    // Add parameter 1
    //
    FunctionCallParameter parameter1 ("parameter1", 3, (unsigned char *)"123");
    clog << "\tFunctionSciMsgTest -> FunctionSciMsg::addParameter" << endl;
    CPPUNIT_ASSERT_MESSAGE (  CPPUNIT_NS::Message("addParameter failed"),
                              mpFunctionSciMsg->addParameter(parameter1) );
    // Add parameter 2
    //
    FunctionCallParameter parameter2 ("parameter2", 10, (unsigned char *)"0123456789");
    clog << "\tFunctionSciMsgTest -> FunctionSciMsg::addParameter" << endl;
    CPPUNIT_ASSERT_MESSAGE (  CPPUNIT_NS::Message("addParameter failed"),
                              mpFunctionSciMsg->addParameter(parameter2) );
                              
    // Add parameter 3
    //
    FunctionCallParameter parameter3 = parameter2;
    clog << "\tFunctionSciMsgTest -> FunctionSciMsg::addParameter" << endl;
    CPPUNIT_ASSERT_MESSAGE (  CPPUNIT_NS::Message("addParameter failed"),
                              mpFunctionSciMsg->addParameter(parameter3) );
  }
  else
  {
    CPPUNIT_FAIL ( "Initialized FunctionSciMsg pointer is NULL" );
  }
  
  clog << "-------------------------------------------------------------------------------------" << endl;
  clog << endl;
}


void FunctionSciMsgTest::bindParameterTest (void)
{
  clog << endl;
  clog << "-------------------------------------------------------------------------------------" << endl;
  clog << "*** UNITARY TEST OF FunctionSciMsg::bindParameter ***" << endl;
  
  if (NULL != mpFunctionSciMsg)
  {
    // Add parameter 1
    //
    FunctionCallParameter parameter1 ("parameter1", 3, (unsigned char *)"123");
    clog << "\tFunctionSciMsgTest -> FunctionSciMsg::addParameter" << endl;
    CPPUNIT_ASSERT_MESSAGE (  CPPUNIT_NS::Message("addParameter failed"),
                              mpFunctionSciMsg->addParameter(parameter1) );

    // Add parameter 2
    //
    FunctionCallParameter parameter2  ("parameter2", 10, (unsigned char *)"0123456789");
    clog << "\tFunctionSciMsgTest -> FunctionSciMsg::addParameter" << endl;
    CPPUNIT_ASSERT_MESSAGE (  CPPUNIT_NS::Message("addParameter failed"),
                              mpFunctionSciMsg->addParameter(parameter2)  );

    // Add parameter 3
    //
    FunctionCallParameter parameter3 = parameter2;
    clog << "\tFunctionSciMsgTest -> FunctionSciMsg::addParameter" << endl;
    CPPUNIT_ASSERT_MESSAGE (  CPPUNIT_NS::Message("addParameter failed"),
                              mpFunctionSciMsg->addParameter(parameter3)  );
    
    const string name = "parameter1";
    unsigned long dataLength = 0;
    unsigned char * pData = NULL;
    clog << "\tFunctionSciMsgTest -> FunctionSciMsg::bindParameter" << endl;    
    CPPUNIT_ASSERT_MESSAGE (  CPPUNIT_NS::Message("bindParameter failed"),
                              mpFunctionSciMsg->bindParameter(name, dataLength, pData)  );
                
    // Check results
    //
    CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("bindParameterTest failed: wrong data length"), (3 == dataLength) );
    CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("bindParameterTest failed: data pointer is NULL"), (NULL != pData) );
    CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("bindParameterTest failed: wrong data"), (!strcmp("123", (char*)pData)) );

    // Free memory allocated into 'FunctionSciMsg::bindParameter'
    //
    if (NULL != pData)
    {
      delete [] pData;
      pData = NULL;
    }    
  }
  else
  {
    CPPUNIT_FAIL ( "Initialized FunctionSciMsg pointer is NULL" );
  }
  
  clog << "-------------------------------------------------------------------------------------" << endl;
  clog << endl;
}


void FunctionSciMsgTest::fillSpecializedSciMsgToSendTest (void)
{
  clog << endl;
  clog << "-------------------------------------------------------------------------------------" << endl;
  clog << "*** UNITARY TEST OF FunctionSciMsg::fillSpecializedSciMsgToSend ***" << endl;
  
  if (NULL != mpFunctionSciMsg)
  {
    // Add parameter 1
    //
    FunctionCallParameter parameter1 ("parameter1", 3, (unsigned char *)"123");
    clog << "\tFunctionSciMsgTest -> FunctionSciMsg::addParameter" << endl;
    CPPUNIT_ASSERT_MESSAGE (  CPPUNIT_NS::Message("addParameter failed"),
                              mpFunctionSciMsg->addParameter(parameter1) );
    
    // Add parameter 2
    //
    FunctionCallParameter parameter2 ("parameter2", 10, (unsigned char *)"0123456789");
    clog << "\tFunctionSciMsgTest -> FunctionSciMsg::addParameter" << endl;
    CPPUNIT_ASSERT_MESSAGE (  CPPUNIT_NS::Message("addParameter failed"),
                              mpFunctionSciMsg->addParameter(parameter2) );
    
    // Add parameter 3
    //
    FunctionCallParameter parameter3 = parameter2;
    clog << "\tFunctionSciMsgTest -> FunctionSciMsg::addParameter" << endl;
    CPPUNIT_ASSERT_MESSAGE (  CPPUNIT_NS::Message("addParameter failed"),
                              mpFunctionSciMsg->addParameter(parameter3) );

    clog << "\tFunctionSciMsgTest -> FunctionSciMsg::setFunctionCallName" << endl;
    CPPUNIT_ASSERT_MESSAGE (  CPPUNIT_NS::Message("setFunctionName failed"),
                              mpFunctionSciMsg->setFunctionName ("function_to_call\0")  );
    CPPUNIT_ASSERT_MESSAGE (  CPPUNIT_NS::Message("fillSpecializedSciMsgToSend failed"),
                              mpFunctionSciMsg->fillSpecializedSciMsgToSend() );
  }  
  else
  {
    CPPUNIT_FAIL ( "Initialized FunctionSciMsg pointer is NULL" );
  }
  
  clog << "-------------------------------------------------------------------------------------" << endl;
  clog << endl;  
}