1  /*
     2   * Copyright the original author or authors.
     3   * 
     4   * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   * 
     8   *      http://www.mozilla.org/MPL/MPL-1.1.html
     9   * 
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  import org.as2lib.core.BasicClass;
    18  import org.as2lib.test.speed.TestResult;
    19  import org.as2lib.test.speed.ConfigurableTestSuiteResult;
    20  import org.as2lib.test.speed.layout.MethodInvocationLayout;
    21  import org.as2lib.test.speed.layout.MethodLayout;
    22  import org.as2lib.test.speed.layout.ClassLayout;
    23  import org.as2lib.test.speed.layout.PackageLayout;
    24  import org.as2lib.test.speed.layout.MethodInvocationTreeLayout;
    25  
    26  /**
    27   * {@code AbstractTest} provides implementations for methods needed when implementing
    28   * the {@link Test} interface and some extra methods commonly needed.
    29   * 
    30   * @author Simon Wacker
    31   */
    32  class org.as2lib.test.speed.AbstractTest extends BasicClass {
    33  	
    34  	/** Do not layout the result in any specific way. */
    35  	public static var NONE:Number = -1;
    36  	
    37  	/** Layout the result with method invocations as highest structural level. */
    38  	public static var METHOD_INVOCATION:Number = 0;
    39  	
    40  	/** Layout the result with methods as highest structural level. */
    41  	public static var METHOD:Number = 1;
    42  	
    43  	/** Layout the result with classes as highest structural level. */
    44  	public static var CLASS:Number = 2;
    45  	
    46  	/** Layout the result with packages as highest structural level. */
    47  	public static var PACKAGE:Number = 3;
    48  	
    49  	/**
    50  	 * Layout the result to depict the order of method invocations. This means that the
    51  	 * tree is ordered firstly in depth according to which method called which other
    52  	 * method and secondly sorted by the correct succession of method invocations.
    53  	 */
    54  	public static var METHOD_INVOCATION_TREE:Number = 4;
    55  	
    56  	/** The result of this test. */
    57  	private var result:ConfigurableTestSuiteResult;
    58  	
    59  	/**
    60  	 * Constructs a new {@code AbstractTest} instance.
    61  	 */
    62  	private function AbstractTest(Void) {
    63  	}
    64  	
    65  	/**
    66  	 * Return the result of this test.
    67  	 * 
    68  	 * <p>The following layouts are applicable:
    69  	 * <ul>
    70  	 *   <li>{@link #NONE}</li>
    71  	 *   <li>{@link #METHOD_INVOCATION}</li>
    72  	 *   <li>{@link #METHOD}</li>
    73  	 *   <li>{@link #CLASS}</li>
    74  	 *   <li>{@link #PACKAGE}</li>
    75  	 *   <li>{@link #METHOD_INVOCATION_TREE} (default)</li>
    76  	 * </ul>
    77  	 * 
    78  	 * @param layout (optional) the layout of the returned test result
    79  	 * @return this test's result
    80  	 */
    81  	public function getResult(layout:Number):TestResult {
    82  		switch (layout) {
    83  			case NONE:
    84  				return this.result;
    85  				break;
    86  			case METHOD_INVOCATION:
    87  				return (new MethodInvocationLayout()).layOut(this.result);
    88  				break;
    89  			case METHOD:
    90  				return (new MethodLayout()).layOut(this.result);
    91  				break;
    92  			case CLASS:
    93  				return (new ClassLayout()).layOut(this.result);
    94  				break;
    95  			case PACKAGE:
    96  				return (new PackageLayout()).layOut(this.result);
    97  				break;
    98  			default:
    99  				return (new MethodInvocationTreeLayout()).layOut(this.result);
   100  				break;
   101  		}
   102  	}
   103  	
   104  	/**
   105  	 * Sets this test's result.
   106  	 * 
   107  	 * @param result this test's result
   108  	 */
   109  	private function setResult(result:ConfigurableTestSuiteResult):Void {
   110  		this.result = result;
   111  	}
   112  	
   113  }