<?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">
<!--
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="mySendID"/>	
	<var name="myConnectionID"/>
	<var name="newConnectionID"/>
	<var name="count_events"/>
  <var name="count_progressing_151"/>

	<script><![CDATA[
		var i=0;
		
		assertions[i++] = init_assertion('964');		
		assertions[i++] = init_assertion('151');		
		
			
		var assert_last = i - 1;
		var assert_index = -1;
		
		//
		// out of the loop assertions (children)
		// Children of 964
		add_2_assert_trace('963');

		// Children of 151
		add_2_assert_trace('1275');
		add_2_assert_trace('182');
		add_2_assert_trace('1115');
		add_2_assert_trace('188');
		add_2_assert_trace('1107');

		
		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">
			<conf:comment expr="'Event: ' + event$.name"/>
	    <assign name="myConnectionID" expr="event$.connectionid"/>			
	    <send targettype="'ccxml'" target="session.id" name="'user.timeout'" delay="TEST_VERY_LONG_TIMEOUT"/>			
			<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>

    	      			
    
<!--

964.
If <disconnect> is used to abandon an outbound call, it results in the generation of a 'connection.disconnected' event.

963.
A CCXML document may use <disconnect> to abandon an outbound connection created using <createcall> which has not yet entered the CONNECTED state.


-->

		<transition event="user.START_ASSERTION_964" state="ASSERTION_NMBR_964">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>	
			<createcall dest="TEST_CREATECALL_DEST_NOANSWER" connectionid="newConnectionID"/>
		</transition>

		<transition event="connection.progressing" state="ASSERTION_NMBR_964">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>			
			<assign name="current_state" expr="'ASSERTION_NMBR_964_GOING_TO_BE_DISCONNECTED'"/>
			<disconnect connectionid="newConnectionID"/>	
		</transition>
		
		<transition event="connection.progressing" state="ASSERTION_NMBR_964_GOING_TO_BE_DISCONNECTED">		
				<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>	
							
		</transition>		
		
		<transition event="connection.disconnected" state="ASSERTION_NMBR_964_GOING_TO_BE_DISCONNECTED">		
			 	<script>assertions[assert_index].P_F = s_PASS;</script>				

  		<!-- Begin Related Tests -->
			<assign name="ASSERTION_NUM" expr="'963'"/>		
			<conf:pass/>
  		<!-- End Related Tests -->
  		
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>				 	    		 	  		
  		
		</transition>

		<transition event="*" state="ASSERTION_NMBR_964_GOING_TO_BE_DISCONNECTED">		
			 	<script>assertions[assert_index].P_F = s_FAIL;</script>				
				<assign name="t_ASSERT_REASON" expr="'connection.disconnected expected, '+ event$.name + ' received.'"/>			 	

  		<!-- Begin Related Tests -->
			<assign name="ASSERTION_NUM" expr="'963'"/>		
			<conf:fail/>
  		<!-- End Related Tests -->
  		
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>				 	    		 	
  		
		</transition>
		
		<transition event="*" state="ASSERTION_NMBR_964">		
				<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>			
		</transition>		

<!--

151.
If the connection had been bridged when the <disconnect> request was made, the platform MUST tear down all bridges to the connection and send a conference.unjoined to the CCXML document once the media paths have been freed.
 	
1275.
The platform is not required to generate the connection.disconnected /connection.failed or conference.unjoined in any particular order, unless an outbound call was abandoned in which case a connection.failed event MUST be generated

182  	
section 10.6.3  	
connection.progressing
This event MUST be emitted when the underlying telephony connection sends a notification of call progress while the Connection Object is in the PROGRESSING state.

188  	
section 10.6.3  	
Subsequent connection.progressing events MAY be generated to support protocols which exchange multiple messages during the PROGRESSING state.


1115  	
section 10.6.3  	
The connection.progressing event is a transition to state PROGRESSING.


1107  	
section 10.6.5  	
connection.disconnected
If this is an off-platform disconnected event, the platform MUST implicitly tear down any existing bridges to the connection and send a conference.unjoined to the CCXML document once the media paths have been freed.

-->
    
    
    
		<transition event="user.START_ASSERTION_151" state="ASSERTION_NMBR_151">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>				
			<assign name="count_progressing_151" expr="0"/>	
			<createcall dest="TEST_CREATECALL_DEST_ANSWER_AND_STAY_ACTIVE[0]" connectionid="newConnectionID"/>
		</transition>

		<transition event="connection.progressing" state="ASSERTION_NMBR_151">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>			
			<assign name="count_progressing_151" expr="count_progressing_151+1"/>	
			
  		<!-- Begin Related Tests -->
  		<if cond="count_progressing_151 == 1">
  		
				<assign name="ASSERTION_NUM" expr="'182'"/>		
				<conf:pass/>
				
				<assign name="ASSERTION_NUM" expr="'1115'"/>		
				<if cond="event$.connection.state == Connection.PROGRESSING">
					<conf:pass/>
				<else/>
					<conf:fail/>
				</if>
			
			</if>

  		<if cond="count_progressing_151 == 2">			
				<assign name="ASSERTION_NUM" expr="'188'"/>		
				<conf:pass/>
			</if>
  		<!-- End Related Tests -->					
  		
		</transition>
		
		<transition event="connection.connected" state="ASSERTION_NMBR_151">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>					
			<join id1="myConnectionID" id2="newConnectionID" duplex="'full'"/>
		</transition>

		<transition event="conference.joined" state="ASSERTION_NMBR_151">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>					
			<assign name="count_events" expr="0"/>
	    <send targettype="'ccxml'" target="session.id" name="'ccxml.disconnect.timeout'" delay="'10s'" sendid="mySendID"/>			
      <disconnect connectionid="newConnectionID"/>
		</transition>

		<transition event="conference.unjoined" state="ASSERTION_NMBR_151">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>		
			<assign name="count_events" expr="count_events+1"/>			
			<if cond="count_events==2">
			 	<script>assertions[assert_index].P_F = s_PASS;</script>				
	  		<!-- Begin Related Tests -->
				<assign name="ASSERTION_NUM" expr="'1275'"/>		
				<conf:pass/>
				<assign name="ASSERTION_NUM" expr="'1107'"/>		
				<conf:pass/>
				
	  		<!-- End Related Tests -->
				 	
 			 	<cancel sendid="mySendID"/>	
				<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>				 	    		 			 	
			</if>
		</transition>

		<transition event="connection.disconnected" state="ASSERTION_NMBR_151">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>		
			<assign name="count_events" expr="count_events+1"/>			
			<if cond="count_events==2">
			 	<script>assertions[assert_index].P_F = s_PASS;</script>					
			 	
	  		<!-- Begin Related Tests -->
				<assign name="ASSERTION_NUM" expr="'1275'"/>		
				<conf:pass/>
				<assign name="ASSERTION_NUM" expr="'1107'"/>		
				<conf:pass/>
				
	  		<!-- End Related Tests -->
			 	
 			 	<cancel sendid="mySendID"/>
				<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>				 	    		 			 	
			</if>
		</transition>
		
		<transition event="cancel.successful" state="ASSERTION_NMBR_151">		
					<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>		
		</transition>
		
		<transition event="ccxml.disconnect.timeout" state="ASSERTION_NMBR_151">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>		
		 	<script>assertions[assert_index].P_F = s_FAIL;</script>					
	  		<!-- Begin Related Tests -->
				<assign name="ASSERTION_NUM" expr="'1275'"/>		
				<conf:fail/>
				<assign name="ASSERTION_NUM" expr="'1107'"/>		
				<conf:fail/>
				
	  		<!-- End Related Tests -->
		 	
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>				 	    		 	
    </transition>
    
	
	<!--  ***************** COMMON ******************************** -->
		<transition event="send.successful">
		</transition>


    <transition event="user.timeout">
			<assign name="current_state" expr="'GEN'"/>
			<conf:uncond_exit expr="'TEST-TIMEOUT.' + show_remained_assertions()"/>
		</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>
