Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJan Belle2017-10-22 11:13:55 -0400
committerJan Belle2017-10-22 11:13:55 -0400
commit6f34422d3f9216bc5b620c1ce80e998a2e745b40 (patch)
treef75649c4b3e32db64f7287b26735ea63ae2b30eb /tests
parent92c3dc64f5c9d841fd5823cd923d552bafb0ac08 (diff)
downloadorg.eclipse.etrice-6f34422d3f9216bc5b620c1ce80e998a2e745b40.tar.gz
org.eclipse.etrice-6f34422d3f9216bc5b620c1ce80e998a2e745b40.tar.xz
org.eclipse.etrice-6f34422d3f9216bc5b620c1ce80e998a2e745b40.zip
[runtime.c] static deque implementation
added tests and documentation for static deque Change-Id: I1631e94cc83df8d683ea5da5de415b6ec1dcb0c5
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.etrice.runtime.c.tests/src/runtime/RunCRuntimeTestcases.c4
-rw-r--r--tests/org.eclipse.etrice.runtime.c.tests/src/runtime/container/TestEtStaticDeque.c104
-rw-r--r--tests/org.eclipse.etrice.runtime.c.tests/src/runtime/container/TestEtStaticDeque.h18
3 files changed, 126 insertions, 0 deletions
diff --git a/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/RunCRuntimeTestcases.c b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/RunCRuntimeTestcases.c
index 8aed2e209..40be33446 100644
--- a/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/RunCRuntimeTestcases.c
+++ b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/RunCRuntimeTestcases.c
@@ -32,6 +32,8 @@
#include "helpers/TestEtTimeHelpers.h"
#include "util/TestUtil.h"
+#include "container/TestEtStaticDeque.h"
+
#include "etUnit/etUnit.h"
#include "debugging/etMSCLogger.h"
@@ -52,6 +54,8 @@ void RunCRuntimeTestcases(void){
TestEtTimeHelpers_runSuite();
TestUtil_runSuite();
+ TestEtStaticDeque_runSuite();
+
etUnit_close();
/* special situation for testing openAll and closeAll of etUnit
diff --git a/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/container/TestEtStaticDeque.c b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/container/TestEtStaticDeque.c
new file mode 100644
index 000000000..67d4a5a8f
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/container/TestEtStaticDeque.c
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * Copyright (c) 2017 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 "TestEtStaticDeque.h"
+
+#include "etUnit/etUnit.h"
+#include "container/etStaticDeque.h"
+
+typedef struct {
+ int attr1;
+ double attr2;
+ const char* attr3;
+}
+DataClass;
+
+bool compareDataClass(DataClass* d1, DataClass* d2) {
+ return d1->attr1 == d2->attr1
+ && d1->attr2 == d2->attr2
+ && d1->attr3 == d2->attr3;
+}
+
+void TestEtStaticDeque_testConstruct(etInt16 caseId) {
+ const char* failMsg = "testConstructors failed";
+
+ // Test constructor StaticDeque(void)
+ etStaticDeque deque;
+ int memory[10];
+ etStaticDeque_construct(&deque, memory, 10, sizeof(int));
+ EXPECT_EQUAL_INT32(caseId, failMsg, 0, deque.size);
+ EXPECT_TRUE(caseId, failMsg, deque.size == 0);
+}
+
+void TestEtStaticDeque_testPushPop(etInt16 caseId) {
+ const char* failMsg = "testPushPop failed";
+
+ // Test push_back and push_front with 6 objects of type DataClass
+ etStaticDeque deque;
+ DataClass memory[6];
+ etStaticDeque_construct(&deque, memory, 6, sizeof(DataClass));
+ DataClass d1 = { 1, 1.5, "Data 1" };
+ DataClass d2 = { 2, 2.5, "Data 2" };
+ DataClass d3 = { 3, 3.5, "Data 3" };
+ DataClass d4 = { 4, 4.5, "Data 4" };
+ DataClass d5 = { 5, 5.5, "Data 5" };
+ DataClass d6 = { 1, 1.5, "Data 6" };
+ etStaticDeque_push_front(&deque, &d3);
+ etStaticDeque_push_front(&deque, &d2);
+ etStaticDeque_push_back(&deque, &d4);
+ etStaticDeque_push_front(&deque, &d1);
+ etStaticDeque_push_back(&deque, &d5);
+ etStaticDeque_push_back(&deque, &d6);
+
+ EXPECT_TRUE(caseId, failMsg, compareDataClass(&d1, etStaticDeque_front(&deque)));
+ EXPECT_TRUE(caseId, failMsg, compareDataClass(&d2, etStaticDeque_get(&deque, 1)));
+ EXPECT_TRUE(caseId, failMsg, compareDataClass(&d3, etStaticDeque_get(&deque, 2)));
+ EXPECT_TRUE(caseId, failMsg, compareDataClass(&d4, etStaticDeque_get(&deque, 3)));
+ EXPECT_TRUE(caseId, failMsg, compareDataClass(&d5, etStaticDeque_get(&deque, 4)));
+ EXPECT_TRUE(caseId, failMsg, compareDataClass(&d6, etStaticDeque_back(&deque)));
+ EXPECT_EQUAL_INT32(caseId, failMsg, 6, deque.size);
+ EXPECT_FALSE(caseId, failMsg, deque.size == 0);
+
+ // Test pop_back and pop_front
+ etStaticDeque_pop_back(&deque);
+ etStaticDeque_pop_front(&deque);
+ etStaticDeque_pop_front(&deque);
+ etStaticDeque_pop_back(&deque);
+
+ EXPECT_TRUE(caseId, failMsg, compareDataClass(&d3, etStaticDeque_get(&deque, 0)));
+ EXPECT_TRUE(caseId, failMsg, compareDataClass(&d4, etStaticDeque_get(&deque, 1)));
+ EXPECT_EQUAL_INT32(caseId, failMsg, 2, deque.size);
+ EXPECT_FALSE(caseId, failMsg, deque.size == 0);
+
+ // Test pushing after popping
+ etStaticDeque_push_front(&deque, &d2);
+ etStaticDeque_push_back(&deque, &d5);
+
+ EXPECT_TRUE(caseId, failMsg, compareDataClass(&d2, etStaticDeque_front(&deque)));
+ EXPECT_TRUE(caseId, failMsg, compareDataClass(&d3, etStaticDeque_get(&deque, 1)));
+ EXPECT_TRUE(caseId, failMsg, compareDataClass(&d4, etStaticDeque_get(&deque, 2)));
+ EXPECT_TRUE(caseId, failMsg, compareDataClass(&d5, etStaticDeque_back(&deque)));
+ EXPECT_EQUAL_INT32(caseId, failMsg, 4, deque.size);
+ EXPECT_FALSE(caseId, failMsg, deque.size == 0);
+
+ // Test pop all objects
+ while(deque.size > 0) {
+ etStaticDeque_pop_front(&deque);
+ }
+}
+
+void TestEtStaticDeque_runSuite(void) {
+ etUnit_openTestSuite("org.eclipse.etrice.runtime.c.tests.TestEtStaticDeque");
+ ADD_TESTCASE(TestEtStaticDeque_testConstruct);
+ ADD_TESTCASE(TestEtStaticDeque_testPushPop);
+ etUnit_closeTestSuite();
+}
diff --git a/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/container/TestEtStaticDeque.h b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/container/TestEtStaticDeque.h
new file mode 100644
index 000000000..877eb37c6
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/container/TestEtStaticDeque.h
@@ -0,0 +1,18 @@
+/*******************************************************************************
+ * Copyright (c) 2017 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_RUNTIME_CONTAINER_TESTETSTATICDEQUE_H_
+#define SRC_RUNTIME_CONTAINER_TESTETSTATICDEQUE_H_
+
+void TestEtStaticDeque_runSuite(void);
+
+#endif /* SRC_RUNTIME_CONTAINER_TESTETSTATICDEQUE_H_ */

Back to the top