[runtime.cpp.test] Initial commit of MessageTest

Change-Id: I8d98124fe86884b38d3520a8a0085f797cdcbf62
Signed-off-by: Jan Belle <jan.belle@protos.de>
diff --git a/tests/org.eclipse.etrice.runtime.cpp.tests/src/RunAllTestCases.cpp b/tests/org.eclipse.etrice.runtime.cpp.tests/src/RunAllTestCases.cpp
index 579693e..390f4a2 100644
--- a/tests/org.eclipse.etrice.runtime.cpp.tests/src/RunAllTestCases.cpp
+++ b/tests/org.eclipse.etrice.runtime.cpp.tests/src/RunAllTestCases.cpp
@@ -10,25 +10,66 @@
  *
  *******************************************************************************/
 
-#include "messaging/AddressTest.h"
 #include "containers/StaticArrayTest.h"
 #include "containers/StaticStringTest.h"
+//#include "debugging/MSCFilterTest.h"
+//#include "debugging/MSCLoggerTest.h"
+//#include "debugging/DebuggingServiceTest.h"
+#include "messaging/AddressTest.h"
+#include "messaging/MessageTest.h"
+//#include "messaging/RTObjectTest.h"
+//#include "messaging/MessageSeQueueTest.h"
+//#include "messaging/MessageDispatcherTest.h"
+//#include "messaging/MessageServiceTest.h"
+//#include "messaging/MessageServiceControllerTest.h"
 
 #include "etUnit/etUnit.h"
 
-int main(){
+int main() {
 
-	etUnit_open("log/testlog","TestCppRuntime");
+	etUnit_open("log/testlog", "TestCppRuntime");
 
-	AddressTest addressTest;
-	addressTest.run();
-
+	// Test containers
 	StaticArrayTest staticArrayTest;
 	staticArrayTest.run();
 
 	StaticStringTest staticStringTest;
 	staticStringTest.run();
 
+	// Test debugging
+//	MSCFilterTest filterTest;
+//	filterTest.run();
+//
+//	MSCLoggerTest loggerTest;
+//	loggerTest.run();
+//
+//	DebuggingServiceTest debugSvcTest;
+//	debugSvcTest.run();
+
+// Test messaging
+	AddressTest addressTest;
+	addressTest.run();
+
+	MessageTest messageTest;
+	messageTest.run();
+
+//	RTObjectTest rtobjectTest;
+//	 rtobjectTest.run();
+//
+//	 MessageSeQueueTest msgQueueTest;
+//	 msgQueueTest.run();
+//
+//	 MessageDispatcherTest msgDispatcherTest;
+//	 msgDispatcherTest.run();
+//
+//	 MessageServiceTest msgServiceTest;
+//	 msgServiceTest.run();
+//
+//	 MessageServiceControllerTest msgSvcCtrlTest;
+//	 msgSvcCtrlTest.run();
+
+// Test modelbase
+
 	etUnit_close();
 
 	return 0;
diff --git a/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/MessageTest.cpp b/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/MessageTest.cpp
new file mode 100644
index 0000000..db8c29d
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/MessageTest.cpp
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2016 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * 		Jan Belle (initial contribution)
+ *
+ *******************************************************************************/
+
+#include "messaging/MessageTest.h"
+
+#include "etUnit/etUnit.h"
+#include "common/messaging/Address.h"
+#include "common/messaging/Message.h"
+
+using namespace etRuntime;
+
+void MessageTest::testConstructors() {
+
+	const char *failMsg = "Message constructor test failed";
+	Address addr(1, 2, 3);
+	int data = 128;
+
+	// Test constructor Message(const Address& addr, int evtId)
+	Message msg1(addr, 1);
+	EXPECT_TRUE(m_caseId, failMsg, msg1.getAddress() == addr);
+	EXPECT_EQUAL_INT16(m_caseId, failMsg, 1, msg1.getEvtId());
+	EXPECT_EQUAL_PTR(m_caseId, failMsg, 0, msg1.getData());
+
+	// Test constructor Message(const Address& addr, int evtm_caseId, void* dataPtr)
+	Message msg2(addr, 1, &data);
+	EXPECT_TRUE(m_caseId, failMsg, msg2.getAddress() == addr);
+	EXPECT_EQUAL_INT16(m_caseId, failMsg, 1, msg2.getEvtId());
+	EXPECT_EQUAL_PTR(m_caseId, failMsg, &data, msg2.getData());
+
+	// Test constructor Message(const Address& addr, int evtm_caseId, const void* dataToCopy, std::size_t dataSize)
+	Message msg3(addr, 1, &data, sizeof(int));
+	EXPECT_TRUE(m_caseId, failMsg, msg3.getAddress() == addr);
+	EXPECT_EQUAL_INT16(m_caseId, failMsg, 1, msg3.getEvtId());
+	EXPECT_TRUE(m_caseId, failMsg,
+			*(static_cast<int*>(msg3.getData())) == data);
+}
+
+void MessageTest::testGetters() {
+
+	const char *failMsg = "Message getter test failed";
+	Address addr(1, 2, 3);
+	int data = 128;
+	Message msg(addr, 1, &data);
+
+	// Test getAddress()
+	EXPECT_TRUE(m_caseId, failMsg, msg.getAddress() == addr);
+
+	// Test getEvtId()
+	EXPECT_EQUAL_INT16(m_caseId, failMsg, 1, msg.getEvtId());
+
+	// Test getData()
+	EXPECT_TRUE(m_caseId, failMsg, *(static_cast<int*>(msg.getData())) == data);
+}
+
+void MessageTest::testToString() {
+	Address addr(1, 2, 3);
+	Message msg(addr, 1);
+	EXPECT_TRUE(m_caseId, "Message toString test failed",
+			!msg.toString().compare("Message(1_2_3, evt=1)"));
+}
+
+void MessageTest::runAllTestCases() {
+	ADD_TESTCASE_CPP(testConstructors)
+	ADD_TESTCASE_CPP(testGetters)
+	ADD_TESTCASE_CPP(testToString)
+}
diff --git a/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/MessageTest.h b/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/MessageTest.h
new file mode 100644
index 0000000..213e8ae
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/MessageTest.h
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2016 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * 		Jan Belle (initial contribution)
+ *
+ *******************************************************************************/
+
+#ifndef SRC_MESSAGING_MESSAGETEST_H_
+#define SRC_MESSAGING_MESSAGETEST_H_
+
+#include "util/etTestSuite.h"
+
+class MessageTest: public etTestSuite {
+public:
+	MessageTest(void) :
+			etTestSuite("MessageTest") {
+	}
+
+protected:
+	void testConstructors(void);
+	void testGetters(void);
+	void testToString(void);
+
+	virtual void runAllTestCases(void);
+};
+
+#endif /* SRC_MESSAGING_MESSAGETEST_H_ */