asproject 0.1.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. data/CHANGELOG.txt +0 -0
  2. data/History.txt +0 -0
  3. data/MIT-LICENSE.txt +20 -0
  4. data/Manifest.txt +16 -0
  5. data/README.txt +3 -0
  6. data/TODO.txt +10 -0
  7. data/bin/asclass +16 -0
  8. data/bin/asproject +16 -0
  9. data/lib/asclass.rb +254 -0
  10. data/lib/asclass_arguments.rb +147 -0
  11. data/lib/asproject.rb +248 -0
  12. data/lib/asproject/version.rb +9 -0
  13. data/lib/asproject_arguments.rb +175 -0
  14. data/lib/asproject_base.rb +43 -0
  15. data/lib/asproject_utils.rb +57 -0
  16. data/lib/eclipse_project.rb +32 -0
  17. data/lib/path_finder.rb +286 -0
  18. data/lib/platform.rb +107 -0
  19. data/lib/project.rb +82 -0
  20. data/lib/template_resolver.rb +144 -0
  21. data/lib/test_suite_generator.rb +128 -0
  22. data/rakefile.rb +85 -0
  23. data/setup.rb +1585 -0
  24. data/templates/asclass/as2/Class.as +11 -0
  25. data/templates/asclass/as2/Component.as +8 -0
  26. data/templates/asclass/as2/Interface.as +3 -0
  27. data/templates/asclass/as2/TestCase.as +30 -0
  28. data/templates/asclass/as2/TestSuite.as +15 -0
  29. data/templates/asclass/as3/Class.as +9 -0
  30. data/templates/asclass/as3/Component.as +9 -0
  31. data/templates/asclass/as3/Component.mxml +1 -0
  32. data/templates/asclass/as3/Interface.as +6 -0
  33. data/templates/asclass/as3/TestCase.as +30 -0
  34. data/templates/asclass/as3/TestSuite.as +18 -0
  35. data/templates/asproject/as2/project/rakefile.rb +18 -0
  36. data/templates/asproject/as2/project/src/AsProject.as +13 -0
  37. data/templates/asproject/as2/project/test/AsProjectRunner.as +12 -0
  38. data/templates/asproject/as3/project/rakefile.rb +18 -0
  39. data/templates/asproject/as3/project/src/AsProject.as +9 -0
  40. data/templates/asproject/as3/project/src/AsProjectRunner.as +11 -0
  41. data/templates/asproject/asunit2/project/lib/asunit/AsUnitUi.swf +0 -0
  42. data/templates/asproject/asunit2/project/lib/asunit/Sys.as +70 -0
  43. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/LocalOutputPanel.as +182 -0
  44. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/LocalOutputPanelTest.as +84 -0
  45. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/LocalOutputPanelTextArea.as +111 -0
  46. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/LocalOutputPanelTextAreaTest.as +26 -0
  47. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/LocalOutputPanelTitleBar.as +81 -0
  48. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/ResizeHandle.as +35 -0
  49. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/ScrollArrow.as +34 -0
  50. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/ScrollHandle.as +43 -0
  51. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/ScrollListener.as +10 -0
  52. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/TextScroller.as +169 -0
  53. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/shapes/Rectangle.as +29 -0
  54. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/shapes/Triangle.as +27 -0
  55. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/AsUnit.as +19 -0
  56. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/Assert.as +408 -0
  57. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/Assertion.as +27 -0
  58. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/Reflection.as +68 -0
  59. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/Test.as +3 -0
  60. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestCase.as +191 -0
  61. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestCaseXml.as +31 -0
  62. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestFailure.as +15 -0
  63. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestResult.as +15 -0
  64. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestRunner.as +41 -0
  65. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestSetup.as +19 -0
  66. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestSuite.as +22 -0
  67. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/ui/Main.as +325 -0
  68. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/ui/RemoteVersion.as +24 -0
  69. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/ui/SuccessMeter.as +32 -0
  70. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/Comparable.as +7 -0
  71. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/EventListener.as +29 -0
  72. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/EventSource.as +89 -0
  73. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalConnClient.as +42 -0
  74. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalConnGateway.as +47 -0
  75. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalConnServer.as +61 -0
  76. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalMessageBroker.as +58 -0
  77. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/Observable.as +11 -0
  78. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/TextFile.as +30 -0
  79. data/templates/asproject/asunit25/project/lib/asunit/AsUnitTestRunner.as +13 -0
  80. data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/AssertionFailedError.as +7 -0
  81. data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/AssertionPassedError.as +7 -0
  82. data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/ClassNotFoundError.as +7 -0
  83. data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/IllegalOperationError.as +7 -0
  84. data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/InstanceNotFoundError.as +7 -0
  85. data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/InvocationTargetError.as +7 -0
  86. data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/UnimplementedFeatureError.as +7 -0
  87. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/Assert.as +376 -0
  88. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/AssertMock.as +15 -0
  89. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/AssertTest.as +59 -0
  90. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/ITestListener.as +13 -0
  91. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/Test.as +11 -0
  92. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestCase.as +277 -0
  93. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestCaseMock.as +23 -0
  94. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestCaseTest.as +29 -0
  95. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestCaseXml.as +38 -0
  96. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestFailure.as +47 -0
  97. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestResult.as +168 -0
  98. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestSuite.as +102 -0
  99. data/templates/asproject/asunit25/project/lib/asunit/asunit/runner/BaseTestRunner.as +101 -0
  100. data/templates/asproject/asunit25/project/lib/asunit/asunit/runner/IResultPrinter.as +8 -0
  101. data/templates/asproject/asunit25/project/lib/asunit/asunit/textui/ResultPrinter.as +254 -0
  102. data/templates/asproject/asunit25/project/lib/asunit/asunit/textui/SuccessBar.as +41 -0
  103. data/templates/asproject/asunit25/project/lib/asunit/asunit/textui/TestRunner.as +17 -0
  104. data/templates/asproject/asunit25/project/lib/asunit/asunit/util/ArrayIterator.as +24 -0
  105. data/templates/asproject/asunit25/project/lib/asunit/asunit/util/ArrayIteratorTest.as +52 -0
  106. data/templates/asproject/asunit25/project/lib/asunit/asunit/util/Iterator.as +5 -0
  107. data/templates/asproject/asunit3/project/lib/asunit/AsUnitTestRunner.as +10 -0
  108. data/templates/asproject/asunit3/project/lib/asunit/asunit/errors/AbstractMemberCalledError.as +10 -0
  109. data/templates/asproject/asunit3/project/lib/asunit/asunit/errors/AssertionFailedError.as +10 -0
  110. data/templates/asproject/asunit3/project/lib/asunit/asunit/errors/ClassNotFoundError.as +10 -0
  111. data/templates/asproject/asunit3/project/lib/asunit/asunit/errors/InstanceNotFoundError.as +10 -0
  112. data/templates/asproject/asunit3/project/lib/asunit/asunit/errors/UnimplementedFeatureError.as +10 -0
  113. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/Assert.as +271 -0
  114. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/AsynchronousTestCase.as +52 -0
  115. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/AsynchronousTestCaseExample.as +71 -0
  116. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/Test.as +15 -0
  117. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestCase.as +351 -0
  118. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestCaseExample.as +73 -0
  119. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestFailure.as +47 -0
  120. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestListener.as +22 -0
  121. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestResult.as +158 -0
  122. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestSuite.as +115 -0
  123. data/templates/asproject/asunit3/project/lib/asunit/asunit/runner/BaseTestRunner.as +15 -0
  124. data/templates/asproject/asunit3/project/lib/asunit/asunit/runner/TestSuiteLoader.as +9 -0
  125. data/templates/asproject/asunit3/project/lib/asunit/asunit/runner/Version.as +11 -0
  126. data/templates/asproject/asunit3/project/lib/asunit/asunit/textui/FlexRunner.as +19 -0
  127. data/templates/asproject/asunit3/project/lib/asunit/asunit/textui/FlexTestRunner.as +55 -0
  128. data/templates/asproject/asunit3/project/lib/asunit/asunit/textui/ResultPrinter.as +245 -0
  129. data/templates/asproject/asunit3/project/lib/asunit/asunit/textui/TestRunner.as +121 -0
  130. data/templates/asproject/asunit3/project/lib/asunit/asunit/util/ArrayIterator.as +26 -0
  131. data/templates/asproject/asunit3/project/lib/asunit/asunit/util/Iterator.as +9 -0
  132. data/templates/asproject/asunit3/project/lib/asunit/asunit/util/Properties.as +30 -0
  133. data/templates/asproject/asunit3/project/lib/asunit/mx/managers/LayoutManager.as +945 -0
  134. data/templates/asproject/config/project/config/asclass_config.rb +58 -0
  135. data/templates/asproject/fb2as/project/.actionScriptProperties +21 -0
  136. data/templates/asproject/fb2as/project/.project +29 -0
  137. data/templates/asproject/fdt/project/.as2_classpath +6 -0
  138. data/templates/asproject/fdt/project/.project +19 -0
  139. data/templates/ide/mate/Create Class.tmCommand +37 -0
  140. data/templates/ide/mate/Rebuild Test Suites.tmCommand +33 -0
  141. data/templates/ide/mate/Run Rake Task.tmCommand +127 -0
  142. metadata +266 -0
