Merge branch 'master' into change/77452/5

Conflicts:
	runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/StaticArray.h

Change-Id: I804be9a3f19c12072c0733e054e8883f6fa21321
diff --git a/plugins/org.eclipse.etrice.etunit.converter/src/org/eclipse/etrice/etunit/converter/EtUnitReportConverter.java b/plugins/org.eclipse.etrice.etunit.converter/src/org/eclipse/etrice/etunit/converter/EtUnitReportConverter.java
index 704524c..aba3de1 100644
--- a/plugins/org.eclipse.etrice.etunit.converter/src/org/eclipse/etrice/etunit/converter/EtUnitReportConverter.java
+++ b/plugins/org.eclipse.etrice.etunit.converter/src/org/eclipse/etrice/etunit/converter/EtUnitReportConverter.java
@@ -337,6 +337,12 @@
 			TestsuiteType currentSuite = null;
 			String line = bufRead.readLine();
 			++count;
+			if (line==null) {
+				System.err.println("Error: file "+report+", is empty - no etunit file");
+				bufRead.close();
+				input.close();
+				return null;
+			}
 			if (!line.equals("etUnit report")) {
 				System.err.println("Error: file "+report+", line "+line+" is missing header line - no etunit file");
 				bufRead.close();
diff --git a/plugins/org.eclipse.etrice.generator.ui.cdt/src/org/eclipse/etrice/generator/ui/cdt/CProjectConfigurator.java b/plugins/org.eclipse.etrice.generator.ui.cdt/src/org/eclipse/etrice/generator/ui/cdt/CProjectConfigurator.java
index 74900cf..3fe5f93 100644
--- a/plugins/org.eclipse.etrice.generator.ui.cdt/src/org/eclipse/etrice/generator/ui/cdt/CProjectConfigurator.java
+++ b/plugins/org.eclipse.etrice.generator.ui.cdt/src/org/eclipse/etrice/generator/ui/cdt/CProjectConfigurator.java
@@ -72,6 +72,10 @@
 			return true;
 		if (id.startsWith("cdt.managedbuild.tool.gnu.c.compiler.input"))
 			return true;
+		if (id.startsWith("com.ifx.xmc1000.compiler.option.include.paths"))
+			return true;
+		if (id.startsWith("com.ifx.xmc1000.cppcompiler.option.include.paths"))
+			return true;
 		if (id.startsWith("com.ifx.xmc4000.compiler.option.include.paths"))
 			return true;
 		if (id.startsWith("com.ifx.xmc4000.cppcompiler.option.include.paths"))
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/StaticArray.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/StaticArray.cpp
deleted file mode 100644
index 60a33f4..0000000
--- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/StaticArray.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-/*******************************************************************************
- * 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:
- * 		Thomas Schuetz (initial contribution)
- *
- *******************************************************************************/
-
-#include "common/containers/StaticArray.h"
-
-namespace etRuntime {
-
-} /* namespace etRuntime */
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/StaticArray.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/StaticArray.h
index 93db9b2..2838083 100644
--- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/StaticArray.h
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/StaticArray.h
@@ -14,43 +14,76 @@
 #define STATICARRAY_H_
 
 #include "etDatatypes.h"
-#include <string.h>
+#include <cstring>
 
 namespace etRuntime {
 
 template<class Type, int Size>
 class StaticArray {
 public:
+	/**
+	 * default constructor
+	 */
 	StaticArray() {
 	}
 
+	/**
+	 * copy constructor forwards to deepCopy()
+	 */
 	StaticArray(const StaticArray<Type, Size> &rhs) {
 		this->deepCopy(rhs);
 	}
 
+	/**
+	 * initializes each array element to t
+	 */
 	StaticArray(const Type& t) {
 		for (int i = 0; i < Size; i++) {
 			data[i] = t;
 		}
 	}
 
+	/**
+	 * virtual destructor
+	 */
 	virtual ~StaticArray(void) {
 	}
 
+	/**
+	 * returns the size of this array
+	 */
 	int getSize(void) const {
 		return Size;
 	}
 
+	/**
+	 * returns a pointer to the data of this array (as a C array)
+	 */
 	Type* getData(void) {
 		return this->data;
 	}
 
+	/**
+	 * returns a const pointer to the data of this array (as a C array)
+	 */
+	const Type* getData(void) const {
+		return this->data;
+	}
+
+	/**
+	 * indexed access without range check
+	 */
 	Type& operator[](int index) {
 		return data[index];
 	}
 
+	/**
+	 * copy assignment makes a deep copy
+	 */
 	StaticArray<Type, Size>& operator=(const StaticArray<Type, Size> &rhs) {
-		this->deepCopy(rhs);
+		if (&rhs!=this) {
+			this->deepCopy(rhs);
+		}
 		return *this;
 	}
 
@@ -67,11 +100,29 @@
 //			return false;
 //		}
 //	}
+	/**
+	 * comparison operator based on memcmp()
+	 */
+	bool operator==(const StaticArray<Type, Size> &rhs) const {
+		return std::memcmp(this->data, rhs.data, sizeof(data)) == 0;
+	}
 
 protected:
+	/**
+	 * the C array holding the data
+	 */
 	Type data[Size];
+
+	/**
+	 * makes a copy of the array including all elements
+	 */
 	void deepCopy(const StaticArray<Type, Size> &rhs) {
-		memcpy(this->data, rhs.data, sizeof(data));
+		std::memcpy(this->data, rhs.data, sizeof(data));
+	}
+	void deepCopy2(const StaticArray<Type, Size> &rhs) {
+		for (int i=0; i<Size; ++i) {
+			data[i] = rhs.data[i];
+		}
 	}
 
 };
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/StaticString.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/StaticString.h
new file mode 100644
index 0000000..ffa5303
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/StaticString.h
@@ -0,0 +1,139 @@
+/*******************************************************************************
+ * 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:
+ * 		Thomas Schuetz (initial contribution)
+ *
+ *******************************************************************************/
+
+#ifndef STATICSTRING_H_
+#define STATICSTRING_H_
+
+#include "StaticArray.h"
+
+namespace etRuntime {
+
+/**
+ * a static size string class that basically encapsulates a C string
+ */
+template<int Size>
+class StaticString: public StaticArray<char, Size> {
+public:
+	/**
+	 * default constructor is empty string
+	 */
+	StaticString()
+	{
+		this->data[0] = 0;
+	}
+
+	/**
+	 * copy constructor calls operator=(const char *rhs)
+	 */
+	template<int RhsSize> StaticString(const StaticString<RhsSize> &rhs)
+	{
+		operator=(rhs.getData());
+	}
+
+	/**
+	 * constructor calls operator=(const char *rhs)
+	 */
+	StaticString(const char *rhs)
+	{
+		operator=(rhs);
+	}
+
+	/**
+	 * virtual destructor
+	 */
+	virtual ~StaticString(void) {
+	}
+
+	/**
+	 * returns the length of the C string stored
+	 */
+	int length(void) const {
+		return std::strlen(this->data);
+	}
+
+	/**
+	 * forwards to operator=(const char *rhs)
+	 */
+	template<int RhsSize> StaticString<Size>& operator=(const StaticString<RhsSize> &rhs) {
+		return operator=(rhs.data);
+	}
+
+	/**
+	 * works like strncpy() with the size of this string. Will be 0 terminated.
+	 */
+	StaticString<Size>& operator=(const char *rhs) {
+		if (rhs && rhs!=this->data) {
+			std::strncpy(this->data, rhs, Size);
+			this->data[Size-1] = 0;
+		}
+		return *this;
+	}
+
+	/**
+	 * concatenates the rhs to the end of the string if the result fits.
+	 * If it doesn't fit nothing is done.
+	 */
+	template<int RhsSize> const StaticString<Size> operator+(const StaticString<RhsSize> &other) const {
+		// make a copy and add
+		return StaticString<Size>(*this) += other;
+	}
+
+	/**
+	 * concatenates the rhs to the end of the string if the result fits.
+	 * If it doesn't fit nothing is done.
+	 */
+	const StaticString<Size> operator+(const char* other) const {
+		// make a copy and add
+		return StaticString<Size>(*this) += other;
+	}
+
+	/*
+	 * concatenates the rhs to the end of the string if the result fits.
+	 * If it doesn't fit nothing is done.
+	 */
+	template<int RhsSize> const StaticString<Size> operator+=(const StaticString<RhsSize>& rhs) {
+		return operator+=(rhs.data);
+	}
+
+	/*
+	 * concatenates the rhs to the end of the string if the result fits.
+	 * If it doesn't fit nothing is done.
+	 */
+	const StaticString<Size> operator+=(const char* rhs) {
+		if (rhs && (this->length() + std::strlen(rhs)) < Size) {
+			std::strcat(this->data, rhs);
+		};
+
+		// Note: this function returns a const, not a const&!
+		// this prohibits things like (a + b) = c
+		return *this;
+	}
+
+	/**
+	 * compares two strings using std::strcmp()
+	 */
+	template<int RhsSize> bool operator==(const StaticString<RhsSize> &rhs) {
+		return operator==(rhs.data);
+	}
+
+	/**
+	 * compares two strings using std::strcmp()
+	 */
+	bool operator==(const char *rhs) {
+		return strcmp(this->data, rhs)==0;
+	}
+};
+
+} /* namespace etRuntime */
+
+#endif /* STATICSTRING_H_ */
+
diff --git a/tests/org.eclipse.etrice.etunit.converter.tests/reports/report6.etu b/tests/org.eclipse.etrice.etunit.converter.tests/reports/report6.etu
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/org.eclipse.etrice.etunit.converter.tests/reports/report6.etu
diff --git a/tests/org.eclipse.etrice.etunit.converter.tests/src/org/eclipse/etrice/etunit/converter/ConverterTest.java b/tests/org.eclipse.etrice.etunit.converter.tests/src/org/eclipse/etrice/etunit/converter/ConverterTest.java
index 51f18a8..48aa82a 100644
--- a/tests/org.eclipse.etrice.etunit.converter.tests/src/org/eclipse/etrice/etunit/converter/ConverterTest.java
+++ b/tests/org.eclipse.etrice.etunit.converter.tests/src/org/eclipse/etrice/etunit/converter/ConverterTest.java
@@ -93,4 +93,13 @@
 		String[] arguments = new String[args.size()];
 		EtUnitReportConverter.main(args.toArray(arguments));
 	}
+
+	@Test
+	public void testEmptyFile() {
+		ArrayList<String> args = new ArrayList<String>();
+		args.add(basePath+"report6.etu");
+		
+		String[] arguments = new String[args.size()];
+		EtUnitReportConverter.main(args.toArray(arguments));
+	}
 }
diff --git a/tests/org.eclipse.etrice.runtime.cpp.tests/.cproject b/tests/org.eclipse.etrice.runtime.cpp.tests/.cproject
index 0bdbf55..211b8d3 100644
--- a/tests/org.eclipse.etrice.runtime.cpp.tests/.cproject
+++ b/tests/org.eclipse.etrice.runtime.cpp.tests/.cproject
@@ -295,9 +295,7 @@
 							<tool id="cdt.managedbuild.tool.gnu.cpp.linker.mingw.exe.debug.326802020" name="MinGW C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.mingw.exe.debug">
 								<option id="gnu.cpp.link.option.paths.1352233185" name="Library search path (-L)" superClass="gnu.cpp.link.option.paths" valueType="libPaths">
 									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/org.eclipse.etrice.runtime.cpp/WindowsMinGW}&quot;"/>
-									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/org.eclipse.etrice.runtime.c/ExternalMakefile}&quot;"/>
-									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/org.eclipse.etrice.runtime.c}&quot;"/>
-									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/org.eclipse.etrice.runtime.c/buildTools}&quot;"/>
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/org.eclipse.etrice.runtime.c/WindowsMinGW}&quot;"/>
 								</option>
 								<option id="gnu.cpp.link.option.libs.1439602349" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" valueType="libs">
 									<listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="org.eclipse.etrice.runtime.cpp"/>
