Commit 51169938 authored by stancakapost's avatar stancakapost
Browse files

added a macro for generating XML files for each test

parent 1c8c465b
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/TestMacroProcessor/src/MessageGenerator.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="MessageGenerator"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="TestMacroProcessor"/>
</launchConfiguration>
+16 −0
Original line number Diff line number Diff line
	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 := "${module}.xml_";
//        if (not(fileExists(xmlfilename))) {
            writeFileFromUTF8Charstring(xmlfilename, fileContent);
//        }
    }

    control {
        execute(TC_${module}(), 5.0);
    }
+14 −0
Original line number Diff line number Diff line
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);
	}

}
+33 −0
Original line number Diff line number Diff line
@@ -17,7 +17,19 @@ public class TestMacroProcessor {
	
	private File macroFolder = new File("macros");

	private String forceMacroGeneration = null;

	private ArrayList<String> processedModules = new ArrayList<String>();

	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");
@@ -28,6 +40,7 @@ public class TestMacroProcessor {
		
		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")));
	}

@@ -42,6 +55,22 @@ public class TestMacroProcessor {
			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 {
@@ -93,6 +122,10 @@ public class TestMacroProcessor {
					bw.newLine();
					String moduleName = inputFile.getName();
					moduleName = moduleName.substring(0, moduleName.lastIndexOf('.'));
					if (forceMacroGeneration != null) {
						macro = forceMacroGeneration;
					}
					processedModules.add(moduleName);
					writeMacro(macro, bw, moduleName);
				} else {
					bw.write(line);