<?xml version="1.0" encoding="UTF-8"?>
<ccxml xmlns="http://www.w3.org/2002/09/ccxml" xmlns:conf="http://www.w3.org/2005/ccxml-conformance" version="1.0">

<!--
Release 1.1 - 2010-07-05
FIXED: 
added a <block> tag before <prompt> in 312.vxml

ISSUE 706-3): 
added a do nothing transition for conference.unjoined
-->

	<!--
Serguei's infrastructure performs a loop on the 'assertions' Ecma array, based on "name_prepare_new" event for doing the "loop".

Mainly we have to different levels of assertions: 

- Main assertions, stored in 'assertions' array
- Children assertions, stored into 'assert_trace'

An assertion is a child assertion if it does not need to perform any action, but it is sufficient to test its father assertion result to determine if it passes or fails.

The test finishes when all the main assertions have been tested. Children assertions are tested after the father itself.

If an unexpected event is caught by the <transition event"*"/> a comment is printed and the loop continues with the next iteration.

An hang up event causes the interruption of test: session exits.

All the send.successful events are caught and ignored (they are generated by the loop mechanism).
-->
	<conf:docsetup/>
	<var name="DialogID" expr="undefined"/>
	<var name="ConnectionID" expr="undefined"/>
	<var name="myCcxmlSendId" expr="undefined"/>
	
	<var name="cgi_1" expr="'312.ircgi'"/>
	<var name="cgi_2" expr="'320.ircgi'"/>
	<var name="cgi_3" expr="'350.ircgi'"/>

  	
	<var name="bPreparedReceived" expr="false"/>
	<var name="bMyEventReceived" expr="false"/>
	<var name="var320_1" expr="1"/>  
	<var name="var320_2" expr="'hallo'"/>  
	<var name="var320_3" expr="100 + 100"/>  
	<var name="var350_1" expr="1"/>  
	<var name="var350_2" expr="'hallo'"/>  
	<var name="var350_3" expr="100 + 100"/>  
	<var name= "bFatherPASS" expr="false"/>
	
	<var name="chld_reason"/>

	
	<script><![CDATA[
		var i=0;
		assertions[i++] = init_assertion('312');
		assertions[i++] = init_assertion('320');
		assertions[i++] = init_assertion('350');
		
		
		
		var assert_last = i - 1;
		var assert_index = -1;
		//
		// out of the loop assertions (children)
		
		// Child of 320 
		add_2_assert_trace('321');
		
		// Child of 350 
		add_2_assert_trace('351');
		
		
		s_ASSERTIONS_LEFT = show_remained_assertions();
		var b_in_test = false;
	]]></script>
	<eventprocessor statevariable="current_state">
	
	<conf:setup type="connected"/>
    
		<transition event="connection.connected" state="init">
			<assign name="ConnectionID" expr="event$.connectionid"/>
			<send targettype="'ccxml'" target="session.id" name="'user.timeout'" delay="'60s'"/>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
	
		<transition event="user.PREPARE_NEW">
			<conf:comment expr="'Event: ' + event$.name"/>
			<if cond="assert_index &gt;= 0">
				<assign name="ASSERTION_NUM" expr="assertions[assert_index].number"/>
				<assign name="t_ASSERT_RESULT" expr="assertions[assert_index].P_F"/>
				<script>assertions[assert_index].reason = t_ASSERT_REASON;</script>
				<if cond="t_ASSERT_RESULT == s_PASS">
					<conf:pass reason="t_ASSERT_REASON"/>
					<elseif cond="t_ASSERT_RESULT == s_FAIL"/>
					<conf:fail reason="t_ASSERT_REASON"/>
					<else/>
					<conf:not_exec reason="t_ASSERT_REASON"/>
				</if>
			</if>
			<assign name="assert_index" expr="assert_index + 1"/>
			<if cond="assert_index &gt; assert_last">
				<log label="s_TA" expr="s_ASSERTIONS_LEFT"/>
				<conf:uncond_exit expr="'DONE'"/>
				<else/>
				<log label="s_TA" expr="s_ASSERTIONS_LEFT"/>
				<assign name="ASSERTION_NUM" expr=" assertions[assert_index].number"/>
				<assign name="t_ASSERT_REASON" expr="''"/>
				<script>assertions[assert_index].P_F = s_FAIL;</script>
				<assign name="current_state" expr="state_prefix + ASSERTION_NUM"/>
				<send targettype="'ccxml'" target="session.id" name="start_name_prefix + ASSERTION_NUM"/>
			</if>
		</transition>
		
		<transition event="user.START_ASSERTION_312" state="ASSERTION_NMBR_312">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<dialogprepare src="'cgi-bin/' + cgi_1" dialogid="DialogID" connectionid="ConnectionID"/>
			<send target="session.id" targettype="'ccxml'" name="'ccxml.myEvent'" delay="'5s'" sendid="myCcxmlSendId"/>
		</transition>
		<transition event="ccxml.myEvent" state="ASSERTION_NMBR_312">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<assign name="bMyEventReceived" expr="true"/>
			<if cond="!bPreparedReceived">
				<script>assertions[assert_index].P_F = s_PASS;</script>
			<else/>
				<assign name="t_ASSERT_REASON" expr="'ccxml.myEvent received after dialog.prepared event , STATE ' + current_state"/>
				<script>
					assertions[assert_index].P_F = s_FAIL;
					assertions[assert_index].reason = t_ASSERT_REASON;  
				</script>
			</if>
			<!-- 312 FAILED , anyway we must go on next TAs
			But before going on  next TAs we must terminate the previous prepared dialog -->
			<if cond="bPreparedReceived">
				<assign name="bPreparedReceived" expr="false"/> <!-- reset variable for future purposes -->
				<!-- Before go on we must terminate the previous prepared dialog -->
				<send target="session.id" targettype="'ccxml'" name="'ccxml.closeDialog'" sendid="myCcxmlSendId"/>
			</if>
		</transition>
		<transition event="dialog.prepared" state="ASSERTION_NMBR_312">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<assign name="bPreparedReceived" expr="true"/>
			<!-- 312 PASSED, dialog.prepared event has been received. 
			But before going on  next TAs we must terminate the previous prepared dialog -->
			<if cond="bMyEventReceived">
				<assign name="bMyEventReceived" expr="false"/> <!-- reset variable for future purposes -->
				<!-- Before go on we must terminate the previous prepared dialog -->
				<send target="session.id" targettype="'ccxml'" name="'ccxml.closeDialog'" sendid="myCcxmlSendId"/>
			</if>
		</transition>
		<transition event="ccxml.closeDialog" state="ASSERTION_NMBR_312">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<dialogterminate dialogid="DialogID"/>
		</transition>
		<transition event="dialog.exit" state="ASSERTION_NMBR_312">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name +' so now we can go on next TAs '"/>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>				
		</transition>
		<transition event="user.START_ASSERTION_320" state="ASSERTION_NMBR_320">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<dialogprepare src="'cgi-bin/' + cgi_2" dialogid="DialogID" connectionid="ConnectionID" namelist="var320_1 var320_2 var320_3"/>
		</transition>
		<transition event="dialog.prepared" state="ASSERTION_NMBR_320">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<dialogstart prepareddialogid="DialogID"/>	
		</transition>	
		<transition event="dialog.started" state="ASSERTION_NMBR_320">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<send target="session.id" targettype="'ccxml'"  name="'ccxml.terminateDialog'" delay="'7s'"/> 			
		</transition>	
		
		<transition event="ccxml.terminateDialog" state="ASSERTION_NMBR_320">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<dialogterminate dialogid="DialogID"/>
		</transition>	
		
		<transition event="dialog.exit" state="ASSERTION_NMBR_320">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<if cond="event$.values != undefined">
				<if cond="event$.values.result == 'pass'">	
					<script>assertions[assert_index].P_F = s_PASS;</script>		
					<assign name="bFatherPASS" expr="true"/>
				<elseif cond="event$.values.result == 'fail'"/>	
					<assign name="t_ASSERT_REASON" expr="'Namelist variables do not have the expected values'"/>				
				 	<script>
						assertions[assert_index].P_F = s_FAIL;
						assertions[assert_index].reason = t_ASSERT_REASON;  
					</script>
				<else/>
				 	<assign name="t_ASSERT_REASON" expr="'Unexpected returned value : ' + event$.values.result "/>				
				 	<script>
						assertions[assert_index].P_F = s_FAIL;
						assertions[assert_index].reason = t_ASSERT_REASON;  
					</script>
				</if>			
			<else/>		
				<assign name="t_ASSERT_REASON" expr="'Unexpected empty returned value result' "/>						
				<script>
					assertions[assert_index].P_F = s_FAIL;
					assertions[assert_index].reason = t_ASSERT_REASON;  
				</script>
			</if>	
			<assign name="ASSERTION_NUM" expr="'321'"/>
			<if cond="bFatherPASS">
				<assign name="bFatherPASS" expr="false"/>  <!-- Resetting boolean-->
				<conf:pass/>
			<else/>
				<conf:fail reason="'value not converted into a string before submitted to Web Server on TA 321'"/>
			</if>			
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>			
		</transition>	
	
		<transition event="user.START_ASSERTION_350" state="ASSERTION_NMBR_350">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<dialogstart src="'cgi-bin/' + cgi_3" connectionid="ConnectionID" dialogid="DialogID" namelist="var350_1 var350_2 var350_3"/>
		</transition>
		<transition event="dialog.started" state="ASSERTION_NMBR_350">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>				    
				<send target="session.id" targettype="'ccxml'"  name="'ccxml.terminateDialog'" delay="'7s'"/> 		
		</transition>
    
    	<transition event="ccxml.terminateDialog" state="ASSERTION_NMBR_350">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<dialogterminate dialogid="DialogID" immediate="false"/>    
		</transition>	
		
    
		<transition event="dialog.exit" state="ASSERTION_NMBR_350">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>				    
			<if cond="typeof event$.values != 'undefined'">
				<if cond="event$.values.result == 'pass'">	
					<assign name="bFatherPASS" expr="true"/>
					<script>assertions[assert_index].P_F = s_PASS;</script>		
				<elseif cond="event$.values.result == 'fail'"/>	
					<script>assertions[assert_index].P_F = s_FAIL;</script>		
				 	<assign name="t_ASSERT_REASON" expr="'Namelist variables do not have the expected values'"/>				
				<else/>
					<script>assertions[assert_index].P_F = s_FAIL;</script>		
				 	<assign name="t_ASSERT_REASON" expr="'Unexpected returned value : ' + event$.values.data "/>				
				</if>			
			<else/>		
		  	<script>assertions[assert_index].P_F = s_FAIL;</script>		
	 	  	<assign name="t_ASSERT_REASON" expr="'Unexpected empty returned value data' "/>						
			</if>	
			<assign name="ASSERTION_NUM" expr="'351'"/>
			<if cond="bFatherPASS">
				<assign name="bFatherPASS" expr="false"/>  <!-- Resetting boolean-->
				<conf:pass/>
			<else/>
				<conf:fail reason="'value not converted into a string before submitted to Web Server on TA 351'"/>
			</if>			
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>					
		</transition>
    	
    	
    	<transition event="conference.unjoined">
		</transition>
		
  		<!-- Safety timeout -->					
		 <transition event="user.timeout">
			<assign name="current_state" expr="'GEN'"/>
			<conf:uncond_exit expr="'TEST-TIMEOUT.' + show_remained_assertions()"/>
        </transition>		
		<transition event="send.successful">
		</transition>
		
		
		
		<transition event="connection.disconnected">
			<conf:uncond_exit expr="'CONNECTION-DISCONNECTED'"/>
		</transition>
		<transition event="*">
			<assign name="t_ASSERT_REASON" expr="'UNEXPECTED EVENT ' + event$.name + ' IN STATE ' + current_state"/>
			<conf:comment expr="t_ASSERT_REASON"/>
			<if cond="current_state == 'init'">
				<conf:uncond_exit expr="'Did not come out from init state.'"/>
				<else/>
				<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
			</if>
		</transition>
	</eventprocessor>
</ccxml>