@@ -320,9 +318,7 @@
 						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="includePath" name="/org.eclipse.etrice.runtime.c/src/config"/>
 						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="includePath" name="/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW"/>
 						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="includePath" name="/org.eclipse.etrice.runtime.c/src/util"/>
-						<entry flags="VALUE_WORKSPACE_PATH" kind="libraryPath" name="/org.eclipse.etrice.runtime.c/ExternalMakefile"/>
-						<entry flags="VALUE_WORKSPACE_PATH" kind="libraryPath" name="/org.eclipse.etrice.runtime.c"/>
-						<entry flags="VALUE_WORKSPACE_PATH" kind="libraryPath" name="/org.eclipse.etrice.runtime.c/buildTools"/>
+						<entry flags="VALUE_WORKSPACE_PATH" kind="libraryPath" name="/org.eclipse.etrice.runtime.c/WindowsMinGW"/>
 						<entry flags="RESOLVED" kind="libraryFile" name="org.eclipse.etrice.runtime.c" srcPrefixMapping="" srcRootPath=""/>
 					</externalSetting>
 				</externalSettings>
diff --git a/tests/org.eclipse.etrice.runtime.cpp.tests/.project b/tests/org.eclipse.etrice.runtime.cpp.tests/.project
index d05e35b..48ecbc9 100644
--- a/tests/org.eclipse.etrice.runtime.cpp.tests/.project
+++ b/tests/org.eclipse.etrice.runtime.cpp.tests/.project
@@ -9,7 +9,7 @@
 	<buildSpec>
 		<buildCommand>
 			<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