@@ -0,0 +1,52 @@
1
+ package asunit.framework {
2
+ import flash.net.URLRequest;
3
+ import flash.net.URLLoader;
4
+ import flash.events.*;
5
+ import flash.errors.IllegalOperationError;
6
+
7
+ /**
8
+ * Extend this class if you have a TestCase that requires the
9
+ * asynchronous load of external data.
10
+ */
11
+ public class AsynchronousTestCase extends TestCase {
12
+
13
+ public function AsynchronousTestCase(testMethod:String = null) {
14
+ super(testMethod);
15
+ }
16
+
17
+ protected function configureListeners(loader:URLLoader):void {
18
+ loader.addEventListener(Event.COMPLETE, completeHandler);
19
+ loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
20
+ loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
21
+ loader.addEventListener(Event.OPEN, openHandler);
22
+ loader.addEventListener(ProgressEvent.PROGRESS, progressHandler);
23
+ loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
24
+ }
25
+
26
+ // override this method and implement your own completeHandler
27
+ // you should be sure to call super.run() from the body of
28
+ // this override.
29
+ protected function completeHandler(event:Event):void {
30
+ }
31
+
32
+ // TODO: add support for failing status events...
33
+ protected function httpStatusHandler(event:HTTPStatusEvent):void {
34
+ }
35
+
36
+ protected function ioErrorHandler(event:IOErrorEvent):void {
37
+ result.addError(this, new IllegalOperationError(event.toString()));
38
+ isComplete = true;
39
+ }
40
+
41
+ protected function openHandler(event:Event):void {
42
+ }
43
+
44
+ protected function progressHandler(event:ProgressEvent):void {
45
+ }
46
+
47
+ protected function securityErrorHandler(event:SecurityErrorEvent):void {
48
+ result.addError(this, new IllegalOperationError(event.toString()));
49
+ isComplete = true;
50
+ }
51
+ }
52
+ }
@@ -0,0 +1,71 @@
1
+ package asunit.framework {
2
+ import flash.net.URLRequest;
3
+ import flash.net.URLLoader;
4
+ import flash.events.*;
5
+
6
+ /**
7
+ * This example is built on the following mock data:
8
+ * <books>
9
+ * <book publisher="Addison-Wesley" name="Design Patterns" />
10
+ * <book publisher="Addison-Wesley" name="The Pragmattic Programmer" />
11
+ * <book publisher="Addison-Wesley" name="Test Driven Development" />
12
+ * <book publisher="Addison-Wesley" name="Refactoring to Patterns" />
13
+ * <book publisher="O'Reilly Media" name="The Cathedral & the Bazaar" />
14
+ * <book publisher="O'Reilly Media" name="Unit Test Frameworks" />
15
+ * </books>
16
+ *
17
+ * This example was created to illustrate how one can build an synchronous
18
+ * TestCase - one that relies on remote data of some sort.
19
+ * This use case is now diminished by the creation of E4X and easily
20
+ * readable/editable XML data directly in source form.
21
+ * But asynchronous tests will probably need to be built at some point
22
+ * by somebody... If you're them, maybe you can use this as a template.
23
+ */
24
+
25
+ public class AsynchronousTestCaseExample extends AsynchronousTestCase {
26
+ private var source:String = "asunit/framework/MockData.xml";
27
+ private var dataSource:XML;
28
+ private var instance:Object;
29
+
30
+ // Override the run method and begin the request for remote data
31
+ public override function run():void {
32
+ var request:URLRequest = new URLRequest(source);
33
+ var loader:URLLoader = new URLLoader();
34
+ // configureListeners is a method on the AsynchronousTestCase
35
+ // and it will handle error states by failing loudly...
36
+ configureListeners(loader);
37
+ loader.load(request);
38
+ }
39
+
40
+ protected override function completeHandler(event:Event):void {
41
+ // put a copy of the data into a member reference
42
+ dataSource = XML(event.target.data).copy();
43
+ // call super.run() to execute test methods
44
+ super.run();
45
+ }
46
+
47
+ protected override function setUp():void {
48
+ // create a new instance of the class under test
49
+ instance = new Object();
50
+ // copy the data into a member or method of the instance
51
+ instance.data = dataSource.copy();
52
+ }
53
+
54
+ protected override function tearDown():void {
55
+ // destroy the class under test instance
56
+ instance = null;
57
+ }
58
+
59
+ public function testBookCount():void {
60
+ var data:XML = XML(instance.data);
61
+ var list:XMLList = data..book;
62
+ assertTrue("list.length() == " + list.length() + " (6?)", list.length() == 6);
63
+ }
64
+
65
+ public function testOReillyBookCount():void {
66
+ var data:XML = XML(instance.data);
67
+ var list:XMLList = data..book.(@publisher == "O'Reilly Media");
68
+ assertTrue("list.length() == " + list.length() + " (2?)", list.length() == 2);
69
+ }
70
+ }
71
+ }
@@ -0,0 +1,15 @@
1
+ package asunit.framework {
2
+ import flash.display.DisplayObjectContainer;
3
+ import flash.events.IEventDispatcher;
4
+
5
+ public interface Test extends IEventDispatcher {
6
+ function countTestCases():int;
7
+ function toString():String;
8
+ function setResult(result:TestResult):void;
9
+ function run():void;
10
+ function getCurrentMethod():String;
11
+ function getIsComplete():Boolean;
12
+ function setContext(context:DisplayObjectContainer):void;
13
+ function getContext():DisplayObjectContainer;
14
+ }
15
+ }
@@ -0,0 +1,351 @@
1
+ package asunit.framework {
2
+ import asunit.errors.AssertionFailedError;
3
+
4
+ import flash.display.DisplayObject;
5
+ import flash.display.DisplayObjectContainer;
6
+ import flash.errors.IllegalOperationError;
7
+ import flash.utils.describeType;
8
+ import asunit.util.Iterator;
9
+ import asunit.util.ArrayIterator;
10
+ import flash.net.getClassByAlias;
11
+ import flash.events.Event;
12
+ import flash.utils.Timer;
13
+ import flash.events.TimerEvent;
14
+ import flash.utils.setTimeout;
15
+ import flash.utils.clearTimeout;
16
+ import flash.utils.getDefinitionByName;
17
+
18
+ /**
19
+ * A test case defines the fixture to run multiple tests. To define a test case<br>
20
+ * 1) implement a subclass of TestCase<br>
21
+ * 2) define instance variables that store the state of the fixture<br>
22
+ * 3) initialize the fixture state by overriding <code>setUp</code><br>
23
+ * 4) clean-up after a test by overriding <code>tearDown</code>.<br>
24
+ * Each test runs in its own fixture so there
25
+ * can be no side effects among test runs.
26
+ * Here is an example:
27
+ * <pre>
28
+ * public class MathTest extends TestCase {
29
+ * protected double fValue1;
30
+ * protected double fValue2;
31
+ *
32
+ * protected void setUp() {
33
+ * fValue1= 2.0;
34
+ * fValue2= 3.0;
35
+ * }
36
+ * }
37
+ * </pre>
38
+ *
39
+ * For each test implement a method which interacts
40
+ * with the fixture. Verify the expected results with assertions specified
41
+ * by calling <code>assertTrue</code> with a boolean.
42
+ * <pre>
43
+ * public void testAdd() {
44
+ * double result= fValue1 + fValue2;
45
+ * assertTrue(result == 5.0);
46
+ * }
47
+ * </pre>
48
+ * Once the methods are defined you can run them. The framework supports
49
+ * both a static type safe and more dynamic way to run a test.
50
+ * In the static way you override the runTest method and define the method to
51
+ * be invoked. A convenient way to do so is with an anonymous inner class.
52
+ * <pre>
53
+ * TestCase test= new MathTest("add") {
54
+ * public void runTest() {
55
+ * testAdd();
56
+ * }
57
+ * };
58
+ * test.run();
59
+ * </pre>
60
+ * The dynamic way uses reflection to implement <code>runTest</code>. It dynamically finds
61
+ * and invokes a method.
62
+ * In this case the name of the test case has to correspond to the test method
63
+ * to be run.
64
+ * <pre>
65
+ * TestCase= new MathTest("testAdd");
66
+ * test.run();
67
+ * </pre>
68
+ * The tests to be run can be collected into a TestSuite. JUnit provides
69
+ * different <i>test runners</i> which can run a test suite and collect the results.
70
+ * A test runner either expects a static method <code>suite</code> as the entry
71
+ * point to get a test to run or it will extract the suite automatically.
72
+ * <pre>
73
+ * public static Test suite() {
74
+ * suite.addTest(new MathTest("testAdd"));
75
+ * suite.addTest(new MathTest("testDivideByZero"));
76
+ * return suite;
77
+ * }
78
+ * </pre>
79
+ * @see TestResult
80
+ * @see TestSuite
81
+ */
82
+ public class TestCase extends Assert implements Test {
83
+ /**
84
+ * the name of the test case
85
+ */
86
+ protected static const DEFAULT_TIMEOUT:int = 1000;
87
+ protected var fName:String;
88
+ protected var result:TestResult;
89
+ protected var testMethods:Array;
90
+ protected var isComplete:Boolean;
91
+ protected var context:DisplayObjectContainer;
92
+ protected var methodIsAsynchronous:Boolean;
93
+ protected var timeout:Timer;
94
+ private var currentMethod:String;
95
+ private var runSingle:Boolean;
96
+ private var methodIterator:Iterator;
97
+ private var layoutManager:Object;
98
+
99
+ /**
100
+ * Constructs a test case with the given name.
101
+ */
102
+ public function TestCase(testMethod:String = null) {
103
+ var description:XML = describeType(this);
104
+ var className:Object = description.@name;
105
+ var methods:XMLList = description..method.(@name.match("^test"));
106
+ if(testMethod != null) {
107
+ testMethods = testMethod.split(", ").join(",").split(",");
108
+ if(testMethods.length == 1) {
109
+ runSingle = true;
110
+ }
111
+ } else {
112
+ setTestMethods(methods);
113
+ }
114
+ setName(className.toString());
115
+ resolveLayoutManager();
116
+ }
117
+
118
+ private function resolveLayoutManager():void {
119
+ // Avoid creating import dependencies on flex framework
120
+ // If you have the framework.swc in your classpath,
121
+ // the layout manager will be found, if not, a mcok
122
+ // will be used.
123
+ try {
124
+ var manager:Class = getDefinitionByName("mx.managers.LayoutManager") as Class;
125
+ layoutManager = manager["getInstance"]();
126
+ }
127
+ catch(e:Error) {
128
+ layoutManager = new Object();
129
+ layoutManager.resetAll = function():void {
130
+ }
131
+ }
132
+ }
133
+
134
+ /**
135
+ * Sets the name of a TestCase
136
+ * @param name The name to set
137
+ */
138
+ public function setName(name:String):void {
139
+ fName = name;
140
+ }
141
+
142
+ protected function setTestMethods(methodNodes:XMLList):void {
143
+ testMethods = new Array();
144
+ var methodNames:Object = methodNodes.@name;
145
+ var name:String;
146
+ for each(var item:Object in methodNames) {
147
+ name = item.toString();
148
+ testMethods.push(name);
149
+ }
150
+ }
151
+
152
+ /**
153
+ * Counts the number of test cases executed by run(TestResult result).
154
+ */
155
+ public function countTestCases():int {
156
+ return testMethods.length;
157
+ }
158
+
159
+ /**
160
+ * Creates a default TestResult object
161
+ *
162
+ * @see TestResult
163
+ */
164
+ protected function createResult():TestResult {
165
+ return new TestResult();
166
+ }
167
+
168
+ /**
169
+ * A convenience method to run this test, collecting the results with
170
+ * either the TestResult provided or a default, new TestResult object.
171
+ * Expects either:
172
+ * run():void // will return the newly created TestResult
173
+ * run(result:TestResult):TestResult // will use the TestResult
174
+ * that was passed in.
175
+ *
176
+ * @see TestResult
177
+ */
178
+ public function run():void {
179
+ getResult().run(this);
180
+ }
181
+
182
+ public function setResult(result:TestResult):void {
183
+ this.result = result;
184
+ }
185
+
186
+ protected function getResult():TestResult {
187
+ return (result == null) ? createResult() : result;
188
+ }
189
+
190
+ /**
191
+ * Runs the bare test sequence.
192
+ * @exception Error if any exception is thrown
193
+ * throws Error
194
+ */
195
+ public function runBare():void {
196
+ if(isComplete) {
197
+ return;
198
+ }
199
+ var name:String;
200
+ var itr:Iterator = getMethodIterator();
201
+ if(itr.hasNext()) {
202
+ name = String(itr.next());
203
+ runMethod(name);
204
+ }
205
+ else {
206
+ cleanUp();
207
+ getResult().endTest(this);
208
+ isComplete = true;
209
+ dispatchEvent(new Event(Event.COMPLETE));
210
+ }
211
+ }
212
+
213
+ private function getMethodIterator():Iterator {
214
+ if(methodIterator == null) {
215
+ methodIterator = new ArrayIterator(testMethods);
216
+ }
217
+ return methodIterator;
218
+ }
219
+
220
+ // Override this method in Asynchronous test cases
221
+ // or any other time you want to perform additional
222
+ // member cleanup after all test methods have run
223
+ protected function cleanUp():void {
224
+ }
225
+
226
+ private function runMethod(methodName:String):void {
227
+ try {
228
+ setUp();
229
+ currentMethod = methodName;
230
+ methodIsAsynchronous = false;
231
+ this[methodName]();
232
+ }
233
+ catch(assertionFailedError:AssertionFailedError) {
234
+ getResult().addFailure(this, assertionFailedError);
235
+ }
236
+ catch(unknownError:Error) {
237
+ getResult().addError(this, unknownError);
238
+ }
239
+ finally {
240
+ if(!methodIsAsynchronous) {
241
+ runTearDown();
242
+ }
243
+ }
244
+ }
245
+
246
+ /**
247
+ * Sets up the fixture, for example, instantiate a mock object.
248
+ * This method is called before each test is executed.
249
+ * throws Exception on error
250
+ */
251
+ protected function setUp():void {
252
+ }
253
+ /**
254
+ * Tears down the fixture, for example, delete mock object.
255
+ * This method is called after a test is executed.
256
+ * throws Exception on error
257
+ */
258
+ protected function tearDown():void {
259
+ }
260
+ /**
261
+ * Returns a string representation of the test case
262
+ */
263
+ override public function toString():String {
264
+ return getName() + "." + getCurrentMethod() + "()";
265
+ }
266
+ /**
267
+ * Gets the name of a TestCase
268
+ * @return returns a String
269
+ */
270
+ public function getName():String {
271
+ return fName;
272
+ }
273
+
274
+ public function getCurrentMethod():String {
275
+ return currentMethod;
276
+ }
277
+
278
+ public function getIsComplete():Boolean {
279
+ return isComplete;
280
+ }
281
+
282
+ public function setContext(context:DisplayObjectContainer):void {
283
+ this.context = context;
284
+ }
285
+
286
+ public function getContext():DisplayObjectContainer {
287
+ return context;
288
+ }
289
+
290
+ protected function addAsync(handler:Function = null, duration:Number=DEFAULT_TIMEOUT):Function {
291
+ if(handler == null) {
292
+ handler = function(args:*):* {};
293
+ }
294
+ methodIsAsynchronous = true;
295
+ timeout = new Timer(duration, 1);
296
+ timeout.addEventListener(TimerEvent.TIMER_COMPLETE, getTimeoutComplete(duration));
297
+ timeout.start();
298
+ // try ..args
299
+ var context:TestCase = this;
300
+ return function(args:*):* {
301
+ context.timeout.stop();
302
+ try {
303
+ handler.apply(context, arguments);
304
+ }
305
+ catch(e:AssertionFailedError) {
306
+ context.getResult().addFailure(context, e);
307
+ }
308
+ catch(ioe:IllegalOperationError) {
309
+ context.getResult().addError(context, ioe);
310
+ }
311
+ finally {
312
+ context.runTearDown();
313
+ }
314
+ }
315
+ }
316
+
317
+ private function getTimeoutComplete(duration:Number):Function {
318
+ var context:TestCase = this;
319
+ return function(event:Event):void {
320
+ context.getResult().addError(context, new IllegalOperationError("TestCase.timeout (" + duration + "ms) exceeded on an asynchronous test method."));
321
+ context.runTearDown();
322
+ }
323
+ }
324
+
325
+ protected function runTearDown():void {
326
+ if(isComplete) {
327
+ return;
328
+ }
329
+ if(!runSingle) {
330
+ tearDown();
331
+ layoutManager.resetAll();
332
+ }
333
+ setTimeout(runBare, 5);
334
+ }
335
+
336
+ protected function addChild(child:DisplayObject):DisplayObject {
337
+ return getContext().addChild(child);
338
+ }
339
+
340
+ protected function removeChild(child:DisplayObject):DisplayObject {
341
+ if(child == null) {
342
+ throw new IllegalOperationError("TestCase.removeChild must have non-null parameter child");
343
+ }
344
+ return getContext().removeChild(child);
345
+ }
346
+
347
+ // public function fail(message:String):void {
348
+ // result.addFailure(this, new AssertionFailedError(message));
349
+ // }
350
+ }
351
+ }