<?xml version="1.0"?>
<mx:Application name="lightspark_net_NetConnection_test"
	xmlns:mx="http://www.adobe.com/2006/mxml"
	layout="absolute"
	applicationComplete="appComplete();"
	backgroundColor="white">

<mx:Script>
	<![CDATA[
	import Tests;
	private var callbackCount:int = 0;
	private function report():void
	{
		Tests.assertEquals(2, callbackCount, "Number of callback called");
		Tests.report(visual, this.name);
	}
	private function onResult(result:Object):void
	{
		Tests.assertEquals(3, result, "Value returned from RPC");
		callbackCount++;
		report();
	}
	private function onNullConnectStatus(status:Object):void
	{
		Tests.assertEquals("NetConnection.Connect.Success", status.info.code, "NetConnection.connect succeed");
		callbackCount++;
	}
	private function onHttpConnectStatus(status:Object):void
	{
		Tests.assertTrue(false, "NetConnection.connect should not use netStatus events for RPC connections");
		callbackCount++;
	}
	private function onCallStatus(status:Object):void
	{
		Tests.assertTrue(false, "NetConnection.call should not fail");
		callbackCount++;
		//This should not be called in successful execution
		report();
	}
	private function appComplete():void
	{
		//To test, start a default installation of amfphp-2.0.1 on localhost
		var connection1:NetConnection=new NetConnection();
		connection1.addEventListener("netStatus", onNullConnectStatus);
		connection1.connect(null);

		var connection2:NetConnection=new NetConnection();
		connection2.addEventListener("netStatus", onHttpConnectStatus);
		connection2.connect("http://127.0.0.1/index.php");
		var responder:Responder = new Responder(onResult, onCallStatus);
		//This must be the last statement, the report is done in the callback of this method
		connection2.call("ExampleService.returnOneParam", responder, 3);
	}
	]]>
</mx:Script>

<mx:UIComponent id="visual" />

</mx:Application>