-			<triggers></triggers>
+			<triggers>clean,full,incremental,</triggers>
 			<arguments>
 			</arguments>
 		</buildCommand>
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 d47f041..579693e 100644
--- a/tests/org.eclipse.etrice.runtime.cpp.tests/src/RunAllTestCases.cpp
+++ b/tests/org.eclipse.etrice.runtime.cpp.tests/src/RunAllTestCases.cpp
@@ -12,6 +12,7 @@
 
 #include "messaging/AddressTest.h"
 #include "containers/StaticArrayTest.h"
+#include "containers/StaticStringTest.h"
 
 #include "etUnit/etUnit.h"
 
@@ -25,6 +26,9 @@
 	StaticArrayTest staticArrayTest;
 	staticArrayTest.run();
 
+	StaticStringTest staticStringTest;
+	staticStringTest.run();
+
 	etUnit_close();
 
 	return 0;
diff --git a/tests/org.eclipse.etrice.runtime.cpp.tests/src/containers/StaticArrayTest.cpp b/tests/org.eclipse.etrice.runtime.cpp.tests/src/containers/StaticArrayTest.cpp
index 9d28942..def2ac5 100644
--- a/tests/org.eclipse.etrice.runtime.cpp.tests/src/containers/StaticArrayTest.cpp
+++ b/tests/org.eclipse.etrice.runtime.cpp.tests/src/containers/StaticArrayTest.cpp
@@ -125,14 +125,13 @@
 	EXPECT_EQUAL_INT32(m_caseId, "copy operator wrong", 11, addressArray3[9].m_objectID);
 
 	// Compare Operator
-	// TODO: fix implementation of operator== and activate testcase
-//	EXPECT_TRUE(m_caseId, "compare operator wrong", intArray2 == intArray3);
-//	intArray2[4]=99;
-//	EXPECT_FALSE(m_caseId, "compare operator wrong", intArray2 == intArray3);
-//
-//	EXPECT_TRUE(m_caseId, "compare operator wrong", addressArray2 == addressArray3);
-//	addressArray2[9]=Address(99,88,77);
-//	EXPECT_FALSE(m_caseId, "compare operator wrong", addressArray2 == addressArray3);
+	EXPECT_TRUE(m_caseId, "compare operator wrong", intArray2 == intArray3);
+	intArray2[4] = 99;
+	EXPECT_FALSE(m_caseId, "compare operator wrong", intArray2 == intArray3);
+
+	EXPECT_TRUE(m_caseId, "compare operator wrong", addressArray2 == addressArray3);
+	addressArray2[9] = Address(99, 88, 77);
+	EXPECT_FALSE(m_caseId, "compare operator wrong", addressArray2 == addressArray3);
 
 }
 
