summaryrefslogtreecommitdiff
path: root/cesar/maximus/functioncall/src/FunctionSciMsgTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/maximus/functioncall/src/FunctionSciMsgTest.cpp')
-rw-r--r--cesar/maximus/functioncall/src/FunctionSciMsgTest.cpp206
1 files changed, 206 insertions, 0 deletions
diff --git a/cesar/maximus/functioncall/src/FunctionSciMsgTest.cpp b/cesar/maximus/functioncall/src/FunctionSciMsgTest.cpp
new file mode 100644
index 0000000000..440a271c67
--- /dev/null
+++ b/cesar/maximus/functioncall/src/FunctionSciMsgTest.cpp
@@ -0,0 +1,206 @@
+
+#include "FunctionSciMsgTest.h"
+
+#include "FunctionSciMsg.h"
+#include "SciServer.h"
+#include "FunctionCallManager.h"
+#include "FunctionCallParameter.h"
+
+#include "Error.h"
+#include "Logger.h"
+
+#include <iostream>
+using namespace std;
+
+CPPUNIT_TEST_SUITE_REGISTRATION (FunctionSciMsgTest);
+
+
+void FunctionSciMsgTest::setUp (void)
+{
+ logTest();
+
+ mpSciServer = new SciServer();
+ mpFunctionCallManager = new FunctionCallManager (mpSciServer);
+ mpFunctionSciMsg = new FunctionSciMsg (mpFunctionCallManager);
+}
+
+
+void FunctionSciMsgTest::tearDown (void)
+{
+ logTest();
+
+ if (NULL != mpSciServer)
+ {
+ delete (mpSciServer);
+ mpSciServer = NULL;
+ }
+ if (NULL != mpFunctionCallManager)
+ {
+ delete (mpFunctionCallManager);
+ mpFunctionCallManager = NULL;
+ }
+ if (NULL != mpFunctionSciMsg)
+ {
+ delete mpFunctionSciMsg;
+ mpFunctionSciMsg = NULL;
+ }
+}
+
+
+void FunctionSciMsgTest::addParameterTest (void)
+{
+ logTest();
+
+ if (NULL != mpFunctionSciMsg)
+ {
+ // Add parameter 1
+ //
+ FunctionCallParameter parameter1 ("parameter1", 3, (unsigned char *)"123");
+
+ CPPUNIT_ASSERT_MESSAGE ( "addParameter failed",
+ mpFunctionSciMsg->addParameter(parameter1) );
+
+ // Add parameter 2
+ //
+ FunctionCallParameter parameter2 ("parameter2", 10, (unsigned char *)"0123456789");
+
+ CPPUNIT_ASSERT_MESSAGE ( "addParameter failed",
+ mpFunctionSciMsg->addParameter(parameter2) );
+
+ // Add parameter 3
+ //
+ FunctionCallParameter parameter3 = parameter2;
+
+ CPPUNIT_ASSERT_MESSAGE ( "addParameter failed",
+ mpFunctionSciMsg->addParameter(parameter3) );
+ }
+ else
+ {
+ CPPUNIT_FAIL ( "Initialized FunctionSciMsg pointer is NULL" );
+ }
+}
+
+
+void FunctionSciMsgTest::bindParameterTest (void)
+{
+ logTest();
+
+ if (NULL != mpFunctionSciMsg)
+ {
+ // Add parameter 1
+ //
+ FunctionCallParameter parameter1 ("parameter1", 3, (unsigned char *)"123");
+
+ CPPUNIT_ASSERT_MESSAGE ( "addParameter failed",
+ mpFunctionSciMsg->addParameter(parameter1) );
+
+ // Add parameter 2
+ //
+ FunctionCallParameter parameter2 ("parameter2", 10, (unsigned char *)"0123456789");
+
+ CPPUNIT_ASSERT_MESSAGE ( "addParameter failed",
+ mpFunctionSciMsg->addParameter(parameter2) );
+
+ // Add parameter 3
+ //
+ FunctionCallParameter parameter3 = parameter2;
+
+ CPPUNIT_ASSERT_MESSAGE ( "addParameter failed",
+ mpFunctionSciMsg->addParameter(parameter3) );
+
+ const string name = "parameter1";
+ unsigned long dataLength = FUNCTION_CALL_PARAM_MAX_SIZE;
+ unsigned char * pData = new unsigned char [FUNCTION_CALL_PARAM_MAX_SIZE];
+
+ CPPUNIT_ASSERT_MESSAGE ( "bindParameter failed",
+ mpFunctionSciMsg->bindParameter(name, dataLength, pData) );
+
+ // Check results
+ //
+ CPPUNIT_ASSERT_MESSAGE ( "bindParameterTest failed: wrong data length", 3 == dataLength) ;
+
+ CPPUNIT_ASSERT_MESSAGE ( "bindParameterTest failed: data pointer is NULL", NULL != pData) ;
+
+ pData[dataLength] = '\0';
+
+ CPPUNIT_ASSERT_MESSAGE ( "bindParameterTest failed: wrong data", !strcmp("123", (char*)pData)) ;
+
+ // Free memory allocated for 'FunctionSciMsg::bindParameter'
+ //
+ if (NULL != pData)
+ {
+ delete [] pData;
+ pData = NULL;
+ }
+ }
+ else
+ {
+ CPPUNIT_FAIL ( "Initialized FunctionSciMsg pointer is NULL" );
+ }
+}
+
+
+void FunctionSciMsgTest::fillSpecializedSciMsgToSendTest (void)
+{
+ logTest();
+
+ if (NULL != mpFunctionSciMsg)
+ {
+ // Add parameter 1
+ //
+ FunctionCallParameter parameter1 ("parameter1", 3, (unsigned char *)"123");
+
+ CPPUNIT_ASSERT_MESSAGE ( "addParameter failed",
+ mpFunctionSciMsg->addParameter(parameter1) );
+
+ // Add parameter 2
+ //
+ FunctionCallParameter parameter2 ("parameter2", 10, (unsigned char *)"0123456789");
+
+ CPPUNIT_ASSERT_MESSAGE ( "addParameter failed",
+ mpFunctionSciMsg->addParameter(parameter2) );
+
+ // Add parameter 3
+ //
+ FunctionCallParameter parameter3 = parameter2;
+
+ CPPUNIT_ASSERT_MESSAGE ( "addParameter failed",
+ mpFunctionSciMsg->addParameter(parameter3) );
+
+ CPPUNIT_ASSERT_MESSAGE ( "setFunctionName failed",
+ mpFunctionSciMsg->setFunctionName ("function_to_call") );
+
+ CPPUNIT_ASSERT_MESSAGE ( "fillSpecializedSciMsgToSend failed",
+ mpFunctionSciMsg->fillSpecializedSciMsgToSend() );
+ }
+ else
+ {
+ CPPUNIT_FAIL ( "Initialized FunctionSciMsg pointer is NULL" );
+ }
+}
+
+
+void FunctionSciMsgTest::setSpecializedSciMsgFlagsTest (void)
+{
+ logTest();
+
+ if (NULL != mpFunctionSciMsg)
+ {
+ mpFunctionSciMsg->setSpecializedSciMsgFlags(FUNCTION_CALL_FLAG_MAX + 1);
+ CPPUNIT_ASSERT_MESSAGE ( "setSpecializedSciMsgFlags failed",
+ FUNCTION_CALL_FLAG_NONE == mpFunctionSciMsg->getSpecializedSciMsgFlags() );
+
+ mpFunctionSciMsg->setSpecializedSciMsgFlags(FUNCTION_CALL_FLAG_FAILED);
+ CPPUNIT_ASSERT_MESSAGE ( "setSpecializedSciMsgFlags failed",
+ FUNCTION_CALL_FLAG_FAILED == mpFunctionSciMsg->getSpecializedSciMsgFlags() );
+
+ mpFunctionSciMsg->setSpecializedSciMsgFlags(FUNCTION_CALL_FLAG_NONE);
+ CPPUNIT_ASSERT_MESSAGE ( "setSpecializedSciMsgFlags failed",
+ FUNCTION_CALL_FLAG_NONE == mpFunctionSciMsg->getSpecializedSciMsgFlags() );
+ }
+ else
+ {
+ CPPUNIT_FAIL ( "Initialized FunctionSciMsg pointer is NULL" );
+ }
+}
+