Показать сообщение отдельно
Старый 08.05.2011, 17:57
wvxvw вне форума Посмотреть профиль Отправить личное сообщение для wvxvw Найти все сообщения от wvxvw
  № 28  
Ответить с цитированием
wvxvw
Modus ponens
 
Аватар для wvxvw

модератор форума
Регистрация: Jul 2006
Адрес: #1=(list #1#)
Сообщений: 8,049
Записей в блоге: 38
expl.
ОК, пример
Код AS3:
package tests
{
	import com.***.net.tcp.NinjaEvent;
	import com.***.net.tcp.NinjaMethods;
	import com.***.net.tcp.NinjaService;
 
	import flash.events.Event;
 
	import flexunit.framework.Assert;
 
	import org.flexunit.async.Async;
 
	public class TestNinjaKillActivity
	{
		private var _activityDead:Boolean;
		// Падаван хотел это сделать синглотоном :) А тут внезапно их два - облом :)
		private var _sender:NinjaService = 
			new NinjaService("123456", "127.0.0.1");
		private var _receiver:NinjaService = 
			new NinjaService("654321", "127.0.0.1");
 
		public function TestNinjaKillActivity() { super(); }
 
		[Before(async)]
		public function before():void
		{
			this._sender.addEventListener(Event.CONNECT, this.sender_connectHandler);
			this._receiver.addEventListener(
				Event.CONNECT, this.receiver_connectHandler);
			this._receiver.addEventListener(
				NinjaEvent.GET_ACTION, this.getActionHandler);
			this._receiver.addEventListener(
				NinjaEvent.CALL_RECEIVED, this.receiver_callReceivedHandler);
			this._sender.addEventListener(
				NinjaEvent.CALL_STARTED, this.sender_callStartedHandler);
			Async.proceedOnEvent(this, this._receiver, "test", 10000);
			this._sender.connect();
			this._receiver.connect();
		}
 
		private function sender_connectHandler(event:Event):void
		{
			if (this._receiver.connected) this.bothConnected();
			trace("sender_connectHandler");
		}
 
		private function receiver_connectHandler(event:Event):void
		{
			if (this._sender.connected) this.bothConnected();
			trace("receiver_connectHandler");
		}
 
		private function sender_callStartedHandler(event:NinjaEvent):void
		{
			this.killActivity();
			trace("sender_callStartedHandler");
		}
 
		private function receiver_callReceivedHandler(event:NinjaEvent):void
		{
			(this._receiver.methods as NinjaMethods)
			.acceptCall(this._sender.clientId);
			trace("receiver_callReceivedHandler");
		}
 
		public function bothConnected():void
		{
			(this._sender.methods as NinjaMethods)
			.startCall(this._receiver.clientId, "externalId", "a", "b", "c", "d");
			trace("bothConnected");
		}
 
		private function killActivity():void
		{
			(this._sender.methods as NinjaMethods)
				.killActivity(this._receiver.clientId);
		}
 
		private function getActionHandler(event:NinjaEvent):void
		{
			this._activityDead = true;
			this._receiver.dispatchEvent(new Event("test"));
			this.testReceive();
			trace("getActionHandler");
		}
 
		[Test(async, timeout="10000")]
		public function testReceive():void
		{
			Assert.assertTrue(this._activityDead);
		}
	}
}
(Названия не я придумывал, это тяжелое наследие царского режима).
__________________
Hell is the possibility of sanity