|
From: <acl...@us...> - 2006-10-14 00:06:58
|
Revision: 599
http://svn.sourceforge.net/asapframework/?rev=599&view=rev
Author: aclemens
Date: 2006-10-13 17:06:54 -0700 (Fri, 13 Oct 2006)
Log Message:
-----------
test: Watcher in package watcher
Added Paths:
-----------
trunk/asapframework/tests/unit/tests/org/asapframework/util/watcher/
trunk/asapframework/tests/unit/tests/org/asapframework/util/watcher/WatcherTest.as
Removed Paths:
-------------
trunk/asapframework/tests/unit/tests/org/asapframework/util/WatcherTest.as
Deleted: trunk/asapframework/tests/unit/tests/org/asapframework/util/WatcherTest.as
===================================================================
--- trunk/asapframework/tests/unit/tests/org/asapframework/util/WatcherTest.as 2006-10-14 00:04:30 UTC (rev 598)
+++ trunk/asapframework/tests/unit/tests/org/asapframework/util/WatcherTest.as 2006-10-14 00:06:54 UTC (rev 599)
@@ -1,177 +0,0 @@
-// testlib classes
-import org.as2lib.test.unit.TestCase;
-import org.as2lib.test.mock.MockControl;
-
-// ASAP classes
-import org.asapframework.util.watch.Watcher;
-import org.asapframework.util.FrameDelay;
-import org.asapframework.util.MovieClipUtils;
-import org.asapframework.util.actionqueue.ActionQueue;
-import org.asapframework.util.actionqueue.AQFade;
-
-
-class org.asapframework.util.WatcherTest extends TestCase {
-
- private static var sCounter1:Number = 0;
- private static var RESULT_COUNTER_1:Number = 1;
-
- private static var sCounter2: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
-
-
-
- /**
- Test function call.
- Test isBusy()
- */
- public function testIsBusy () : Void {
- var family:Object = new Object();
- family.memberCount = 2;
- 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);
- watcher.start();
-
- family.birth();
- assertTrue("WatcherTest doTest1 isBusy 1", watcher.isBusy());
- family.birth();
- family.birth();
- new FrameDelay(this, evaluateWatcher1, [true, watcher], 20 );
- }
-
- /**
- As test 1 but now with function reference and parameters
- */
- public function testIsBusyWithFunctionReferences () : Void {
-
- var family:Object = new Object();
- family.memberCount = 2;
- 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);
- watcher.start();
-
- family.birth();
- assertTrue("WatcherTest doTest2 isBusy 1", watcher.isBusy());
- family.birth();
- family.birth();
- new FrameDelay(this, evaluateWatcher2, [true, watcher], 20 );
- }
-
- /**
- Test a variable watch
- */
- public function testVariable () : Void {
-
- var mc:MovieClip = _level0.createEmptyMovieClip("WatcherTest_doTest3_box", _level0.getNextHighestDepth());
- MovieClipUtils.drawBox(mc, 0, 0, 100, 50, [0, 0xff0000, 100]);
- mc._x = 100;
- mc._y = 100;
-
- var watcher:Watcher = new Watcher(mc, "_alpha", 0, 1/31);
- watcher.setAfterMethod(this, "test2AfterZero", true);
- watcher.start();
-
- var queue:ActionQueue = new ActionQueue();
- queue.addAction( AQFade.fade, mc, 1, null, 0 );
- queue.addPause(1);
- queue.addAction( this, "evaluateWatcher3", 1, true );
- queue.run();
- }
-
- /**
- Start and stopping
- */
- public function testStartStopRestart () : Void {
- var watcher:Watcher = new Watcher(null, null, null, 1/12);
- assertFalse("WatcherTest doTest4 isBusy 1", watcher.isBusy());
- watcher.start();
- assertTrue("WatcherTest doTest4 isBusy 2", watcher.isBusy());
- watcher.stop();
- assertFalse("WatcherTest doTest4 isBusy 3", watcher.isBusy());
- watcher.restart();
- assertTrue("WatcherTest doTest4 isBusy 4", watcher.isBusy());
- watcher.stop();
- assertFalse("WatcherTest doTest4 isBusy 5", watcher.isBusy());
- }
-
- /**
- Callback
- */
- public function testSetCallback () : Void {
-
- var mc:MovieClip = _level0.createEmptyMovieClip("WatcherTest_doTest5_box", _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");
- watcher.start();
-
- var queue:ActionQueue = new ActionQueue();
- queue.addAction( AQFade.fade, mc, 1, null, 0 );
- queue.addPause(1);
- queue.addAction( this, "evaluateWatcher5", 0, true );
- queue.run();
- }
-
- /**
-
- */
- private function evaluateWatcher1 (inWatcher:Watcher) : Void {
- assertTrue("WatcherTest evaluateWatcher1", sCounter1 == RESULT_COUNTER_1);
- assertFalse("WatcherTest doTest1 isBusy 2", inWatcher.isBusy());
- }
-
- /**
-
- */
- private function evaluateWatcher2 (inWatcher:Watcher) : Void {
- assertTrue("WatcherTest evaluateWatcher2", sCounter2 == RESULT_COUNTER_2);
- assertFalse("WatcherTest doTest2 isBusy 2", inWatcher.isBusy());
- }
-
-
- /**
-
- */
- public function doTest5Callback (inAlpha:Number) : Void {
- sValue5 = inAlpha;
- }
-
- /**
-
- */
- public function evaluateWatcher5 (inValue:Number, inResult:Boolean) : Void {
- var result:Boolean = (inValue == sValue5);
- assertTrue("WatcherTest evaluateWatcher5", result == inResult);
- }
-}
Added: trunk/asapframework/tests/unit/tests/org/asapframework/util/watcher/WatcherTest.as
===================================================================
--- trunk/asapframework/tests/unit/tests/org/asapframework/util/watcher/WatcherTest.as (rev 0)
+++ trunk/asapframework/tests/unit/tests/org/asapframework/util/watcher/WatcherTest.as 2006-10-14 00:06:54 UTC (rev 599)
@@ -0,0 +1,177 @@
+// testlib classes
+import org.as2lib.test.unit.TestCase;
+import org.as2lib.test.mock.MockControl;
+
+// ASAP classes
+import org.asapframework.util.watch.Watcher;
+import org.asapframework.util.FrameDelay;
+import org.asapframework.util.MovieClipUtils;
+import org.asapframework.util.actionqueue.ActionQueue;
+import org.asapframework.util.actionqueue.AQFade;
+
+
+class org.asapframework.util.watcher.WatcherTest extends TestCase {
+
+ private static var sCounter1:Number = 0;
+ private static var RESULT_COUNTER_1:Number = 1;
+
+ private static var sCounter2: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
+
+
+
+ /**
+ Test function call.
+ Test isBusy()
+ */
+ public function testIsBusy () : Void {
+ var family:Object = new Object();
+ family.memberCount = 2;
+ 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);
+ watcher.start();
+
+ family.birth();
+ assertTrue("WatcherTest doTest1 isBusy 1", watcher.isBusy());
+ family.birth();
+ family.birth();
+ new FrameDelay(this, evaluateWatcher1, [true, watcher], 20 );
+ }
+
+ /**
+ As test 1 but now with function reference and parameters
+ */
+ public function testIsBusyWithFunctionReferences () : Void {
+
+ var family:Object = new Object();
+ family.memberCount = 2;
+ 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);
+ watcher.start();
+
+ family.birth();
+ assertTrue("WatcherTest doTest2 isBusy 1", watcher.isBusy());
+ family.birth();
+ family.birth();
+ new FrameDelay(this, evaluateWatcher2, [true, watcher], 20 );
+ }
+
+ /**
+ Test a variable watch
+ */
+ public function testVariable () : Void {
+
+ var mc:MovieClip = _level0.createEmptyMovieClip("WatcherTest_doTest3_box", _level0.getNextHighestDepth());
+ MovieClipUtils.drawBox(mc, 0, 0, 100, 50, [0, 0xff0000, 100]);
+ mc._x = 100;
+ mc._y = 100;
+
+ var watcher:Watcher = new Watcher(mc, "_alpha", 0, 1/31);
+ watcher.setAfterMethod(this, "test2AfterZero", true);
+ watcher.start();
+
+ var queue:ActionQueue = new ActionQueue();
+ queue.addAction( AQFade.fade, mc, 1, null, 0 );
+ queue.addPause(1);
+ queue.addAction( this, "evaluateWatcher3", 1, true );
+ queue.run();
+ }
+
+ /**
+ Start and stopping
+ */
+ public function testStartStopRestart () : Void {
+ var watcher:Watcher = new Watcher(null, null, null, 1/12);
+ assertFalse("WatcherTest doTest4 isBusy 1", watcher.isBusy());
+ watcher.start();
+ assertTrue("WatcherTest doTest4 isBusy 2", watcher.isBusy());
+ watcher.stop();
+ assertFalse("WatcherTest doTest4 isBusy 3", watcher.isBusy());
+ watcher.restart();
+ assertTrue("WatcherTest doTest4 isBusy 4", watcher.isBusy());
+ watcher.stop();
+ assertFalse("WatcherTest doTest4 isBusy 5", watcher.isBusy());
+ }
+
+ /**
+ Callback
+ */
+ public function testSetCallback () : Void {
+
+ var mc:MovieClip = _level0.createEmptyMovieClip("WatcherTest_doTest5_box", _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");
+ watcher.start();
+
+ var queue:ActionQueue = new ActionQueue();
+ queue.addAction( AQFade.fade, mc, 1, null, 0 );
+ queue.addPause(1);
+ queue.addAction( this, "evaluateWatcher5", 0, true );
+ queue.run();
+ }
+
+ /**
+
+ */
+ private function evaluateWatcher1 (inWatcher:Watcher) : Void {
+ assertTrue("WatcherTest evaluateWatcher1", sCounter1 == RESULT_COUNTER_1);
+ assertFalse("WatcherTest doTest1 isBusy 2", inWatcher.isBusy());
+ }
+
+ /**
+
+ */
+ private function evaluateWatcher2 (inWatcher:Watcher) : Void {
+ assertTrue("WatcherTest evaluateWatcher2", sCounter2 == RESULT_COUNTER_2);
+ assertFalse("WatcherTest doTest2 isBusy 2", inWatcher.isBusy());
+ }
+
+
+ /**
+
+ */
+ public function doTest5Callback (inAlpha:Number) : Void {
+ sValue5 = inAlpha;
+ }
+
+ /**
+
+ */
+ public function evaluateWatcher5 (inValue:Number, inResult:Boolean) : Void {
+ var result:Boolean = (inValue == sValue5);
+ assertTrue("WatcherTest evaluateWatcher5", result == inResult);
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|