<?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 - 2011-03-30
FIXED: 
- updated implementation of TA 72 to better adhere to spec
-->

<!--
      <conf:fail reason="'Unexpected Event ' + event$.name"/>
-->
	<conf:docsetup/>
	<var name="chld_reason"/>
	<var name="general_connid"/>
	<var name="general_connid2"/>
	<var name="A72_confid"/>
	<var name="A72_confid2"/>
	<var name="A72_confid3"/>
	<var name="A72_child_session_id"/>
	<var name="A75_confid"/>
	<var name="A994_confid"/>
	<var name="A994_child_session_id"/>
	<var name="A994_failevent"/>
	<var name="A80_confid"/>
	<script>
	   function GetMilliseconds() {
     var d = new Date();
     return d.getTime();  // ms from midnight on Jan 1, 2000.
   }

var t_start, t_end, t_delay = 2000, t_delta, t_delta_e = 0.05 * t_delay;
		   </script>
	<script>

var i=0;
assertions[i++] = init_assertion('72');
assertions[i++] = init_assertion('75');
assertions[i++] = init_assertion('994');
assertions[i++] = init_assertion('77');
assertions[i++] = init_assertion('79');
assertions[i++] = init_assertion('80');



var assert_last = i - 1;
var assert_index = -1;
//
// out of the loop assertions (children?)
//
//
s_ASSERTIONS_LEFT = show_remained_assertions();
var b_in_test = false;


</script>
	<eventprocessor statevariable="current_state">
		<conf:setup type="alerting"/>
		<transition event="connection.alerting" state="init">
			<send targettype="'ccxml'" target="session.id" name="'user.timeout'" delay="TEST_LONG_TIMEOUT"/>
			<accept connectionid="event$.connectionid"/>
		</transition>
		<transition event="connection.connected" state="init">
			<assign name="general_connid" expr="event$.connectionid"/>
			<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>t_ASSERT_REASON = assertions[assert_index].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" sendid="cur_event_ID"/>
				<log label="s_TA" expr="'Loop event: SendID=' + cur_event_ID"/>
			</if>
		</transition>
		<transition event="user.START_ASSERTION_72" state="ASSERTION_NMBR_72"><!--
72  	
10.5.6.1  	
<destroyconference> destroys the conference if no other sessions are attached to it.  	
rachel.muller@aspect.com  	Complete
-->
			<createconference conferenceid="A72_confid" confname="'A72_conference1'"/>
		</transition>
		<transition event="conference.created" state="ASSERTION_NMBR_72">
			<conf:comment expr="'Event: ' + event$.name"/>
			<destroyconference conferenceid="A72_confid"/>
		</transition>
		<transition event="conference.destroyed" state="ASSERTION_NMBR_72">
			<conf:comment expr="'Event: ' + event$.name"/>
			<assign name="current_state" expr="'ASSERTION_NMBR_72_IN_PROGRESS'"/>
			<join id1="A72_confid" id2="general_connid"/>
		</transition>
		
		<transition event="error.conference.join" state="ASSERTION_NMBR_72_IN_PROGRESS">
				<conf:comment expr="'Event: ' + event$.name"/>
				<createconference conferenceid="A72_confid2" confname="'A72_conference1'"/>
		</transition>
		
		<transition event="conference.created" state="ASSERTION_NMBR_72_IN_PROGRESS">
			<conf:comment expr="'Event: ' + event$.name"/>
			<assign name="current_state" expr="'ASSERTION_NMBR_72_PART_2'"/>
			<createccxml next="'10_5_6_A_72.ccxml'" sessionid="A72_child_session_id"/>
		</transition>
		
		<transition event="conference.joined" state="ASSERTION_NMBR_72_IN_PROGRESS">
				<conf:comment expr="'Event: ' + event$.name"/>
				<script>assertions[assert_index].P_F = s_FAIL;
					assertions[assert_index].reason = 'destroyconference element did not properly destroy a conference that had no other sessions attached to it.'</script>
				<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
		
		<transition event="user.A72_conference_created" state="ASSERTION_NMBR_72_PART_2">
			<conf:comment expr="'Event: ' + event$.name"/>
			<destroyconference conferenceid="A72_confid2"/>
		</transition>
		
		<transition event="conference.destroyed" state="ASSERTION_NMBR_72_PART_2">
			<conf:comment expr="'Event: ' + event$.name"/>
			<createconference conferenceid="A72_confid3" confname="'A72_conference1'"/>
		</transition>
		<transition event="conference.created" state="ASSERTION_NMBR_72_PART_2">
			<conf:comment expr="'Event: ' + event$.name"/>
			<if cond="A72_confid2==A72_confid3">
				<script>assertions[assert_index].P_F = s_PASS;</script>
				<else/>
				<script>assertions[assert_index].P_F = s_FAIL;
						assertions[assert_index].reason = 'destroyconference element destroyed a conference that had other sessions attached to it.'</script>
			</if>
			<send targettype="'ccxml'" target="A72_child_session_id" name="'user.A72_finished'"/>
		</transition>
		<transition event="ccxml.exit" state="ASSERTION_NMBR_72_PART_2">
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
		<transition event="user.START_ASSERTION_75" state="ASSERTION_NMBR_75"><!--
