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.mock.ArgumentsMatcher;
    19  
    20  /**
    21   * {@code DefaultArgumentsMatcher} matches the expected arguments agains the actual
    22   * arguments. If an argument is itself an array the elements of this array are
    23   * matched, not the array as object itself.
    24   * 
    25   * @author Simon Wacker
    26   */
    27  class org.as2lib.test.mock.support.DefaultArgumentsMatcher extends BasicClass implements ArgumentsMatcher {
    28  	
    29  	/**
    30  	 * Constructs a new {@code DefaultArgumentsMatcher} instance.
    31  	 */
    32  	public function DefaultArgumentsMatcher(Void) {
    33  	}
    34  	
    35  	/**
    36  	 * Matches the passed-in {@code expectedArguments} against the
    37  	 * {@code actualArguments}. Inner arrays are stepped through recursively.
    38  	 *
    39  	 * @param expectedArguments the expected arguments
    40  	 * @param actualArguments the actual arguments
    41  	 * @return {@code true} if the passed-in arguments match else {@code false}
    42  	 */
    43  	public function matchArguments(expectedArguments:Array, actualArguments:Array):Boolean {
    44  		if (expectedArguments.length != actualArguments.length) return false;
    45  		for (var i:Number = 0; i < expectedArguments.length; i++) {
    46  			if (expectedArguments[i] !== actualArguments[i]) {
    47  				if (expectedArguments[i] instanceof Array) {
    48  					if (!matchArguments(expectedArguments[i], actualArguments[i])) {
    49  						return false;
    50  					}
    51  				} else {
    52  					if (expectedArguments[i].prototype == actualArguments[i].prototype) {
    53  						return ( expectedArguments[i].valueOf() == actualArguments[i].valueOf());
    54  					} else {
    55  						return false;
    56  					}
    57  				}
    58  			}
    59  		}
    60  		return true;
    61  	}
    62  	
    63  }