summaryrefslogtreecommitdiff
path: root/cesar/maximus/sci/utest/scimsg/src/TestFunctionCall.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/maximus/sci/utest/scimsg/src/TestFunctionCall.cpp')
-rw-r--r--cesar/maximus/sci/utest/scimsg/src/TestFunctionCall.cpp169
1 files changed, 169 insertions, 0 deletions
diff --git a/cesar/maximus/sci/utest/scimsg/src/TestFunctionCall.cpp b/cesar/maximus/sci/utest/scimsg/src/TestFunctionCall.cpp
new file mode 100644
index 0000000000..a5ede75be9
--- /dev/null
+++ b/cesar/maximus/sci/utest/scimsg/src/TestFunctionCall.cpp
@@ -0,0 +1,169 @@
+/* Maximus project {{{
+ *
+ * Copyright (C) 2012 MStar Semiconductor
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file maximus/sci/utest/scimsg/src/TestFunctionCall.cpp
+ * \ingroup maximus_sci_utest_scimsg
+ *
+ */
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "inc/TestFunctionCall.h"
+#include "maximus/sci/inc/FunctionSciMsg.h"
+#include "maximus/sci/inc/SciServer.h"
+#include <sys/types.h>
+#include <string.h>
+#include <ostream>
+
+extern uint expected_msg_id;
+CPPUNIT_TEST_SUITE_REGISTRATION (TestFunctionCall);
+
+void
+TestFunctionCall::setUp ()
+{
+ fake_server = new SciServer (fake_sta_list);
+ fake_server->register_current_tick_addr (&time_base);
+ time_base = 0xBEEFBEEFBEEFBEEFll;
+}
+
+void
+TestFunctionCall::tearDown ()
+{
+ delete fake_server;
+ fake_server = NULL;
+}
+
+inline void
+TestFunctionCall::__build_functioncall_msg (
+ unsigned char *expected,
+ size_t msg_size,
+ size_t data_size,
+ Sci_Msg_Station_Id test_staid,
+ Function_Call_Type test_type,
+ Function_Call_Msg_Id test_msg_id)
+{
+ /* Build the expected buffer in network format. */
+
+ /* 34 = sizeof (Sci_Msg_Header) + sizeof (Function_Call_Header). */
+ CPPUNIT_ASSERT (msg_size >= 34);
+
+ memset (expected, 0, msg_size);
+ size_t test_length = data_size + sizeof (Function_Call_Header);
+
+ /* SciMsg Header from here. */
+ expected[0] = 'M';
+ expected[1] = 'A';
+ expected[2] = 'X';
+ expected[3] = 'I';
+ expected[4] = SCI_MSG_VERSION;
+ expected[5] = SCI_MSG_TYPE_FUNCTION_CALL;
+ expected[6] = test_length >> 24;
+ expected[7] = test_length >> 16;
+ expected[8] = test_length >> 8;
+ expected[9] = test_length;
+ expected[10] = static_cast <uint16_t> (test_staid) >> 8;
+ expected[11] = static_cast <uint16_t> (test_staid);
+ expected[12] = expected_msg_id >> 8;
+ expected[13] = expected_msg_id;
+ expected[14] = time_base >> 56;
+ expected[15] = time_base >> 48;
+ expected[16] = time_base >> 40;
+ expected[17] = time_base >> 32;
+ expected[18] = time_base >> 24;
+ expected[19] = time_base >> 16;
+ expected[20] = time_base >> 8;
+ expected[21] = time_base;
+ /* functioncall Header from here. */
+ expected[26] = FUNCTION_CALL_VERSION;
+ expected[27] = static_cast <uint8_t> (test_type);
+ expected[28] = static_cast <uint16_t> (test_msg_id) >> 8;
+ expected[29] = static_cast <uint16_t> (test_msg_id);
+}
+
+void
+TestFunctionCall::test_encode ()
+{
+ std::cout << "TestFunctionCall_encode" << std::endl;
+ const unsigned char *serial_msg;
+ const size_t msg_data_size = 0;
+
+ Sci_Msg_Station_Id staid = 30;
+ Function_Call_Type type = FUNCTION_CALL_TYPE_REQ;
+ Function_Call_Msg_Id msg_id = 0x17;
+
+ const size_t msg_size = msg_data_size
+ + sizeof (Sci_Msg_Header)
+ + sizeof (Function_Call_Header);
+ unsigned char *expected = new unsigned char [msg_size];
+ ++expected_msg_id;
+ __build_functioncall_msg (
+ expected,
+ msg_size,
+ msg_data_size,
+ staid,
+ type,
+ msg_id);
+
+ FunctionSciMsg msg (msg_data_size);
+ msg.set_sci_stationid (staid);
+ msg.set_fc_msg_id (msg_id);
+
+ msg.setup_and_send (*fake_server);
+ serial_msg = msg.get_sci_alloc_addr ();
+ CPPUNIT_ASSERT (serial_msg);
+ CPPUNIT_ASSERT (msg.get_sci_alloc_size ()
+ != (msg_data_size + sizeof (Function_Call_Header)));
+
+ for (uint i = 0; i < msg_size; i++)
+ {
+ if (expected[i] != serial_msg[i])
+ {
+ std::ostringstream oss;
+ oss << "expected[" << i << "] = "
+ << (uint) expected[i]
+ << " != "
+ << (uint) serial_msg[i]
+ << " = serial_msg[" << i << "]";
+ CPPUNIT_FAIL (oss.str ().c_str ());
+ }
+ }
+ delete [] expected;
+}
+
+void
+TestFunctionCall::test_decode ()
+{
+ std::cout << "TestFunctionCall_decode" << std::endl;
+ const size_t msg_data_size = 15;
+
+ Sci_Msg_Station_Id staid = 42;
+ Function_Call_Type type = FUNCTION_CALL_TYPE_RSP;
+ Function_Call_Msg_Id msg_id = 0x37;
+
+ const size_t msg_size = msg_data_size
+ + sizeof (Sci_Msg_Header)
+ + sizeof (Function_Call_Header);
+ unsigned char *expected = new unsigned char [msg_size];
+ __build_functioncall_msg (
+ expected,
+ msg_size,
+ msg_data_size,
+ staid,
+ type,
+ msg_id);
+
+ FunctionSciMsg msg (*((struct Sci_Msg_Header *)expected), expected);
+
+ CPPUNIT_ASSERT (msg.get_sci_alloc_size () == msg_size);
+ CPPUNIT_ASSERT (msg.get_sci_alloc_addr () == expected);
+ CPPUNIT_ASSERT (msg.get_sci_data_addr () == (expected + sizeof (Sci_Msg_Header)));
+ CPPUNIT_ASSERT (msg.get_sci_datalength () == (msg_size - sizeof (Sci_Msg_Header)));
+ CPPUNIT_ASSERT (msg.get_sci_stationid () == staid);
+
+ CPPUNIT_ASSERT (msg.get_fc_type () == type);
+ CPPUNIT_ASSERT (msg.get_fc_msgid () == msg_id);
+}