75  	
10.5.6.1  	
The successful execution of <destroyconference> MUST result in the generation of a conference.destroyed event.  	
rachel.muller@aspect.com  	Complete	
-->
			<createconference conferenceid="A75_confid"/>
		</transition>
		<transition event="conference.created" state="ASSERTION_NMBR_75">
			<conf:comment expr="'Event: ' + event$.name"/>
			<destroyconference conferenceid="A75_confid"/>
		</transition>
		<transition event="conference.destroyed" state="ASSERTION_NMBR_75">
			<conf:comment expr="'Event: ' + event$.name"/>
			<script>assertions[assert_index].P_F = s_PASS;</script>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
		<transition event="conference.*" state="ASSERTION_NMBR_75">
			<conf:comment expr="'Event: ' + event$.name"/>
			<script>assertions[assert_index].P_F = s_FAIL;
					assertions[assert_index].reason = 'expected event conference.destroyed, got ' + event$.name;</script>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
		<transition event="error.*" state="ASSERTION_NMBR_75">
			<conf:comment expr="'Event: ' + event$.name"/>
			<script>assertions[assert_index].P_F = s_FAIL;
					assertions[assert_index].reason = 'got an error while destroying a conference: ' + event$.name + ' : ' + event$.reason;</script>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
		<transition event="user.START_ASSERTION_994" state="ASSERTION_NMBR_994"><!--
994  	
10.5.6.1  	
Since other sessions may have created bridges to a conference using the conference's ID, but without performing a <createconference>, destroying a conference MAY affect the bridges established by other sessions. If any bridges are terminated in this fashion, a 'conference.unjoined' event MUST be posted to indicate to the session that its Connection is no longer bridged to the Conference.  	
rachel.muller@aspect.com  	Complete
-->
			<createconference conferenceid="A994_confid"/>
		</transition>
		<transition event="conference.created" state="ASSERTION_NMBR_994">
			<conf:comment expr="'Event: ' + event$.name"/>
			<createccxml next="'10_5_6_A_994.ccxml'" sessionid="A994_child_session_id" parameters="A994_confid"/><!--parameters="A994_confid" />-->
		</transition>
		<transition event="user.A994_call_leg_joined" state="ASSERTION_NMBR_994">
			<conf:comment expr="'Event: ' + event$.name"/>
			<send targettype="'ccxml'" target="session.id" name="'user.A994_failed'" delay="'3000s'" sendid="A994_failevent"/>
			<destroyconference conferenceid="A994_confid"/>
		</transition>
		<transition event="user.A994_passed" state="ASSERTION_NMBR_994">
			<conf:comment expr="'Event: ' + event$.name"/>
			<cancel sendid="A994_failevent"/>
			<script>assertions[assert_index].P_F = s_PASS;</script>
			<send targettype="'ccxml'" target="A994_child_session_id" name="'user.A994_finished'"/>
		</transition>
		<transition event="user.A994_failed" state="ASSERTION_NMBR_994">
			<conf:comment expr="'Event: ' + event$.name"/>
			<script>assertions[assert_index].P_F = s_FAIL;
					assertions[assert_index].reason = 'conference.unjoined event was not posted to a session which had a bridge destroyed by a destroyconference tag.'</script>
			<send targettype="'ccxml'" target="A994_child_session_id" name="'user.A994_finished'"/>
		</transition>
		<transition event="ccxml.exit" state="ASSERTION_NMBR_994">
			<conf:comment expr="'Event: ' + event$.name"/>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
		<transition event="conference.joined" state="ASSERTION_NMBR_994">
			<conf:comment expr="'Event: ' + event$.name"/>
		</transition>
		<transition event="user.START_ASSERTION_77" state="ASSERTION_NMBR_77"><!--
