public bool PosTest4() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest4: Return type is a value type, parameter is a value type"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ValueParameterValueDelegate = new ValueParameterValueDelegate(dd.TestValueParameterValueCallback); if (null == dd.ValueParameterValueDelegate) { TestLibrary.TestFramework.LogError("008", "Failed to assign a call back function to a delegate"); retVal = false; } int returnObject = dd.ValueParameterValueDelegate(DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER); if (DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER != returnObject) { TestLibrary.TestFramework.LogError("009", "Incorrect delegate return value: " + returnObject); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("010", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } 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 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 PosTest4() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest4: Return type is a value type, parameter is a value type"); try { DelegateDefinitions dd = new DelegateDefinitions(); dd.ValueParameterValueDelegate = new ValueParameterValueDelegate(dd.TestValueParameterValueCallback); if (null == dd.ValueParameterValueDelegate) { TestLibrary.TestFramework.LogError("008", "Failed to assign a call back function to a delegate"); retVal = false; } int returnObject = dd.ValueParameterValueDelegate(DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER); if (DelegateDefinitions.c_DELEGATE_TEST_DEFAULT_VALUE_PARAMETER != returnObject) { TestLibrary.TestFramework.LogError("009", "Incorrect delegate return value: " + returnObject); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("010", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }