<?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-09-06
FIXED: 

ISSUE-704: 
added a do nothing transition for conference.unjoined

ISSUES 691-2) and 712
added a <block> tag before <prompt> in 7_4.vxml
-->

<!--
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="bIsOK" expr="false"/>
		
	<var name="vxmlFile" expr="'7_4.vxml'"/>
	
	<var name="ConferenceID" expr="undefined"/>
	<var name="myConfName" expr="'SimpleConference'"/>
		
	<var name="chld_reason"/>

		
	<script><![CDATA[
		var i=0;
		assertions[i++] = init_assertion('330');
		assertions[i++] = init_assertion('329');
		assertions[i++] = init_assertion('331');
		assertions[i++] = init_assertion('361');
		assertions[i++] = init_assertion('360');
		assertions[i++] = init_assertion('362');
				
		
		var assert_last = i - 1;
		var assert_index = -1;
		//
		// out of the loop assertions (children)
		
		// Child of 330 dialogprepare on connectionid
		add_2_assert_trace('324');
		
		// Child of 331 dialogprepare on conferenceid
		add_2_assert_trace('327');

		// Child of 361 dialogstart on connectionid
		add_2_assert_trace('353');
		
		s_ASSERTIONS_LEFT = show_remained_assertions();
		var b_in_test = false;
	]]></script>
	
	
	<script><![CDATA[
	function bOutputsContainsID(ID, outputs) {
	
	var bIsFound=0;
	var idx = 0;
	 
	 while ((idx<outputs.length) && (bIsFound==0))
	{
		if (outputs[idx] == ID)  
			bIsFound = 1;
		else
			idx++;
	}
	return bIsFound;
	}	
	]]></script>
	

	<eventprocessor statevariable="current_state">
		<conf:setup type="alerting"/>
    
		<transition event="connection.alerting" state="init">
			<assign name="ConnectionID" expr="event$.connectionid"/>
			<send targettype="'ccxml'" target="session.id" name="'user.timeout'" delay="TEST_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>

		<!-- TA 330:  dialogprepare with mediadirection = dialogtransmit - use of connection -->
		<transition event="user.START_ASSERTION_330" state="ASSERTION_NMBR_330">
			<dialogprepare src="vxmlFile" dialogid="DialogID" connectionid="ConnectionID" mediadirection="'dialogtransmit'"/>
		</transition>
		<transition event="dialog.prepared" state="ASSERTION_NMBR_330">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<!--  Accepting the call ...-->
			<accept connectionid="ConnectionID"/>
		</transition>	
		<transition event="connection.connected" state="ASSERTION_NMBR_330">
			<conf:comment expr="'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<dialogstart prepareddialogid="DialogID"/>
		</transition>	
		<transition event="dialog.started" state="ASSERTION_NMBR_330">
			<conf:comment expr="'Current state : ' + current_state + ' , Event: ' + event$.name"/>			
			<if cond="event$.dialog.input == undefined &amp;&amp; bOutputsContainsID(ConnectionID, event$.dialog.outputs) == 1 &amp;&amp; session.connections[ConnectionID].input == DialogID &amp;&amp; bOutputsContainsID(DialogID, session.connections[ConnectionID].outputs) == 0">
				<assign name="bIsOK" expr="true"/>
				<script>assertions[assert_index].P_F = s_PASS;</script>
			<else/>
				<assign name="t_ASSERT_REASON" expr="'Invalid input/outputs values on dialog object , STATE ' + current_state"/>
				<script>
                    [assert_index].P_F = s_FAIL;
                    [assert_index].reason = t_ASSERT_REASON;  
				</script>
			</if>
			<!-- Child management -->
			<assign name="ASSERTION_NUM" expr="'324'"/>
			<if cond="bIsOK">
				<assign name="bIsOK" expr="false"/>
				<conf:pass/>
			<else/>
				<conf:fail reason="'Incorrect mediadirection between dialog and connection!'"/>
			</if>
			<dialogterminate dialogid="DialogID"/>
		</transition>
		<transition event="dialog.exit" state="ASSERTION_NMBR_330">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
		<!-- END TA 330 and child -->
		<!-- TA 329:  dialogprepare with mediadirection = both - use of connection -->
		<transition event="user.START_ASSERTION_329" state="ASSERTION_NMBR_329">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<dialogprepare src="vxmlFile" dialogid="DialogID" connectionid="ConnectionID" mediadirection="'both'"/>
		</transition>
		<transition event="dialog.prepared" state="ASSERTION_NMBR_329">
			<conf:comment expr="'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<dialogstart prepareddialogid="DialogID"/>
		</transition>
		<transition event="dialog.started" state="ASSERTION_NMBR_329">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<if cond="event$.dialog.input == ConnectionID  &amp;&amp; bOutputsContainsID(ConnectionID, event$.dialog.outputs) == 1  &amp;&amp; session.connections[ConnectionID].input == DialogID  &amp;&amp; bOutputsContainsID(DialogID, session.connections[ConnectionID].outputs) == 1">		
				<script>assertions[assert_index].P_F = s_PASS;</script>
			<else/>	
				<assign name="t_ASSERT_REASON" expr="'mediadirection is both but the connection is not duplex , STATE ' + current_state"/>
				<script>
                    [assert_index].P_F = s_FAIL;
                    [assert_index].reason = t_ASSERT_REASON;  
				</script>
			</if>
			<dialogterminate dialogid="DialogID"/>
		</transition>
		<transition event="dialog.exit" state="ASSERTION_NMBR_329">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
		<!-- END TA 329 -->
		<!-- TA 331:  dialogprepare with mediadirection = dialogreceive - use of conference -->
		<transition event="user.START_ASSERTION_331" state="ASSERTION_NMBR_331">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<createconference conferenceid="ConferenceID" confname="myConfName"/>
		</transition>
		<transition event="conference.created" state="ASSERTION_NMBR_331">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<dialogprepare src="vxmlFile" dialogid="DialogID" conferenceid="ConferenceID" mediadirection="'dialogreceive'"/>
		</transition>
		<transition event="dialog.prepared" state="ASSERTION_NMBR_331">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<dialogstart prepareddialogid="DialogID"/>
		</transition>
		<transition event="dialog.started" state="ASSERTION_NMBR_331">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<if cond="event$.dialog.input==ConferenceID &amp;&amp; bOutputsContainsID(ConferenceID,event$.dialog.outputs) == 0">
				<script>assertions[assert_index].P_F = s_PASS;</script>
				<assign name="bIsOK" expr="true"/>
			<else/>	
				<assign name="t_ASSERT_REASON" expr="'mediadirection is dialogtransmit but the input/outputs on dialog are incorrect , STATE ' + current_state"/>
				<script>
                    [assert_index].P_F = s_FAIL;
                    [assert_index].reason = t_ASSERT_REASON;  
				</script>
			</if>
			<!-- Child management -->
			<assign name="ASSERTION_NUM" expr="'327'"/>
			<if cond="bIsOK">
				<assign name="bIsOK" expr="false"/>
				<conf:pass/>
			<else/>
				<conf:fail reason="'Incorrect mediadirection between dialog and conference!'"/>
			</if>
			<dialogterminate dialogid="DialogID"/>
		</transition>
		<transition event="dialog.exit" state="ASSERTION_NMBR_331">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
		<!-- END TA 331 and child -->
		<!-- TA 361:  dialogstart with mediadirection = dialogtransmit - use of connection -->
		<transition event="user.START_ASSERTION_361" state="ASSERTION_NMBR_361">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<dialogstart src="vxmlFile" dialogid="DialogID" connectionid="ConnectionID" mediadirection="'dialogtransmit'"/>
		</transition>		
		<transition event="dialog.started" state="ASSERTION_NMBR_361">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<if cond="event$.dialog.input==undefined  &amp;&amp; bOutputsContainsID(ConnectionID, event$.dialog.outputs) == 1  &amp;&amp; session.connections[ConnectionID].input == DialogID  &amp;&amp; bOutputsContainsID(DialogID, session.connections[ConnectionID].outputs) == 0">		
				<script>assertions[assert_index].P_F = s_PASS;</script>
				<assign name="bIsOK" expr="true"/>
			<else/>
				<assign name="t_ASSERT_REASON" expr="'Invalid input/outputs values on dialog object , STATE ' + current_state"/>
				<script>
                    [assert_index].P_F = s_FAIL;
                    [assert_index].reason = t_ASSERT_REASON;  
				</script>
			</if>
			<!-- Child management -->
			<assign name="ASSERTION_NUM" expr="'353'"/>
			<if cond="bIsOK">
				<assign name="bIsOK" expr="false"/>
				<conf:pass/>
			<else/>
				<conf:fail reason="'Incorrect mediadirection between dialog and connection!'"/>
			</if>
			<dialogterminate dialogid="DialogID"/>
		</transition>		
		<transition event="dialog.exit" state="ASSERTION_NMBR_361">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
		<!-- END TA 361 and child -->
		<!-- TA 360:  dialogstart with mediadirection = both  - use of conference -->
		<transition event="user.START_ASSERTION_360" state="ASSERTION_NMBR_360">
			<conf:comment expr="'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<dialogstart src="vxmlFile" dialogid="DialogID" conferenceid="ConferenceID" mediadirection="'both'"/>
		</transition>		
		<transition event="dialog.started" state="ASSERTION_NMBR_360">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<if cond="event$.dialog.input==ConferenceID &amp;&amp; bOutputsContainsID(ConferenceID,event$.dialog.outputs) == 1">
				<script>assertions[assert_index].P_F = s_PASS;</script>
			<else/>
				<assign name="t_ASSERT_REASON" expr="'Invalid input/outputs values on dialog object , STATE ' + current_state"/>
				<script>
                    [assert_index].P_F = s_FAIL;
                    [assert_index].reason = t_ASSERT_REASON;  
				</script>
			</if>
			<dialogterminate dialogid="DialogID"/>
		</transition>		
		<transition event="dialog.exit" state="ASSERTION_NMBR_360">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
		<!-- END TA 360 -->
		<!-- TA 362:  dialogstart with mediadirection = dialogreceive - use of connection -->
		<transition event="user.START_ASSERTION_362" state="ASSERTION_NMBR_362">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<dialogstart src="vxmlFile" dialogid="DialogID" connectionid="ConnectionID" mediadirection="'dialogreceive'"/>
		</transition>		
		<transition event="dialog.started" state="ASSERTION_NMBR_362">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<if cond="event$.dialog.input == ConnectionID  &amp;&amp; bOutputsContainsID(ConnectionID, event$.dialog.outputs) == 0  &amp;&amp; session.connections[ConnectionID].input == undefined  &amp;&amp; bOutputsContainsID(DialogID, session.connections[ConnectionID].outputs) == 1">	
				<script>assertions[assert_index].P_F = s_PASS;</script>
			<else/>
				<assign name="t_ASSERT_REASON" expr="'Invalid input/outputs values on dialog object , STATE ' + current_state"/>
				<script>
                    [assert_index].P_F = s_FAIL;
                    [assert_index].reason = t_ASSERT_REASON;  
				</script>
			</if>
			<dialogterminate dialogid="DialogID"/>
		</transition>			
		<transition event="dialog.exit" state="ASSERTION_NMBR_362">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<destroyconference conferenceid="ConferenceID"/>
		</transition>
		<transition event="conference.destroyed" state="ASSERTION_NMBR_362">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
		<!-- END TA 362 -->

		<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>
