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
fa4f7ce5
Commit
fa4f7ce5
authored
May 21, 2012
by
Florian Hölzl
Browse files
first working version of C equivalence test
added TestingUtils refs 727
parent
e6241cb4
Changes
2
Hide whitespace changes
Inline
Side-by-side
org.fortiss.af3.testing.ui/trunk/test-src/test/org/fortiss/af3/testing/ui/gcctest/CCodeEquivalenceTest.java
View file @
fa4f7ce5
...
...
@@ -24,7 +24,9 @@ import static org.fortiss.af3.expression.model.terms.impl.BoolConstStaticImpl.TR
import
static
org
.
fortiss
.
af3
.
generator
.
common
.
utils
.
CSourcePackageUtils
.
findSubPackageByName
;
import
static
org
.
fortiss
.
af3
.
project
.
utils
.
FileUtils
.
loadTextFileFromPlugin
;
import
static
org
.
fortiss
.
af3
.
project
.
utils
.
ProjectUtils
.
loadProjectFromPlugin
;
import
static
org
.
fortiss
.
af3
.
testing
.
utils
.
TestingUtils
.
getTestOutputFor
;
import
static
org
.
fortiss
.
tooling
.
kernel
.
utils
.
EcoreUtils
.
pickFirstInstanceOf
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
...
...
@@ -56,6 +58,7 @@ import org.fortiss.af3.project.model.typesystem.ITerm;
import
org.fortiss.af3.project.services.IExecutionService
;
import
org.fortiss.af3.testing.Af3TestingActivator
;
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.tools.gcc.BuiltProgramRunner
;
...
...
@@ -84,6 +87,9 @@ public class CCodeEquivalenceTest {
/** The executable of the deployment generator. */
private
DeploymentExecutable
executable
;
/** The test-case to be used. */
private
TestCase
testCase
;
/** The location where the source code is placed. */
private
File
targetLocation
;
...
...
@@ -111,6 +117,11 @@ public class CCodeEquivalenceTest {
SourcePackage
sourcePackage
=
executable
.
getSourcePackage
();
// addTestcaseCode(deployment, sourcePackage);
Component
testee
=
deployment
.
getComponentAllocations
(
0
)
.
getComponent
();
// FIXME: generalize
testCase
=
pickFirstInstanceOf
(
TestSuite
.
class
,
testee
.
getSpecificationsList
()).
getTestCases
(
0
);
sourcePackage
.
writeToLocation
(
targetLocation
.
getAbsolutePath
());
...
...
@@ -208,7 +219,25 @@ public class CCodeEquivalenceTest {
"./LocalMachine.run"
,
buildDir
);
result
=
localRunner
.
runTool
().
get
(
TIMEOUT_IN_MILLISECONDS
);
assertNotNull
(
result
);
// assertRunSuccess(result, "Hello world");
verifyResult
(
result
);
}
/** Verifies the given result. */
private
void
verifyResult
(
List
<
String
>
result
)
{
int
step
=
0
;
for
(
String
stepResult
:
result
)
{
TestStep
testStep
=
testCase
.
getTestSteps
(
step
);
String
[]
outputs
=
stepResult
.
split
(
","
);
for
(
String
output
:
outputs
)
{
String
[]
test
=
output
.
split
(
"="
);
String
portName
=
test
[
0
];
String
value
=
test
[
1
];
TestOutput
tOut
=
getTestOutputFor
(
testStep
,
portName
);
assertEquals
(
tOut
.
getSimulatedValue
().
toString
(),
value
);
}
step
++;
}
}
/** Copies the test data files to the target location. */
...
...
org.fortiss.af3.testing/trunk/src/org/fortiss/af3/testing/utils/TestingUtils.java
0 → 100644
View file @
fa4f7ce5
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2012 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
org.fortiss.af3.testing.utils
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.fortiss.af3.component.model.InputPort
;
import
org.fortiss.af3.component.model.OutputPort
;
import
org.fortiss.af3.testing.model.TestCase
;
import
org.fortiss.af3.testing.model.TestInput
;
import
org.fortiss.af3.testing.model.TestOutput
;
import
org.fortiss.af3.testing.model.TestStep
;
import
org.fortiss.af3.testing.model.TestSuiteSpecification
;
/**
* Utility methods for {@link TestSuiteSpecification} and other testing model elements.
*
* @author hoelzlf
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 8D4C0B35AF0A6912C9AEE65CF0D227FE
*/
public
class
TestingUtils
{
/**
* Returns the test input of the given step for the given input port.
*
* @param step
* the test step
* @param port
* the input port
* @return the test input for the given port in the given step
*/
public
static
TestInput
getTestInputFor
(
TestStep
step
,
InputPort
port
)
{
int
index
=
step
.
getTestCase
().
getTestSuite
().
getInputPortsList
().
indexOf
(
port
);
return
step
.
getInputs
(
index
);
}
/**
* Returns the test input of the given step for the given input port name.
*
* @param step
* the test step
* @param name
* the input port name
* @return the test input for the given port name in the given step or {@code null}.
*/
public
static
TestInput
getTestInputFor
(
TestStep
step
,
String
name
)
{
int
index
=
0
;
for
(
InputPort
inport
:
step
.
getTestCase
().
getTestSuite
().
getInputPortsList
())
{
if
(
name
.
equals
(
inport
.
getName
()))
{
return
step
.
getInputs
(
index
);
}
index
++;
}
return
null
;
}
/**
* Returns the test output of the given step for the given output port.
*
* @param step
* the test step
* @param port
* the output port
* @return the test output for the given port in the given step
*/
public
static
TestOutput
getTestOutputFor
(
TestStep
step
,
OutputPort
port
)
{
int
index
=
step
.
getTestCase
().
getTestSuite
().
getOutputPortsList
().
indexOf
(
port
);
return
step
.
getOutputs
(
index
);
}
/**
* Returns the test output of the given step for the given output port name.
*
* @param step
* the test step
* @param name
* the output port name
* @return the test output for the given port name in the given step or {@code null}.
*/
public
static
TestOutput
getTestOutputFor
(
TestStep
step
,
String
name
)
{
int
index
=
0
;
for
(
OutputPort
outport
:
step
.
getTestCase
().
getTestSuite
().
getOutputPortsList
())
{
if
(
name
.
equals
(
outport
.
getName
()))
{
return
step
.
getOutputs
(
index
);
}
index
++;
}
return
null
;
}
/**
* Returns the list of TestInputs for the given port in the given test case.
*
* @param testCase
* the test case
* @param port
* the input port
* @return the list of {@link TestInput}s
*/
public
static
List
<
TestInput
>
getTestInputListFor
(
TestCase
testCase
,
InputPort
port
)
{
List
<
TestInput
>
result
=
new
ArrayList
<
TestInput
>();
for
(
TestStep
step
:
testCase
.
getTestStepsList
())
{
result
.
add
(
getTestInputFor
(
step
,
port
));
}
return
result
;
}
/**
* Returns the list of TestOutputs for the given port in the given test case.
*
* @param testCase
* the test case
* @param port
* the input port
* @return the list of {@link TestOutput}s
*/
public
static
List
<
TestOutput
>
getTestOutputListFor
(
TestCase
testCase
,
OutputPort
port
)
{
List
<
TestOutput
>
result
=
new
ArrayList
<
TestOutput
>();
for
(
TestStep
step
:
testCase
.
getTestStepsList
())
{
result
.
add
(
getTestOutputFor
(
step
,
port
));
}
return
result
;
}
}
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