Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ace7fa309eddcf9119af496fe214c0b48e53bd5d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*******************************************************************************
 * 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:
 * 		Henrik Rentz-Reichert (initial contribution)
 * 
 *******************************************************************************/

package org.eclipse.etrice.core.genmodel.fsm.tests

import org.eclipse.etrice.core.fsm.fSM.RefinedState
import org.eclipse.etrice.core.fsm.util.FSMHelpers
import org.eclipse.etrice.core.genmodel.fsm.FsmGenChecker
import org.eclipse.etrice.core.genmodel.fsm.NullLogger
import org.eclipse.etrice.core.genmodel.fsm.fsmgen.GraphContainer
import org.junit.Before
import org.junit.Test

import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertFalse
import static org.junit.Assert.assertNotNull
import static org.junit.Assert.assertNull
import static org.junit.Assert.assertTrue

import static extension org.eclipse.etrice.core.genmodel.fsm.FsmGenExtensions.*

class TestCodeInheritance extends FsmGenTestBase {
	
	GraphContainer gc
	
	extension FSMHelpers fsmHelpers = new FSMHelpers
	
	@Before
	def void SetUp() {
		gc = getGraphContainer("CodeInheritanceExample.room", "TestActor")
		assertNotNull("graph context was created", gc)
		
		val logger = new NullLogger
		FsmGenChecker.check(gc, logger)
		assertFalse("logger has no errors", logger.hasErrors)
		assertFalse("diagnostician has no errors", diagnostician.isFailed)
	}
	
	@Test
	def void testActionCodes_BaseEntryExit() {
		val s = gc.graph.allStateNodes.findFirst[name.equals("BaseEntryExit")]
		assertNotNull("state found", s)
		assertTrue("refined state", s.stateGraphNode instanceof RefinedState)
		val rs = s.stateGraphNode as RefinedState
		assertEquals("entry code", "// derived entry\n", rs.entryCode.detailCode)
		assertNull("exit code", rs.exitCode)
		assertEquals("inherited entry", "// base entry\n", rs.inheritedEntryCode.detailCode)
		assertEquals("inherited exit", "// base exit\n", rs.inheritedExitCode.detailCode)
	}
	
	@Test
	def void testActionCodes_Base() {
		val s = gc.graph.allStateNodes.findFirst[name.equals("Base")]
		assertNotNull("state found", s)
		assertTrue("refined state", s.stateGraphNode instanceof RefinedState)
		val rs = s.stateGraphNode as RefinedState
		assertNull("entry code", rs.entryCode)
		assertEquals("exit code", "// derived exit\n", rs.exitCode.detailCode)
		assertEquals("inherited entry", "", rs.inheritedEntryCode.detailCode)
		assertEquals("inherited exit", "", rs.inheritedExitCode.detailCode)
	}
	
	@Test
	def void testActionCodes_BaseSub() {
		val s = gc.graph.allStateNodes.findFirst[name.equals("BaseSub")]
		assertNotNull("state found", s)
		assertTrue("refined state", s.stateGraphNode instanceof RefinedState)
		val rs = s.stateGraphNode as RefinedState
		assertEquals("entry code", "// derived entry\n", rs.entryCode.detailCode)
		assertNull("exit code", rs.exitCode)
		assertEquals("inherited entry", "", rs.inheritedEntryCode.detailCode)
		assertEquals("inherited exit", "", rs.inheritedExitCode.detailCode)
	}
}

Back to the top