Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
af3
AF3
Commits
93a42f66
Commit
93a42f66
authored
May 10, 2012
by
Daniel Ratiu
Browse files
test for semantic alignment
refs 799
parent
44e3a290
Changes
1
Hide whitespace changes
Inline
Side-by-side
org.fortiss.af3.testing.ui/trunk/test-src/test/org/fortiss/af3/testing/ui/SemanticBackboneTest.java
0 → 100644
View file @
93a42f66
/*--------------------------------------------------------------------------+
$Id: TestCasesGeneratorTest.java 4076 2012-04-29 19:27:27Z ratiu $
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package
test.org.fortiss.af3.testing.ui
;
import
static
org
.
fortiss
.
af3
.
testing
.
utils
.
TestingModelElementFactory
.
createStateCoverage
;
import
static
org
.
fortiss
.
af3
.
testing
.
utils
.
TestingModelElementFactory
.
createTestSuiteSpecification
;
import
static
org
.
fortiss
.
tooling
.
kernel
.
utils
.
EcoreUtils
.
getChildrenWithType
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
fail
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
import
org.eclipse.core.runtime.NullProgressMonitor
;
import
org.fortiss.af3.analyses.modelchecking.ModelCheckerConfig
;
import
org.fortiss.af3.component.model.Component
;
import
org.fortiss.af3.component.model.ComponentArchitecture
;
import
org.fortiss.af3.project.model.FileProject
;
import
org.fortiss.af3.project.model.typesystem.ITerm
;
import
org.fortiss.af3.project.utils.ProjectUtils
;
import
org.fortiss.af3.state.model.StateAutomaton
;
import
org.fortiss.af3.testing.Af3TestingActivator
;
import
org.fortiss.af3.testing.generator.modelchecking.ModelCheckingTestSuiteGenerator
;
import
org.fortiss.af3.testing.generator.modelchecking.StatesCoverageAnalyzer
;
import
org.fortiss.af3.testing.model.TestCase
;
import
org.fortiss.af3.testing.model.TestOutput
;
import
org.fortiss.af3.testing.model.TestStep
;
import
org.fortiss.af3.testing.model.TestSuite
;
import
org.fortiss.af3.testing.model.TestSuiteSpecification
;
import
org.fortiss.af3.testing.model.coverage.StateCoverage
;
import
org.fortiss.af3.tools.base.ToolRunnerBase
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Parameterized
;
import
org.junit.runners.Parameterized.Parameters
;
import
test.org.fortiss.af3.analyses.base.ModelCheckerAnalysesTestBase
;
import
test.org.fortiss.af3.expression.evaluator.EvaluatorTestData
;
/**
* Tests for assuring the semantic alignment between the model-checker and the
* simulator.
*
* @author ratiu
* @author $Author: ratiu $
* @version $Rev: 4076 $
* @ConQAT.Rating YELLOW Hash: 76E1E98574A3E0CFDA45E4CC808C9153
*/
@RunWith
(
Parameterized
.
class
)
public
class
SemanticBackboneTest
extends
ModelCheckerAnalysesTestBase
{
/** The component on which the tests are run. */
private
Component
current
;
/** The generator. */
private
ModelCheckingTestSuiteGenerator
gen
;
/** Constructor. */
public
SemanticBackboneTest
(
Component
current
)
{
this
.
current
=
current
;
ModelCheckerConfig
config
=
new
ModelCheckerConfig
(-
100
,
100
);
TestSuiteSpecification
spec
=
createTestSuiteSpecification
();
StateCoverage
specPart
=
createStateCoverage
(
spec
);
specPart
.
setMaxLength
(
20
);
gen
=
new
ModelCheckingTestSuiteGenerator
(
new
StatesCoverageAnalyzer
(
config
,
specPart
));
}
/** Test data. */
@Parameters
public
static
Collection
<
Component
[]>
testDataCollection
()
{
String
[]
fileNames
=
{
"platform:/plugin/org.fortiss.af3.analyses/test-data/ModelCheckerBasicTests.af3_20"
,
"platform:/plugin/org.fortiss.af3.rcp.application/test-data/ACC.af3_20"
};
List
<
Component
>
topmostComponents
=
new
ArrayList
<
Component
>();
for
(
String
fileName
:
fileNames
)
{
collectTopComponentsWithOutputPorts
(
topmostComponents
,
fileName
);
}
// SimpleTrafficLightsStateAutomatonExample tlc =
// SimpleTrafficLightsStateAutomatonExample.INSTANCE;
// collectTopComponentsWithOutputPorts(topmostComponents,
// tlc.createProject("TLC"));
return
EvaluatorTestData
.
toListOfOneElementArrays
(
topmostComponents
.
toArray
(
new
Component
[]
{}));
}
/** Testing the semantic alignment for the current component. */
@Test
public
void
testSemanticsAlignment
()
{
ToolRunnerBase
.
DEBUG
=
true
;
System
.
out
.
println
(
"############# Checking semantics alignment on component: "
+
current
.
getName
());
TestSuiteSpecification
tss
=
createTestSuiteSpecification
();
current
.
getSpecificationsList
().
add
(
tss
);
TestSuite
testSuite
=
null
;
try
{
testSuite
=
gen
.
generate
(
tss
,
new
NullProgressMonitor
());
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
fail
(
"Error occurred while processing component: "
+
current
.
getName
());
}
int
testSteps
=
0
;
for
(
TestCase
tc
:
testSuite
.
getTestCasesList
())
{
for
(
TestStep
ts
:
tc
.
getTestStepsList
())
{
testSteps
++;
for
(
TestOutput
to
:
ts
.
getOutputsList
())
{
ITerm
expected
=
to
.
getExpectedValue
();
ITerm
simulated
=
to
.
getSimulatedValue
();
assertEquals
(
"Error with step "
+
testSteps
+
" in component "
+
current
.
getName
(),
expected
,
simulated
);
}
}
}
System
.
out
.
println
(
"############# Successful run on "
+
testSuite
.
getTestCasesLength
()
+
" test-cases and "
+
testSteps
+
" test steps."
);
ToolRunnerBase
.
DEBUG
=
false
;
}
/** Collects the topmost components with output ports from a project. */
private
static
void
collectTopComponentsWithOutputPorts
(
List
<
Component
>
topmostComponents
,
String
fileName
)
{
FileProject
project
=
ProjectUtils
.
loadProjectFromPlugin
(
Af3TestingActivator
.
PLUGIN_ID
,
fileName
,
true
);
collectTopComponentsWithOutputPorts
(
topmostComponents
,
project
);
}
/** Collects the topmost components with output ports from a project. */
private
static
void
collectTopComponentsWithOutputPorts
(
List
<
Component
>
topmostComponents
,
FileProject
project
)
{
ComponentArchitecture
ca
=
getChildrenWithType
(
project
,
ComponentArchitecture
.
class
).
get
(
0
);
Component
current
=
ca
.
getTopComponent
();
collectTopmostComponents
(
topmostComponents
,
current
);
}
/** Collects the sub-components that have output ports. */
private
static
void
collectTopmostComponents
(
List
<
Component
>
topmostComponents
,
Component
current
)
{
if
(
current
.
getOutputPorts
().
size
()
!=
0
&&
!
getChildrenWithType
(
current
,
StateAutomaton
.
class
)
.
isEmpty
())
{
topmostComponents
.
add
(
current
);
return
;
}
for
(
Component
subComponent
:
current
.
getSubComponents
())
{
collectTopmostComponents
(
topmostComponents
,
subComponent
);
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment