/*****************************************************************
 ** @author 	TTF 014
 ** @version 	0.0.1
 ** @purpose	1:15.3, Ensure that signature templates with restriction e) are accepted.
 ** @verdict 	pass reject
 *****************************************************************/
/* The following requirements are tested:
 * After completing initialization, signature templates that do not contain the @abstract modifier
 * and fulfil the following condition:
 * 		All in and inout procedure parameters are completely initialized and
 * 		all out procedure parameters are either unitialized or marked as not relevant using the NotUsedSymbol.
 *
 * Are safe to be used in call and getcall operations, but they shall not be used in reply and getreply operations.
 */
module NegSem_1503_GlobalAndLocalTemplates_007 {
	signature p_NegSem_1503_GlobalAndLocalTemplates_007_SignatureTemplate(in integer p_in,
										   inout integer p_inout,
										   out integer p_out);


	template p_NegSem_1503_GlobalAndLocalTemplates_007_SignatureTemplate s_notToUseInReplyTemplate := {
		p_in := 1,
		p_inout := 2,
		p_out := - //NotUsedSymbol
	}


	type port remotePort procedure {
		inout p_NegSem_1503_GlobalAndLocalTemplates_007_SignatureTemplate;
	}

	type component GeneralComp {
		port remotePort PCO;
	}

	function f_ClientQuery() runs on GeneralComp {

		PCO.call(p_NegSem_1503_GlobalAndLocalTemplates_007_SignatureTemplate:s_notToUseInReplyTemplate, 5.0) { //safe to be used in call
			[] PCO.getreply(p_NegSem_1503_GlobalAndLocalTemplates_007_SignatureTemplate:?) {
					// any reply is accepted
					setverdict(pass);
				}
			[] PCO.catch(timeout) {
					setverdict(fail);
				}
		};
	}

	function f_ServerResponses() runs on GeneralComp {

		timer t_timeout := 30.0;

		t_timeout.start;

		alt {
		[] PCO.getcall(p_NegSem_1503_GlobalAndLocalTemplates_007_SignatureTemplate:?) {
			 	// Error: template shall not be used in reply
				PCO.reply(p_NegSem_1503_GlobalAndLocalTemplates_007_SignatureTemplate:s_notToUseInReplyTemplate);
				setverdict(fail);
			}
		[] t_timeout.timeout {
				setverdict(fail);
			}
		}
	}


	testcase TC_NegSem_1503_GlobalAndLocalTemplates_007()
		runs on GeneralComp system GeneralComp {
		var GeneralComp server := GeneralComp.create("RemoteProcedure Service");
		var GeneralComp client := GeneralComp.create("RemoteProcedure Client");
		// map the PTCs to the system port
		connect(server:PCO, client:PCO);

		server.start(f_ServerResponses());
		client.start(f_ClientQuery());

		alt {
		[] client.done {
				server.stop;
			}
		}

		alt {
		[] all component.done {}
		}

		disconnect(server:PCO);
	}

	control {
		execute(TC_NegSem_1503_GlobalAndLocalTemplates_007());
	};
}