浏览代码

isActive returns correct results on inactive statecharts (#1391)

* Change order of the State enum

* Implement isActiveFunction with for loop

* Add forgotten ';'

* Correct initial value of result

* Fix formatting

* Remove accidentally pasted stuff

* Test for issue #1318

This test fails without the changes made for issue #1318, but should pass
with them.

* Add tests to AllTests
Rene Beckmann 8 年之前
父节点
当前提交
96de1fa47c

+ 3 - 3
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/StatemachineHeader.xtend

@@ -123,10 +123,10 @@ class StatemachineHeader implements IContentTemplate {
 		/*! Enumeration of all states */ 
 		typedef enum
 		{
-			«FOR state : states»
-				«state.shortName»,
+			«null_state»,
+			«FOR state : states SEPARATOR ","»
+				«state.shortName»
 			«ENDFOR»
-			«null_state»
 		} «statesEnumType»;
 	'''
 

+ 7 - 8
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/StatemachineSource.xtend

@@ -70,7 +70,7 @@ class StatemachineSource implements IContentTemplate {
 		«runCycleFunction»
 		
 		«raiseTimeEventFunction»
-		
+
 		«isStateActiveFunction»
 		
 		«interfaceFunctions»
@@ -220,15 +220,14 @@ class StatemachineSource implements IContentTemplate {
 	def isActiveFunction(ExecutionFlow it) '''
 		sc_boolean «isActiveFctID»(const «scHandleDecl»)
 		{
-			sc_boolean result;
-			if («FOR i : 0 ..< stateVector.size SEPARATOR ' || '»«scHandle»->stateConfVector[«i»] != «null_state»«ENDFOR»)
-			{
-				result =  bool_true;
-			}
-			else
+			sc_boolean result = bool_false;
+			int i;
+			
+			for(i = 0; i < «type.toUpperCase»_MAX_ORTHOGONAL_STATES; i++)
 			{
-				result = bool_false;
+				result = result || «scHandle»->stateConfVector[i] != «null_state»;
 			}
+			
 			return result;
 		}
 	'''

+ 30 - 0
test-plugins/org.yakindu.sct.generator.c.test/gtests/ActiveBeforeInit/ActiveBeforeInit.cc

@@ -0,0 +1,30 @@
+/**
+* Copyright (c) 2017 committers of YAKINDU and others.
+* 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:
+*     committers of YAKINDU - initial API and implementation
+*/
+#include "gtest/gtest.h"
+#include "AlwaysOncycle.h"
+
+/** Attention - this file is NOT generated */
+
+AlwaysOncycle handle;
+
+class StatemachineTest : public ::testing::Test{
+	protected:
+	virtual void SetUp() {
+            // do NOT init the statechart
+        }
+};
+
+
+TEST_F(StatemachineTest, alwaysOncycleTest) {					
+        EXPECT_TRUE(alwaysOncycle_isActive(&handle) == false);
+}
+
+

+ 40 - 0
test-plugins/org.yakindu.sct.generator.c.test/src/org/yakindu/sct/generator/c/test/ActiveBeforeInit.java

@@ -0,0 +1,40 @@
+/**
+ * Copyright (c) 2014 committers of YAKINDU and others.
+ * 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:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.generator.c.test;
+
+import java.util.Collection;
+
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.yakindu.sct.generator.c.gtest.GTest;
+import org.yakindu.sct.generator.c.gtest.GTestRunner;
+import org.yakindu.sct.generator.c.gtest.GTestHelper;
+
+@GTest(sourceFile = "gtests/ActiveBeforeInit/ActiveBeforeInit.cc", program = "gtests/AlwaysOncycleTest/AlwaysOncycle", model = "testmodels/SCTUnit/AlwaysOncycle.sct")
+@RunWith(GTestRunner.class)
+public class ActiveBeforeInit {
+
+	protected final GTestHelper helper = new GTestHelper(this) {
+		
+		@Override
+		protected void getSourceFiles(Collection<String> files) {
+			super.getSourceFiles(files);
+			files.add(getFileName(getTestProgram()) + ".c");
+		}
+		
+	};
+
+	@Before
+	public void setUp() {
+		helper.generate();
+		helper.compile();
+	}
+}

+ 1 - 1
test-plugins/org.yakindu.sct.generator.c.test/src/org/yakindu/sct/generator/c/test/AllTestsTestCustom.java

@@ -15,6 +15,6 @@ import org.junit.runners.Suite;
 import org.junit.runners.Suite.SuiteClasses;
 
 @RunWith(Suite.class)
-@SuiteClasses({OperationsWithoutBracesCustom.class, VariadicOperations.class})
+@SuiteClasses({OperationsWithoutBracesCustom.class, VariadicOperations.class, ActiveBeforeInit.class})
 public class AllTestsTestCustom {
 }