|
From: <luk...@us...> - 2006-09-19 21:40:56
|
Revision: 99
http://svn.sourceforge.net/asunit/?rev=99&view=rev
Author: lukebayes
Date: 2006-09-19 14:40:51 -0700 (Tue, 19 Sep 2006)
Log Message:
-----------
got a basic async test method working, still not ideal though
Modified Paths:
--------------
trunk/framework/as3/AsUnitTestRunner.as
trunk/framework/as3/asunit/framework/TestCase.as
trunk/framework/as3/asunit/textui/TestRunnerTest.as
Modified: trunk/framework/as3/AsUnitTestRunner.as
===================================================================
--- trunk/framework/as3/AsUnitTestRunner.as 2006-09-19 20:35:05 UTC (rev 98)
+++ trunk/framework/as3/AsUnitTestRunner.as 2006-09-19 21:40:51 UTC (rev 99)
@@ -6,8 +6,8 @@
public class AsUnitTestRunner extends TestRunner {
public function AsUnitTestRunner() {
- start(AllTests, null, TestRunner.SHOW_TRACE);
-// start(TestRunnerTest);
+// start(AllTests, null, TestRunner.SHOW_TRACE);
+ start(TestRunnerTest);
}
}
}
Modified: trunk/framework/as3/asunit/framework/TestCase.as
===================================================================
--- trunk/framework/as3/asunit/framework/TestCase.as 2006-09-19 20:35:05 UTC (rev 98)
+++ trunk/framework/as3/asunit/framework/TestCase.as 2006-09-19 21:40:51 UTC (rev 99)
@@ -76,7 +76,7 @@
* @see TestResult
* @see TestSuite
*/
- public class TestCase extends Assert implements Test {
+ dynamic public class TestCase extends Assert implements Test {
/**
* the name of the test case
*/
@@ -88,12 +88,14 @@
private var currentMethod:String;
private var runSingle:Boolean;
private var methodIterator:Iterator;
+ private var asyncMethods:Object;
/**
* Constructs a test case with the given name.
*/
public function TestCase(testMethod:String = null) {
+ asyncMethods = new Object();
var description:XML = describeType(this);
var className:Object = description.@name;
var methods:XMLList = description..method.(@name.match("^test"));
@@ -123,7 +125,6 @@
name = item.toString();
if(name.match(/Complete$/)) {
completeMethods.push(name);
- swapCompleteMethod(name);
}
else {
testMethods.push(name);
@@ -135,6 +136,9 @@
if(testMethods.indexOf(baseName) == -1) {
testMethods.push(name);
}
+ else {
+ swapCompleteMethod(name);
+ }
}
}
@@ -185,12 +189,14 @@
public function runBare():void {
var name:String;
var itr:Iterator = getMethodIterator();
+ var isWaiting:Boolean = false;
try {
while(itr.hasNext()) {
name = String(itr.next());
- trace("itrating with: " + getName() + "." + name);
+ trace("name: " + name);
if(!runMethod(name)) {
- trace("RETURNING ON : " + name);
+ trace("BLOCKING EXECUTION ON : " + name);
+ isWaiting = true;
break;
}
}
@@ -198,7 +204,8 @@
finally {
if(!runSingle) {
cleanUp();
- if(!itr.hasNext()) {
+ if(!itr.hasNext() && !isWaiting) {
+ trace("itr hasNext was false");
result.endTest(this);
isComplete = true;
}
@@ -219,12 +226,16 @@
protected function cleanUp():void {
}
-// override flash_proxy function hasProperty(name:*):Boolean {
-// return (this[name] != undefined);
-// }
+ override flash_proxy function hasProperty(name:*):Boolean {
+ return (this[name] != undefined);
+ }
-// override flash_proxy function getProperty(name:*):* {
-// return this[name];
+ override flash_proxy function getProperty(name:*):* {
+ return asyncMethods[name];
+ }
+
+// override flash_proxy function setProperty(name:*, value:*):void {
+// this[name] = value;
// }
private function runMethod(methodName:String):Boolean {
@@ -232,6 +243,11 @@
setUp();
currentMethod = methodName;
try {
+ if((methodName + "Complete") in this) {
+ trace("FOUND YOU! at: " + methodName);
+ this[methodName]();
+ return false;
+ }
// var ns:Namespace = flash_proxy;
// if(this.flash_proxy::hasProperty(methodName + "Complete")) {
// trace("HAS PROP : " + methodName);
@@ -260,15 +276,15 @@
private function swapCompleteMethod(name:String):void {
trace("swapping complete method with: " + name);
- var obj:Object = new Object();
- obj[name] = this[name];
-// this[name] = defaultCompleteMethod;
-// this.prototype["__" + name] = this.prototype[name];
-// this[name] = defaultCompleteMethod;
+ asyncMethods["__" + name] = this[name];
+ asyncMethods[name] = defaultCompleteMethod;
+// this[name] = this.defaultCompleteMethod;
+ //var result:Boolean = delete this[name];
+ //trace("RESULT: " + result);
}
- private function defaultCompleteMethod():void {
- trace("default complete method called");
+ public function defaultCompleteMethod():void {
+ trace("asunit complete called");
}
/**
* Sets up the fixture, for example, instantiate a mock object.
@@ -322,5 +338,8 @@
return getContext().removeChild(child);
}
+ public function fail(message:String):void {
+ result.addFailure(this, new AssertionFailedError(message));
+ }
}
}
\ No newline at end of file
Modified: trunk/framework/as3/asunit/textui/TestRunnerTest.as
===================================================================
--- trunk/framework/as3/asunit/textui/TestRunnerTest.as 2006-09-19 20:35:05 UTC (rev 98)
+++ trunk/framework/as3/asunit/textui/TestRunnerTest.as 2006-09-19 21:40:51 UTC (rev 99)
@@ -23,17 +23,17 @@
assertTrue("TestRunner instantiated", instance is TestRunner);
}
-// public function testAsync():void {
-// setTimeout(testAsyncComplete, 10);
-// }
+ public function testAsync():void {
+ setTimeout(testAsyncComplete, 10);
+ }
-// public function testAsyncComplete():void {
-// fail("test async complete failed");
-// runBare();
-// }
+ public function testAsyncComplete():void {
+ trace("user complete called");
+ fail("test async complete failed");
+ runBare();
+ }
public function testSomethingComplete():void {
- trace("testSomethignCOmplete executed");
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|