1
16
17 import org.as2lib.core.BasicClass;
18 import org.as2lib.env.except.IllegalArgumentException;
19 import org.as2lib.test.speed.TestResultLayout;
20 import org.as2lib.test.speed.TestSuiteResult;
21 import org.as2lib.test.speed.MethodInvocation;
22 import org.as2lib.test.speed.MethodInvocationTestSuiteResult;
23 import org.as2lib.test.speed.ConfigurableTestSuiteResult;
24 import org.as2lib.test.speed.SimpleTestSuiteResult;
25
26
33 class org.as2lib.test.speed.layout.MethodInvocationTreeLayout extends BasicClass implements TestResultLayout {
34
35
36 private var allMethodInvocations:Array;
37
38
41 public function MethodInvocationTreeLayout(Void) {
42 }
43
44
51 public function layOut(testSuiteResult:TestSuiteResult):TestSuiteResult {
52 if (!testSuiteResult) throw new IllegalArgumentException("Argument 'testSuiteResult' [" + testSuiteResult + "] must not be 'null' nor 'undefined'.", this, arguments);
53 var result:SimpleTestSuiteResult = new SimpleTestSuiteResult(testSuiteResult.getName());
54 this.allMethodInvocations = testSuiteResult.getAllMethodInvocations();
55 if (this.allMethodInvocations) {
56 var rootMethodInvocations:Array = findRootMethodInvocations();
57 buildMethodInvocationTree(result, rootMethodInvocations);
58 }
59 result.sort(SimpleTestSuiteResult.METHOD_INVOCATION_SUCCESSION);
60 return result;
61 }
62
63
69 private function findRootMethodInvocations(Void):Array {
70 return findChildMethodInvocations(null);
71 }
72
73
81 private function findChildMethodInvocations(parentMethodInvocation:MethodInvocation):Array {
82 var result:Array = new Array();
83 for (var i:Number = 0; i < this.allMethodInvocations.length; i++) {
84 var methodInvocation:MethodInvocation = this.allMethodInvocations[i];
85 if (methodInvocation.getCaller() == parentMethodInvocation) {
86 result.push(methodInvocation);
87 }
88 }
89 return result;
90 }
91
92
100 private function buildMethodInvocationTree(testSuiteResult:ConfigurableTestSuiteResult, methodInvocations:Array):Void {
101 if (testSuiteResult && methodInvocations) {
102 for (var i:Number = 0; i < methodInvocations.length; i++) {
103 var methodInvocation:MethodInvocation = methodInvocations[i];
104 var p:MethodInvocationTestSuiteResult = new MethodInvocationTestSuiteResult(methodInvocation);
105 testSuiteResult.addTestResult(p);
106 var childMethodInvocations:Array = findChildMethodInvocations(methodInvocation);
107 buildMethodInvocationTree(p, childMethodInvocations);
108 }
109 }
110 }
111
112 }