using System; | |
using System.Collections.Generic; | |
using System.Text; | |
using Export2TTCN; | |
namespace MBT.Adapter | |
{ | |
public class NewExporter : TTCNExporter | |
{ | |
public NewExporter(string p_modulename,string p_path) : base(p_modulename,p_path) | |
{ | |
} | |
protected override void write_imports() | |
{ | |
if (!is_started()) return; | |
write("import from MBT_SpecExpl_Demo all;"); | |
write("import from EPTF_MBT_LGen_Definitions all;"); | |
} | |
protected override void write_types() | |
{ | |
if (!is_started()) return; | |
write("type port netInPort message\n {\n inout SIPResp;\n inout SIPReq;\n } with { extension \"internal\" }\n"); | |
write("type port userInPort message\n {\n inout UserInput;\n } with { extension \"internal\" }\n"); | |
write("type port netOutPort message\n {\n inout SIPResp;\n inout SIPReq;\n } with { extension \"internal\" }\n"); | |
write("type port userOutPort message\n {\n inout TimeOutIndication;\n } with { extension \"internal\" }\n"); | |
write("type record SIPReq\n {\n charstring op,\n charstring param_\n }\n"); | |
write("type record SIPResp\n {\n integer status,\n charstring cseq\n }\n"); | |
write("type record UserInput\n {\n charstring input1,\n charstring input2\n }\n"); | |
write("type record TimeOutIndication\n {\n\n }\n"); | |
write("type component SpecExpl_CT extends MBT_SpecExpl_Demo_Main_CT\n {\n port netInPort netIn;\n port userInPort userIn;\n port netOutPort netOut;\n port userOutPort userOut;\n timer harnessTimer := 0.0;\n }\n"); | |
} | |
protected override void write_altsteps() | |
{ | |
if (!is_started()) return; | |
write("altstep SpecExplDefaultAlt() runs on SpecExpl_CT\n {"); | |
ind_p(); | |
write("[] any port.receive\n {\n harnessTimer.stop;\n setverdict(fail);\n f_MBT_SpecExpl_Demo_endTestCase();\n stop;\n }"); | |
write("[] harnessTimer.timeout\n {\n setverdict(fail);\n f_MBT_SpecExpl_Demo_endTestCase();\n stop;\n }"); | |
ind_n(); | |
write("}"); | |
} | |
protected override void write_else() | |
{ | |
if (!is_started()) return; | |
write("function specexpl_send_SIPResp_to_netIn(template SIPResp msgToSend) runs on SpecExpl_CT"); | |
write("{"); | |
ind_p(); | |
write("netIn.send(msgToSend);"); | |
ind_n(); | |
write("}\n"); | |
write("function specexpl_send_SIPReq_to_netIn(template SIPReq msgToSend) runs on SpecExpl_CT"); | |
write("{"); | |
ind_p(); | |
write("netIn.send(msgToSend);"); | |
ind_n(); | |
write("}\n"); | |
write("function specexpl_send_UserInput_to_userIn(template UserInput msgToSend) runs on SpecExpl_CT"); | |
write("{"); | |
ind_p(); | |
write("userIn.send(msgToSend);"); | |
ind_n(); | |
write("}\n"); | |
write("function specexpl_receive_SIPResp_from_netOut(template SIPResp tmplToMatch) runs on SpecExpl_CT"); | |
write("{"); | |
ind_p(); | |
write("netOut.receive(tmplToMatch);"); | |
ind_n(); | |
write("}\n"); | |
write("function specexpl_receive_SIPReq_from_netOut(template SIPReq tmplToMatch) runs on SpecExpl_CT"); | |
write("{"); | |
ind_p(); | |
write("netOut.receive(tmplToMatch);"); | |
ind_n(); | |
write("}\n"); | |
write("function specexpl_receive_TimeOutIndication_from_userOut(template TimeOutIndication tmplToMatch) runs on SpecExpl_CT"); | |
write("{"); | |
ind_p(); | |
write("userOut.receive(tmplToMatch);"); | |
ind_n(); | |
write("}\n"); | |
} | |
public void send(string command, string message) | |
{ | |
write_tc(command + "(" + message + ");"); | |
//write_tc("oldtimer := 0.0;"); | |
} | |
public void receive(string command, string message, double wait) | |
{ | |
write_tc("harnessTimer.start(" + wait.ToString("F2") + " + SLACK);"); | |
//write_tc("log(\"Waiting for: " + message + "\");"); | |
write_tc(command + "(" + message + ");"); | |
write_tc("harnessTimer.stop;"); | |
//write_tc("oldtimer := 0.0;"); | |
} | |
protected override void beginning_tc() | |
{ | |
write_tc("var float oldtimer := 0.0;"); | |
write_tc("var float SLACK := 10.0;"); | |
write_tc("var default default_behaviour_ref;"); | |
write_tc("f_MBT_SpecExpl_Demo_beginTestCase();"); | |
write_tc("default_behaviour_ref := activate(SpecExplDefaultAlt());"); | |
} | |
protected override void ending_tc() | |
{ | |
write_tc("setverdict(pass);"); | |
write_tc("deactivate(default_behaviour_ref);"); | |
write_tc("f_MBT_SpecExpl_Demo_endTestCase();"); | |
} | |
} | |
public static class Adapter | |
{ | |
private static NewExporter exporter = new NewExporter("MBT_SpecExpl_Testcases", "C:/Users/eolicze/Documents/Visual Studio 2010/Projects/MBT_SIP/"); | |
private static double[] timeouts = {0.0, 0.5, 1.0, 2.0, 4.0}; | |
public static void start() | |
{ | |
/**/ | |
exporter.start(); | |
} | |
public static void end() | |
{ | |
exporter.end(); | |
} | |
private static string getmessage_UserInput(string input1, string input2) | |
{ | |
return "{" + | |
"input1 := \"" + input1 + "\", " + | |
"input2 := \"" + input2 + "\"}"; | |
} | |
private static string getmessage_SIPReq(string op, string param_) | |
{ | |
return "{" + | |
"op := \"" + op + "\", " + | |
"param_ := \"" + param_ + "\"}"; | |
} | |
private static string getmessage_SIPResp(int status, string cseq) | |
{ | |
return "{" + | |
"status := " + status + ", " + | |
"cseq := \"" + cseq + "\"}"; | |
} | |
public static void Init_Calling() | |
{ | |
exporter.write_tc("//Init_Calling"); | |
exporter.write_tc("log(\"Init_Calling\");"); | |
exporter.send("specexpl_send_UserInput_to_userIn", getmessage_UserInput("invite", "sip:127.0.0.1:5061")); | |
exporter.receive("specexpl_receive_SIPReq_from_netOut", getmessage_SIPReq("INVITE", "sip:127.0.0.1:5061"),0.0); | |
} | |
public static void Calling_Ringing() | |
{ | |
exporter.write_tc("//Calling_Ringing"); | |
exporter.write_tc("log(\"Calling_Ringing\");"); | |
exporter.send("specexpl_send_SIPResp_to_netIn",getmessage_SIPResp(180,"")); | |
} | |
public static void Calling_Timeout() | |
{ | |
exporter.write_tc("//Calling_Timeout"); | |
exporter.write_tc("log(\"Calling_Timeout\");"); | |
exporter.send("specexpl_send_UserInput_to_userIn", getmessage_UserInput("invite", "sip:127.0.0.1:5061")); | |
foreach (double timeout in timeouts) | |
{ exporter.receive("specexpl_receive_SIPReq_from_netOut", getmessage_SIPReq("INVITE", "sip:127.0.0.1:5061"), timeout); } | |
} | |
public static void Ringing_Canceling() | |
{ | |
exporter.write_tc("//Ringing_Canceling"); | |
exporter.write_tc("log(\"Ringing_Canceling\");"); | |
exporter.send("specexpl_send_UserInput_to_userIn",getmessage_UserInput("cancel","")); | |
exporter.receive("specexpl_receive_SIPReq_from_netOut", getmessage_SIPReq("CANCEL", "sip:127.0.0.1:5061"),0.0); | |
} | |
public static void Ringing_Ready() | |
{ | |
exporter.write_tc("//Ringing_Ready"); | |
exporter.write_tc("log(\"Ringing_Ready\");"); | |
exporter.send("specexpl_send_SIPResp_to_netIn", getmessage_SIPResp(200, "INVITE")); | |
exporter.receive("specexpl_receive_SIPReq_from_netOut", getmessage_SIPReq("ACK", "sip:127.0.0.1:5061"),0.0); | |
} | |
public static void Ringing_Reject() | |
{ | |
exporter.write_tc("//Ringing_Reject"); | |
exporter.write_tc("log(\"Ringing_Reject\");"); | |
exporter.send("specexpl_send_SIPResp_to_netIn", getmessage_SIPResp(486, "INVITE")); | |
exporter.receive("specexpl_receive_SIPReq_from_netOut", getmessage_SIPReq("ACK", "sip:127.0.0.1:5061"),0.0); | |
} | |
public static void Canceling_WaitingResponse() | |
{ | |
exporter.write_tc("//Canceling_WaitingResponse"); | |
exporter.write_tc("log(\"Canceling_WaitingResponse\");"); | |
exporter.send("specexpl_send_SIPResp_to_netIn", getmessage_SIPResp(200, "CANCEL")); | |
} | |
public static void Canceling_Timeout() | |
{ | |
exporter.write_tc("//Canceling_Timeout"); | |
exporter.write_tc("log(\"Canceling_Timeout\");"); | |
exporter.send("specexpl_send_UserInput_to_userIn", getmessage_UserInput("cancel", "")); | |
foreach (double timeout in timeouts) | |
{ exporter.receive("specexpl_receive_SIPReq_from_netOut", getmessage_SIPReq("CANCEL", "sip:127.0.0.1:5061"), timeout); } | |
} | |
public static void WaitingResponse_Terminate() | |
{ | |
exporter.write_tc("//WaitingResponse_Terminate"); | |
exporter.write_tc("log(\"WaitingResponse_Terminate\");"); | |
exporter.send("specexpl_send_SIPResp_to_netIn", getmessage_SIPResp(487, "INVITE")); | |
exporter.receive("specexpl_receive_SIPReq_from_netOut", getmessage_SIPReq("ACK", "sip:127.0.0.1:5061"),0.0); | |
} | |
public static void Ready_Terminating() | |
{ | |
exporter.write_tc("//Ready_Terminating"); | |
exporter.write_tc("log(\"Ready_Terminating\");"); | |
exporter.send("specexpl_send_UserInput_to_userIn", getmessage_UserInput("bye", "")); | |
exporter.receive("specexpl_receive_SIPReq_from_netOut", getmessage_SIPReq("BYE", "sip:127.0.0.1:5061"), 0.0); | |
} | |
public static void Ready_End() | |
{ | |
exporter.write_tc("//Ready_End"); | |
exporter.write_tc("log(\"Ready_End\");"); | |
exporter.send("specexpl_send_SIPReq_to_netIn", getmessage_SIPReq("BYE", "sip:127.0.0.1")); | |
exporter.receive("specexpl_receive_SIPResp_from_netOut", getmessage_SIPResp(200, "BYE"),0.0); | |
} | |
public static void Terminating_OK() | |
{ | |
exporter.write_tc("//Terminating_OK"); | |
exporter.write_tc("log(\"Terminating_OK\");"); | |
exporter.send("specexpl_send_SIPResp_to_netIn", getmessage_SIPResp(200, "")); | |
} | |
public static void Terminating_Timeout() | |
{ | |
exporter.write_tc("//Terminating_Timeout"); | |
exporter.write_tc("log(\"Terminating_Timeout\");"); | |
exporter.send("specexpl_send_UserInput_to_userIn", getmessage_UserInput("bye", "")); | |
foreach (double timeout in timeouts) | |
{ exporter.receive("specexpl_receive_SIPReq_from_netOut", getmessage_SIPReq("BYE", "sip:127.0.0.1:5061"), timeout); } | |
} | |
} | |
} |