From 04d91f90b35cb9c0829b464f1d1d03346e48453c Mon Sep 17 00:00:00 2001 From: Axel Terfloth Date: Mon, 8 Feb 2016 22:54:45 +0100 Subject: [PATCH] added cpp generator tests for issue #355 --- .../TriggerExpressionPrecedence.sgen | 19 +++++++ .../TriggerExpressionPrecedenceTest.cc | 54 +++++++++++++++++++ .../model/test.sgen | 24 +++++++++ .../sct/generator/cpp/test/AllTestsTest.java | 3 +- .../test/TriggerExpressionPrecedenceTest.java | 39 ++++++++++++++ 5 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 test-plugins/org.yakindu.sct.generator.cpp.test/gtests/TriggerExpressionPrecedenceTest/TriggerExpressionPrecedence.sgen create mode 100644 test-plugins/org.yakindu.sct.generator.cpp.test/gtests/TriggerExpressionPrecedenceTest/TriggerExpressionPrecedenceTest.cc create mode 100644 test-plugins/org.yakindu.sct.generator.cpp.test/test-gen/org/yakindu/sct/generator/cpp/test/TriggerExpressionPrecedenceTest.java diff --git a/test-plugins/org.yakindu.sct.generator.cpp.test/gtests/TriggerExpressionPrecedenceTest/TriggerExpressionPrecedence.sgen b/test-plugins/org.yakindu.sct.generator.cpp.test/gtests/TriggerExpressionPrecedenceTest/TriggerExpressionPrecedence.sgen new file mode 100644 index 0000000000..1ddb07768a --- /dev/null +++ b/test-plugins/org.yakindu.sct.generator.cpp.test/gtests/TriggerExpressionPrecedenceTest/TriggerExpressionPrecedence.sgen @@ -0,0 +1,19 @@ +GeneratorModel for yakindu::cpp { + statechart TriggerExpressionPrecedence { + feature Outlet { + targetProject = "gtests" + targetFolder = "TriggerExpressionPrecedenceTest" + } + feature FunctionInlining { + inlineReactions = false + inlineEntryActions = false + inlineEnterSequences = false + inlineExitActions = false + inlineExitSequences = false + inlineChoices = false + inlineEntries = false + inlineEnterRegion = false + inlineExitRegion = false + } + } +} diff --git a/test-plugins/org.yakindu.sct.generator.cpp.test/gtests/TriggerExpressionPrecedenceTest/TriggerExpressionPrecedenceTest.cc b/test-plugins/org.yakindu.sct.generator.cpp.test/gtests/TriggerExpressionPrecedenceTest/TriggerExpressionPrecedenceTest.cc new file mode 100644 index 0000000000..9a72fbaf95 --- /dev/null +++ b/test-plugins/org.yakindu.sct.generator.cpp.test/gtests/TriggerExpressionPrecedenceTest/TriggerExpressionPrecedenceTest.cc @@ -0,0 +1,54 @@ +/** +* Copyright (c) 2016 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 +#include "gtest/gtest.h" +#include "TriggerExpressionPrecedence.h" + +TEST(StatemachineTest, unsatisfiedTriggerAndFGuardFalseOrFalse) { + TriggerExpressionPrecedence* statechart = new TriggerExpressionPrecedence(); + statechart->init(); + statechart->enter(); + statechart->getDefaultSCI()->set_c1(false); + statechart->getDefaultSCI()->set_c2(false); + statechart->runCycle(); + EXPECT_TRUE(!statechart->getDefaultSCI()->get_e1_transition()); + delete statechart; +} +TEST(StatemachineTest, unsatisfiedTriggerAndFGuardTrueOrFalse) { + TriggerExpressionPrecedence* statechart = new TriggerExpressionPrecedence(); + statechart->init(); + statechart->enter(); + statechart->getDefaultSCI()->set_c1(true); + statechart->getDefaultSCI()->set_c2(false); + statechart->runCycle(); + EXPECT_TRUE(!statechart->getDefaultSCI()->get_e1_transition()); + delete statechart; +} +TEST(StatemachineTest, unsatisfiedTriggerAndFGuardFalseOrTrue) { + TriggerExpressionPrecedence* statechart = new TriggerExpressionPrecedence(); + statechart->init(); + statechart->enter(); + statechart->getDefaultSCI()->set_c1(false); + statechart->getDefaultSCI()->set_c2(true); + statechart->runCycle(); + EXPECT_TRUE(!statechart->getDefaultSCI()->get_e1_transition()); + delete statechart; +} +TEST(StatemachineTest, unsatisfiedTriggerAndFGuardTrueOrTrue) { + TriggerExpressionPrecedence* statechart = new TriggerExpressionPrecedence(); + statechart->init(); + statechart->enter(); + statechart->getDefaultSCI()->set_c1(true); + statechart->getDefaultSCI()->set_c2(true); + statechart->runCycle(); + EXPECT_TRUE(!statechart->getDefaultSCI()->get_e1_transition()); + delete statechart; +} diff --git a/test-plugins/org.yakindu.sct.generator.cpp.test/model/test.sgen b/test-plugins/org.yakindu.sct.generator.cpp.test/model/test.sgen index 9ea352a887..63969976b6 100644 --- a/test-plugins/org.yakindu.sct.generator.cpp.test/model/test.sgen +++ b/test-plugins/org.yakindu.sct.generator.cpp.test/model/test.sgen @@ -1347,6 +1347,30 @@ GeneratorModel for sctunit::cpp { } } + test TriggerExpressionPrecedence { + + feature Outlet{ + targetProject = "org.yakindu.sct.generator.cpp.test" + targetFolder = "test-gen" + } + + feature JUnitWrapper { + WrapToJUnit = "true" + } + + feature FunctionInlining { + inlineReactions = false + inlineEntryActions = false + inlineExitActions = false + inlineEnterSequences = false + inlineExitSequences = false + inlineChoices = false + inlineEnterRegion = false + inlineExitRegion = false + inlineEntries = false + } + } + test TriggerGuardExpressions { feature Outlet{ diff --git a/test-plugins/org.yakindu.sct.generator.cpp.test/test-gen/org/yakindu/sct/generator/cpp/test/AllTestsTest.java b/test-plugins/org.yakindu.sct.generator.cpp.test/test-gen/org/yakindu/sct/generator/cpp/test/AllTestsTest.java index 8f1289acbc..6e50458c1f 100644 --- a/test-plugins/org.yakindu.sct.generator.cpp.test/test-gen/org/yakindu/sct/generator/cpp/test/AllTestsTest.java +++ b/test-plugins/org.yakindu.sct.generator.cpp.test/test-gen/org/yakindu/sct/generator/cpp/test/AllTestsTest.java @@ -28,6 +28,7 @@ ShallowHistoryWithDeepEntryTest.class, SimpleEventTest.class, SimpleHierachyTest.class, StatechartActiveTest.class, StatechartLocalReactionsTest.class, StateIsActiveTest.class, StaticChoiceTest.class, STextKeywordsInStatesAndRegionsTest.class, StringExpressionsTest.class, SyncForkTest.class, SyncJoinTest.class, - TransitionWithoutConditionTest.class, TriggerGuardExpressionsTest.class, ValuedEventsTest.class}) + TransitionWithoutConditionTest.class, TriggerGuardExpressionsTest.class, TriggerExpressionPrecedenceTest.class, + ValuedEventsTest.class}) public class AllTestsTest { } diff --git a/test-plugins/org.yakindu.sct.generator.cpp.test/test-gen/org/yakindu/sct/generator/cpp/test/TriggerExpressionPrecedenceTest.java b/test-plugins/org.yakindu.sct.generator.cpp.test/test-gen/org/yakindu/sct/generator/cpp/test/TriggerExpressionPrecedenceTest.java new file mode 100644 index 0000000000..5b11732350 --- /dev/null +++ b/test-plugins/org.yakindu.sct.generator.cpp.test/test-gen/org/yakindu/sct/generator/cpp/test/TriggerExpressionPrecedenceTest.java @@ -0,0 +1,39 @@ +/** +* Copyright (c) 2016 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.cpp.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/TriggerExpressionPrecedenceTest/TriggerExpressionPrecedenceTest.cc", program = "gtests/TriggerExpressionPrecedenceTest/TriggerExpressionPrecedence", model = "testmodels/SCTUnit/expressions/TriggerExpressionPrecedence.sct") +@RunWith(GTestRunner.class) +public class TriggerExpressionPrecedenceTest { + + protected final GTestHelper helper = new GTestHelper(this) { + + @Override + protected void getSourceFiles(Collection files) { + super.getSourceFiles(files); + files.add(getFileName(getTestProgram()) + ".cpp"); + } + }; + + @Before + public void setUp() { + helper.generate(); + helper.compile(); + } +}