diff --git a/tests/org.eclipse.etrice.runtime.cpp.tests/src/containers/StaticStringTest.cpp b/tests/org.eclipse.etrice.runtime.cpp.tests/src/containers/StaticStringTest.cpp
new file mode 100644
index 0000000..e64ff85
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.cpp.tests/src/containers/StaticStringTest.cpp
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * 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:
+ * 		Thomas Schuetz (initial contribution)
+ *
+ *******************************************************************************/
+
+#include "StaticStringTest.h"
+
+#include "common/containers/StaticString.h"
+#include "util/etAssert.h"
+
+using namespace etRuntime;
+
+void StaticStringTest::testConstructors(void) {
+	// default constructors for simple types
+	StaticString<5> string1; // nothing happens, but should not crash
+	StaticString<10> string2("eTrice");
+	StaticString<8> string3(string2);	// copy construction for unequal sizes
+
+	EXPECT_EQUAL_INT8(m_caseId, "default string is not 0 at pos 0", 0,
+			string1[0]);
+	EXPECT_EQUAL_INT8(m_caseId, "value for string2 at pos 2 is wrong", 'r',
+			string2[2]);
+	EXPECT_EQUAL_INT8(m_caseId, "value for string2 at pos 4 is wrong", 'c',
+			string2[4]);
+
+	EXPECT_EQUAL_INT8(m_caseId, "copy constructor for string3 wrong", 'e',
+			string3[0]);
+	EXPECT_EQUAL_INT8(m_caseId, "copy constructor for string3 wrong", 'r',
+			string3[2]);
+	EXPECT_EQUAL_INT8(m_caseId, "copy constructor for string3 wrong", 'c',
+			string3[4]);
+}
+
+void StaticStringTest::testSettersAndGetters(void) {
+	StaticString<8> string1("eTrice"); // nothing happens, but should not crash
+
+	// getSize
+	EXPECT_EQUAL_INT8(m_caseId, "length wrong", 6, string1.length());
+
+	// getData
+	EXPECT_EQUAL_INT8(m_caseId, "getData wrong", 'i', string1.getData()[3]);
+}
+
+void StaticStringTest::testOperators(void) {
+	StaticString<8> string1("eTrice"); // nothing happens, but should not crash
+
+	StaticString<8> string2;
+	string2 = string1;
+	EXPECT_TRUE(m_caseId, "strings should be equal", std::strcmp(string1.getData(), string2.getData())==0);
+
+	string2 = "ROOM";
+	EXPECT_TRUE(m_caseId, "strings should be equal", std::strcmp("ROOM", string2.getData())==0);
+
+	StaticString<32> string3("ROOM with ");
+	string3 += "eTrice";
+	EXPECT_TRUE(m_caseId, "strings should be equal", std::strcmp("ROOM with eTrice", string3.getData())==0);
+
+	StaticString<32> string4("ROOM with ");
+	StaticString<32> string5("eTrice");
+	string4 += string5;
+	EXPECT_TRUE(m_caseId, "strings should be equal", std::strcmp("ROOM with eTrice", string4.getData())==0);
+
+	StaticString<32> string6("ROOM with ");
+	StaticString<32> string7("eTrice");
+	StaticString<32> string8 = string6 + string7;
+	EXPECT_TRUE(m_caseId, "strings should be equal", std::strcmp("ROOM with eTrice", string8.getData())==0);
+
+	StaticString<32> string9("ROOM with ");
+	StaticString<32> string10 = string9 + "eTrice";
+	EXPECT_TRUE(m_caseId, "strings should be equal", std::strcmp("ROOM with eTrice", string10.getData())==0);
+
+	StaticString<32> string11("something");
+	EXPECT_TRUE(m_caseId, "strings should be equal", string11=="something");
+
+	StaticString<32> string12("something");
+	EXPECT_TRUE(m_caseId, "strings should be equal", string11==string12);
+}
+
+void StaticStringTest::runAllTestCases() {
+	ADD_TESTCASE(testConstructors)
+	ADD_TESTCASE(testSettersAndGetters)
+	ADD_TESTCASE(testOperators)
+}
diff --git a/tests/org.eclipse.etrice.runtime.cpp.tests/src/containers/StaticStringTest.h b/tests/org.eclipse.etrice.runtime.cpp.tests/src/containers/StaticStringTest.h
new file mode 100644
index 0000000..fcbc86b
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.cpp.tests/src/containers/StaticStringTest.h
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * 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:
+ * 		Thomas Schuetz (initial contribution)
+ *
+ *******************************************************************************/
+
+#ifndef SRC_CONTAINERS_STATICSTRINGTEST_H_
+#define SRC_CONTAINERS_STATICSTRINGTEST_H_
+
+#include "etUnit/etUnit.h"
+#include "util/etTestSuite.h"
+
+class StaticStringTest : public etTestSuite {
+
+public:
+	StaticStringTest() :
+		etTestSuite("StaticStringTest"){
+	}
+
+protected:
+	void testConstructors(void);
+	void testSettersAndGetters(void);
+	void testOperators(void);
+
+	virtual void runAllTestCases();
+};
+
+
+#endif /* SRC_CONTAINERS_STATICSTRINGTEST_H_ */