<?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="myFetchID"/>

	<var name="CorrectCCXMLPage" expr="'6_2_OK.ccxml'"/>
	<var name="UncorrectCCXMLPage" expr="'6_2_KO.ccxml'"/>
	
 	<var name="var_cond_aaa" expr="'aaa'"/>
 	<var name="var_cond"/>
 	<var name="count_finish"/>
	<var name="loadedReceived" expr="false"/>
 	

	<script><![CDATA[
		var i=0;
		
		assertions[i++] = init_assertion('624');		
		assertions[i++] = init_assertion('625');
		assertions[i++] = init_assertion('626');		
		assertions[i++] = init_assertion('627');				
		assertions[i++] = init_assertion('628');		
		assertions[i++] = init_assertion('629');		
		assertions[i++] = init_assertion('684');		
		assertions[i++] = init_assertion('686');		
			
		// goto
		assertions[i++] = init_assertion('652');		
		assertions[i++] = init_assertion('653');		
		assertions[i++] = init_assertion('657');		
		assertions[i++] = init_assertion('655');		
		
			
		var assert_last = i - 1;
		var assert_index = -1;
		//
		// out of the loop assertions (children)

		// Children of 625
		add_2_assert_trace('623');

		// Children of 686
		add_2_assert_trace('685');
		add_2_assert_trace('693');
		add_2_assert_trace('694');
		add_2_assert_trace('695');
		add_2_assert_trace('1006');

		// Children of 684
		add_2_assert_trace('689');
		add_2_assert_trace('690');
		
		// Children of 655
		add_2_assert_trace('703');

		
		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">
			<assign name="loadedReceived" expr="true"/>
		</transition>
    
    
		<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">
			<conf:comment expr="'Event: ' + event$.name"/>
			<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>

    	      			
<!--
625.

If an <if> has no immediate <elseif> or <else> children, the full contents of the <if> will be selected when the cond attribute is true

623.

A CCXML document may contain an <if> element. An <if> is a container for conditionally executed elements

-->

		<transition event="user.START_ASSERTION_625" state="ASSERTION_NMBR_625">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>					
			
		 	<script>assertions[assert_index].P_F = s_FAIL;</script>
		 	<assign name="t_ASSERT_REASON" expr="'cond not successfully evaluated' "/>
    	<if cond="var_cond_aaa == 'aaa'">
			 	<script>assertions[assert_index].P_F = s_PASS;</script>
		 	  <assign name="t_ASSERT_REASON" expr="'' "/>			 	
    	</if>

			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
  		<!-- Begin Related Tests -->
			<assign name="ASSERTION_NUM" expr="'623'"/>		
			<conf:pass/>
			<conf:comment expr="'if you do not receive FAIL, test passed'"/>		
  		<!-- End Related Tests -->
    	  		    	
    </transition>

		<transition event="error.*" state="ASSERTION_NMBR_625">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>		
		
  		<!-- Begin Related Tests -->
			<assign name="ASSERTION_NUM" expr="'623'"/>		
			<conf:fail reason="'if must be supported'"/>
  		<!-- End Related Tests -->
		
    </transition>

<!--
624.

<else> and <elseif> can optionally appear within an <if> as immediate children

-->
		<transition event="user.START_ASSERTION_624" state="ASSERTION_NMBR_624">		
			<assign name="count_finish" expr="0"/>
		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>		

    	<if cond="var_cond == 'aaa'">
 				<conf:comment expr=" 'Current state : ' + current_state + ' in if'"/>		
			<elseif cond="var_cond == 'bbb'"/>
 				<conf:comment expr=" 'Current state : ' + current_state + ' in elseif'"/>		
			<else/>
 				<conf:comment expr=" 'Current state : ' + current_state + ' in else'"/>					
    	</if>
		 	<script>assertions[assert_index].P_F = s_PASS;</script>

			<send targettype="'ccxml'" target="session.id" name="'finish_test'"/>		 	
			<!-- This event is sent in any case -->
  		    	
    </transition>

		<transition event="error.*" state="ASSERTION_NMBR_624">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>	
		 	<script>assertions[assert_index].P_F = s_FAIL;</script>
		 	<assign name="t_ASSERT_REASON" expr="'else/elseif not successfully evaluated' "/>

			<send targettype="'ccxml'" target="session.id" name="'finish_test'"/>		 	
			
    </transition>
    
    <transition event="finish_test" state="ASSERTION_NMBR_624">
 			<assign name="count_finish" expr="count_finish+1"/>

    	<if cond="assertions[assert_index].P_F == s_FAIL">
    		<!-- 2 finish_test events must be received -->
    		<if cond="count_finish == 2">
					<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>		
				</if>
    	<else/>
					<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>		    		
    	</if>
    </transition>
    
<!--

626.
A CCXML <if> element must contain a cond attribute. If not provided, an error.fetch event is thrown.

-->
		<transition event="user.START_ASSERTION_626" state="ASSERTION_NMBR_626">		
			<fetch next="'6_2_626.ccxml'"/>
    </transition>

		<transition event="error.fetch" state="ASSERTION_NMBR_626">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , 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="fetch.done" state="ASSERTION_NMBR_626">
		 	<script>assertions[assert_index].P_F = s_FAIL;</script>
		 	<assign name="t_ASSERT_REASON" expr="'if tag must have cond attribute' "/>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>				 	    
    </transition>
    	      			
<!--
628.
A CCXML <elseif> element must contain a cond atribute.If a cond atribute is not provided for an <elseif>, error.fetch event is thrown.

-->    	      			
		<transition event="user.START_ASSERTION_628" state="ASSERTION_NMBR_628">		
			<fetch next="'6_2_628.ccxml'"/>
    </transition>

		<transition event="error.fetch" state="ASSERTION_NMBR_628">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , 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="fetch.done" state="ASSERTION_NMBR_628">
		 	<script>assertions[assert_index].P_F = s_FAIL;</script>
		 	<assign name="t_ASSERT_REASON" expr="'if tag must have cond attribute' "/>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>				 	    
    </transition>    	      			

<!--
627.
An <elseif> partitions the content of an <if>, and provides a condition that determines the selection of the partition it begins
-->

		<transition event="user.START_ASSERTION_627" state="ASSERTION_NMBR_627">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>		
		 	<script>assertions[assert_index].P_F = s_FAIL;</script>
		 	<assign name="t_ASSERT_REASON" expr="'cond not successfully evaluated' "/>
    	<if cond="var_cond_aaa != 'aaa'">
			 	<script>assertions[assert_index].P_F = s_FAIL;</script>
		 	  <assign name="t_ASSERT_REASON" expr="'cond for if is not true' "/>			 	
    	<elseif cond="var_cond_aaa == 'aaa'"/>
			 	<script>assertions[assert_index].P_F = s_PASS;</script>
		 	  <assign name="t_ASSERT_REASON" expr="'' "/>			 	
    	</if>

			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
    	  		    	
    </transition>

<!--
<else> is a synonym for <elseif cond="true"/>.
-->    
		<transition event="user.START_ASSERTION_629" state="ASSERTION_NMBR_629">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>		
		 	<script>assertions[assert_index].P_F = s_FAIL;</script>
		 	<assign name="t_ASSERT_REASON" expr="'cond not successfully evaluated' "/>
    	<if cond="var_cond_aaa != 'aaa'">
			 	<script>assertions[assert_index].P_F = s_FAIL;</script>
		 	  <assign name="t_ASSERT_REASON" expr="'cond for if is not true' "/>		
    	<elseif cond="var_cond_aaa != 'aaa'"/>		 	  
			 	<script>assertions[assert_index].P_F = s_FAIL;</script>
		 	  <assign name="t_ASSERT_REASON" expr="'cond for elseif is not true' "/>			 		
    	<else/>
			 	<script>assertions[assert_index].P_F = s_PASS;</script>
		 	  <assign name="t_ASSERT_REASON" expr="'' "/>			 	
    	</if>

			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
    	  		    	
    </transition>
        
<!--

684.
The <log> element may have a label attribute to indicate the purpose of the log.

689.
A fetch.done event will contain a fetchid property set to the internally generated unique fetch identifier

690.
A fetch.done event will contain a uri property set to the URI of the fetch request.

-->
        
		<transition event="user.START_ASSERTION_684" state="ASSERTION_NMBR_684">		
			<fetch next="'6_2_684.ccxml'" fetchid="myFetchID"/>
    </transition>

		<transition event="error.fetch" state="ASSERTION_NMBR_684">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>	
		 	<script>assertions[assert_index].P_F = s_FAIL;</script>
		 	<assign name="t_ASSERT_REASON" expr="'log tag must allow label attribute' "/>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>				 	
			
    </transition>
    
    <transition event="fetch.done" state="ASSERTION_NMBR_684">
    
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
		 	<script>assertions[assert_index].P_F = s_PASS;</script>			
		 	
		 	
  		<!-- Begin Related Tests -->
			
			<assign name="ASSERTION_NUM" expr="'689'"/>		
			<if cond = "event$.fetchid == myFetchID">
				<conf:pass/>
			<else/>
				<conf:fail reason="'fetchid attribute not correct in fetch.done, expected '+myFetchID+' received '+event$.fetchid"/>			
			</if>
						
			<assign name="ASSERTION_NUM" expr="'690'"/>		
			<if cond = "event$.uri.match('6_2_684.ccxml') != null">
				<conf:pass/>
			<else/>
				<conf:fail reason="'uri attribute not correct in fetch.done, expected 6_2_684.ccxml, received:'+event$.uri"/>			
			</if>
						

												
  		<!-- End Related Tests -->		 	
    
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>				 	    
    </transition>        

<!--
686.
If an expr attribute is not provided, an error.fetch event will be thrown.

685.
The <log> element must provide an expr attribute evaluating to string to be logged

693.
An error.fetch event will contain a fetchid property set to the internally generated unique fetch identifier

694.
An error.fetch event will contain a reason property set to a string describing the fetch error.

695.
An error.fetch event will contain a uri property set to the URI of the fetch request.

1006.
An error.fetch event will contain a statuscode property set to the numeric HTTP status code of the failed HTTP request
-->        	      	
        	      	
		<transition event="user.START_ASSERTION_686" state="ASSERTION_NMBR_686">		
			<fetch next="'6_2_686.ccxml'" fetchid="myFetchID"/>
    </transition>

		<transition event="error.fetch" state="ASSERTION_NMBR_686">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>	
		 	<script>assertions[assert_index].P_F = s_PASS;</script>			
		 	
  		<!-- Begin Related Tests -->
			<assign name="ASSERTION_NUM" expr="'685'"/>		
			<conf:pass/>
			
			<assign name="ASSERTION_NUM" expr="'693'"/>		
			<if cond = "event$.fetchid == myFetchID">
				<conf:pass/>
			<else/>
				<conf:fail reason="'fetchid attribute not correct in error.fetch, expected '+myFetchID+' received '+event$.fetchid"/>			
			</if>
			
			<assign name="ASSERTION_NUM" expr="'694'"/>		
			<if cond = "event$.reason == undefined">
				<conf:fail reason="'missing attribute reason error.fetch'"/>			
			<else/>
				<conf:pass/>			
			</if>
			
			<assign name="ASSERTION_NUM" expr="'695'"/>		
			<if cond = "event$.uri.match('6_2_686.ccxml') != null">
				<conf:pass/>
			<else/>
				<conf:fail reason="'uri attribute not correct in error.fetch, expected 6_2_686.ccxml, received:'+event$.uri"/>			
			</if>
						
			<assign name="ASSERTION_NUM" expr="'1006'"/>		
			<if cond = "event$.statuscode == undefined">
				<conf:fail reason="'statuscode attribute reason error.fetch'"/>			
			<else/>
				<conf:pass/>			
			</if>
												
  		<!-- End Related Tests -->
		 	
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>				 	
    </transition>
    
    <transition event="fetch.done" state="ASSERTION_NMBR_686">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>	
    
		 	<script>assertions[assert_index].P_F = s_FAIL;</script>
		 	<assign name="t_ASSERT_REASON" expr="'log tag must have expr attribute' "/>
		 	
		 	
  		<!-- Begin Related Tests -->
			<assign name="ASSERTION_NUM" expr="'685'"/>		
			<conf:fail reason="'expr attribute missing but tag accepted'"/>
  		<!-- End Related Tests -->
		 	
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>				 	    
    </transition>
    
<!--
652.
The fetch completion event MUST have arrived before the <goto> is executed, otherwise, an error.semantic event is generated.

-->    
		<transition event="user.START_ASSERTION_652" state="ASSERTION_NMBR_652">	
		 	<script>assertions[assert_index].P_F = s_FAIL;</script>						
			<fetch next="CorrectCCXMLPage" fetchid="myFetchID"/>
			<goto fetchid="myFetchID"/>
    </transition>

		<transition event="error.semantic" state="ASSERTION_NMBR_652">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>	
		 	<script>assertions[assert_index].P_F = s_PASS;</script>			
    </transition>
    
    <transition event="fetch.done" state="ASSERTION_NMBR_652">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>	
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>				 				
    </transition>
    	      			    
<!--
653. 
If the fetched content referenced by the fetch identifier is not a CCXML document, or the fetch identifier is invalid and does not correspond to any fetch request, this also results in an error.semantic event.
--> 	      			    
		<transition event="user.START_ASSERTION_653" state="ASSERTION_NMBR_653">	
		 	<script>assertions[assert_index].P_F = s_FAIL;</script>						
			<fetch next="CorrectCCXMLPage" fetchid="myFetchID"/>
    </transition>
    
    <transition event="fetch.done" state="ASSERTION_NMBR_653">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>	
			<goto fetchid="'bogus_fetch_id'"/>
    </transition>
    
		<transition event="error.semantic" state="ASSERTION_NMBR_653">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>	
			<assign name="current_state" expr="'ASSERTION_NMBR_653_second'"/>
		 	<fetch next="UncorrectCCXMLPage" type="'text/ecmascript'" fetchid="myFetchID"/>
    </transition>

    <transition event="fetch.done" state="ASSERTION_NMBR_653_second">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<goto fetchid="event$.fetchid"/>	
		 	<script>assertions[assert_index].P_F = s_FAIL;</script>									
    </transition>                	      								

    <transition event="error.fetch" state="ASSERTION_NMBR_653_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>                	      								


    <transition event="error.semantic" state="ASSERTION_NMBR_653_second">
        <conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
        <script>assertions[assert_index].P_F = s_PASS;</script>
        <send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
    </transition>


<!--
A CCXML <goto> element must contain a fetchid attribute. If the fetchid attribute is not provided and error.fetch event is thrown.

-->
		<transition event="user.START_ASSERTION_657" state="ASSERTION_NMBR_657">	
		 	<script>assertions[assert_index].P_F = s_FAIL;</script>						
			<fetch next="'6_2_657.ccxml'"/>
    </transition>

		<transition event="error.fetch" state="ASSERTION_NMBR_657">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , 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="fetch.done" state="ASSERTION_NMBR_657">
			<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>

<!--
655.
Event sources associated with this session are inherited by the target document

703.
The CCXML platform MUST generate this event when the CCXML document is first loaded at session startup.
-->
		<transition event="user.START_ASSERTION_655" state="ASSERTION_NMBR_655">	
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>	

  		<!-- Begin Related Tests -->
			<assign name="ASSERTION_NUM" expr="'703'"/>		
			<if cond="loadedReceived == true">
				<conf:pass/>
			<else/>
				<conf:fail/>
			</if>
  		<!-- End Related Tests -->
  		
			<fetch next="'6_2_A.ccxml'" fetchid="myFetchID"/>
    </transition>
    
    <transition event="fetch.done" state="ASSERTION_NMBR_655">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>	
			<assign name="application.gotoevent" expr="'goto_655'"/>
			<send target="session.id" name="application.gotoevent" delay="'10s'"/>
			<assign name="application.var656" expr="'ok656'"/>			
			<assign name="application.oldsessID" expr="session.id"/>
			<goto fetchid="myFetchID"/>
			<!-- from here the control goes to the fetched page 6_2_A -->
			
			<assign name="application.var656" expr="'ko656'"/>			

    </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>
