Commit abbd1769 authored by urbant's avatar urbant
Browse files

TestCast testing environment updated

parent 2889f205
Loading
Loading
Loading
Loading
+54 −9
Original line number Original line Diff line number Diff line
@@ -14,15 +14,21 @@ import java.util.regex.Pattern;


public class FileUtils {
public class FileUtils {


	public static void visitAllFiles(File f, ArrayList<T3ScriptFile> files) {
	public static boolean visitAllFiles(File f, ArrayList<T3ScriptFile> files) {
		boolean bRes = false;
		if (f.isDirectory()) {
		if (f.isDirectory()) {
			String[] children = f.list();
			String[] children = f.list();
			ArrayList<File> t3Files = null, xsdFiles = null;
			ArrayList<File> t3Files = null, xsdFiles = null, directories = null;
			File xmlFile = null;
			File xmlFile = null;
			for (int i = 0; i < children.length; i++) {
			for (int i = 0; i < children.length; i++) {
				File localFile = new File(f, children[i]);
				File localFile = new File(f, children[i]);
				if (localFile.isDirectory())
				if (localFile.isDirectory()) {
					visitAllFiles(localFile, files);
					if (!visitAllFiles(localFile, files)) {
						if (directories == null)
							directories = new ArrayList<File>();
						directories.add(localFile);
					}
				}
				else {
				else {
					String fileName = localFile.toString();
					String fileName = localFile.toString();
					if (fileName.endsWith(".ttcn")) {
					if (fileName.endsWith(".ttcn")) {
@@ -39,13 +45,16 @@ public class FileUtils {
				}
				}
			}
			}
			if (t3Files == null)
			if (t3Files == null)
				return;
				return false;
			for(File t3File : t3Files) {
			for(File t3File : t3Files) {
				files.add(new T3ScriptFile(t3File, xsdFiles, xmlFile));
				files.add(new T3ScriptFile(t3File, xsdFiles, xmlFile, directories));
				bRes = true;
			}
			}
		} else if (f.toString().endsWith(".ttcn")) {				
		} else if (f.toString().endsWith(".ttcn")) {				
				files.add(new T3ScriptFile(f, null, null));
				files.add(new T3ScriptFile(f, null, null, null));
				bRes = true;
		}
		}
		return bRes;
	}
	}


	// -----------------------------------------------------------------------------------------------
	// -----------------------------------------------------------------------------------------------
@@ -81,6 +90,36 @@ public class FileUtils {
		}
		}
	}
	}
	
	
	public static void copyDirectory(File sourceLocation , File targetLocation)
		    throws IOException {

        if (sourceLocation.isDirectory()) {
            if (!targetLocation.exists()) {
                targetLocation.mkdir();
            }

            String[] children = sourceLocation.list();
            for (int i = 0; i < children.length; i++) {
                copyDirectory(new File(sourceLocation, children[i]),
                        new File(targetLocation, children[i]));
            }
        } else {
        	copyFile(sourceLocation, targetLocation);
        }
	}
	
	public static void deleteDirectoryContent(File dir) {
	    File[] files = dir.listFiles();
	    if(files != null) { //some JVMs return null for empty dirs
	        for(File f: files) {
	            if(f.isDirectory()) {
	                deleteDirectoryContent(f);
	            } 
	            f.delete();
	        }
	    }
	}

	// -----------------------------------------------------------------------------------------------
	// -----------------------------------------------------------------------------------------------


	public static int countT3Modules(File f) {
	public static int countT3Modules(File f) {
@@ -108,6 +147,9 @@ public class FileUtils {


	// -----------------------------------------------------------------------------------------------
	// -----------------------------------------------------------------------------------------------


	private static Pattern s_verdictPassMatch = Pattern.compile("^^\\s*\\*\\*\\s*@verdict\\s*pass\\s*(.*)");
	private static Pattern s_verdictMatch = Pattern.compile("^\\s*\\*\\*\\s*@verdict\\s*.*");
	private static Pattern s_configMatch = Pattern.compile("^\\s*\\*\\*\\s*@configuration\\s*(.*)");
	public static T3ExpectedOutput extractExpectedOutput(File f) {
	public static T3ExpectedOutput extractExpectedOutput(File f) {
		T3ExpectedOutput t3ExpectedOutput = new T3ExpectedOutput();
		T3ExpectedOutput t3ExpectedOutput = new T3ExpectedOutput();
		
		
@@ -117,9 +159,10 @@ public class FileUtils {
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			BufferedReader br = new BufferedReader(new InputStreamReader(in));


			String strLine = "";
			String strLine = "";
			Matcher configMatch;
			while ((strLine = br.readLine()) != null) {
			while ((strLine = br.readLine()) != null) {
				if (strLine.matches("^\\s*\\*\\*\\s*@verdict\\s*.*")) {
				if (s_verdictMatch.matcher(strLine).matches()) {
					Matcher matcher = Pattern.compile("^^\\s*\\*\\*\\s*@verdict\\s*pass\\s*(.*)").matcher(strLine);
					Matcher matcher = s_verdictPassMatch.matcher(strLine);
					if (matcher.find()) {
					if (matcher.find()) {
						String result = matcher.group(1);
						String result = matcher.group(1);
						String[] split = result.split(",");
						String[] split = result.split(",");
@@ -129,6 +172,8 @@ public class FileUtils {
					}
					}
					
					
//					System.out.println(strLine);
//					System.out.println(strLine);
				} else if ((configMatch = s_configMatch.matcher(strLine)).matches()) {
					t3ExpectedOutput.setConfiguration(configMatch.group(1));
				}
				}
			}
			}
			in.close();
			in.close();
+12 −0
Original line number Original line Diff line number Diff line
public class T3ExpectedOutput {
public class T3ExpectedOutput {
	private String expectedOutput;
	private String expectedOutput;
	private String executionResult;
	private String executionResult;
	private String m_configuration;


	public String getExpectedOutput() {
	public String getExpectedOutput() {
		return expectedOutput;
		return expectedOutput;
@@ -24,4 +25,15 @@ public class T3ExpectedOutput {
				+ ", executionResult=" + executionResult + "]";
				+ ", executionResult=" + executionResult + "]";
	}
	}


	public void setConfiguration(String config) {
		m_configuration = config;
	}

	public String getConfiguration() {
		return m_configuration;
	}

	public boolean isConfiguration(String config) {
		return m_configuration != null && m_configuration.equals(config);
	}
}
}
+4 −2
Original line number Original line Diff line number Diff line
@@ -4,13 +4,15 @@ import java.util.ArrayList;


public class T3ScriptFile {
public class T3ScriptFile {
	private File t3File, xmlFile;
	private File t3File, xmlFile;
	private ArrayList<File> xsdFiles;
	private ArrayList<File> xsdFiles, m_direcories;
	public T3ScriptFile (File t3File, ArrayList<File> xsdFiles, File xmlFile) {
	public T3ScriptFile (File t3File, ArrayList<File> xsdFiles, File xmlFile, ArrayList<File> directories) {
		this.t3File = t3File;
		this.t3File = t3File;
		this.xsdFiles = xsdFiles;
		this.xsdFiles = xsdFiles;
		this.xmlFile = xmlFile;
		this.xmlFile = xmlFile;
		m_direcories = directories;
	}
	}
	public File getT3File() { return t3File; }
	public File getT3File() { return t3File; }
	public File getXmlFile() { return xmlFile; }
	public File getXmlFile() { return xmlFile; }
	public ArrayList<File> getXsdFiles() { return xsdFiles; }
	public ArrayList<File> getXsdFiles() { return xsdFiles; }
	public ArrayList<File> getDirectories() { return m_direcories;}
}
}
+33 −6
Original line number Original line Diff line number Diff line
@@ -7,6 +7,7 @@ import java.io.PrintWriter;
public class TestCastProjectBuilder {
public class TestCastProjectBuilder {
	private String files = "";
	private String files = "";
	private String sut = "";
	private String sut = "";
	private boolean m_bElemSubst, m_bTypeSubst;
	
	
	private String template1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + 
	private String template1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + 
	"<solution>\n" + 
	"<solution>\n" + 
@@ -33,7 +34,7 @@ public class TestCastProjectBuilder {
	" </TestCampaigns>\n" + 
	" </TestCampaigns>\n" + 
	" <ttcn3_settings>\n" + 
	" <ttcn3_settings>\n" + 
	"  <tc_block />\n" + 
	"  <tc_block />\n" + 
	"  <ttcn3_version>Ttcn3_2013</ttcn3_version>\n" + 
	"  <ttcn3_version>Ttcn3_2016</ttcn3_version>\n" + 
	"  <asn>BER</asn>\n" + 
	"  <asn>BER</asn>\n" + 
	"  <dll_timeout>10</dll_timeout>\n" + 
	"  <dll_timeout>10</dll_timeout>\n" + 
	"  <port>7777</port>\n" + 
	"  <port>7777</port>\n" + 
@@ -50,11 +51,18 @@ public class TestCastProjectBuilder {
	"    <ws> \\t</ws>\n" + 
	"    <ws> \\t</ws>\n" + 
	"    <sep>;</sep>\n" + 
	"    <sep>;</sep>\n" + 
	"   </text>\n" + 
	"   </text>\n" + 
	"  </enc>\n" + 
	"  </enc>\n";
	
	private String template4 = 
	"  <no_bs_dq />\n" + 
	"  <no_bs_dq />\n" + 
	"  <length-form>definite</length-form>\n" + 
	"  <length-form>definite</length-form>\n" + 
	"  <forbidden_ctrl_warn />\n" +
	"  <forbidden_ctrl_warn />\n" +
	"  <omit-match-err />\n" +
	"  <log-tmpt-names />\n" +
	"  <strict-def-check />\n" +
	"  <default-step>0.1</default-step>\n" +
	"  <default-step>0.1</default-step>\n" +
	"  <strict-ver-check />\n" +
	"  <dll_ctimeout>10</dll_ctimeout>\n" +
	" </ttcn3_settings>\n" + 
	" </ttcn3_settings>\n" + 
	"</solution>";
	"</solution>";
	
	
@@ -80,7 +88,18 @@ public class TestCastProjectBuilder {
	}
	}
	
	
	public String getProjectFileString() {
	public String getProjectFileString() {
		return template1 + files + template2 + sut + template3;
		StringBuilder sb = new StringBuilder();
		sb.append(template1);
		sb.append(files);
		sb.append(template2);
		sb.append(sut);
		sb.append(template3);
		if (m_bElemSubst)
			sb.append("  <elem_subst />");
		if (m_bTypeSubst)
			sb.append("  <type_subst />");
		sb.append(template4);
		return sb.toString();
	}
	}
	
	
	public void saveProjectFile(File f) {
	public void saveProjectFile(File f) {
@@ -93,4 +112,12 @@ public class TestCastProjectBuilder {
			e.printStackTrace();
			e.printStackTrace();
		}
		}
	}
	}

	public void setElementSubstitutions(boolean bEnabled) {
		m_bElemSubst = bEnabled;
	}

	public void setTypeSubstitutions(boolean bEnabled) {
		m_bTypeSubst = bEnabled;
	}
}
}
Loading