pax_global_header 0000666 0000000 0000000 00000000064 12412201412 0014477 g ustar 00root root 0000000 0000000 52 comment=335be004334dee1ecd6143104ceaa89ef6c5850a
TTCN3_PART9-TestMacroProcessor_with_test_data@205/ 0000775 0000000 0000000 00000000000 12412201412 0022026 5 ustar 00root root 0000000 0000000 TTCN3_PART9-TestMacroProcessor_with_test_data@205/.classpath 0000664 0000000 0000000 00000000447 12412201412 0024016 0 ustar 00root root 0000000 0000000
TTCN3_PART9-TestMacroProcessor_with_test_data@205/.project 0000664 0000000 0000000 00000001711 12412201412 0023475 0 ustar 00root root 0000000 0000000
TestMacroProcessor
com.testingtech.ttworkbench.ttthree.modelBuilder
org.eclipse.jdt.core.javabuilder
com.testingtech.ttworkbench.ttthree.todoBuilder
com.testingtech.ttworkbench.ttthree.tt3pluginbuilder
com.testingtech.ttworkbench.xcleditor.todoBuilder
com.testingtech.ttworkbench.core.ttcn3nature
org.eclipse.jdt.core.javanature
TTCN3_PART9-TestMacroProcessor_with_test_data@205/.settings/ 0000775 0000000 0000000 00000000000 12412201412 0023744 5 ustar 00root root 0000000 0000000 TTCN3_PART9-TestMacroProcessor_with_test_data@205/.settings/com.testingtech.ttworkbench.core.prefs 0000664 0000000 0000000 00000000112 12412201412 0033355 0 ustar 00root root 0000000 0000000 eclipse.preferences.version=1
ttcn3.source_folders=//PROJECT_NAME//macros
com.testingtech.ttworkbench.xsd.tt3.ui.prefs 0000664 0000000 0000000 00000001475 12412201412 0034306 0 ustar 00root root 0000000 0000000 TTCN3_PART9-TestMacroProcessor_with_test_data@205/.settings eclipse.preferences.version=1
gen-xsd-codec=true
xsd-convert-sets-into-records=true
xsd-convert-unions-into-records-of-optionals=false
xsd-generate-all-fields-optional=false
xsd-generate-enumerations=true
xsd-implicitly-import-xsdaux=true
xsd-interleave-text-and-elements=false
xsd-mangle-attribute-names=false
xsd-mangle-element-names=false
xsd-mangle-names-standard-conform=true
xsd-map-any-to-anytype=false
xsd-map-optional-union-fields-to-record-of=true
xsd-map-substitution-groups-with-unions=false
xsd-map-subtyping-with-unions=false
xsd-merge-attributes-into-parent=true
xsd-merge-elements-into-parent=true
xsd-merge-namespaces-into-one-module=false
xsd-output-path=tt3plugins
xsd-package-name=
xsd-profile=standard
xsd-replace-bad-chars-with-underscore=true
xsd-strip-namespaces=false
xsd-use-anyattribute-aux-type=false
TTCN3_PART9-TestMacroProcessor_with_test_data@205/.settings/org.eclipse.jdt.core.prefs 0000664 0000000 0000000 00000001113 12412201412 0030722 0 ustar 00root root 0000000 0000000 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
TTCN3_PART9-TestMacroProcessor_with_test_data@205/MessageGenerator.launch 0000664 0000000 0000000 00000001322 12412201412 0026453 0 ustar 00root root 0000000 0000000
TTCN3_PART9-TestMacroProcessor_with_test_data@205/README.txt 0000664 0000000 0000000 00000001055 12412201412 0023525 0 ustar 00root root 0000000 0000000 Generate the ATS from preATS if both projects are in the workspace
please check the configuration in config.properties to specify input, output and macro folder
Right click on the TestMacroProcessor.launch and run as Java Application
- generate tests in the target folder as defined by the respective *.ttcn_macro file from the macros folder
Right click on the MessageGenerator.launch and run as Java Application
- uses TC_gen_XML.ttcn_macro macro
- generates tests that for each template a .ttcn.xml_ file containing the encoded template is generated TTCN3_PART9-TestMacroProcessor_with_test_data@205/TestMacroProcessor.launch 0000664 0000000 0000000 00000001344 12412201412 0027025 0 ustar 00root root 0000000 0000000
TTCN3_PART9-TestMacroProcessor_with_test_data@205/config.properties 0000664 0000000 0000000 00000000101 12412201412 0025401 0 ustar 00root root 0000000 0000000 input.ats.path=../preATS
output.ats.path=../ATS
macro.path=macros TTCN3_PART9-TestMacroProcessor_with_test_data@205/macros/ 0000775 0000000 0000000 00000000000 12412201412 0023312 5 ustar 00root root 0000000 0000000 TTCN3_PART9-TestMacroProcessor_with_test_data@205/macros/TC.ttcn_macro 0000664 0000000 0000000 00000004603 12412201412 0025676 0 ustar 00root root 0000000 0000000
/**
* @desc The timeout given in seconds after which the test case will be stopped.
*/
modulepar float PX_TC_EXECUTION_TIMEOUT := 5.0;
type universal charstring Raw;
type universal charstring File;
type record of File FileList;
type port P message {
inout all;
}
type component C {
port P p;
}
/**
* @desc lexical compare the charstring p_textToMatch with the contents of the reference XML file and returns true if they represent the same XML structure
* @param p_textToMatch text to be compared with the UTF-8 contents of the XML file
* @param p_referenceXmlFile the XML file
* @param p_xsdFileList the list of XSD files
* @param p_matchError the error result in case it did not match
* @param p_referenceTTCN3File the file of the TTCN-3 test module. This path is used to find the reference XML file relative to this path, by keeping the TTCN-3 code file system independent.
* @return true if p_textToMatch and the contents of p_referenceXmlFile represent the same XML structure
*/
external function matchFile(Raw p_textToMatch, File p_referenceXmlFile, FileList p_xsdFileList, out universal charstring p_matchError, File p_referenceTTCN3File := __FILE__) return boolean;
testcase TC_${module}() runs on C system C {
var Raw v_rcv;
var universal charstring v_matchError;
map(self:p, system:p);
// encode the message
p.send(m_msg);
alt {
// compare the encoded message with the reference XML file
[] p.check(receive(Raw:?) -> value v_rcv) {
log("XML message ", v_rcv);
if (matchFile(v_rcv, "${module}.xml", ${xsdFileList}, v_matchError)) {
alt {
// match decoded value to pass test
[] p.receive(m_msg) {
setverdict(pass, "Decoded value matches encoded template and reference XML");
}
[] p.receive {
setverdict(fail, "XML decoding failure");
}
}
} else {
setverdict(fail, v_matchError);
}
}
[] p.receive {
setverdict(fail, "Raw decoding failure");
}
}
}
control {
execute(TC_${module}(), PX_TC_EXECUTION_TIMEOUT);
}
TTCN3_PART9-TestMacroProcessor_with_test_data@205/macros/TC_Decode.ttcn_macro 0000664 0000000 0000000 00000003152 12412201412 0027137 0 ustar 00root root 0000000 0000000
/**
* @desc The timeout given in seconds after which the test case will be stopped.
*/
modulepar float PX_TC_EXECUTION_TIMEOUT := 5.0;
type universal charstring Raw;
type port P message {
inout all;
}
type component C {
port P p;
}
/**
* @desc Read a UTF-8 formated XML file from disc.
* @param p_referenceXmlFile the XML file
* @param p_referenceTTCN3File the file of the TTCN-3 test module. This path is used to find the reference XML file relative to this path, by keeping the TTCN-3 code file system independent.
* @return the UTF-8 contents of p_referenceXmlFile
*/
external function readFile(universal charstring p_referenceXmlFile, universal charstring p_referenceTTCN3File := __FILE__) return universal charstring;
testcase TC_${module}() runs on C system C {
var Raw v_rcv;
map(self:p, system:p);
v_rcv := readFile("${module}.xml");
// send the encoded the message
p.send(v_rcv);
alt {
[] p.check(receive(Raw:?) -> value v_rcv) {
log("XML message ", v_rcv);
alt {
// decode the message
[] p.receive(m_msg) {
setverdict(pass, "Decoded value matches template");
}
[] p.receive {
setverdict(fail, "XML decoding failure");
}
}
}
[] p.receive {
setverdict(fail, "Raw decoding failure");
}
}
}
control {
execute(TC_${module}(), PX_TC_EXECUTION_TIMEOUT);
}
TTCN3_PART9-TestMacroProcessor_with_test_data@205/macros/TC_Neg.ttcn_macro 0000664 0000000 0000000 00000001262 12412201412 0026465 0 ustar 00root root 0000000 0000000
/**
* @desc The timeout given in seconds after which the test case will be stopped.
*/
modulepar float PX_TC_EXECUTION_TIMEOUT := 5.0;
type universal charstring Raw;
type port P message {
inout all;
}
type component C {
port P p;
}
testcase TC_${module}() runs on C system C {
map(self:p, system:p);
// encode the message
p.send(m_msg);
log("template should either be rejected by compiler or by runtime latest while encoding");
setverdict(fail, "Invalid template should not be encoded");
unmap(self:p, system:p);
}
control {
execute(TC_${module}(), PX_TC_EXECUTION_TIMEOUT);
}
TTCN3_PART9-TestMacroProcessor_with_test_data@205/macros/TC_NoXMLMatch.ttcn_macro 0000664 0000000 0000000 00000002135 12412201412 0027666 0 ustar 00root root 0000000 0000000
/**
* @desc The timeout given in seconds after which the test case will be stopped.
*/
modulepar float PX_TC_EXECUTION_TIMEOUT := 5.0;
type universal charstring Raw;
type port P message {
inout all;
}
type component C {
port P p;
}
testcase TC_${module}() runs on C system C {
var Raw v_rcv;
map(self:p, system:p);
// encode the message
p.send(m_msg);
alt {
[] p.check(receive(Raw:?) -> value v_rcv) {
log("XML message ", v_rcv);
alt {
// match decoded value to pass test
[] p.receive(m_msg) {
setverdict(pass, "Decoded value matches encoded template");
}
[] p.receive {
setverdict(fail, "XML decoding failure");
}
}
}
[] p.receive {
setverdict(fail, "Raw decoding failure");
}
}
}
control {
execute(TC_${module}(), PX_TC_EXECUTION_TIMEOUT);
}
TTCN3_PART9-TestMacroProcessor_with_test_data@205/macros/TC_gen_XML.ttcn_macro 0000664 0000000 0000000 00000001161 12412201412 0027243 0 ustar 00root root 0000000 0000000
/**
* @desc The timeout given in seconds after which the test case will be stopped.
*/
modulepar float PX_TC_EXECUTION_TIMEOUT := 5.0;
import from TTlibrary all;
type component C {}
testcase TC_${module}() runs on C system C {
var bitstring res := encvalue(m_msg);
var charstring fileContent := oct2char(bit2oct(res));
var charstring xmlfilename := __FILE__ & ".xml_";
// if (not(fileExists(xmlfilename))) {
writeFileFromUTF8Charstring(xmlfilename, fileContent);
// }
}
control {
execute(TC_${module}(), PX_TC_EXECUTION_TIMEOUT);
}
TTCN3_PART9-TestMacroProcessor_with_test_data@205/output/ 0000775 0000000 0000000 00000000000 12412201412 0023366 5 ustar 00root root 0000000 0000000 TTCN3_PART9-TestMacroProcessor_with_test_data@205/output/empty 0000664 0000000 0000000 00000000000 12412201412 0024435 0 ustar 00root root 0000000 0000000 TTCN3_PART9-TestMacroProcessor_with_test_data@205/src/ 0000775 0000000 0000000 00000000000 12412201412 0022615 5 ustar 00root root 0000000 0000000 TTCN3_PART9-TestMacroProcessor_with_test_data@205/src/MessageGenerator.java 0000664 0000000 0000000 00000000505 12412201412 0026713 0 ustar 00root root 0000000 0000000 import java.io.IOException;
public class MessageGenerator {
private static final String XML_GEN = "TC_gen_XML";
/**
* Generate an XML write test and also a main module for importing them
* @param args ignored
*/
public static void main(String[] args) throws IOException {
TestMacroProcessor.run(XML_GEN);
}
}
TTCN3_PART9-TestMacroProcessor_with_test_data@205/src/TestMacroProcessor.java 0000664 0000000 0000000 00000016074 12412201412 0027271 0 ustar 00root root 0000000 0000000 import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Properties;
public class TestMacroProcessor {
private static final String MACRO_PREFIX = "//#";
private File macroFolder = new File("macros");
private String forceMacroGeneration = null;
private ArrayList processedModules = new ArrayList();
public static void main(String[] args) throws IOException {
run(null);
}
/**
* Generate for all .ttcn_ files from the input.ats.path .ttcn files into the output.ats.path
* @param forceMacroGeneration if not null, will generate always the given macro instead of real one
*/
static void run(String forceMacroGeneration) throws FileNotFoundException, IOException {
File configFile = new File("config.properties");
if (!configFile.exists()) {
throw new FileNotFoundException("No config.properties file found in current path");
}
Properties config = new Properties();
config.load(new FileInputStream(configFile));
TestMacroProcessor testMacroProcessor = new TestMacroProcessor();
testMacroProcessor.macroFolder = new File(config.getProperty("macro.path"));
testMacroProcessor.forceMacroGeneration = forceMacroGeneration;
testMacroProcessor.run(new File(config.getProperty("input.ats.path")), new File(config.getProperty("output.ats.path")));
}
public void run(File inputPath, File outputPath) throws IOException {
ArrayList files = new ArrayList();
visitAllFiles(inputPath, files, ".ttcn_");
visitAllFiles(inputPath, files, ".xsd");
visitAllFiles(inputPath, files, ".xml");
Collections.sort(files);
for (File inputFile : files) {
runForFile(inputFile, inputPath, outputPath);
}
System.out.println("Processed "+files.size()+" file(s) and stored to folder\n"+outputPath);
// generate main module for force macro generation
if (forceMacroGeneration != null) {
String importModule = "ImportAllGeneratedModules";
File importAllModule = new File(outputPath, importModule+".ttcn3");
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(importAllModule), "UTF-8"));
bw.write("module "+importModule+" {");
bw.newLine();
for (String moduleName : processedModules) {
bw.write(" import from "+moduleName+" all;");
bw.newLine();
}
bw.write("}");
bw.close();
}
}
public void runForFile(File inputFile, File inputPath, File outputPath) throws IOException {
try {
File targetFile = computeTargetFileName(inputFile, inputPath, outputPath);
targetFile.getParentFile().mkdirs();
if (inputFile.getName().endsWith(".ttcn_")) {
replaceInFile(inputFile, targetFile);
} else {
copyFile(inputFile, targetFile);
}
} finally {
System.out.println("Processed file: "+inputFile);
}
}
public static void copyFile(File in, File out) throws IOException {
FileChannel inChannel = new FileInputStream(in).getChannel();
FileChannel outChannel = new FileOutputStream(out).getChannel();
try {
inChannel.transferTo(0, inChannel.size(), outChannel);
} catch (IOException e) {
throw e;
} finally {
if (inChannel != null)
inChannel.close();
if (outChannel != null)
outChannel.close();
}
}
/**
* Expecting //# TC or //# TC2(param1, param2)
*/
private void replaceInFile(File inputFile, File outputFile) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile), "UTF-8"));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8"));
try {
String line;
while ((line = br.readLine()) != null) {
if (line.trim().startsWith(MACRO_PREFIX)) {
int indexOfMacroPrefix = line.indexOf(MACRO_PREFIX);
int beginIndex = indexOfMacroPrefix+MACRO_PREFIX.length();
int endIndex = line.indexOf('(', beginIndex);
if (endIndex <= beginIndex) {
endIndex = line.length();
}
String macro = line.substring(beginIndex, endIndex).trim();
bw.newLine();
String moduleName = inputFile.getName();
moduleName = moduleName.substring(0, moduleName.lastIndexOf('.'));
if (forceMacroGeneration != null) {
macro = forceMacroGeneration;
}
processedModules.add(moduleName);
writeMacro(macro, bw, moduleName, inputFile);
} else {
bw.write(line);
bw.newLine();
}
}
} finally {
try {
br.close();
} catch (IOException e) {
// ignore
}
try {
bw.close();
} catch (IOException e) {
// ignore
}
}
}
private String readMacro(BufferedReader br) throws IOException {
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line).append("\n");
}
return sb.toString();
}
private void writeMacro(String macro, BufferedWriter bw, String moduleName, File inputFile) throws IOException {
File macroFile = new File(macroFolder, macro+".ttcn_macro");
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(macroFile), "UTF-8"));
String macroString = readMacro(br);
macroString = macroString.replace("${module}", moduleName);
StringBuilder xsdFileList = new StringBuilder();
xsdFileList.append("{ ");
File[] listXSDFiles = inputFile.getParentFile().listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(".xsd");
}
});
boolean firstFile = true;
for (File xsdFile : listXSDFiles) {
if (!firstFile) {
xsdFileList.append(", ");
}
firstFile = false;
xsdFileList.append("\"").append(xsdFile.getName()).append("\"");
}
xsdFileList.append(" }");
macroString = macroString.replace("${xsdFileList}", xsdFileList);
bw.write(macroString);
bw.newLine();
try {
br.close();
} catch (Exception e) {
// ignore
}
}
private File computeTargetFileName(File inputFile, File inputPath, File outputPath) throws IOException, IOException {
String canonicalInputFile = inputFile.getCanonicalPath();
String canonicalInputPath = inputPath.getCanonicalPath();
String relativeInputPath = canonicalInputFile.substring(canonicalInputPath.length()+1);
if (!new File(inputPath, relativeInputPath).equals(inputFile)) {
throw new IOException("parent inputPath not matching inputFile");
}
// cut _ at end of file
if (relativeInputPath.endsWith(".ttcn_")) {
relativeInputPath = relativeInputPath.substring(0, relativeInputPath.length()-1);
}
return new File(outputPath, relativeInputPath);
}
public static void visitAllFiles(File f, ArrayList files, String extension) {
if (f.isDirectory()) {
String[] children = f.list();
for (int i = 0; i < children.length; i++) {
visitAllFiles(new File(f, children[i]), files, extension);
}
} else {
if (f.toString().endsWith(extension)) {
files.add(f);
}
}
}
}
TTCN3_PART9-TestMacroProcessor_with_test_data@205/test/ 0000775 0000000 0000000 00000000000 12412201412 0023005 5 ustar 00root root 0000000 0000000 TTCN3_PART9-TestMacroProcessor_with_test_data@205/test/Pos_050102_includes_001/ 0000775 0000000 0000000 00000000000 12412201412 0026623 5 ustar 00root root 0000000 0000000 Pos_050102_includes_001.ttcn_ 0000664 0000000 0000000 00000001205 12412201412 0033411 0 ustar 00root root 0000000 0000000 TTCN3_PART9-TestMacroProcessor_with_test_data@205/test/Pos_050102_includes_001 /***************************************************
** @author STF 475
** @version 0.0.1
** @purpose 9:5.1.2, Test inclusion of a schema with the same namespace
** @verdict pass accept, ttcn3verdict:pass
***************************************************/
// The following requirements are tested:
// XSD include element information items shall be ignored if the included schema element has the same target
// namespace as the including one (implying the absence of the target namespace).
module Pos_050102_includes_001 {
import from schema_Pos_050102_includes_001 language "XSD" all;
template MyType m_msg := 1;
//#TC
}
Pos_050102_includes_001.xml 0000664 0000000 0000000 00000000243 12412201412 0033103 0 ustar 00root root 0000000 0000000 TTCN3_PART9-TestMacroProcessor_with_test_data@205/test/Pos_050102_includes_001
1