|
From: <acl...@us...> - 2006-10-14 21:06:17
|
Revision: 603
http://svn.sourceforge.net/asapframework/?rev=603&view=rev
Author: aclemens
Date: 2006-10-14 14:06:03 -0700 (Sat, 14 Oct 2006)
Log Message:
-----------
new unit tests
Modified Paths:
--------------
trunk/asapframework/tests/unit/includes/testlist.as
trunk/asapframework/tests/unit/tests/org/asapframework/util/watcher/WatcherTest.as
Added Paths:
-----------
trunk/asapframework/tests/unit/tests/org/asapframework/util/FrameDelayTest.as
Modified: trunk/asapframework/tests/unit/includes/testlist.as
===================================================================
--- trunk/asapframework/tests/unit/includes/testlist.as 2006-10-14 21:02:33 UTC (rev 602)
+++ trunk/asapframework/tests/unit/includes/testlist.as 2006-10-14 21:06:03 UTC (rev 603)
@@ -1,4 +1,4 @@
-/*
+
// data
org.asapframework.data.array.ArrayEnumeratorTest; // complete
org.asapframework.data.array.TraverseArrayEnumeratorTest; // complete
@@ -10,11 +10,12 @@
org.asapframework.util.MovieClipUtilsTest; // complete
org.asapframework.util.PointUtilsTest; // complete
org.asapframework.util.RectangleUtilsTest; // complete
+org.asapframework.util.FrameDelayTest; // complete
// util.types
org.asapframework.util.types.PointTest; // complete
org.asapframework.util.types.RectangleTest; // complete
-*/
// util.watch
-org.asapframework.util.watcher.WatcherTest; // in progress
\ No newline at end of file
+org.asapframework.util.watcher.WatcherTest; // in progress
+
Added: trunk/asapframework/tests/unit/tests/org/asapframework/util/FrameDelayTest.as
===================================================================
--- trunk/asapframework/tests/unit/tests/org/asapframework/util/FrameDelayTest.as (rev 0)
+++ trunk/asapframework/tests/unit/tests/org/asapframework/util/FrameDelayTest.as 2006-10-14 21:06:03 UTC (rev 603)
@@ -0,0 +1,39 @@
+// testlib classes
+import org.as2lib.test.unit.TestCase;
+import org.as2lib.test.mock.MockControl;
+
+// ASAP classes
+import org.asapframework.util.*;
+
+
+class org.asapframework.util.FrameDelayTest extends TestCase {
+
+ private static var ALL_METHODS_CALLED_COUNT:Number = 3;
+ private static var sMethodsCalledCount:Number = 0;
+ private static var sCallTestCalled:Boolean = false;
+
+ public function testNew () : Void {
+ sMethodsCalledCount++;
+ pause();
+ var fd:FrameDelay = new FrameDelay(this, callTest);
+ var fd:FrameDelay = new FrameDelay(this, assertCallTest, [], 2);
+ }
+
+ public function testResult () : Void {
+ assertTrue("FrameDelayTest testResult", sMethodsCalledCount == ALL_METHODS_CALLED_COUNT);
+ }
+
+ // PRIVATE METHODS
+
+ private function callTest () : Void {
+ sMethodsCalledCount++;
+ sCallTestCalled = true;
+ }
+
+ private function assertCallTest () : Void {
+ sMethodsCalledCount++;
+ resume();
+ assertTrue("FrameDelayTest assertCallTest", sCallTestCalled == true);
+ }
+
+}
Modified: trunk/asapframework/tests/unit/tests/org/asapframework/util/watcher/WatcherTest.as
===================================================================
--- trunk/asapframework/tests/unit/tests/org/asapframework/util/watcher/WatcherTest.as 2006-10-14 21:02:33 UTC (rev 602)
+++ trunk/asapframework/tests/unit/tests/org/asapframework/util/watcher/WatcherTest.as 2006-10-14 21:06:03 UTC (rev 603)
@@ -9,86 +9,92 @@
import org.asapframework.util.actionqueue.ActionQueue;
import org.asapframework.util.actionqueue.AQFade;
+/**
+This test is in package 'watcher' instead of 'watch' because as2lib's testing framework somehow parses the package path wrong.
+*/
class org.asapframework.util.watcher.WatcherTest extends TestCase {
- private static var sCounter1:Number = 0;
+ private static var ALL_METHODS_CALLED_COUNT:Number = 7;
+ private static var sMethodsCalledCount:Number = 0;
+ private static var sFrameDelayCount:Number = 1;
+
+ private static var sMethodActCalled:Number = 0;
private static var RESULT_COUNTER_1:Number = 1;
- private static var sCounter2:Number = 0;
+ private static var sGetMemberCountWithFunctionReferenceCalled:Number = 0;
private static var RESULT_COUNTER_2:Number = 1;
- private static var sCounter3:Number = 0; // for test 3
- private static var sValue5:Number = 0; // for test 5
-
+ private static var sAlphaAfterFadeOut:Number = 10;
/**
Test function call.
Test isBusy()
*/
- public function testIsBusy () : Void {
+ public function testAfterMethod () : Void {
+ sMethodsCalledCount++;
+
var family:Object = new Object();
- family.memberCount = 2;
+ family.memberCount = 0;
family.birth = function () {
family.memberCount++;
}
family.getMemberCount = function () {
return family.memberCount;
}
- var birthControl:Object = new Object();
- birthControl.act = function () {
- sCounter1++;
- }
-
- var watcher:Watcher = new Watcher(family, "getMemberCount", 5, 1/31);
- watcher.setAfterMethod(birthControl, "act", true);
+
+ // watch until getMemberCount returns 5, watch each 1/31 second
+ var watcher:Watcher = new Watcher(family, family.getMemberCount, 2, 1/31);
+ // after watching, call method 'act'
+ watcher.setAfterMethod(this, afterMethodHandler);
watcher.start();
+ pause();
+
family.birth();
- assertTrue("WatcherTest doTest1 isBusy 1", watcher.isBusy());
+ assertTrue("WatcherTest testAfterMethod isBusy", watcher.isBusy());
family.birth();
- family.birth();
- new FrameDelay(this, evaluateWatcher1, [true, watcher], 20 );
+
+ new FrameDelay(this, evaluateAfterMethodWatcher, [watcher], sFrameDelayCount++ );
}
/**
As test 1 but now with function reference and parameters
*/
- public function testIsBusyWithFunctionReferences () : Void {
+ public function testAfterMethodWithCallbackParams () : Void {
+ sMethodsCalledCount++;
var family:Object = new Object();
- family.memberCount = 2;
+ family.memberCount = 0;
family.birth = function () {
family.memberCount++;
}
- family.toString = function () { return "family"; }
family.getMemberCount = function (inCheck:String) {
if (inCheck == "thewholelot") {
return this.memberCount;
}
return 0;
}
- var birthControl:Object = new Object();
- birthControl.act = function () {
- sCounter2++;
- }
- var watcher:Watcher = new Watcher(family, family.getMemberCount, 5, 1/31, true, "thewholelot");
- watcher.setAfterMethod(birthControl, birthControl.act, true);
+ var watcher:Watcher = new Watcher(family, family.getMemberCount, 2, 1/31, true, "thewholelot");
+ watcher.setAfterMethod(this, afterMethodHandlerWithCallbackParams);
watcher.start();
+ pause();
+
family.birth();
- assertTrue("WatcherTest doTest2 isBusy 1", watcher.isBusy());
+ assertTrue("WatcherTest testAfterMethodWithCallbackParams isBusy", watcher.isBusy());
family.birth();
- family.birth();
- new FrameDelay(this, evaluateWatcher2, [true, watcher], 20 );
+
+ new FrameDelay(this, evaluateAfterMethodWithCallbackParamsWatcher, [ watcher], sFrameDelayCount++ );
}
/**
Test a variable watch
*/
public function testVariable () : Void {
+ sMethodsCalledCount++;
var mc:MovieClip = _level0.createEmptyMovieClip("WatcherTest_doTest3_box", _level0.getNextHighestDepth());
MovieClipUtils.drawBox(mc, 0, 0, 100, 50, [0, 0xff0000, 100]);
@@ -96,13 +102,14 @@
mc._y = 100;
var watcher:Watcher = new Watcher(mc, "_alpha", 0, 1/31);
- watcher.setAfterMethod(this, "test2AfterZero", true);
watcher.start();
+ pause();
+
var queue:ActionQueue = new ActionQueue();
queue.addAction( AQFade.fade, mc, 1, null, 0 );
queue.addPause(1);
- queue.addAction( this, "evaluateWatcher3", 1, true );
+ queue.addAction( this, "evaluateTestVariableWatcher", watcher, mc);
queue.run();
}
@@ -110,68 +117,107 @@
Start and stopping
*/
public function testStartStopRestart () : Void {
- var watcher:Watcher = new Watcher(null, null, null, 1/12);
- assertFalse("WatcherTest doTest4 isBusy 1", watcher.isBusy());
+ sMethodsCalledCount++;
+
+ var watcher:Watcher = new Watcher();
+ watcher.setIntervalDuration(1/12);
+ assertFalse("WatcherTest testStartStopRestart isBusy 1", watcher.isBusy());
watcher.start();
- assertTrue("WatcherTest doTest4 isBusy 2", watcher.isBusy());
+ assertTrue("WatcherTest testStartStopRestart isBusy 2", watcher.isBusy());
watcher.stop();
- assertFalse("WatcherTest doTest4 isBusy 3", watcher.isBusy());
+ assertFalse("WatcherTest testStartStopRestart isBusy 3", watcher.isBusy());
watcher.restart();
- assertTrue("WatcherTest doTest4 isBusy 4", watcher.isBusy());
+ assertTrue("WatcherTest testStartStopRestart isBusy 4", watcher.isBusy());
watcher.stop();
- assertFalse("WatcherTest doTest4 isBusy 5", watcher.isBusy());
+ assertFalse("WatcherTest testStartStopRestart isBusy 5", watcher.isBusy());
}
/**
Callback
*/
public function testSetCallback () : Void {
+ sMethodsCalledCount++;
- var mc:MovieClip = _level0.createEmptyMovieClip("WatcherTest_doTest5_box", _level0.getNextHighestDepth());
+ var mc:MovieClip = _level0.createEmptyMovieClip("testSetCallback", _level0.getNextHighestDepth());
MovieClipUtils.drawBox(mc, 0, 0, 100, 50, [0, 0xff0000, 100]);
mc._x = 300;
mc._y = 100;
- var watcher:Watcher = new Watcher(mc, "_alpha", 0, 1/31);
- watcher.setCallback(this, "doTest5Callback");
+ var watcher:Watcher = new Watcher(mc, "_alpha", sAlphaAfterFadeOut, 1/31);
+ watcher.setCallback(this, callbackHandler);
watcher.start();
+ pause();
+
var queue:ActionQueue = new ActionQueue();
queue.addAction( AQFade.fade, mc, 1, null, 0 );
- queue.addPause(1);
- queue.addAction( this, "evaluateWatcher5", 0, true );
+ queue.addPause(.1);
+ queue.addAction( this, evaluateTestSetCallbackWatcher, 0, true, mc );
queue.run();
}
+ public function testResult () : Void {
+ assertTrue("FrameDelayTest testResult", sMethodsCalledCount == ALL_METHODS_CALLED_COUNT);
+ }
+
+ // PRIVATE METHODS
+
+ private function afterMethodHandler () : Void {
+ sMethodsCalledCount++;
+ sMethodActCalled++;
+ }
+
+ private function afterMethodHandlerWithCallbackParams () : Void {
+ sMethodsCalledCount++;
+ sGetMemberCountWithFunctionReferenceCalled++;
+ }
+
/**
*/
- private function evaluateWatcher1 (inWatcher:Watcher) : Void {
- assertTrue("WatcherTest evaluateWatcher1", sCounter1 == RESULT_COUNTER_1);
- assertFalse("WatcherTest doTest1 isBusy 2", inWatcher.isBusy());
+ private function evaluateAfterMethodWatcher (inWatcher:Watcher) : Void {
+ resume();
+
+ assertTrue("WatcherTest evaluateAfterMethodWatcher", sMethodActCalled == RESULT_COUNTER_1);
+ assertFalse("WatcherTest evaluateAfterMethodWatcher isBusy", inWatcher.isBusy());
+ inWatcher.stop();
}
/**
*/
- private function evaluateWatcher2 (inWatcher:Watcher) : Void {
- assertTrue("WatcherTest evaluateWatcher2", sCounter2 == RESULT_COUNTER_2);
- assertFalse("WatcherTest doTest2 isBusy 2", inWatcher.isBusy());
+ private function evaluateAfterMethodWithCallbackParamsWatcher (inWatcher:Watcher) : Void {
+ resume();
+
+ assertTrue("WatcherTest evaluateAfterMethodWithCallbackParamsWatcher", sGetMemberCountWithFunctionReferenceCalled == RESULT_COUNTER_2);
+ assertFalse("WatcherTest evaluateAfterMethodWithCallbackParamsWatcher isBusy", inWatcher.isBusy());
+ inWatcher.stop();
}
+ /**
+
+ */
+ private function evaluateTestVariableWatcher (inWatcher:Watcher, inClip:MovieClip) : Void {
+ resume();
+ assertFalse("WatcherTest evaluateTestVariableWatcher isBusy", inWatcher.isBusy());
+ inClip.removeMovieClip;
+ }
+
/**
*/
- public function doTest5Callback (inAlpha:Number) : Void {
- sValue5 = inAlpha;
+ public function callbackHandler (inAlpha:Number) : Void {
+ sAlphaAfterFadeOut = inAlpha;
}
/**
*/
- public function evaluateWatcher5 (inValue:Number, inResult:Boolean) : Void {
- var result:Boolean = (inValue == sValue5);
- assertTrue("WatcherTest evaluateWatcher5", result == inResult);
+ public function evaluateTestSetCallbackWatcher (inValue:Number, inResult:Boolean, inClip:MovieClip) : Void {
+ resume();
+ var result:Boolean = (inValue == sAlphaAfterFadeOut);
+ assertTrue("WatcherTest evaluateTestSetCallbackWatcher", result == inResult);
+ inClip.removeMovieClip;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|