Commit 17c2840c authored by stancakapost's avatar stancakapost
Browse files

added readFile extfun and fixed matchFile

parent 1add5278
Loading
Loading
Loading
Loading
+28 −8
Original line number Diff line number Diff line
@@ -19,23 +19,35 @@ import de.tu_berlin.cs.uebb.muttcn.runtime.TestCaseError;
@ExternalFunction.Definitions(XmlDiffExtFctPlugin.class)
public class XmlDiffExtFctPlugin extends AnnotationsExternalFunctionPlugin {

	// external function matchFile(Raw p_textToMatch, universal charstring p_referenceXmlFile, XsdFileList p_xsdFileList, out universal charstring p_matchError) return boolean;
	/**
	 * 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;
	@ExternalFunction(name = "matchFile")
	public BooleanValue matchFile_2(UniversalCharstringValue p_textToMatch,
			UniversalCharstringValue p_referenceXmlFile, RecordOfValue xsdFileList, UniversalCharstringValue p_matchError) {
	public BooleanValue matchFile(UniversalCharstringValue p_textToMatch,
			UniversalCharstringValue p_referenceXmlFile, RecordOfValue xsdFileList, UniversalCharstringValue p_matchError, UniversalCharstringValue p_referenceTTCN3File) {
        String stringToMatch = p_textToMatch.getString();
        File parentFolder = new File(p_referenceTTCN3File.getString()).getAbsoluteFile().getParentFile();
        String strReferenceXmlFile = p_referenceXmlFile.getString();
        strReferenceXmlFile = new File(parentFolder, strReferenceXmlFile).getAbsolutePath();
        
        String[] xsdFileArray = null;
        if (xsdFileList.getLength() > 0) {
            xsdFileArray = new String[xsdFileList.getLength()];
            for(int i = 0; i < xsdFileList.getLength(); i++) {
                ((UniversalCharstringValue)xsdFileList.getField(i)).getString();
            	xsdFileArray[0] = ((UniversalCharstringValue)xsdFileList.getField(i)).getString();
            }
        }
        String description = "";
        boolean res = false;
        try {
            XmlDiff diff = new XmlDiff(strReferenceXmlFile, xsdFileArray, null);
            XmlDiff diff = new XmlDiff(strReferenceXmlFile, xsdFileArray, new String[]{parentFolder.getAbsolutePath()});
            StringBuilder sb = new StringBuilder();
            res = diff.diff(stringToMatch, sb);
            if (sb.length() > 0)
@@ -51,12 +63,20 @@ public class XmlDiffExtFctPlugin extends AnnotationsExternalFunctionPlugin {
        return newBooleanValue(res);
    }
	
	//external function readFile(universal charstring p_referenceXmlFile) return universal charstring;
	/**
	 * 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;
	@ExternalFunction(name = "readFile")
	public UniversalCharstringValue readFile(UniversalCharstringValue p_referenceXmlFile) {
	public UniversalCharstringValue readFile(UniversalCharstringValue p_referenceXmlFile, UniversalCharstringValue p_referenceTTCN3File) {
	    FileInputStream in = null;
	    try {
	      File file = new File(p_referenceXmlFile.getString());
		  File referenceTTCN3File = new File(p_referenceTTCN3File.getString());
		  String strReferenceXmlFile = p_referenceXmlFile.getString();
		  File file = new File(referenceTTCN3File.getAbsoluteFile().getParentFile(), strReferenceXmlFile);
	      in = new FileInputStream(file);
	      ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
	      FileUtil.copy(in, out);