as3signals 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.textile +51 -0
- data/Gemfile +6 -0
- data/MIT-LICENSE.txt +22 -0
- data/README.textile +43 -0
- data/Rakefile +52 -0
- data/as3-signals.as3proj +87 -0
- data/as3-signals.docproj +9 -0
- data/as3signals.gemspec +24 -0
- data/build-asunit.properties +7 -0
- data/build-asunit.xml +34 -0
- data/build.properties +20 -0
- data/build.xml +53 -0
- data/lib/as3signals.rb +15 -0
- data/src/org/osflash/signals/DeluxeSignal.as +260 -0
- data/src/org/osflash/signals/IDeluxeSignal.as +34 -0
- data/src/org/osflash/signals/IDispatcher.as +15 -0
- data/src/org/osflash/signals/ISignal.as +44 -0
- data/src/org/osflash/signals/ISignalOwner.as +13 -0
- data/src/org/osflash/signals/Signal.as +206 -0
- data/src/org/osflash/signals/events/GenericEvent.as +44 -0
- data/src/org/osflash/signals/events/IBubbleEventHandler.as +14 -0
- data/src/org/osflash/signals/events/IEvent.as +27 -0
- data/src/org/osflash/signals/natives/INativeDispatcher.as +34 -0
- data/src/org/osflash/signals/natives/NativeMappedSignal.as +230 -0
- data/src/org/osflash/signals/natives/NativeRelaySignal.as +71 -0
- data/src/org/osflash/signals/natives/NativeSignal.as +176 -0
- data/tests/org/osflash/signals/AllTests.as +44 -0
- data/tests/org/osflash/signals/AllTestsRunner.as +19 -0
- data/tests/org/osflash/signals/AmbiguousRelationshipTest.as +60 -0
- data/tests/org/osflash/signals/DeluxeSignalAmbiguousRelationshipTest.as +60 -0
- data/tests/org/osflash/signals/DeluxeSignalDispatchExtraArgsTest.as +43 -0
- data/tests/org/osflash/signals/DeluxeSignalDispatchNoArgsTest.as +55 -0
- data/tests/org/osflash/signals/DeluxeSignalDispatchNonEventTest.as +67 -0
- data/tests/org/osflash/signals/DeluxeSignalSplitInterfacesTest.as +41 -0
- data/tests/org/osflash/signals/DeluxeSignalTest.as +134 -0
- data/tests/org/osflash/signals/DeluxeSignalWithBubblingEventTest.as +129 -0
- data/tests/org/osflash/signals/DeluxeSignalWithCustomEventTest.as +84 -0
- data/tests/org/osflash/signals/DeluxeSignalWithGenericEventTest.as +190 -0
- data/tests/org/osflash/signals/GenericEventTest.as +62 -0
- data/tests/org/osflash/signals/PriorityListenersTest.as +68 -0
- data/tests/org/osflash/signals/RedispatchedEventTest.as +51 -0
- data/tests/org/osflash/signals/SignalDispatchArgsTest.as +74 -0
- data/tests/org/osflash/signals/SignalDispatchNoArgsTest.as +55 -0
- data/tests/org/osflash/signals/SignalDispatchNonEventTest.as +81 -0
- data/tests/org/osflash/signals/SignalSplitInterfacesTest.as +47 -0
- data/tests/org/osflash/signals/SignalTest.as +267 -0
- data/tests/org/osflash/signals/SignalWithCustomEventTest.as +107 -0
- data/tests/org/osflash/signals/natives/AmbiguousRelationshipInNativeSignalTest.as +63 -0
- data/tests/org/osflash/signals/natives/NativeMappedSignalBoundaryUseTest.as +100 -0
- data/tests/org/osflash/signals/natives/NativeMappedSignalDefaultsTest.as +78 -0
- data/tests/org/osflash/signals/natives/NativeMappedSignalFunctionArgTest.as +148 -0
- data/tests/org/osflash/signals/natives/NativeMappedSignalFunctionNoArgsTest.as +95 -0
- data/tests/org/osflash/signals/natives/NativeMappedSignalObjectArgTest.as +85 -0
- data/tests/org/osflash/signals/natives/NativeRelaySignalTest.as +174 -0
- data/tests/org/osflash/signals/natives/NativeSignalTest.as +312 -0
- metadata +152 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
package org.osflash.signals
|
2
|
+
{
|
3
|
+
import asunit.asserts.*;
|
4
|
+
import asunit.framework.IAsync;
|
5
|
+
|
6
|
+
public class DeluxeSignalDispatchExtraArgsTest
|
7
|
+
{
|
8
|
+
[Inject]
|
9
|
+
public var async:IAsync;
|
10
|
+
|
11
|
+
public var completed:DeluxeSignal;
|
12
|
+
|
13
|
+
[Before]
|
14
|
+
public function setUp():void
|
15
|
+
{
|
16
|
+
completed = new DeluxeSignal(this);
|
17
|
+
}
|
18
|
+
|
19
|
+
[After]
|
20
|
+
public function tearDown():void
|
21
|
+
{
|
22
|
+
completed.removeAll();
|
23
|
+
completed = null;
|
24
|
+
}
|
25
|
+
//////
|
26
|
+
[Test]
|
27
|
+
public function dispatch_extra_args_should_call_listener_with_extra_args():void
|
28
|
+
{
|
29
|
+
completed.add( async.add(onCompleted, 10) );
|
30
|
+
completed.dispatch(22, 'done', new Date());
|
31
|
+
}
|
32
|
+
|
33
|
+
private function onCompleted(a:uint, b:String, c:Date):void
|
34
|
+
{
|
35
|
+
assertEquals(3, arguments.length);
|
36
|
+
assertEquals(22, a);
|
37
|
+
assertEquals('done', b);
|
38
|
+
assertTrue(c is Date);
|
39
|
+
}
|
40
|
+
//////
|
41
|
+
|
42
|
+
}
|
43
|
+
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
package org.osflash.signals
|
2
|
+
{
|
3
|
+
import asunit.asserts.*;
|
4
|
+
import asunit.framework.IAsync;
|
5
|
+
|
6
|
+
public class DeluxeSignalDispatchNoArgsTest
|
7
|
+
{
|
8
|
+
[Inject]
|
9
|
+
public var async:IAsync;
|
10
|
+
|
11
|
+
public var completed:DeluxeSignal;
|
12
|
+
|
13
|
+
[Before]
|
14
|
+
public function setUp():void
|
15
|
+
{
|
16
|
+
completed = new DeluxeSignal(this);
|
17
|
+
}
|
18
|
+
|
19
|
+
[After]
|
20
|
+
public function tearDown():void
|
21
|
+
{
|
22
|
+
completed.removeAll();
|
23
|
+
completed = null;
|
24
|
+
}
|
25
|
+
//////
|
26
|
+
[Test]
|
27
|
+
public function dispatch_no_args_should_call_listener_with_no_args():void
|
28
|
+
{
|
29
|
+
completed.add( async.add(onCompleted, 10) );
|
30
|
+
completed.dispatch();
|
31
|
+
}
|
32
|
+
|
33
|
+
private function onCompleted():void
|
34
|
+
{
|
35
|
+
assertEquals(0, arguments.length);
|
36
|
+
}
|
37
|
+
//////
|
38
|
+
[Test]
|
39
|
+
public function addOnce_in_handler_and_dispatch_should_call_new_listener():void
|
40
|
+
{
|
41
|
+
completed.addOnce( async.add(addOnceInHandler, 10) );
|
42
|
+
completed.dispatch();
|
43
|
+
}
|
44
|
+
|
45
|
+
protected function addOnceInHandler():void
|
46
|
+
{
|
47
|
+
completed.addOnce( async.add(secondAddOnceListener, 10) );
|
48
|
+
completed.dispatch();
|
49
|
+
}
|
50
|
+
|
51
|
+
protected function secondAddOnceListener():void
|
52
|
+
{
|
53
|
+
}
|
54
|
+
}
|
55
|
+
}
|
@@ -0,0 +1,67 @@
|
|
1
|
+
package org.osflash.signals
|
2
|
+
{
|
3
|
+
import asunit.asserts.*;
|
4
|
+
import asunit.framework.IAsync;
|
5
|
+
|
6
|
+
public class DeluxeSignalDispatchNonEventTest
|
7
|
+
{
|
8
|
+
[Inject]
|
9
|
+
public var async:IAsync;
|
10
|
+
|
11
|
+
public var completed:DeluxeSignal;
|
12
|
+
|
13
|
+
[Before]
|
14
|
+
public function setUp():void
|
15
|
+
{
|
16
|
+
completed = new DeluxeSignal(this, Date);
|
17
|
+
}
|
18
|
+
|
19
|
+
[After]
|
20
|
+
public function tearDown():void
|
21
|
+
{
|
22
|
+
completed.removeAll();
|
23
|
+
completed = null;
|
24
|
+
}
|
25
|
+
|
26
|
+
/**
|
27
|
+
* Captures bug where dispatching 0 was considered null.
|
28
|
+
*/
|
29
|
+
[Test]
|
30
|
+
public function dispatch_zero_should_call_listener_with_zero():void
|
31
|
+
{
|
32
|
+
completed = new DeluxeSignal(this, Number);
|
33
|
+
completed.add( async.add(onZero, 10) );
|
34
|
+
completed.dispatch(0);
|
35
|
+
}
|
36
|
+
|
37
|
+
private function onZero(num:Number):void
|
38
|
+
{
|
39
|
+
assertEquals(0, num);
|
40
|
+
}
|
41
|
+
//////
|
42
|
+
[Test]
|
43
|
+
public function dispatch_null_should_call_listener_with_null():void
|
44
|
+
{
|
45
|
+
completed.addOnce( async.add(checkNullDate, 10) );
|
46
|
+
completed.dispatch(null);
|
47
|
+
}
|
48
|
+
|
49
|
+
private function checkNullDate(date:Date):void
|
50
|
+
{
|
51
|
+
assertNull(date);
|
52
|
+
}
|
53
|
+
//////
|
54
|
+
[Test]
|
55
|
+
public function dispatch_null_through_int_DeluxeSignal_should_be_autoconverted_to_zero():void
|
56
|
+
{
|
57
|
+
completed = new DeluxeSignal(int);
|
58
|
+
completed.addOnce( async.add(checkNullConvertedToZero, 10) );
|
59
|
+
completed.dispatch(null);
|
60
|
+
}
|
61
|
+
|
62
|
+
private function checkNullConvertedToZero(intValue:int):void
|
63
|
+
{
|
64
|
+
assertEquals('null was converted to 0', 0, intValue);
|
65
|
+
}
|
66
|
+
}
|
67
|
+
}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
package org.osflash.signals
|
2
|
+
{
|
3
|
+
import asunit.asserts.*;
|
4
|
+
import asunit.framework.IAsync;
|
5
|
+
|
6
|
+
public class DeluxeSignalSplitInterfacesTest
|
7
|
+
{
|
8
|
+
[Inject]
|
9
|
+
public var async:IAsync;
|
10
|
+
|
11
|
+
// Notice the use of the smaller IListeners interface, rather than ISignal.
|
12
|
+
// This makes dispatch() inaccessible unless the Signal is typed to IDispatcher.
|
13
|
+
public var completed:IDeluxeSignal;
|
14
|
+
|
15
|
+
[Before]
|
16
|
+
public function setUp():void
|
17
|
+
{
|
18
|
+
completed = new DeluxeSignal(this);
|
19
|
+
}
|
20
|
+
|
21
|
+
[After]
|
22
|
+
public function tearDown():void
|
23
|
+
{
|
24
|
+
DeluxeSignal(completed).removeAll();
|
25
|
+
completed = null;
|
26
|
+
}
|
27
|
+
//////
|
28
|
+
[Test]
|
29
|
+
public function cast_to_IDispatcher_and_dispatch_should_work():void
|
30
|
+
{
|
31
|
+
completed.addOnce( async.add(onCompleted, 10) );
|
32
|
+
IDispatcher(completed).dispatch();
|
33
|
+
}
|
34
|
+
|
35
|
+
private function onCompleted():void
|
36
|
+
{
|
37
|
+
assertEquals(0, arguments.length);
|
38
|
+
}
|
39
|
+
|
40
|
+
}
|
41
|
+
}
|
@@ -0,0 +1,134 @@
|
|
1
|
+
package org.osflash.signals
|
2
|
+
{
|
3
|
+
import asunit.asserts.*;
|
4
|
+
import asunit.framework.IAsync;
|
5
|
+
|
6
|
+
public class DeluxeSignalTest
|
7
|
+
{
|
8
|
+
[Inject]
|
9
|
+
public var async:IAsync;
|
10
|
+
|
11
|
+
private var completed:DeluxeSignal;
|
12
|
+
|
13
|
+
[Before]
|
14
|
+
public function setUp():void
|
15
|
+
{
|
16
|
+
completed = new DeluxeSignal(this);
|
17
|
+
}
|
18
|
+
|
19
|
+
[After]
|
20
|
+
public function tearDown():void
|
21
|
+
{
|
22
|
+
completed.removeAll();
|
23
|
+
completed = null;
|
24
|
+
}
|
25
|
+
|
26
|
+
[Test]
|
27
|
+
public function add_listener_then_remove_function_not_in_listeners_should_do_nothing():void
|
28
|
+
{
|
29
|
+
completed.add(newEmptyHandler());
|
30
|
+
completed.remove(newEmptyHandler());
|
31
|
+
assertEquals(1, completed.numListeners);
|
32
|
+
}
|
33
|
+
|
34
|
+
private function newEmptyHandler():Function
|
35
|
+
{
|
36
|
+
return function():void {};
|
37
|
+
}
|
38
|
+
|
39
|
+
//////
|
40
|
+
[Test]
|
41
|
+
public function dispatch_2_listeners_1st_listener_removes_itself_then_2nd_listener_is_still_called():void
|
42
|
+
{
|
43
|
+
completed.add(selfRemover);
|
44
|
+
// async.add verifies the second listener is called
|
45
|
+
completed.add(async.add(newEmptyHandler(), 10));
|
46
|
+
completed.dispatch();
|
47
|
+
}
|
48
|
+
|
49
|
+
private function selfRemover():void
|
50
|
+
{
|
51
|
+
completed.remove(selfRemover);
|
52
|
+
}
|
53
|
+
//////
|
54
|
+
[Test]
|
55
|
+
public function dispatch_2_listeners_1st_listener_removes_all_then_2nd_listener_is_still_called():void
|
56
|
+
{
|
57
|
+
completed.add(async.add(allRemover, 10));
|
58
|
+
completed.add(async.add(newEmptyHandler(), 10));
|
59
|
+
completed.dispatch();
|
60
|
+
}
|
61
|
+
|
62
|
+
private function allRemover():void
|
63
|
+
{
|
64
|
+
completed.removeAll();
|
65
|
+
}
|
66
|
+
//////
|
67
|
+
[Test]
|
68
|
+
public function adding_a_listener_during_dispatch_should_not_call_it():void
|
69
|
+
{
|
70
|
+
completed.add(async.add(addListenerDuringDispatch, 10));
|
71
|
+
completed.dispatch();
|
72
|
+
}
|
73
|
+
|
74
|
+
private function addListenerDuringDispatch():void
|
75
|
+
{
|
76
|
+
completed.add(failIfCalled);
|
77
|
+
}
|
78
|
+
|
79
|
+
private function failIfCalled():void
|
80
|
+
{
|
81
|
+
fail("This listener should not be called.");
|
82
|
+
}
|
83
|
+
|
84
|
+
|
85
|
+
//////
|
86
|
+
[Test]
|
87
|
+
public function can_use_anonymous_listeners():void
|
88
|
+
{
|
89
|
+
var listeners:Array = [];
|
90
|
+
|
91
|
+
for ( var i:int = 0; i < 100; i++ )
|
92
|
+
{
|
93
|
+
listeners.push(completed.add(function():void{}));
|
94
|
+
}
|
95
|
+
|
96
|
+
assertTrue("there should be 100 listeners", completed.numListeners == 100);
|
97
|
+
|
98
|
+
for each( var fnt:Function in listeners )
|
99
|
+
{
|
100
|
+
completed.remove(fnt);
|
101
|
+
}
|
102
|
+
assertTrue("all anonymous listeners removed", completed.numListeners == 0);
|
103
|
+
}
|
104
|
+
|
105
|
+
//////
|
106
|
+
[Test]
|
107
|
+
public function can_use_anonymous_listeners_in_addOnce():void
|
108
|
+
{
|
109
|
+
var listeners:Array = [];
|
110
|
+
|
111
|
+
for ( var i:int = 0; i < 100; i++ )
|
112
|
+
{
|
113
|
+
listeners.push(completed.addOnce(function():void{}));
|
114
|
+
}
|
115
|
+
|
116
|
+
assertTrue("there should be 100 listeners", completed.numListeners == 100);
|
117
|
+
|
118
|
+
for each( var fnt:Function in listeners )
|
119
|
+
{
|
120
|
+
completed.remove(fnt);
|
121
|
+
}
|
122
|
+
assertTrue("all anonymous listeners removed", completed.numListeners == 0);
|
123
|
+
}
|
124
|
+
|
125
|
+
//////
|
126
|
+
[Test]
|
127
|
+
public function removed_listener_should_be_returned():void
|
128
|
+
{
|
129
|
+
var listener:Function = completed.add(function():void{});
|
130
|
+
|
131
|
+
assertTrue("Listener is returned", listener == completed.remove(listener));
|
132
|
+
}
|
133
|
+
}
|
134
|
+
}
|
@@ -0,0 +1,129 @@
|
|
1
|
+
package org.osflash.signals
|
2
|
+
{
|
3
|
+
import asunit.asserts.*;
|
4
|
+
import asunit.framework.IAsync;
|
5
|
+
|
6
|
+
import org.osflash.signals.events.GenericEvent;
|
7
|
+
import org.osflash.signals.events.IBubbleEventHandler;
|
8
|
+
import org.osflash.signals.events.IEvent;
|
9
|
+
|
10
|
+
public class DeluxeSignalWithBubblingEventTest implements IBubbleEventHandler
|
11
|
+
{
|
12
|
+
[Inject]
|
13
|
+
public var async:IAsync;
|
14
|
+
|
15
|
+
protected var theParent:IBubbleEventHandler;
|
16
|
+
protected var theChild:Child;
|
17
|
+
protected var theGrandChild:Child;
|
18
|
+
protected var cancelTimeout:Function;
|
19
|
+
|
20
|
+
[Before]
|
21
|
+
public function setUp():void
|
22
|
+
{
|
23
|
+
theParent = this;
|
24
|
+
theChild = new Child(this, 'theChild');
|
25
|
+
theGrandChild = new Child(theChild, 'theGrandChild');
|
26
|
+
}
|
27
|
+
|
28
|
+
[After]
|
29
|
+
public function tearDown():void
|
30
|
+
{
|
31
|
+
theChild = null;
|
32
|
+
theGrandChild = null;
|
33
|
+
cancelTimeout = null;
|
34
|
+
}
|
35
|
+
|
36
|
+
[Test]
|
37
|
+
public function parent_child_relationships():void
|
38
|
+
{
|
39
|
+
assertSame("theChild's parent is this", this, theChild.parent);
|
40
|
+
assertTrue("this can handle bubbling events", this is IBubbleEventHandler);
|
41
|
+
}
|
42
|
+
|
43
|
+
[Test]
|
44
|
+
public function dispatch_bubbling_event_from_theGrandChild_should_bubble_to_parent_IBubbleHandler():void
|
45
|
+
{
|
46
|
+
// If cancelTimeout() isn't called, this test will fail.
|
47
|
+
cancelTimeout = async.add(null, 10);
|
48
|
+
var event:IEvent = new GenericEvent();
|
49
|
+
event.bubbles = true;
|
50
|
+
|
51
|
+
theGrandChild.completed.dispatch(event);
|
52
|
+
}
|
53
|
+
|
54
|
+
public function onEventBubbled(e:IEvent):Boolean
|
55
|
+
{
|
56
|
+
cancelTimeout();
|
57
|
+
assertSame('e.target should be the object that originally dispatched event', theGrandChild, e.target);
|
58
|
+
assertSame('e.currentTarget should be the object receiving the bubbled event', this, e.currentTarget);
|
59
|
+
return false;
|
60
|
+
}
|
61
|
+
|
62
|
+
[Test]
|
63
|
+
public function returning_false_from_onEventBubbled_should_stop_bubbling():void
|
64
|
+
{
|
65
|
+
var bubbleHater:BubbleHater = new BubbleHater();
|
66
|
+
theChild = new Child(bubbleHater, 'bubblePopper');
|
67
|
+
theChild.popsBubbles = true;
|
68
|
+
theGrandChild = new Child(theChild, 'bubbleBlower');
|
69
|
+
|
70
|
+
var bubblingEvent:IEvent = new GenericEvent(true);
|
71
|
+
// Will only complete without error if theChild pops the bubble.
|
72
|
+
theGrandChild.completed.dispatch(bubblingEvent);
|
73
|
+
}
|
74
|
+
|
75
|
+
[Test(expects="flash.errors.IllegalOperationError")]
|
76
|
+
public function returning_true_from_onEventBubbled_should_continue_bubbling():void
|
77
|
+
{
|
78
|
+
var bubbleHater:BubbleHater = new BubbleHater();
|
79
|
+
theChild = new Child(bubbleHater, 'bubblePopper');
|
80
|
+
// Changing popsBubbles to false will fail the test nicely.
|
81
|
+
theChild.popsBubbles = false;
|
82
|
+
theGrandChild = new Child(theChild, 'bubbleBlower');
|
83
|
+
|
84
|
+
var bubblingEvent:IEvent = new GenericEvent(true);
|
85
|
+
// Because theChild didn't pop the bubble, this causes bubbleHater to throw an error.
|
86
|
+
theGrandChild.completed.dispatch(bubblingEvent);
|
87
|
+
}
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
import org.osflash.signals.DeluxeSignal;
|
92
|
+
import org.osflash.signals.events.IBubbleEventHandler;
|
93
|
+
import org.osflash.signals.events.IEvent;
|
94
|
+
|
95
|
+
import flash.errors.IllegalOperationError;
|
96
|
+
|
97
|
+
class Child implements IBubbleEventHandler
|
98
|
+
{
|
99
|
+
public var parent:Object;
|
100
|
+
public var completed:DeluxeSignal;
|
101
|
+
public var name:String;
|
102
|
+
public var popsBubbles:Boolean = false;
|
103
|
+
|
104
|
+
public function Child(parent:Object = null, name:String = '')
|
105
|
+
{
|
106
|
+
this.parent = parent;
|
107
|
+
this.name = name;
|
108
|
+
completed = new DeluxeSignal(this);
|
109
|
+
}
|
110
|
+
|
111
|
+
public function toString():String
|
112
|
+
{
|
113
|
+
return '[Child '+name+']';
|
114
|
+
}
|
115
|
+
|
116
|
+
public function onEventBubbled(event:IEvent):Boolean
|
117
|
+
{
|
118
|
+
return !popsBubbles;
|
119
|
+
}
|
120
|
+
}
|
121
|
+
|
122
|
+
class BubbleHater implements IBubbleEventHandler
|
123
|
+
{
|
124
|
+
public function onEventBubbled(event:IEvent):Boolean
|
125
|
+
{
|
126
|
+
throw new IllegalOperationError('I SAID NO BUBBLES!!!');
|
127
|
+
return false;
|
128
|
+
}
|
129
|
+
}
|
@@ -0,0 +1,84 @@
|
|
1
|
+
package org.osflash.signals
|
2
|
+
{
|
3
|
+
import asunit.asserts.*;
|
4
|
+
import asunit.framework.IAsync;
|
5
|
+
|
6
|
+
import org.osflash.signals.events.GenericEvent;
|
7
|
+
|
8
|
+
public class DeluxeSignalWithCustomEventTest
|
9
|
+
{
|
10
|
+
[Inject]
|
11
|
+
public var async:IAsync;
|
12
|
+
|
13
|
+
public var messaged:DeluxeSignal;
|
14
|
+
|
15
|
+
[Before]
|
16
|
+
public function setUp():void
|
17
|
+
{
|
18
|
+
messaged = new DeluxeSignal(this, MessageEvent);
|
19
|
+
}
|
20
|
+
|
21
|
+
[After]
|
22
|
+
public function tearDown():void
|
23
|
+
{
|
24
|
+
messaged.removeAll();
|
25
|
+
messaged = null;
|
26
|
+
}
|
27
|
+
//////
|
28
|
+
[Test]
|
29
|
+
public function valueClasses_roundtrip_through_constructor():void
|
30
|
+
{
|
31
|
+
assertSame(MessageEvent, messaged.valueClasses[0]);
|
32
|
+
}
|
33
|
+
|
34
|
+
[Test]
|
35
|
+
public function add_one_listener_and_dispatch():void
|
36
|
+
{
|
37
|
+
messaged.add(async.add(onMessage, 50));
|
38
|
+
messaged.dispatch(new MessageEvent('ok'));
|
39
|
+
}
|
40
|
+
|
41
|
+
protected function onMessage(e:MessageEvent):void
|
42
|
+
{
|
43
|
+
assertEquals('source of the event', messaged, e.signal);
|
44
|
+
assertEquals('target of the event', this, e.target);
|
45
|
+
assertEquals('message value in the event', 'ok', e.message);
|
46
|
+
}
|
47
|
+
//////
|
48
|
+
[Test(expects="ArgumentError")]
|
49
|
+
public function dispatch_wrong_event_type_should_throw_ArgumentError():void
|
50
|
+
{
|
51
|
+
messaged.dispatch(new GenericEvent());
|
52
|
+
}
|
53
|
+
|
54
|
+
[Test(expects="ArgumentError")]
|
55
|
+
public function signal_with_eventClass_adding_listener_without_args_should_throw_ArgumentError():void
|
56
|
+
{
|
57
|
+
messaged.add(function():void {});
|
58
|
+
}
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
import org.osflash.signals.events.GenericEvent;
|
63
|
+
import org.osflash.signals.events.IEvent;
|
64
|
+
|
65
|
+
////// PRIVATE CLASSES //////
|
66
|
+
|
67
|
+
|
68
|
+
class MessageEvent extends GenericEvent implements IEvent
|
69
|
+
{
|
70
|
+
public var message:String;
|
71
|
+
|
72
|
+
public function MessageEvent(message:String)
|
73
|
+
{
|
74
|
+
super();
|
75
|
+
this.message = message;
|
76
|
+
}
|
77
|
+
|
78
|
+
override public function clone():IEvent
|
79
|
+
{
|
80
|
+
return new MessageEvent(message);
|
81
|
+
}
|
82
|
+
|
83
|
+
}
|
84
|
+
|