|
From: <luk...@us...> - 2006-08-18 18:08:55
|
Revision: 66 Author: lukebayes Date: 2006-08-18 11:08:49 -0700 (Fri, 18 Aug 2006) ViewCVS: http://svn.sourceforge.net/asunit/?rev=66&view=rev Log Message: ----------- working on flex2 support Modified Paths: -------------- trunk/framework/as3/asunit/textui/FlexTestRunner.as trunk/framework/as3/asunit/textui/ResultPrinter.as trunk/framework/as3/asunit/textui/TestRunner.as Modified: trunk/framework/as3/asunit/textui/FlexTestRunner.as =================================================================== --- trunk/framework/as3/asunit/textui/FlexTestRunner.as 2006-08-15 21:28:13 UTC (rev 65) +++ trunk/framework/as3/asunit/textui/FlexTestRunner.as 2006-08-18 18:08:49 UTC (rev 66) @@ -1,37 +1,48 @@ package asunit.textui { - import flash.display.DisplayObject; - import flash.events.Event; - - import mx.core.IUIComponent; - - public class FlexTestRunner extends TestRunner { + import flash.display.DisplayObject; + import flash.events.Event; + import mx.core.IUIComponent; + import asunit.textui.TestRunner; - protected override function addedHandler(event:Event):void { - if(event.target === this) { - parent.addEventListener(Event.RESIZE, resizeHandler); - } + public class FlexTestRunner extends TestRunner { + + public function FlexTestRunner(showTrace:Boolean) { + setPrinter(new ResultPrinter(showTrace)); + } + + protected override function addedHandler(event:Event):void { + if(event.target === this) { + parent.addEventListener(Event.RESIZE, resizeHandler); + resizeHandler(new Event(Event.RESIZE)); + } + else { + event.stopPropagation(); } - - public override function set width(w:Number):void { - fPrinter.width = w; - } + } - public override function set height(h:Number):void { - fPrinter.height = h; - } - - private function resizeHandler(event:Event):void { - width = event.target.width; - height = event.target.height; - } - - public override function addChild(child:DisplayObject):DisplayObject { - if(parent) { - return parent.addChild(child); - } - else { - return super.addChild(child); - } - } - } -} \ No newline at end of file + public override function set width(w:Number):void { + fPrinter.width = w; + } + + public override function set height(h:Number):void { + fPrinter.height = h; + } + + public function resizeHandler(event:Event):void { + width = parent.width; + height = parent.height; + } + + public override function addChild(child:DisplayObject):DisplayObject { + if(parent && child is IUIComponent) { + // AND check for 'is' UIUComponent... + trace(">> 1 add child called with: " + child); + return parent.addChild(child); + } + else { + trace(">> 2 add child called with: " + child); + return super.addChild(child); + } + } + } +} Modified: trunk/framework/as3/asunit/textui/ResultPrinter.as =================================================================== --- trunk/framework/as3/asunit/textui/ResultPrinter.as 2006-08-15 21:28:13 UTC (rev 65) +++ trunk/framework/as3/asunit/textui/ResultPrinter.as 2006-08-18 18:08:49 UTC (rev 66) @@ -6,7 +6,7 @@ import asunit.framework.TestResult; import asunit.runner.BaseTestRunner; import asunit.runner.Version; - + import flash.display.Shape; import flash.display.Sprite; import flash.display.Stage; @@ -17,7 +17,7 @@ import flash.text.TextFormat; import flash.ui.Keyboard; import flash.utils.setTimeout; - + public class ResultPrinter extends Sprite implements TestListener { private var fColumn:int = 0; private var textArea:TextField; @@ -26,7 +26,7 @@ private var bar:SuccessBar; private var barHeight:Number = 3; private var showTrace:Boolean; - + public function ResultPrinter(showTrace:Boolean = false) { this.showTrace = showTrace; configureAssets(); @@ -46,11 +46,11 @@ textArea.defaultTextFormat = format; addChild(textArea); println("AsUnit " + Version.id() + " by Luke Bayes and Ali Mills"); - + bar = new SuccessBar(); addChild(bar); } - + public override function set width(w:Number):void { textArea.x = gutter; textArea.width = w - gutter*2; @@ -60,7 +60,7 @@ public override function set height(h:Number):void { textArea.height = h - ((gutter*2) + barHeight); - textArea.y = gutter; + textArea.y = gutter; bar.y = h - (gutter + barHeight); bar.height = barHeight; } @@ -68,13 +68,13 @@ public function println(...args:Array):void { textArea.appendText(args.toString() + "\n"); } - + public function print(...args:Array):void { textArea.appendText(args.toString()); } /* API for use by textui.TestRunner */ - + public function printResult(result:TestResult, runTime:Number):void { printHeader(runTime); printErrors(result); @@ -86,23 +86,23 @@ trace(textArea.text); } } - - /* Internal methods + + /* Internal methods */ protected function printHeader(runTime:Number):void { println(); println(); println("Time: " + elapsedTimeAsString(runTime)); } - + protected function printErrors(result:TestResult):void { printDefects(result.errors(), result.errorCount(), "error"); } - + protected function printFailures(result:TestResult):void { printDefects(result.failures(), result.failureCount(), "failure"); } - + protected function printDefects(booBoos:Object, count:int, type:String):void { if (count == 0) { return; @@ -119,12 +119,12 @@ i++; } } - + public function printDefect(booBoo:TestFailure, count:int ):void { // only public for testing purposes printDefectHeader(booBoo, count); printDefectTrace(booBoo); } - + protected function printDefectHeader(booBoo:TestFailure, count:int):void { // I feel like making this a println, then adding a line giving the throwable a chance to print something // before we get to the stack trace. @@ -138,15 +138,15 @@ // GROSS HACK because of bug in flash player - TextField isn't accepting formats... setTimeout(onFormatTimeout, 1, format, startIndex, endIndex); } - + public function onFormatTimeout(format:TextFormat, startIndex:uint, endIndex:uint):void { textArea.setTextFormat(format, startIndex, endIndex); } - + protected function printDefectTrace(booBoo:TestFailure):void { println(BaseTestRunner.getFilteredTrace(booBoo.thrownException().getStackTrace())); } - + protected function printFooter(result:TestResult):void { println(); if (result.wasSuccessful()) { @@ -154,13 +154,13 @@ println (" (" + result.runCount() + " test" + (result.runCount() == 1 ? "": "s") + ")"); } else { println("FAILURES!!!"); - println("Tests run: " + result.runCount()+ + println("Tests run: " + result.runCount()+ ", Failures: "+result.failureCount()+ ", Errors: "+result.errorCount()); } println(); } - + /** * Returns the formatted string of the elapsed time. * Duplicated from BaseTestRunner. Fix it. @@ -175,20 +175,20 @@ public function addError(test:Test, t:Error):void { print("E"); } - + /** * @see junit.framework.TestListener#addFailure(Test, AssertionFailedError) */ public function addFailure(test:Test, t:AssertionFailedError):void { print("F"); } - + /** * @see junit.framework.TestListener#endTest(Test) */ public function endTest(test:Test):void { } - + /** * @see junit.framework.TestListener#startTest(Test) */ @@ -202,7 +202,7 @@ } } } - } + } } import flash.display.Sprite; @@ -213,10 +213,10 @@ private var bgColor:uint; private var passingColor:uint = 0x00FF00; private var failingColor:uint = 0xFD0000; - + public function SuccessBar() { } - + public function setSuccess(success:Boolean):void { bgColor = (success) ? passingColor : failingColor; draw(); Modified: trunk/framework/as3/asunit/textui/TestRunner.as =================================================================== --- trunk/framework/as3/asunit/textui/TestRunner.as 2006-08-15 21:28:13 UTC (rev 65) +++ trunk/framework/as3/asunit/textui/TestRunner.as 2006-08-18 18:08:49 UTC (rev 66) @@ -2,7 +2,7 @@ import asunit.errors.AbstractMemberCalledError; import asunit.framework.Test; import asunit.framework.TestResult; - + import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; @@ -12,19 +12,19 @@ import flash.utils.describeType; import flash.utils.getTimer; import flash.utils.setInterval; - + /** * A command line based tool to run tests. * <pre> * java junit.textui.TestRunner TestCaseClass * </pre> * TestRunner expects the name of a TestCase class as argument. - * If this class defines a static <code>suite</code> method it - * will be invoked and the returned test is run. Otherwise all + * If this class defines a static <code>suite</code> method it + * will be invoked and the returned test is run. Otherwise all * the methods starting with "test" having no arguments are run. * <p> * TestRunner prints a trace as the tests are executed followed by a - * summary at the end. + * summary at the end. */ public class TestRunner extends Sprite { public static const SUCCESS_EXIT:int = 0; @@ -41,7 +41,7 @@ addEventListener(Event.ADDED, addedHandler); // addEventListener(KeyboardEventType.KEY_DOWN, onKeyDown); } - + protected function addedHandler(event:Event):void { if(event.target === this) { stage.align = StageAlign.TOP_LEFT; @@ -50,7 +50,7 @@ resizeHandler(new Event("resize")); } } - + private function resizeHandler(event:Event):void { fPrinter.width = stage.stageWidth; fPrinter.height = stage.stageHeight; @@ -59,10 +59,10 @@ /** * Starts a test run based on the TestCase/TestSuite provided * Create a new custom class that extends TestRunner - * and call start(TestCaseClass) from within the + * and call start(TestCaseClass) from within the * constructor. */ - protected function start(testCase:Class, testMethod:String = null, showTrace:Boolean = false):TestResult { + public function start(testCase:Class, testMethod:String = null, showTrace:Boolean = false):TestResult { // fscommand("showmenu", "false"); try { @@ -80,18 +80,20 @@ } return null; } - + public function doRun(suite:Test, showTrace:Boolean = false):TestResult { var result:TestResult = new TestResult(); - setPrinter(new ResultPrinter(showTrace)); + if(fPrinter == null) { + setPrinter(new ResultPrinter(showTrace)); + } result.addListener(getPrinter()); var startTime:Number = getTimer(); suite.setResult(result); suite.setContext(this); suite.run(); - + // Wait for all tests to be completed before finishing - // the output. + // the output. // This is how we are going to support asynchronous // TestCases. var intervalObj:Object = new Object(); @@ -105,7 +107,7 @@ return result; } - + private function onTestCompleted(intervalObj:Object):void { if(intervalObj.suite.getIsComplete()) { var endTime:Number = getTimer(); @@ -119,12 +121,14 @@ intervalObj.intervalId = setInterval(onTestCompleted, 20, intervalObj); } } - + public function setPrinter(printer:ResultPrinter):void { - fPrinter = printer; - addChild(fPrinter); + if(fPrinter == null) { + fPrinter = printer; + addChild(fPrinter); + } } - + public function getPrinter():ResultPrinter { return fPrinter; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |