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,267 @@
|
|
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.IEvent;
|
8
|
+
|
9
|
+
import flash.display.Sprite;
|
10
|
+
|
11
|
+
public class SignalTest
|
12
|
+
{
|
13
|
+
[Inject]
|
14
|
+
public var async:IAsync;
|
15
|
+
|
16
|
+
public var completed:Signal;
|
17
|
+
|
18
|
+
[Before]
|
19
|
+
public function setUp():void
|
20
|
+
{
|
21
|
+
completed = new Signal();
|
22
|
+
}
|
23
|
+
|
24
|
+
[After]
|
25
|
+
public function tearDown():void
|
26
|
+
{
|
27
|
+
completed.removeAll();
|
28
|
+
completed = null;
|
29
|
+
}
|
30
|
+
|
31
|
+
[Test]
|
32
|
+
public function numListeners_is_0_after_creation():void
|
33
|
+
{
|
34
|
+
assertEquals(0, completed.numListeners);
|
35
|
+
}
|
36
|
+
|
37
|
+
//////
|
38
|
+
|
39
|
+
[Test]
|
40
|
+
public function dispatch_should_pass_event_to_listener_but_not_set_signal_or_target_properties():void
|
41
|
+
{
|
42
|
+
completed.add(async.add(checkGenericEvent, 10));
|
43
|
+
completed.dispatch(new GenericEvent());
|
44
|
+
}
|
45
|
+
|
46
|
+
protected function checkGenericEvent(e:GenericEvent):void
|
47
|
+
{
|
48
|
+
assertNull('event.signal is not set by Signal', e.signal);
|
49
|
+
assertNull('event.target is not set by Signal', e.target);
|
50
|
+
}
|
51
|
+
|
52
|
+
//////
|
53
|
+
|
54
|
+
[Test]
|
55
|
+
public function add_two_listeners_and_dispatch_should_call_both():void
|
56
|
+
{
|
57
|
+
completed.add(async.add(checkGenericEvent, 10));
|
58
|
+
completed.add(async.add(checkGenericEvent, 10));
|
59
|
+
completed.dispatch(new GenericEvent());
|
60
|
+
}
|
61
|
+
|
62
|
+
//////
|
63
|
+
|
64
|
+
[Test]
|
65
|
+
public function addOnce_and_dispatch_should_remove_listener_automatically():void
|
66
|
+
{
|
67
|
+
completed.addOnce(newEmptyHandler());
|
68
|
+
completed.dispatch(new GenericEvent());
|
69
|
+
assertEquals('there should be no listeners', 0, completed.numListeners);
|
70
|
+
}
|
71
|
+
|
72
|
+
//////
|
73
|
+
|
74
|
+
[Test]
|
75
|
+
public function add_listener_then_remove_then_dispatch_should_not_call_listener():void
|
76
|
+
{
|
77
|
+
completed.add(failIfCalled);
|
78
|
+
completed.remove(failIfCalled);
|
79
|
+
completed.dispatch(new GenericEvent());
|
80
|
+
}
|
81
|
+
|
82
|
+
private function failIfCalled(e:IEvent):void
|
83
|
+
{
|
84
|
+
fail('This event handler should not have been called.');
|
85
|
+
}
|
86
|
+
|
87
|
+
//////
|
88
|
+
|
89
|
+
[Test]
|
90
|
+
public function add_listener_then_remove_function_not_in_listeners_should_do_nothing():void
|
91
|
+
{
|
92
|
+
completed.add(newEmptyHandler());
|
93
|
+
completed.remove(newEmptyHandler());
|
94
|
+
assertEquals(1, completed.numListeners);
|
95
|
+
}
|
96
|
+
|
97
|
+
//////
|
98
|
+
|
99
|
+
[Test]
|
100
|
+
public function add_2_listeners_remove_2nd_then_dispatch_should_call_1st_not_2nd_listener():void
|
101
|
+
{
|
102
|
+
completed.add(async.add(checkGenericEvent, 10));
|
103
|
+
completed.add(failIfCalled);
|
104
|
+
completed.remove(failIfCalled);
|
105
|
+
completed.dispatch(new GenericEvent());
|
106
|
+
}
|
107
|
+
//////
|
108
|
+
[Test]
|
109
|
+
public function add_2_listeners_should_yield_numListeners_of_2():void
|
110
|
+
{
|
111
|
+
completed.add(newEmptyHandler());
|
112
|
+
completed.add(newEmptyHandler());
|
113
|
+
assertEquals(2, completed.numListeners);
|
114
|
+
}
|
115
|
+
|
116
|
+
private function newEmptyHandler():Function
|
117
|
+
{
|
118
|
+
return function(e:*):void {};
|
119
|
+
}
|
120
|
+
|
121
|
+
|
122
|
+
//////
|
123
|
+
[Test]
|
124
|
+
public function add_2_listeners_then_remove_1_should_yield_numListeners_of_1():void
|
125
|
+
{
|
126
|
+
var firstFunc:Function = newEmptyHandler();
|
127
|
+
completed.add(firstFunc);
|
128
|
+
completed.add(newEmptyHandler());
|
129
|
+
|
130
|
+
completed.remove(firstFunc);
|
131
|
+
|
132
|
+
assertEquals(1, completed.numListeners);
|
133
|
+
}
|
134
|
+
|
135
|
+
[Test]
|
136
|
+
public function add_2_listeners_then_removeAll_should_yield_numListeners_of_0():void
|
137
|
+
{
|
138
|
+
completed.add(newEmptyHandler());
|
139
|
+
completed.add(newEmptyHandler());
|
140
|
+
|
141
|
+
completed.removeAll();
|
142
|
+
|
143
|
+
assertEquals(0, completed.numListeners);
|
144
|
+
}
|
145
|
+
|
146
|
+
[Test]
|
147
|
+
public function add_same_listener_twice_should_only_add_it_once():void
|
148
|
+
{
|
149
|
+
var func:Function = newEmptyHandler();
|
150
|
+
completed.add(func);
|
151
|
+
completed.add(func);
|
152
|
+
assertEquals(1, completed.numListeners);
|
153
|
+
}
|
154
|
+
|
155
|
+
[Test]
|
156
|
+
public function addOnce_same_listener_twice_should_only_add_it_once():void
|
157
|
+
{
|
158
|
+
var func:Function = newEmptyHandler();
|
159
|
+
completed.addOnce(func);
|
160
|
+
completed.addOnce(func);
|
161
|
+
assertEquals(1, completed.numListeners);
|
162
|
+
}
|
163
|
+
|
164
|
+
//////
|
165
|
+
[Test]
|
166
|
+
public function dispatch_non_IEvent_without_error():void
|
167
|
+
{
|
168
|
+
completed.addOnce(checkSprite);
|
169
|
+
// Sprite doesn't have a target property,
|
170
|
+
// so if the signal tried to set .target,
|
171
|
+
// an error would be thrown and this test would fail.
|
172
|
+
completed.dispatch(new Sprite());
|
173
|
+
}
|
174
|
+
|
175
|
+
private function checkSprite(sprite:Sprite):void
|
176
|
+
{
|
177
|
+
assertTrue(sprite is Sprite);
|
178
|
+
}
|
179
|
+
//////
|
180
|
+
[Test]
|
181
|
+
public function dispatch_2_listeners_1st_listener_removes_itself_then_2nd_listener_is_still_called():void
|
182
|
+
{
|
183
|
+
completed.add(selfRemover);
|
184
|
+
// async.add verifies the second listener is called
|
185
|
+
completed.add(async.add(newEmptyHandler(), 10));
|
186
|
+
completed.dispatch();
|
187
|
+
}
|
188
|
+
|
189
|
+
private function selfRemover():void
|
190
|
+
{
|
191
|
+
completed.remove(selfRemover);
|
192
|
+
}
|
193
|
+
//////
|
194
|
+
[Test]
|
195
|
+
public function dispatch_2_listeners_1st_listener_removes_all_then_2nd_listener_is_still_called():void
|
196
|
+
{
|
197
|
+
completed.add(async.add(allRemover, 10));
|
198
|
+
completed.add(async.add(newEmptyHandler(), 10));
|
199
|
+
completed.dispatch();
|
200
|
+
}
|
201
|
+
|
202
|
+
//////
|
203
|
+
[Test]
|
204
|
+
public function can_use_anonymous_listeners():void
|
205
|
+
{
|
206
|
+
var listeners:Array = [];
|
207
|
+
|
208
|
+
for ( var i:int = 0; i < 100; i++ )
|
209
|
+
{
|
210
|
+
listeners.push(completed.add(function():void{}));
|
211
|
+
}
|
212
|
+
|
213
|
+
assertTrue("there should be 100 listeners", completed.numListeners == 100);
|
214
|
+
|
215
|
+
for each( var fnt:Function in listeners )
|
216
|
+
{
|
217
|
+
completed.remove(fnt);
|
218
|
+
}
|
219
|
+
assertTrue("all anonymous listeners removed", completed.numListeners == 0);
|
220
|
+
}
|
221
|
+
|
222
|
+
//////
|
223
|
+
[Test]
|
224
|
+
public function can_use_anonymous_listeners_in_addOnce():void
|
225
|
+
{
|
226
|
+
var listeners:Array = [];
|
227
|
+
|
228
|
+
for ( var i:int = 0; i < 100; i++ )
|
229
|
+
{
|
230
|
+
listeners.push(completed.addOnce(function():void{}));
|
231
|
+
}
|
232
|
+
|
233
|
+
assertTrue("there should be 100 listeners", completed.numListeners == 100);
|
234
|
+
|
235
|
+
for each( var fnt:Function in listeners )
|
236
|
+
{
|
237
|
+
completed.remove(fnt);
|
238
|
+
}
|
239
|
+
assertTrue("all anonymous listeners removed", completed.numListeners == 0);
|
240
|
+
}
|
241
|
+
|
242
|
+
private function allRemover():void
|
243
|
+
{
|
244
|
+
completed.removeAll();
|
245
|
+
}
|
246
|
+
//////
|
247
|
+
[Test]
|
248
|
+
public function adding_a_listener_during_dispatch_should_not_call_it():void
|
249
|
+
{
|
250
|
+
completed.add(async.add(addListenerDuringDispatch, 10));
|
251
|
+
completed.dispatch(new GenericEvent());
|
252
|
+
}
|
253
|
+
|
254
|
+
private function addListenerDuringDispatch():void
|
255
|
+
{
|
256
|
+
completed.add(failIfCalled);
|
257
|
+
}
|
258
|
+
//////
|
259
|
+
[Test]
|
260
|
+
public function removed_listener_should_be_returned():void
|
261
|
+
{
|
262
|
+
var listener:Function = completed.add(function():void{});
|
263
|
+
|
264
|
+
assertTrue("Listener is returned", listener == completed.remove(listener));
|
265
|
+
}
|
266
|
+
}
|
267
|
+
}
|
@@ -0,0 +1,107 @@
|
|
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 SignalWithCustomEventTest
|
9
|
+
{
|
10
|
+
[Inject]
|
11
|
+
public var async:IAsync;
|
12
|
+
|
13
|
+
public var messaged:Signal;
|
14
|
+
|
15
|
+
[Before]
|
16
|
+
public function setUp():void
|
17
|
+
{
|
18
|
+
messaged = new Signal(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('message value in the event', 'ok', e.message);
|
44
|
+
}
|
45
|
+
//////
|
46
|
+
[Test(expects="ArgumentError")]
|
47
|
+
public function dispatch_wrong_event_type_should_throw_ArgumentError():void
|
48
|
+
{
|
49
|
+
messaged.dispatch(new GenericEvent());
|
50
|
+
}
|
51
|
+
|
52
|
+
[Test(expects="ArgumentError")]
|
53
|
+
public function signal_with_eventClass_adding_listener_without_args_should_throw_ArgumentError():void
|
54
|
+
{
|
55
|
+
messaged.add(function():void {});
|
56
|
+
}
|
57
|
+
|
58
|
+
[Test(expects="ArgumentError")]
|
59
|
+
public function constructing_signal_with_non_class_should_throw_ArgumentError():void
|
60
|
+
{
|
61
|
+
new Signal(new Date());
|
62
|
+
}
|
63
|
+
|
64
|
+
[Test(expects="ArgumentError")]
|
65
|
+
public function constructing_signal_with_two_nulls_should_throw_ArgumentError():void
|
66
|
+
{
|
67
|
+
new Signal(null, null);
|
68
|
+
}
|
69
|
+
|
70
|
+
[Test(expects="ArgumentError")]
|
71
|
+
public function constructing_signal_with_class_and_non_class_should_throw_ArgumentError():void
|
72
|
+
{
|
73
|
+
new Signal(Date, 42);
|
74
|
+
}
|
75
|
+
|
76
|
+
[Test(expects="ArgumentError")]
|
77
|
+
public function add_listener_with_fewer_args_than_valueClasses_should_throw_ArgumentError():void
|
78
|
+
{
|
79
|
+
var signal:Signal = new Signal(Date, Array);
|
80
|
+
signal.add( function(date:Date):void { } );
|
81
|
+
}
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
import org.osflash.signals.events.GenericEvent;
|
86
|
+
import org.osflash.signals.events.IEvent;
|
87
|
+
|
88
|
+
////// PRIVATE CLASSES //////
|
89
|
+
|
90
|
+
|
91
|
+
class MessageEvent extends GenericEvent implements IEvent
|
92
|
+
{
|
93
|
+
public var message:String;
|
94
|
+
|
95
|
+
public function MessageEvent(message:String)
|
96
|
+
{
|
97
|
+
super();
|
98
|
+
this.message = message;
|
99
|
+
}
|
100
|
+
|
101
|
+
override public function clone():IEvent
|
102
|
+
{
|
103
|
+
return new MessageEvent(message);
|
104
|
+
}
|
105
|
+
|
106
|
+
}
|
107
|
+
|
@@ -0,0 +1,63 @@
|
|
1
|
+
package org.osflash.signals.natives
|
2
|
+
{
|
3
|
+
import asunit.asserts.*;
|
4
|
+
|
5
|
+
import flash.display.Sprite;
|
6
|
+
import flash.events.Event;
|
7
|
+
|
8
|
+
public class AmbiguousRelationshipInNativeSignalTest
|
9
|
+
{
|
10
|
+
private var target:Sprite;
|
11
|
+
|
12
|
+
private var instance:NativeSignal;
|
13
|
+
|
14
|
+
[Before]
|
15
|
+
public function setUp():void
|
16
|
+
{
|
17
|
+
target = new Sprite();
|
18
|
+
instance = new NativeSignal(target, Event.CHANGE);
|
19
|
+
}
|
20
|
+
|
21
|
+
[After]
|
22
|
+
public function tearDown():void
|
23
|
+
{
|
24
|
+
instance = null;
|
25
|
+
}
|
26
|
+
|
27
|
+
[Test(expects="flash.errors.IllegalOperationError")]
|
28
|
+
public function add_then_addOnce_throws_error():void
|
29
|
+
{
|
30
|
+
instance.add(failIfCalled);
|
31
|
+
instance.addOnce(failIfCalled);
|
32
|
+
}
|
33
|
+
|
34
|
+
[Test(expects="flash.errors.IllegalOperationError")]
|
35
|
+
public function addOnce_then_add_should_throw_error():void
|
36
|
+
{
|
37
|
+
instance.addOnce(failIfCalled);
|
38
|
+
instance.add(failIfCalled);
|
39
|
+
}
|
40
|
+
|
41
|
+
[Test]
|
42
|
+
public function add_then_add_should_not_throw_error():void
|
43
|
+
{
|
44
|
+
instance.add(failIfCalled);
|
45
|
+
instance.add(failIfCalled);
|
46
|
+
assertEquals(1, instance.numListeners);
|
47
|
+
}
|
48
|
+
|
49
|
+
[Test]
|
50
|
+
public function addOnce_then_addOnce_should_not_throw_error():void
|
51
|
+
{
|
52
|
+
instance.addOnce(failIfCalled);
|
53
|
+
instance.addOnce(failIfCalled);
|
54
|
+
assertEquals(1, instance.numListeners);
|
55
|
+
}
|
56
|
+
|
57
|
+
private function failIfCalled(event:Event):void
|
58
|
+
{
|
59
|
+
fail("if this listener is called, something horrible is going on");
|
60
|
+
}
|
61
|
+
|
62
|
+
}
|
63
|
+
}
|
@@ -0,0 +1,100 @@
|
|
1
|
+
package org.osflash.signals.natives
|
2
|
+
{
|
3
|
+
import asunit.asserts.*;
|
4
|
+
import asunit.framework.IAsync;
|
5
|
+
|
6
|
+
import org.osflash.signals.IDeluxeSignal;
|
7
|
+
|
8
|
+
import flash.display.Sprite;
|
9
|
+
import flash.events.MouseEvent;
|
10
|
+
|
11
|
+
public class NativeMappedSignalBoundaryUseTest
|
12
|
+
{
|
13
|
+
[Inject]
|
14
|
+
public var async:IAsync;
|
15
|
+
|
16
|
+
private var signalArrayOfFunctions:NativeMappedSignal;
|
17
|
+
private var signalPassArray:NativeMappedSignal;
|
18
|
+
private var signalPassArrayThroughFunction:NativeMappedSignal;
|
19
|
+
private var sprite:Sprite;
|
20
|
+
private const EventType:String = MouseEvent.CLICK;
|
21
|
+
private const func1:Function = function ():String { return 'mapped arg 1'; };
|
22
|
+
private const func2:Function = function ():String { return 'mapped arg 2'; };
|
23
|
+
private const MappedArray:Array = [0, 1];
|
24
|
+
|
25
|
+
[Before]
|
26
|
+
public function setUp():void
|
27
|
+
{
|
28
|
+
sprite = new Sprite();
|
29
|
+
signalArrayOfFunctions = new NativeMappedSignal(sprite, EventType).mapTo(func1, func2);
|
30
|
+
signalPassArray = new NativeMappedSignal(sprite, EventType).mapTo(MappedArray);
|
31
|
+
signalPassArrayThroughFunction = new NativeMappedSignal(sprite, EventType, MouseEvent, Array).mapTo(
|
32
|
+
function ():Array {
|
33
|
+
return MappedArray;
|
34
|
+
}
|
35
|
+
);
|
36
|
+
}
|
37
|
+
|
38
|
+
[After]
|
39
|
+
public function tearDown():void
|
40
|
+
{
|
41
|
+
signalArrayOfFunctions.removeAll();
|
42
|
+
signalArrayOfFunctions = null;
|
43
|
+
signalPassArray.removeAll();
|
44
|
+
signalPassArray = null;
|
45
|
+
signalPassArrayThroughFunction.removeAll();
|
46
|
+
signalPassArrayThroughFunction = null;
|
47
|
+
}
|
48
|
+
|
49
|
+
[Test]
|
50
|
+
public function testInstantiated():void
|
51
|
+
{
|
52
|
+
assertFalse('sprite has no click event listener to start', sprite.hasEventListener(EventType));
|
53
|
+
|
54
|
+
assertTrue("NativeMappedSignal instantiated", signalArrayOfFunctions is NativeMappedSignal);
|
55
|
+
assertTrue('implements ISignal', signalArrayOfFunctions is IDeluxeSignal);
|
56
|
+
assertSame('has no value classes', 0, signalArrayOfFunctions.valueClasses.length);
|
57
|
+
|
58
|
+
assertTrue("NativeMappedSignal instantiated", signalPassArray is NativeMappedSignal);
|
59
|
+
assertTrue('implements IDeluxeSignal', signalPassArray is IDeluxeSignal);
|
60
|
+
assertSame('has no value classed', 0, signalPassArray.valueClasses.length);
|
61
|
+
|
62
|
+
assertTrue("NativeMappedSignal instantiated", signalPassArrayThroughFunction is NativeMappedSignal);
|
63
|
+
assertTrue('implements IDeluxeSignal', signalPassArrayThroughFunction is IDeluxeSignal);
|
64
|
+
assertSame('has only one value class', 1, signalPassArrayThroughFunction.valueClasses.length);
|
65
|
+
assertSame('single value class is of type Array', Array, signalPassArrayThroughFunction.valueClasses[0]);
|
66
|
+
}
|
67
|
+
//////
|
68
|
+
[Test]
|
69
|
+
public function signal_array_of_functions_add_then_callback_called():void
|
70
|
+
{
|
71
|
+
signalArrayOfFunctions.add( async.add(callbackTwoFunctions, 10) );
|
72
|
+
sprite.dispatchEvent(new MouseEvent(EventType));
|
73
|
+
}
|
74
|
+
|
75
|
+
private function callbackTwoFunctions(argFunc1:Function, argFunc2:Function):void
|
76
|
+
{
|
77
|
+
assertSame(func1, argFunc1);
|
78
|
+
assertSame(func2, argFunc2);
|
79
|
+
}
|
80
|
+
|
81
|
+
[Test]
|
82
|
+
public function signal_pass_array_add_then_array_callback_should_be_called():void
|
83
|
+
{
|
84
|
+
signalPassArray.add( async.add(callbackArrayAsArg, 10) );
|
85
|
+
sprite.dispatchEvent(new MouseEvent(EventType));
|
86
|
+
}
|
87
|
+
|
88
|
+
private function callbackArrayAsArg(argArray:Array):void
|
89
|
+
{
|
90
|
+
assertSame(MappedArray, argArray);
|
91
|
+
}
|
92
|
+
|
93
|
+
[Test]
|
94
|
+
public function signal_pass_array_through_function_add_then_array_callback_should_be_called():void
|
95
|
+
{
|
96
|
+
signalPassArrayThroughFunction.add( async.add(callbackArrayAsArg, 10) );
|
97
|
+
sprite.dispatchEvent(new MouseEvent(EventType));
|
98
|
+
}
|
99
|
+
}
|
100
|
+
}
|
@@ -0,0 +1,78 @@
|
|
1
|
+
package org.osflash.signals.natives
|
2
|
+
{
|
3
|
+
import asunit.framework.IAsync;
|
4
|
+
|
5
|
+
import flash.display.Sprite;
|
6
|
+
import flash.events.MouseEvent;
|
7
|
+
|
8
|
+
public class NativeMappedSignalDefaultsTest
|
9
|
+
{
|
10
|
+
[Inject]
|
11
|
+
public var async:IAsync;
|
12
|
+
|
13
|
+
private var signalDefault:NativeMappedSignal;
|
14
|
+
private var signalDefaultWithMappingObject:NativeMappedSignal;
|
15
|
+
private var signalDefaultWithMappingFunction:NativeMappedSignal;
|
16
|
+
private var signalWithValueClassesWithoutMappingFunction:NativeMappedSignal;
|
17
|
+
private var sprite:Sprite;
|
18
|
+
private const EventType:String = MouseEvent.CLICK;
|
19
|
+
private const MappedObject:String = "mapped " + EventType;
|
20
|
+
|
21
|
+
[Before]
|
22
|
+
public function setUp():void
|
23
|
+
{
|
24
|
+
sprite = new Sprite();
|
25
|
+
signalDefault = new NativeMappedSignal(sprite, EventType);
|
26
|
+
signalDefaultWithMappingObject = new NativeMappedSignal(sprite, EventType).mapTo(MappedObject);
|
27
|
+
signalDefaultWithMappingFunction = new NativeMappedSignal(sprite, EventType).mapTo(
|
28
|
+
function ():String {
|
29
|
+
return MappedObject;
|
30
|
+
}
|
31
|
+
);
|
32
|
+
signalWithValueClassesWithoutMappingFunction = new NativeMappedSignal(sprite, EventType, MouseEvent, String);
|
33
|
+
}
|
34
|
+
|
35
|
+
[After]
|
36
|
+
public function tearDown():void
|
37
|
+
{
|
38
|
+
signalDefault.removeAll();
|
39
|
+
signalDefault = null;
|
40
|
+
signalDefaultWithMappingObject.removeAll();
|
41
|
+
signalDefaultWithMappingObject = null;
|
42
|
+
signalDefaultWithMappingFunction.removeAll();
|
43
|
+
signalDefaultWithMappingFunction = null;
|
44
|
+
signalWithValueClassesWithoutMappingFunction.removeAll();
|
45
|
+
signalWithValueClassesWithoutMappingFunction = null;
|
46
|
+
}
|
47
|
+
|
48
|
+
//////
|
49
|
+
[Test]
|
50
|
+
public function signal_default_add_then_emptyCallback_should_be_called():void
|
51
|
+
{
|
52
|
+
signalDefault.add( async.add(emptyCallback, 10) );
|
53
|
+
sprite.dispatchEvent(new MouseEvent(EventType));
|
54
|
+
}
|
55
|
+
|
56
|
+
private function emptyCallback():void {}
|
57
|
+
|
58
|
+
[Test]
|
59
|
+
public function signal_default_with_mapped_object_add_then_emptyCallback_should_be_called():void
|
60
|
+
{
|
61
|
+
signalDefaultWithMappingObject.add( async.add(emptyCallback, 10) );
|
62
|
+
sprite.dispatchEvent(new MouseEvent(EventType));
|
63
|
+
}
|
64
|
+
|
65
|
+
[Test]
|
66
|
+
public function signal_default_with_mapped_function_add_then_emptyCallback_should_be_called():void
|
67
|
+
{
|
68
|
+
signalDefaultWithMappingFunction.add( async.add(emptyCallback, 10) );
|
69
|
+
sprite.dispatchEvent(new MouseEvent(EventType));
|
70
|
+
}
|
71
|
+
|
72
|
+
[Test(expects="ArgumentError")]
|
73
|
+
public function signal_with_value_classes_without_mapping_function():void
|
74
|
+
{
|
75
|
+
signalWithValueClassesWithoutMappingFunction.dispatch(new MouseEvent(EventType));
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|