public bool PosTest10() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest10: Return value is void, with 2 value parameters"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.TwoValueParameterVoidDelegate = new TwoValueParameterVoidDelegate(dd.TestTwoValueParameterVoidCallback); if (null == dd.TwoValueParameterVoidDelegate) { TestLibrary.TestFramework.LogError("026", "Failed to assign a call back function to a delegate"); retVal = false; } dd.TwoValueParameterVoidDelegate( DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER, DelegateDefinitions.c_DELEGATE_TEST_ADDITIONAL_VALUE_PARAMETER); } catch (Exception e) { TestLibrary.TestFramework.LogError("027", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest14() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest14: Return value is void, with 1 value parameter and then set a static function"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ValueParameterVoidDelegate = new ValueParameterVoidDelegate(DelegateDefinitions.TestValueParameterVoidStaticCallback); if (null == dd.ValueParameterVoidDelegate) { TestLibrary.TestFramework.LogError("034", "Failed to assign a call back function to a delegate"); retVal = false; } dd.ValueParameterVoidDelegate( DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER); } catch (Exception e) { TestLibrary.TestFramework.LogError("035", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest9() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest9: Return value is a reference type, without parameter"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.VoidParameterReferenceDelegate = new VoidParameterReferenceDelegate(dd.TestVoidParameterReferenceCallback); if (null == dd.VoidParameterReferenceDelegate) { TestLibrary.TestFramework.LogError("023", "Failed to assign a call back function to a delegate"); retVal = false; } object returnObject = dd.VoidParameterReferenceDelegate(); if (!returnObject.Equals(DelegateDefinitions.c_DELEGATE_TEST_DEFAUTL_REFERENCE_PARAMETER)) { TestLibrary.TestFramework.LogError("024", "Incorrect delegate return value: " + returnObject); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("025", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest3() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest3: Combine a instance method and a class method from same type to a delegate"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ValueParameterVoidDelegate = new ValueParameterVoidDelegate(DelegateDefinitions.TestValueParameterVoidStaticCallback); dd.ValueParameterVoidDelegate += new ValueParameterVoidDelegate(dd.TestValueParameterVoidCallback); dd.ValueParameterVoidDelegate(DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER); } catch (Exception e) { TestLibrary.TestFramework.LogError("003", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest3() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest3: Return type is void, parameter is void"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.VoidParameterVoidDelegate = new VoidParameterVoidDelegate(dd.TestVoidParameterVoidCallback); if (null == dd.VoidParameterVoidDelegate) { TestLibrary.TestFramework.LogError("005", "Failed to assign a call back function to a delegate"); retVal = false; } dd.VoidParameterVoidDelegate(); if ((DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER + 1) != dd.VoidParameterVoidDelegateTestValue) { TestLibrary.TestFramework.LogError("006", "Failed to call a delegate"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("007", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest2: Return type is void, parameter is a reference value"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ReferenceParameterVoidDelegate = new ReferenceParameterVoidDelegate(dd.TestReferenceParameterVoidCallback); if (null == dd.ReferenceParameterVoidDelegate) { TestLibrary.TestFramework.LogError("003", "Failed to assign a call back function to a delegate"); retVal = false; } dd.ReferenceParameterVoidDelegate(DelegateDefinitions.c_DELEGATE_TEST_DEFAUTL_REFERENCE_PARAMETER); } catch (Exception e) { TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool NegTest3() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("NegTest3: Return value of second method is different with first method"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.VoidParameterValueDelegate = delegate { return(DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER); }; dd.VoidParameterValueDelegate += delegate { return(DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER + 1); }; int returnObject = dd.VoidParameterValueDelegate(); if (returnObject != DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER + 1) { TestLibrary.TestFramework.LogError("103", "Incorrect delegate return value: " + returnObject); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("104", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool NegTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("NegTest2: Combine the null value"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ValueParameterVoidDelegate = new ValueParameterVoidDelegate(dd.TestValueParameterVoidCallback); dd.ValueParameterVoidDelegate += null; dd.ValueParameterVoidDelegate += new ValueParameterVoidDelegate(TestValueParameterVoidCallback); dd.ValueParameterVoidDelegate(DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER); } catch (Exception e) { TestLibrary.TestFramework.LogError("102", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1: Combine two function from different type to a delegate"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ValueParameterVoidDelegate = new ValueParameterVoidDelegate(dd.TestValueParameterVoidCallback); dd.ValueParameterVoidDelegate += new ValueParameterVoidDelegate(TestValueParameterVoidCallback); dd.ValueParameterVoidDelegate(DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER); } catch (Exception e) { TestLibrary.TestFramework.LogError("001", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest2: Determine whether two delegate with the same class method from same type are equal"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ValueParameterVoidDelegate = new ValueParameterVoidDelegate(DelegateDefinitions.TestValueParameterVoidStaticCallback); DelegateDefinitions dd1 = new DelegateDefinitions(); dd1.ValueParameterVoidDelegate = new ValueParameterVoidDelegate(DelegateDefinitions.TestValueParameterVoidStaticCallback); if (!dd.ValueParameterVoidDelegate.Equals(dd1.ValueParameterVoidDelegate)) { TestLibrary.TestFramework.LogError("003", "Two delegate with the same class method from same type are not equal"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest8() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest8: Return value is a value type, without parameter"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.VoidParameterValueDelegate = new VoidParameterValueDelegate(dd.TestVoidParameterValueCallback); if (null == dd.VoidParameterValueDelegate) { TestLibrary.TestFramework.LogError("020", "Failed to assign a call back function to a delegate"); retVal = false; } int returnObject = dd.VoidParameterValueDelegate(); if (DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER != returnObject) { TestLibrary.TestFramework.LogError("021", "Incorrect delegate return value: " + returnObject); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("022", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool NagTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("NagTest1: Insert multiple functions with null embeded in the function list"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.VoidParameterValueDelegate = new VoidParameterValueDelegate(DelegateDefinitions.GetCurrentProcessId); dd.VoidParameterValueDelegate += null; dd.VoidParameterValueDelegate += new VoidParameterValueDelegate(DelegateDefinitions.TestVoidParameterValueStaticCallback); dd.VoidParameterValueDelegate += new VoidParameterValueDelegate(dd.TestVoidParameterValueCallback); Delegate[] invocationList = dd.VoidParameterValueDelegate.GetInvocationList(); if (invocationList.Length != 3) { TestLibrary.TestFramework.LogError("101", "Call GetInvocationList against a delegate with one function returns wrong result: " + invocationList.Length); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("102", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest2: Combine two function from same type to a delegate"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ValueParameterVoidDelegate = new ValueParameterVoidDelegate(TestValueParameterVoidCallback1); dd.ValueParameterVoidDelegate += new ValueParameterVoidDelegate(TestValueParameterVoidCallback); dd.ValueParameterVoidDelegate(DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER); } catch (Exception e) { TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1: Call GetInvocationList against a delegate with one function"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.VoidParameterValueDelegate = new VoidParameterValueDelegate(DelegateDefinitions.GetCurrentProcessId); Delegate[] invocationList = dd.VoidParameterValueDelegate.GetInvocationList(); if (invocationList.Length != 1) { TestLibrary.TestFramework.LogError("001", "Call GetInvocationList against a delegate with one function returns wrong result: " + invocationList.Length); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest2: Hash code of two delegate with the same instance function from same type are equal"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ValueParameterVoidDelegate = new ValueParameterVoidDelegate(dd.TestValueParameterVoidCallback); DelegateDefinitions dd1 = new DelegateDefinitions(); dd1.ValueParameterVoidDelegate = new ValueParameterVoidDelegate(dd.TestValueParameterVoidCallback); if (dd.ValueParameterVoidDelegate.GetHashCode() != dd1.ValueParameterVoidDelegate.GetHashCode()) { TestLibrary.TestFramework.LogError("003", "Hash code of two delegate with the same instance function from same type are not equal"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1: Hash code of two delegate with the same P/Invoke function from same type are equal"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.VoidParameterValueDelegate = new VoidParameterValueDelegate(DelegateDefinitions.GetCurrentProcessId); DelegateDefinitions dd1 = new DelegateDefinitions(); dd1.VoidParameterValueDelegate = new VoidParameterValueDelegate(DelegateDefinitions.GetCurrentProcessId); if (dd.VoidParameterValueDelegate.GetHashCode() != dd1.VoidParameterValueDelegate.GetHashCode()) { TestLibrary.TestFramework.LogError("001", "Hash code of two delegate with the same P/Invoke function from same type are not equal"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest5() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest5: Determine two delegate with same number of invoke list which is initialized with same instance methods are equal"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ValueParameterVoidDelegate = new ValueParameterVoidDelegate(dd.TestValueParameterVoidCallback); dd.ValueParameterVoidDelegate += new ValueParameterVoidDelegate(TestValueParameterVoidCallback); DelegateDefinitions dd1 = new DelegateDefinitions(); dd1.ValueParameterVoidDelegate = new ValueParameterVoidDelegate(dd.TestValueParameterVoidCallback); dd1.ValueParameterVoidDelegate += new ValueParameterVoidDelegate(TestValueParameterVoidCallback); if (!dd.ValueParameterVoidDelegate.Equals(dd1.ValueParameterVoidDelegate)) { TestLibrary.TestFramework.LogError("009", "two delegate with same number of invoke list which is initialized with same instance methods are not equal"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("010", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest4() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest4: Determine whether an initialized delegate is not equal to null"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ValueParameterVoidDelegate = new ValueParameterVoidDelegate(dd.TestValueParameterVoidCallback); if (dd.ValueParameterVoidDelegate.Equals(null)) { TestLibrary.TestFramework.LogError("007", "An initiailzed delegate is equal to null"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("008", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest2: Hash code of two delegate with the same instance function from same type are equal"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ValueParameterVoidDelegate = new ValueParameterVoidDelegate(dd.TestValueParameterVoidCallback); DelegateDefinitions dd1 = new DelegateDefinitions(); dd1.ValueParameterVoidDelegate = new ValueParameterVoidDelegate(dd.TestValueParameterVoidCallback); if (dd.ValueParameterVoidDelegate.GetHashCode() != dd1.ValueParameterVoidDelegate.GetHashCode()) { TestLibrary.TestFramework.LogError("003", "Hash code of two delegate with the same instance function from same type are not equal"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool NegTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("NegTest2: Determine whether two delegate with same name function from different type are not equal"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ValueParameterVoidDelegate = new ValueParameterVoidDelegate(dd.TestValueParameterVoidCallback); DelegateDefinitions dd1 = new DelegateDefinitions(); dd1.ValueParameterVoidDelegate = new ValueParameterVoidDelegate(TestValueParameterVoidCallback); if (dd.ValueParameterVoidDelegate.Equals(dd1.ValueParameterVoidDelegate)) { TestLibrary.TestFramework.LogError("103", "Two delegate with the same name function from different type are equal"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("104", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest2: Return type is void, parameter is a reference value"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ReferenceParameterVoidDelegate = new ReferenceParameterVoidDelegate(dd.TestReferenceParameterVoidCallback); if (null == dd.ReferenceParameterVoidDelegate) { TestLibrary.TestFramework.LogError("003", "Failed to assign a call back function to a delegate"); retVal = false; } dd.ReferenceParameterVoidDelegate(DelegateDefinitions.c_DELEGATE_TEST_DEFAUTL_REFERENCE_PARAMETER); } catch (Exception e) { TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1: Hash code of two delegate with the same P/Invoke function from same type are equal"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.VoidParameterValueDelegate = new VoidParameterValueDelegate(DelegateDefinitions.GetCurrentProcessId); DelegateDefinitions dd1 = new DelegateDefinitions(); dd1.VoidParameterValueDelegate = new VoidParameterValueDelegate(DelegateDefinitions.GetCurrentProcessId); if (dd.VoidParameterValueDelegate.GetHashCode() != dd1.VoidParameterValueDelegate.GetHashCode()) { TestLibrary.TestFramework.LogError("001", "Hash code of two delegate with the same P/Invoke function from same type are not equal"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest2: Determine whether two delegate with the same class method from same type are equal"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ValueParameterVoidDelegate = new ValueParameterVoidDelegate(DelegateDefinitions.TestValueParameterVoidStaticCallback); DelegateDefinitions dd1 = new DelegateDefinitions(); dd1.ValueParameterVoidDelegate = new ValueParameterVoidDelegate(DelegateDefinitions.TestValueParameterVoidStaticCallback); if (!dd.ValueParameterVoidDelegate.Equals(dd1.ValueParameterVoidDelegate)) { TestLibrary.TestFramework.LogError("003", "Two delegate with the same class method from same type are not equal"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest3() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest3: Determine whether two delegate with the same P/Invoke method from same type are equal"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.VoidParameterValueDelegate = new VoidParameterValueDelegate(DelegateDefinitions.GetCurrentProcessId); DelegateDefinitions dd1 = new DelegateDefinitions(); dd1.VoidParameterValueDelegate = new VoidParameterValueDelegate(DelegateDefinitions.GetCurrentProcessId); if (!dd.VoidParameterValueDelegate.Equals(dd1.VoidParameterValueDelegate)) { TestLibrary.TestFramework.LogError("005", "Two delegate with the same P/Invoke method from same type are not equal"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("006", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1: Call GetInvocationList against a delegate with one function"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.VoidParameterValueDelegate = new VoidParameterValueDelegate(DelegateDefinitions.GetCurrentProcessId); Delegate[] invocationList = dd.VoidParameterValueDelegate.GetInvocationList(); if (invocationList.Length != 1) { TestLibrary.TestFramework.LogError("001", "Call GetInvocationList against a delegate with one function returns wrong result: " + invocationList.Length); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest6() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest6: Combine two static methods from different class"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ValueParameterVoidDelegate = new ValueParameterVoidDelegate(MulticastDelegateCombineImpl.TestValueParameterVoidStaticCallback); dd.ValueParameterVoidDelegate += new ValueParameterVoidDelegate(DelegateDefinitions.TestValueParameterVoidStaticCallback); dd.ValueParameterVoidDelegate(DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER); } catch (Exception e) { TestLibrary.TestFramework.LogError("006", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest8() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest8: Combine two multifunctions delegates"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.VoidParameterVoidDelegate = new VoidParameterVoidDelegate(DelegateDefinitions.TestVoidParameterVoidStaticCallback); dd.VoidParameterVoidDelegate += new VoidParameterVoidDelegate(dd.TestVoidParameterVoidCallback); DelegateDefinitions dd1 = new DelegateDefinitions(); dd1.VoidParameterVoidDelegate = new VoidParameterVoidDelegate(DelegateDefinitions.TestVoidParameterVoidStaticCallback); dd1.VoidParameterVoidDelegate += new VoidParameterVoidDelegate(dd1.TestVoidParameterVoidCallback); dd.VoidParameterVoidDelegate = (VoidParameterVoidDelegate)MulticastDelegate.Combine(dd.VoidParameterVoidDelegate, dd1.VoidParameterVoidDelegate); dd.VoidParameterVoidDelegate(); if (dd.VoidParameterVoidDelegateTestValue != DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER + 1) { TestLibrary.TestFramework.LogError("009", "Combined delegate does not work: " + dd.VoidParameterVoidDelegateTestValue); retVal = false; } if (dd1.VoidParameterVoidDelegateTestValue != DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER + 1) { TestLibrary.TestFramework.LogError("010", "Combined delegate does not work: " + dd1.VoidParameterVoidDelegateTestValue); retVal = false; } if (DelegateDefinitions.VoidParameterVoidDelegateStaticTestValue != DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER + 2) { TestLibrary.TestFramework.LogError("011", "Combined delegate does not work: " + DelegateDefinitions.VoidParameterVoidDelegateStaticTestValue); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("012", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } finally { // reset the value of static variable DelegateDefinitions.VoidParameterVoidDelegateStaticTestValue = 0; } return(retVal); }
public bool PosTest16() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest16: Initialize a delegate with an anonymous function"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ReferenceValueParameterReferenceDelegate = delegate(object val1, int val2) { if (!val1.Equals(DelegateDefinitions.c_DELEGATE_TEST_DEFAUTL_REFERENCE_PARAMETER)) { VerificationAgent.ThrowVerificationException( "First input reference parameter is not expected", val1, DelegateDefinitions.c_DELEGATE_TEST_DEFAUTL_REFERENCE_PARAMETER); } if (DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER != val2) { VerificationAgent.ThrowVerificationException( "Second input value parameter is not expected", val2, DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER); } return(DelegateDefinitions.c_DELEGATE_TEST_DEFAUTL_REFERENCE_PARAMETER); }; if (null == dd.ReferenceValueParameterReferenceDelegate) { TestLibrary.TestFramework.LogError("039", "Failed to assign a call back function to a delegate"); retVal = false; } object returnObject = dd.ReferenceValueParameterReferenceDelegate( DelegateDefinitions.c_DELEGATE_TEST_DEFAUTL_REFERENCE_PARAMETER, DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER); if (!returnObject.Equals(DelegateDefinitions.c_DELEGATE_TEST_DEFAUTL_REFERENCE_PARAMETER)) { TestLibrary.TestFramework.LogError("040", "Incorrect delegate return value: " + returnObject); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("041", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest2: Verify the function order of the returned invocation list"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.VoidParameterValueDelegate = new VoidParameterValueDelegate(DelegateDefinitions.GetCurrentProcessId); dd.VoidParameterValueDelegate += new VoidParameterValueDelegate(DelegateDefinitions.TestVoidParameterValueStaticCallback); dd.VoidParameterValueDelegate += new VoidParameterValueDelegate(dd.TestVoidParameterValueCallback); Delegate[] invocationList = dd.VoidParameterValueDelegate.GetInvocationList(); if (invocationList.Length != 3) { TestLibrary.TestFramework.LogError("003", "Call GetInvocationList against a delegate with multiple functions returns wrong result: " + invocationList.Length); retVal = false; } // Hack: I don't know how to iterater through the invocation list to verify the invocation order // is correct. I have to hard code the desired invocation order //if (invocationList[0].Method.Name != "GetCurrentProcessId" || ***** MikeRou 8/3: Method's getter is not supported // invocationList[1].Method.Name != "TestVoidParameterValueStaticCallback" || // invocationList[2].Method.Name != "TestVoidParameterValueCallback") //{ // TestLibrary.TestFramework.LogError("004", "Invocation order of the returned invocation list is wrong"); // retVal = false; //} // Test the invocation list can be invoked for (int i = 0; i < invocationList.Length; ++i) { // invocationList[i].Method.Invoke(invocationList[i].Target, null); ***** MikeRou 8/3: Method's getter is not supported } } catch (Exception e) { TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest2: Verify the function order of the returned invocation list"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.VoidParameterValueDelegate = new VoidParameterValueDelegate(DelegateDefinitions.GetCurrentProcessId); dd.VoidParameterValueDelegate += new VoidParameterValueDelegate(DelegateDefinitions.TestVoidParameterValueStaticCallback); dd.VoidParameterValueDelegate += new VoidParameterValueDelegate(dd.TestVoidParameterValueCallback); Delegate[] invocationList = dd.VoidParameterValueDelegate.GetInvocationList(); if (invocationList.Length != 3) { TestLibrary.TestFramework.LogError("003", "Call GetInvocationList against a delegate with multiple functions returns wrong result: " + invocationList.Length); retVal = false; } // Hack: I don't know how to iterater through the invocation list to verify the invocation order // is correct. I have to hard code the desired invocation order //if (invocationList[0].Method.Name != "GetCurrentProcessId" || ***** MikeRou 8/3: Method's getter is not supported // invocationList[1].Method.Name != "TestVoidParameterValueStaticCallback" || // invocationList[2].Method.Name != "TestVoidParameterValueCallback") //{ // TestLibrary.TestFramework.LogError("004", "Invocation order of the returned invocation list is wrong"); // retVal = false; //} // Test the invocation list can be invoked for (int i = 0; i < invocationList.Length; ++i) { // invocationList[i].Method.Invoke(invocationList[i].Target, null); ***** MikeRou 8/3: Method's getter is not supported } } catch (Exception e) { TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest6() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest6: Determine two delegate with same number of invoke list which is initialized with same multi-type functions are equal"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.VoidParameterValueDelegate = new VoidParameterValueDelegate(dd.TestVoidParameterValueCallback); dd.VoidParameterValueDelegate += new VoidParameterValueDelegate(DelegateDefinitions.TestVoidParameterValueStaticCallback); dd.VoidParameterValueDelegate += new VoidParameterValueDelegate(DelegateDefinitions.GetCurrentProcessId); DelegateDefinitions dd1 = new DelegateDefinitions(); dd1.VoidParameterValueDelegate = new VoidParameterValueDelegate(dd.TestVoidParameterValueCallback); dd1.VoidParameterValueDelegate += new VoidParameterValueDelegate(DelegateDefinitions.TestVoidParameterValueStaticCallback); dd1.VoidParameterValueDelegate += new VoidParameterValueDelegate(DelegateDefinitions.GetCurrentProcessId); if (!dd.VoidParameterValueDelegate.Equals(dd1.VoidParameterValueDelegate)) { TestLibrary.TestFramework.LogError("009", "two delegate with same number of invoke list which is initialized with same multi-type functions are not equal"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("010", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool NegTest5() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("NegTest5: Determine whether two delegate with same number of functions but with different order are not equal"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.VoidParameterValueDelegate = new VoidParameterValueDelegate(dd.TestVoidParameterValueCallback); dd.VoidParameterValueDelegate += new VoidParameterValueDelegate(DelegateDefinitions.TestVoidParameterValueStaticCallback); dd.VoidParameterValueDelegate += new VoidParameterValueDelegate(DelegateDefinitions.GetCurrentProcessId); DelegateDefinitions dd1 = new DelegateDefinitions(); dd1.VoidParameterValueDelegate = new VoidParameterValueDelegate(dd.TestVoidParameterValueCallback); dd1.VoidParameterValueDelegate += new VoidParameterValueDelegate(DelegateDefinitions.GetCurrentProcessId); dd1.VoidParameterValueDelegate += new VoidParameterValueDelegate(DelegateDefinitions.TestVoidParameterValueStaticCallback); if (dd.VoidParameterValueDelegate.Equals(dd1.VoidParameterValueDelegate)) { TestLibrary.TestFramework.LogError("109", "two delegate with same number of functions but with different order are equal"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("110", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest18() { bool retVal = true; if (TestLibrary.Utilities.IsWindows) { TestLibrary.TestFramework.BeginScenario("PosTest18: Initialize a delegate with an P/Invoke method"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.VoidParameterValueDelegate = new VoidParameterValueDelegate(DelegateDefinitions.GetCurrentProcessId); if (null == dd.VoidParameterValueDelegate) { TestLibrary.TestFramework.LogError("045", "Failed to assign a P/Invoke call back function to a delegate"); retVal = false; } int returnObject = dd.VoidParameterValueDelegate(); // Suppress unused variable compiler warning. if (returnObject == 0) { TestLibrary.TestFramework.LogError("046", "Incorrect delegate return value: " + returnObject); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("047", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } } return(retVal); }
public bool NegTest5() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("NegTest5: Return type is a reference type with 1 reference type parameter and 1 value type parameter"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ReferenceValueParameterReferenceDelegate = new ReferenceValueParameterReferenceDelegate(dd.TestReferenceValueParameterReferenceCallbackWithNullValue); dd.ReferenceValueParameterReferenceDelegate(null, DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER); } catch (Exception e) { TestLibrary.TestFramework.LogError("052", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool NegTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("NegTest2: Return type is reference, parameter is a reference value"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ReferenceParameterReferenceDelegate = new ReferenceParameterReferenceDelegate(dd.TestReferenceParameterReferenceCallbackWithNullValue); dd.ReferenceParameterReferenceDelegate(null); } catch (Exception e) { TestLibrary.TestFramework.LogError("049", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool NegTest3() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("NegTest3: Return type is void with 1 value type parameter and one reference type parameter"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ValueReferenceParameterVoidDelegate = new ValueReferenceParameterVoidDelegate(dd.TestValueReferenceParameterVoidCallbackWithNullValue); dd.ValueReferenceParameterVoidDelegate(DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER, null); } catch (Exception e) { TestLibrary.TestFramework.LogError("050", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest17() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest17: Initialize a delegate with an private instance method"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ReferenceValueParameterReferenceDelegate = new ReferenceValueParameterReferenceDelegate(TestReferenceValueParameterReferencePrivateCallback); if (null == dd.ReferenceValueParameterReferenceDelegate) { TestLibrary.TestFramework.LogError("042", "Failed to assign a private call back function to a delegate"); retVal = false; } object returnObject = dd.ReferenceValueParameterReferenceDelegate( DelegateDefinitions.c_DELEGATE_TEST_DEFAUTL_REFERENCE_PARAMETER, DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER); if (!returnObject.Equals(DelegateDefinitions.c_DELEGATE_TEST_DEFAUTL_REFERENCE_PARAMETER)) { TestLibrary.TestFramework.LogError("043", "Incorrect delegate return value: " + returnObject); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("044", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest3() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest3: Determine whether two delegate with the same P/Invoke method from same type are equal"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.VoidParameterValueDelegate = new VoidParameterValueDelegate(DelegateDefinitions.GetCurrentProcessId); DelegateDefinitions dd1 = new DelegateDefinitions(); dd1.VoidParameterValueDelegate = new VoidParameterValueDelegate(DelegateDefinitions.GetCurrentProcessId); if (!dd.VoidParameterValueDelegate.Equals(dd1.VoidParameterValueDelegate)) { TestLibrary.TestFramework.LogError("005", "Two delegate with the same P/Invoke method from same type are not equal"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("006", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool NegTest5() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("NegTest5: Return type is a reference type with 1 reference type parameter and 1 value type parameter"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ReferenceValueParameterReferenceDelegate = new ReferenceValueParameterReferenceDelegate(dd.TestReferenceValueParameterReferenceCallbackWithNullValue); dd.ReferenceValueParameterReferenceDelegate(null, DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER); } catch (Exception e) { TestLibrary.TestFramework.LogError("052", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest3() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest3: Return type is void, parameter is void"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.VoidParameterVoidDelegate = new VoidParameterVoidDelegate(dd.TestVoidParameterVoidCallback); if (null == dd.VoidParameterVoidDelegate) { TestLibrary.TestFramework.LogError("005", "Failed to assign a call back function to a delegate"); retVal = false; } dd.VoidParameterVoidDelegate(); if ((DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER + 1) != dd.VoidParameterVoidDelegateTestValue) { TestLibrary.TestFramework.LogError("006", "Failed to call a delegate"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("007", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest6() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest6: Combine two static methods from different class"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ValueParameterVoidDelegate = new ValueParameterVoidDelegate(MulticastDelegateCombineImpl.TestValueParameterVoidStaticCallback); dd.ValueParameterVoidDelegate += new ValueParameterVoidDelegate(DelegateDefinitions.TestValueParameterVoidStaticCallback); dd.ValueParameterVoidDelegate(DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER); } catch (Exception e) { TestLibrary.TestFramework.LogError("006", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest6() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest6: Determine two delegate with same number of invoke list which is initialized with same multi-type functions are equal"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.VoidParameterValueDelegate = new VoidParameterValueDelegate(dd.TestVoidParameterValueCallback); dd.VoidParameterValueDelegate += new VoidParameterValueDelegate(DelegateDefinitions.TestVoidParameterValueStaticCallback); dd.VoidParameterValueDelegate += new VoidParameterValueDelegate(DelegateDefinitions.GetCurrentProcessId); DelegateDefinitions dd1 = new DelegateDefinitions(); dd1.VoidParameterValueDelegate = new VoidParameterValueDelegate(dd.TestVoidParameterValueCallback); dd1.VoidParameterValueDelegate += new VoidParameterValueDelegate(DelegateDefinitions.TestVoidParameterValueStaticCallback); dd1.VoidParameterValueDelegate += new VoidParameterValueDelegate(DelegateDefinitions.GetCurrentProcessId); if (!dd.VoidParameterValueDelegate.Equals(dd1.VoidParameterValueDelegate)) { TestLibrary.TestFramework.LogError("009", "two delegate with same number of invoke list which is initialized with same multi-type functions are not equal"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("010", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool NegTest4() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("NegTest4: Determine whether two delegate with different number of functions are not equal"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ValueParameterVoidDelegate = new ValueParameterVoidDelegate(dd.TestValueParameterVoidCallback); dd.ValueParameterVoidDelegate += new ValueParameterVoidDelegate(TestValueParameterVoidCallback); DelegateDefinitions dd1 = new DelegateDefinitions(); dd1.ValueParameterVoidDelegate = new ValueParameterVoidDelegate(dd.TestValueParameterVoidCallback); dd1.ValueParameterVoidDelegate += new ValueParameterVoidDelegate(TestValueParameterVoidCallback); dd1.ValueParameterVoidDelegate += new ValueParameterVoidDelegate(TestValueParameterVoidCallback); if (dd.ValueParameterVoidDelegate.Equals(dd1.ValueParameterVoidDelegate)) { TestLibrary.TestFramework.LogError("107", "Two delegate with the different number of functions are equal"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("108", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool NegTest3() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("NegTest3: Return value of second method is different with first method"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.VoidParameterValueDelegate = delegate { return DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER; }; dd.VoidParameterValueDelegate += delegate { return DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER + 1; }; int returnObject = dd.VoidParameterValueDelegate(); if (returnObject != DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER + 1) { TestLibrary.TestFramework.LogError("103", "Incorrect delegate return value: " + returnObject); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("104", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest15() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest15: Return value is a reference type, with 1 reference type parameter and 1 value type parameter, then set a static function"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ReferenceValueParameterReferenceDelegate = new ReferenceValueParameterReferenceDelegate(DelegateDefinitions.TestReferenceValueParameterReferenceStaticCallback); if (null == dd.ReferenceValueParameterReferenceDelegate) { TestLibrary.TestFramework.LogError("036", "Failed to assign a call back function to a delegate"); retVal = false; } object returnObject = dd.ReferenceValueParameterReferenceDelegate( DelegateDefinitions.c_DELEGATE_TEST_DEFAUTL_REFERENCE_PARAMETER, DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER); if (!returnObject.Equals(DelegateDefinitions.c_DELEGATE_TEST_DEFAUTL_REFERENCE_PARAMETER)) { TestLibrary.TestFramework.LogError("037", "Incorrect delegate return value: " + returnObject); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("038", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool NegTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("NegTest1: Combine the same method twice"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ValueParameterVoidDelegate = new ValueParameterVoidDelegate(dd.TestValueParameterVoidCallback); dd.ValueParameterVoidDelegate += new ValueParameterVoidDelegate(dd.TestValueParameterVoidCallback); dd.ValueParameterVoidDelegate(DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER); } catch (Exception e) { TestLibrary.TestFramework.LogError("101", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest8() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest8: Combine two multifunctions delegates"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.VoidParameterVoidDelegate = new VoidParameterVoidDelegate(DelegateDefinitions.TestVoidParameterVoidStaticCallback); dd.VoidParameterVoidDelegate += new VoidParameterVoidDelegate(dd.TestVoidParameterVoidCallback); DelegateDefinitions dd1 = new DelegateDefinitions(); dd1.VoidParameterVoidDelegate = new VoidParameterVoidDelegate(DelegateDefinitions.TestVoidParameterVoidStaticCallback); dd1.VoidParameterVoidDelegate += new VoidParameterVoidDelegate(dd1.TestVoidParameterVoidCallback); dd.VoidParameterVoidDelegate = (VoidParameterVoidDelegate)MulticastDelegate.Combine(dd.VoidParameterVoidDelegate, dd1.VoidParameterVoidDelegate); dd.VoidParameterVoidDelegate(); if (dd.VoidParameterVoidDelegateTestValue != DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER + 1) { TestLibrary.TestFramework.LogError("009", "Combined delegate does not work: " + dd.VoidParameterVoidDelegateTestValue); retVal = false; } if (dd1.VoidParameterVoidDelegateTestValue != DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER + 1) { TestLibrary.TestFramework.LogError("010", "Combined delegate does not work: " + dd1.VoidParameterVoidDelegateTestValue); retVal = false; } if (DelegateDefinitions.VoidParameterVoidDelegateStaticTestValue != DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER + 2) { TestLibrary.TestFramework.LogError("011", "Combined delegate does not work: " + DelegateDefinitions.VoidParameterVoidDelegateStaticTestValue); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("012", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } finally { // reset the value of static variable DelegateDefinitions.VoidParameterVoidDelegateStaticTestValue = 0; } return retVal; }
public bool PosTest7() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest7: Combine two anonymous methods"); try { DelegateDefinitions dd = new DelegateDefinitions(); int i = DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER; dd.ValueParameterValueDelegate = delegate(int val) { if (val != DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER) VerificationAgent.ThrowVerificationException( "Input value parameter is not expected", val, DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER); // Test the call order of multicast delegate i++; return DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER; }; dd.ValueParameterValueDelegate += delegate(int val) { if (val != DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER) VerificationAgent.ThrowVerificationException( "Input value parameter is not expected", val, DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER); if (i != DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER + 1) VerificationAgent.ThrowVerificationException( "Value of out variable of anonymous method is not expected", DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER + 1, i); return DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER; }; int returnObject = dd.ValueParameterValueDelegate(DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER); if (returnObject != DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER) { TestLibrary.TestFramework.LogError("007", "Incorrect delegate return value: " + returnObject); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("008", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool NegTest5() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("NegTest5: Determine whether two delegate with same number of functions but with different order are not equal"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.VoidParameterValueDelegate = new VoidParameterValueDelegate(dd.TestVoidParameterValueCallback); dd.VoidParameterValueDelegate += new VoidParameterValueDelegate(DelegateDefinitions.TestVoidParameterValueStaticCallback); dd.VoidParameterValueDelegate += new VoidParameterValueDelegate(DelegateDefinitions.GetCurrentProcessId); DelegateDefinitions dd1 = new DelegateDefinitions(); dd1.VoidParameterValueDelegate = new VoidParameterValueDelegate(dd.TestVoidParameterValueCallback); dd1.VoidParameterValueDelegate += new VoidParameterValueDelegate(DelegateDefinitions.GetCurrentProcessId); dd1.VoidParameterValueDelegate += new VoidParameterValueDelegate(DelegateDefinitions.TestVoidParameterValueStaticCallback); if (dd.VoidParameterValueDelegate.Equals(dd1.VoidParameterValueDelegate)) { TestLibrary.TestFramework.LogError("109", "two delegate with same number of functions but with different order are equal"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("110", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest16() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest16: Initialize a delegate with an anonymous function"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ReferenceValueParameterReferenceDelegate = delegate(object val1, int val2) { if (!val1.Equals(DelegateDefinitions.c_DELEGATE_TEST_DEFAUTL_REFERENCE_PARAMETER)) VerificationAgent.ThrowVerificationException( "First input reference parameter is not expected", val1, DelegateDefinitions.c_DELEGATE_TEST_DEFAUTL_REFERENCE_PARAMETER); if (DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER != val2) VerificationAgent.ThrowVerificationException( "Second input value parameter is not expected", val2, DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER); return DelegateDefinitions.c_DELEGATE_TEST_DEFAUTL_REFERENCE_PARAMETER; }; if (null == dd.ReferenceValueParameterReferenceDelegate) { TestLibrary.TestFramework.LogError("039", "Failed to assign a call back function to a delegate"); retVal = false; } object returnObject = dd.ReferenceValueParameterReferenceDelegate( DelegateDefinitions.c_DELEGATE_TEST_DEFAUTL_REFERENCE_PARAMETER, DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER); if (!returnObject.Equals(DelegateDefinitions.c_DELEGATE_TEST_DEFAUTL_REFERENCE_PARAMETER)) { TestLibrary.TestFramework.LogError("040", "Incorrect delegate return value: " + returnObject); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("041", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool NagTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("NagTest1: Insert multiple functions with null embeded in the function list"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.VoidParameterValueDelegate = new VoidParameterValueDelegate(DelegateDefinitions.GetCurrentProcessId); dd.VoidParameterValueDelegate += null; dd.VoidParameterValueDelegate += new VoidParameterValueDelegate(DelegateDefinitions.TestVoidParameterValueStaticCallback); dd.VoidParameterValueDelegate += new VoidParameterValueDelegate(dd.TestVoidParameterValueCallback); Delegate[] invocationList = dd.VoidParameterValueDelegate.GetInvocationList(); if (invocationList.Length != 3) { TestLibrary.TestFramework.LogError("101", "Call GetInvocationList against a delegate with one function returns wrong result: " + invocationList.Length); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("102", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest18() { bool retVal = true; if (TestLibrary.Utilities.IsWindows) { TestLibrary.TestFramework.BeginScenario("PosTest18: Initialize a delegate with an P/Invoke method"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.VoidParameterValueDelegate = new VoidParameterValueDelegate(DelegateDefinitions.GetCurrentProcessId); if (null == dd.VoidParameterValueDelegate) { TestLibrary.TestFramework.LogError("045", "Failed to assign a P/Invoke call back function to a delegate"); retVal = false; } int returnObject = dd.VoidParameterValueDelegate(); // Suppress unused variable compiler warning. if (returnObject == 0) { TestLibrary.TestFramework.LogError("046", "Incorrect delegate return value: " + returnObject); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("047", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } } return retVal; }
public bool PosTest17() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest17: Initialize a delegate with an private instance method"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ReferenceValueParameterReferenceDelegate = new ReferenceValueParameterReferenceDelegate(TestReferenceValueParameterReferencePrivateCallback); if (null == dd.ReferenceValueParameterReferenceDelegate) { TestLibrary.TestFramework.LogError("042", "Failed to assign a private call back function to a delegate"); retVal = false; } object returnObject = dd.ReferenceValueParameterReferenceDelegate( DelegateDefinitions.c_DELEGATE_TEST_DEFAUTL_REFERENCE_PARAMETER, DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER); if (!returnObject.Equals(DelegateDefinitions.c_DELEGATE_TEST_DEFAUTL_REFERENCE_PARAMETER)) { TestLibrary.TestFramework.LogError("043", "Incorrect delegate return value: " + returnObject); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("044", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest8() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest8: Return value is a value type, without parameter"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.VoidParameterValueDelegate = new VoidParameterValueDelegate(dd.TestVoidParameterValueCallback); if (null == dd.VoidParameterValueDelegate) { TestLibrary.TestFramework.LogError("020", "Failed to assign a call back function to a delegate"); retVal = false; } int returnObject = dd.VoidParameterValueDelegate(); if (DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER != returnObject) { TestLibrary.TestFramework.LogError("021", "Incorrect delegate return value: " + returnObject); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("022", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest14() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest14: Return value is void, with 1 value parameter and then set a static function"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ValueParameterVoidDelegate = new ValueParameterVoidDelegate(DelegateDefinitions.TestValueParameterVoidStaticCallback); if (null == dd.ValueParameterVoidDelegate) { TestLibrary.TestFramework.LogError("034", "Failed to assign a call back function to a delegate"); retVal = false; } dd.ValueParameterVoidDelegate( DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER); } catch (Exception e) { TestLibrary.TestFramework.LogError("035", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest5() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest5: Combine a private instance method and a private class method from the same type to a delegate"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ValueParameterVoidDelegate = new ValueParameterVoidDelegate(MulticastDelegateCombineImpl.TestValueParameterVoidStaticCallback); dd.ValueParameterVoidDelegate += new ValueParameterVoidDelegate(TestValueParameterVoidCallback1); dd.ValueParameterVoidDelegate(DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER); } catch (Exception e) { TestLibrary.TestFramework.LogError("005", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest10() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest10: Return value is void, with 2 value parameters"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.TwoValueParameterVoidDelegate = new TwoValueParameterVoidDelegate(dd.TestTwoValueParameterVoidCallback); if (null == dd.TwoValueParameterVoidDelegate) { TestLibrary.TestFramework.LogError("026", "Failed to assign a call back function to a delegate"); retVal = false; } dd.TwoValueParameterVoidDelegate( DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER, DelegateDefinitions.c_DELEGATE_TEST_ADDITIONAL_VALUE_PARAMETER); } catch (Exception e) { TestLibrary.TestFramework.LogError("027", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest9() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest9: Return value is a reference type, without parameter"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.VoidParameterReferenceDelegate = new VoidParameterReferenceDelegate(dd.TestVoidParameterReferenceCallback); if (null == dd.VoidParameterReferenceDelegate) { TestLibrary.TestFramework.LogError("023", "Failed to assign a call back function to a delegate"); retVal = false; } object returnObject = dd.VoidParameterReferenceDelegate(); if (!returnObject.Equals(DelegateDefinitions.c_DELEGATE_TEST_DEFAUTL_REFERENCE_PARAMETER)) { TestLibrary.TestFramework.LogError("024", "Incorrect delegate return value: " + returnObject); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("025", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool NegTest3() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("NegTest3: Return type is void with 1 value type parameter and one reference type parameter"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ValueReferenceParameterVoidDelegate = new ValueReferenceParameterVoidDelegate(dd.TestValueReferenceParameterVoidCallbackWithNullValue); dd.ValueReferenceParameterVoidDelegate(DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER, null); } catch (Exception e) { TestLibrary.TestFramework.LogError("050", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool NegTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("NegTest2: Return type is reference, parameter is a reference value"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ReferenceParameterReferenceDelegate = new ReferenceParameterReferenceDelegate(dd.TestReferenceParameterReferenceCallbackWithNullValue); dd.ReferenceParameterReferenceDelegate(null); } catch (Exception e) { TestLibrary.TestFramework.LogError("049", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }