Commit c507fd96 authored by stancakapost's avatar stancakapost
Browse files

- added decode test macro: TC_Decode

- added encode/decode test macro (without XML testing): TC_NoXMLMatch
parent 43e797f9
Loading
Loading
Loading
Loading
+30 −0
Original line number Original line Diff line number Diff line
package com.testingtech.tri.extfct;
package com.testingtech.tri.extfct;


import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.text.MessageFormat;

import org.etsi.mts.ttcn.part9.xmldiff.XmlDiff;
import org.etsi.mts.ttcn.part9.xmldiff.XmlDiff;
import org.etsi.ttcn.tci.BooleanValue;
import org.etsi.ttcn.tci.BooleanValue;
import org.etsi.ttcn.tci.RecordOfValue;
import org.etsi.ttcn.tci.RecordOfValue;
@@ -7,6 +12,9 @@ import org.etsi.ttcn.tci.UniversalCharstringValue;


import com.testingtech.ttcn.annotation.ExternalFunction;
import com.testingtech.ttcn.annotation.ExternalFunction;
import com.testingtech.ttcn.tri.AnnotationsExternalFunctionPlugin;
import com.testingtech.ttcn.tri.AnnotationsExternalFunctionPlugin;
import com.testingtech.util.FileUtil;

import de.tu_berlin.cs.uebb.muttcn.runtime.TestCaseError;


@ExternalFunction.Definitions(XmlDiffExtFctPlugin.class)
@ExternalFunction.Definitions(XmlDiffExtFctPlugin.class)
public class XmlDiffExtFctPlugin extends AnnotationsExternalFunctionPlugin {
public class XmlDiffExtFctPlugin extends AnnotationsExternalFunctionPlugin {
@@ -42,4 +50,26 @@ public class XmlDiffExtFctPlugin extends AnnotationsExternalFunctionPlugin {
        
        
        return newBooleanValue(res);
        return newBooleanValue(res);
    }
    }
	
	//external function readFile(universal charstring p_referenceXmlFile) return universal charstring;
	@ExternalFunction(name = "readFile")
	public UniversalCharstringValue readFile(UniversalCharstringValue p_referenceXmlFile) {
	    FileInputStream in = null;
	    try {
	      File file = new File(p_referenceXmlFile.getString());
	      in = new FileInputStream(file);
	      ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
	      FileUtil.copy(in, out);
	      return newUniversalCharstringValue(out.toString("UTF-8"));
	    } catch (Throwable e) {
	      throw new TestCaseError(new RuntimeException(MessageFormat.format("error while reading UTF-8 encoded file: {0} {1}", p_referenceXmlFile.getString(), e.toString()), e));
	    } finally {
	      try {
	        in.close();
	      } catch (Throwable e) {
	        // ignore exception
	      }
	    }
	}

}
}
+1 −2
Original line number Original line Diff line number Diff line
@@ -11,7 +11,6 @@
    }
    }


	external function matchFile(Raw p_textToMatch, XsdFile p_referenceXmlFile, XsdFileList p_xsdFileList, out universal charstring p_matchError) return boolean;
	external function matchFile(Raw p_textToMatch, XsdFile p_referenceXmlFile, XsdFileList p_xsdFileList, out universal charstring p_matchError) return boolean;
//    external function matchFile(Raw p_textToMatch, charstring p_filePath, out charstring p_matchError) return boolean;


    testcase TC_${module}() runs on C system C {
    testcase TC_${module}() runs on C system C {
        var Raw v_rcv;
        var Raw v_rcv;
@@ -23,7 +22,7 @@
                if (matchFile(v_rcv, "${module}.xml", ${xsdFileList}, v_matchError)) {
                if (matchFile(v_rcv, "${module}.xml", ${xsdFileList}, v_matchError)) {
                    alt {
                    alt {
                        [] p.receive(m_msg) {
                        [] p.receive(m_msg) {
                            setverdict(pass);
                        	setverdict(pass, "Decoded value matches encoded template and reference XML");
                        }
                        }
                        [] p.receive {
                        [] p.receive {
                            setverdict(fail, "XML decoding failure");
                            setverdict(fail, "XML decoding failure");
+38 −0
Original line number Original line Diff line number Diff line

    type universal charstring Raw;

    type port P message {
        inout all;
    }
    type component C {
        port P p;
    }

	external function readFile(universal charstring p_referenceXmlFile) 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");
        p.send(v_rcv);
        alt {
            []	p.check(receive(Raw:?) -> value v_rcv) {
            	log("XML message ", v_rcv);
                alt {
                    [] 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}(), 5.0);
    }
+35 −0
Original line number Original line Diff line number Diff line

    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);
        p.send(m_msg);
        alt {
            []	p.check(receive(Raw:?) -> value v_rcv) {
            	log("XML message ", v_rcv);
                alt {
                    [] 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}(), 5.0);
    }