<?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="first_accept_ok"/>
 	

	<script><![CDATA[
		var i=0;
		
		assertions[i++] = init_assertion('148');		
		
			
		var assert_last = i - 1;
		var assert_index = -1;
		//
		// out of the loop assertions (children)

		// Children of 148
		add_2_assert_trace('14');
		add_2_assert_trace('152');
		add_2_assert_trace('155');
		add_2_assert_trace('156');
		add_2_assert_trace('158');
		add_2_assert_trace('195');
		add_2_assert_trace('1117');
		add_2_assert_trace('1108');
		add_2_assert_trace('1109');


		
		s_ASSERTIONS_LEFT = show_remained_assertions();
		var b_in_test = false;
	]]></script>
	
	
	<eventprocessor statevariable="current_state">
		<conf:setup type="noconnection"/>

		<transition event="ccxml.loaded" state="init">
			<conf:comment expr="'Event: ' + event$.name"/>		
		</transition>
    
    
		<transition event="connection.alerting" state="init">
	    <send targettype="'ccxml'" target="session.id" name="'user.timeout'" delay="TEST_LONG_TIMEOUT"/>
	    <assign name="first_accept_ok" expr="false"/>
	    <assign name="myConnectionID" expr="event$.connectionid"/>
      <accept connectionid="myConnectionID"/>
		</transition>
		<transition event="connection.connected" state="init">
			<conf:comment expr="'Event: ' + event$.name"/>
	    <assign name="first_accept_ok" expr="true"/>			
			<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>

    	      			
<!--
148.
During execution of <disconnect>, the underlying platform MUST send the appropriate protocol messages to perform the disconnect, and send an asynchronous event to the CCXML document when the disconnect operation completes.

14.
An <accept> may have a connectionid attribute

section 10.6.5
connection.discoennected:
195.
This event must be emitted when a connection is disconnected due to an action by the underlying network (e.g. the user hanging up), the CCXML platform, or the CCXML application.

1108.
The connection.disconnected event must contain a trigger attribute that indicates which entity caused the disconnection to occur.

1109.
Valid values for the attribute trigger are 'network' for network-initiated disconnections, 'platform' for disconnections triggered by platform-based rules (such as a maximum connection duration), or 'application' for disconnections performed as a result of application actions (such as execution of a <disconnect>).

1117.
The connection.disconnected event is a transition to state DISCONNECTED.
-->

		<transition event="user.START_ASSERTION_148" state="ASSERTION_NMBR_148">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>					

  		<!-- Begin Related Tests -->
  		<if cond="first_accept_ok">
				<assign name="ASSERTION_NUM" expr="'14'"/>		
				<conf:pass/>
			<else/>
				<assign name="ASSERTION_NUM" expr="'14'"/>		
				<conf:fail/>
			</if>			
  		<!-- End Related Tests -->
  		
	    <send targettype="'ccxml'" target="session.id" name="'ccxml.disconnect.timeout'" delay="'10s'" sendid="mySendID"/>
  		
  		<disconnect/>
  		  		
    </transition>

		<transition event="error.semantic" state="ASSERTION_NMBR_148">		

  		<!-- Begin Related Tests -->
			<assign name="ASSERTION_NUM" expr="'155'"/>		
			<conf:pass/>
  		<!-- End Related Tests -->

			<assign name="current_state" expr="'ASSERTION_NMBR_148_SECOND'"/>
      <var name="hints" expr="new Object()"/>
      <assign name="hints.test" expr="'test'"/>

  		<disconnect connectionid="myConnectionID" hints="hints" reason="'test'"/>
 
 		</transition>

		<transition event="connection.disconnected" state="ASSERTION_NMBR_148_SECOND">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>		
  		<!-- Begin Related Tests -->
			<assign name="ASSERTION_NUM" expr="'152'"/>		
			<conf:pass/>	
			<assign name="ASSERTION_NUM" expr="'156'"/>		
			<conf:pass/>			
			<assign name="ASSERTION_NUM" expr="'158'"/>		
			<conf:pass/>								
			<assign name="ASSERTION_NUM" expr="'195'"/>		
			<conf:pass/>								
		
			<assign name="ASSERTION_NUM" expr="'1117'"/>		
			<if cond="event$.connection.state == Connection.DISCONNECTED">
				<conf:pass/>
			<else/>
				<conf:fail/>
			</if>

			<assign name="ASSERTION_NUM" expr="'1108'"/>		
			<if cond="event$.trigger != undefined">
				<conf:pass/>
			<else/>
				<conf:fail/>
			</if>
						
			<assign name="ASSERTION_NUM" expr="'1109'"/>		
			<if cond="(event$.trigger != undefined) &amp;&amp; ((event$.trigger == 'network') || (event$.trigger == 'application') || (event$.trigger == 'platform'))">
				<conf:pass/>
			<else/>
				<conf:fail/>
			</if>						

										
  		<!-- End Related Tests -->
			
		 	<script>assertions[assert_index].P_F = s_PASS;</script>					
		 	<cancel sendid="mySendID"/>
    </transition>

		<transition event="cancel.successful" state="ASSERTION_NMBR_148_SECOND">		
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>				 	    		 	
    </transition>
    
		<transition event="error.*" state="ASSERTION_NMBR_148_SECOND">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>

  		<!-- Begin Related Tests -->
			<assign name="ASSERTION_NUM" expr="'152'"/>		
			<conf:fail/>
			<assign name="ASSERTION_NUM" expr="'156'"/>		
			<conf:fail/>			
			<assign name="ASSERTION_NUM" expr="'158'"/>		
			<conf:fail/>											
			<assign name="ASSERTION_NUM" expr="'195'"/>		
			<conf:fail/>											
			
  		<!-- End Related Tests -->
		
		 	<script>assertions[assert_index].P_F = s_FAIL;</script>					
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>				 	    		 	
    </transition>

		<transition event="ccxml.disconnect.timeout" state="ASSERTION_NMBR_148_SECOND">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>		
		 	<script>assertions[assert_index].P_F = s_FAIL;</script>					
			<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>