77  	
10.5.6.2  	
A <destroyconference> must have a conferenceid attribute. The conferenceid attribute returns a string that is the identifier of the conference that should be destroyed.  	
rachel.muller@aspect.com 	Complete	
-->
			<createccxml next="'10_5_6_A_77.ccxml'"/>
		</transition>
		<transition event="error.createccxml" state="ASSERTION_NMBR_77">
			<conf:comment expr="'Event: ' + event$.name"/>
			<script>assertions[assert_index].P_F = s_PASS;</script>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
		<transition event="ccxml.created" state="ASSERTION_NMBR_77">
			<conf:comment expr="'Event: ' + event$.name"/>
			<script>assertions[assert_index].P_F = s_FAIL;
					assertions[assert_index].reason = 'a destroyconference tag with no conferenceid attribute was successfully compiled';</script>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
		<transition event="user.START_ASSERTION_79" state="ASSERTION_NMBR_79"><!--
79  	
10.5.6.2  	
If the conferenceid attribute value is invalid an error.semantic event must be thrown.  	
rachel.muller@aspect.com  	Complete	
-->
			<destroyconference conferenceid="thisisinvalid"/>
		</transition>
		<transition event="error.semantic" state="ASSERTION_NMBR_79">
			<conf:comment expr="'Event: ' + event$.name"/>
			<script>assertions[assert_index].P_F = s_PASS;</script>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
		<transition event="conference.destroyed" state="ASSERTION_NMBR_79">
			<conf:comment expr="'Event: ' + event$.name"/>
			<script>assertions[assert_index].P_F = s_FAIL;
					assertions[assert_index].reason = 'a destroyconference tag with an invalid conferenceid attribute was successfully processed.';</script>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
		<transition event="user.START_ASSERTION_80" state="ASSERTION_NMBR_80"><!--
80  	
10.5.6.2  	
<destroyconference> may have a hints attribute which is an ECMAScript object that contains information which may be used by the implementing platform when destroying the conference.  	
rachel.muller@aspect.com  	Complete	
-->
			<createconference conferenceid="A80_confid"/>
		</transition>
		<transition event="conference.created" state="ASSERTION_NMBR_80">
			<conf:comment expr="'Event: ' + event$.name"/>
			<script>var Hints = new Object;
				Hints.headers = new Object();
				Hints.headers['x-headerOne'] = 'one'</script>
			<destroyconference conferenceid="A80_confid" hints="Hints"/>
		</transition>
		<transition event="conference.destroyed" state="ASSERTION_NMBR_80">
			<conf:comment expr="'Event: ' + event$.name"/>
			<script>assertions[assert_index].P_F = s_PASS;</script>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition><!--======================================================== All-purpose handlers ========================================================-->
		<transition event="ccxml.created">
			<conf:comment expr="'Event: ' + event$.name"/>
		</transition>
		<transition event="ccxml.exit">
			<conf:comment expr="'Event: ' + event$.name"/>
		</transition>
		<transition event="conference.created">
			<conf:comment expr="'Event: ' + event$.name"/>
		</transition>
		<transition event="conference.destroyed">
			<conf:comment expr="'Event: ' + event$.name"/>
		</transition>
		<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 event="cancel.successful">
			<conf:comment expr="'Event: ' + event$.name + ' (generic handler) state=' + current_state"/>
		</transition>
		<transition event="*">
			<assign name="t_ASSERT_REASON" expr="'UNEXPECTED EVENT ' + event$.name + ' IN STATE ' + current_state"/>
			<conf:comment expr="t_ASSERT_REASON + ' : ' + event$.reason"/>
			<if cond="current_state == 'init'">
				<conf:uncond_exit expr="'Did not come out from init state.'"/>
				<else/>
				<if cond="current_state != 'GEN'">
					<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
				</if>
			</if>
		</transition>
	</eventprocessor>
</ccxml>
