// Returns true if the expected result is right // Returns false if the expected result is wrong public bool PosTest6() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest6: Use the different type's same static method to create two delegate ,then use equals method to compare"); try { DelegateEquals delctor = new DelegateEquals(); booldelegate workDelegate = new booldelegate(TestClass.Completed_Bool); booldelegate workDelegate1 = new booldelegate(TestClass1.Completed_Bool); if (workDelegate.Equals(workDelegate1)) { TestLibrary.TestFramework.LogError("014", "Equals method return error "); retVal = false; } workDelegate(); workDelegate1(); } catch (Exception e) { TestLibrary.TestFramework.LogError("015", "Unexpected exception: " + e); retVal = false; } return(retVal); }
// Returns true if the expected result is right // Returns false if the expected result is wrong public bool PosTest7() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest7: Use the different instance's same instance method to create two delegate ,then use equals method to compare"); try { DelegateEquals delctor = new DelegateEquals(); booldelegate workDelegate = new booldelegate(new TestClass(1).StartWork_Bool); booldelegate workDelegate1 = new booldelegate(new TestClass1(2).StartWork_Bool); if (workDelegate.Equals(workDelegate1)) { TestLibrary.TestFramework.LogError("016", "Equals method return error "); retVal = false; } workDelegate(); workDelegate1(); } catch (Exception e) { TestLibrary.TestFramework.LogError("017", "Unexpected exception: " + e); retVal = false; } return(retVal); }
// Returns true if the expected result is right // Returns false if the expected result is wrong public bool PosTest3() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest3: Use the same type's same static method to create two delegate ,then use equals method to compare"); try { DelegateEquals delctor = new DelegateEquals(); delctor.starkWork = new booldelegate(TestClass.Working_Bool); booldelegate workDelegate = new booldelegate(TestClass.Working_Bool); if (GetCompareResult(workDelegate, (booldelegate)delctor.starkWork)) { if (!workDelegate.Equals((booldelegate)delctor.starkWork)) { TestLibrary.TestFramework.LogError("007", "Equals method return error "); retVal = false; } } else { TestLibrary.TestFramework.LogError("008", "compare condition is error "); retVal = false; } workDelegate(); ((booldelegate)delctor.starkWork)(); } catch (Exception e) { TestLibrary.TestFramework.LogError("009", "Unexpected exception: " + e); retVal = false; } return(retVal); }
// Returns true if the expected result is right // Returns false if the expected result is wrong public bool PosTest4() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest4: Use the same type's different static method to create two delegate ,then use equals method to compare"); try { DelegateEquals delctor = new DelegateEquals(); delctor.starkWork = new booldelegate(TestClass.Working_Bool); booldelegate workDelegate = new booldelegate(TestClass.Completed_Bool); if (workDelegate.Equals((booldelegate)delctor.starkWork)) { TestLibrary.TestFramework.LogError("010", "Equals method return error "); retVal = false; } workDelegate(); ((booldelegate)delctor.starkWork)(); } catch (Exception e) { TestLibrary.TestFramework.LogError("011", "Unexpected exception: " + e); retVal = false; } return(retVal); }
private string GetInvocationListFlag(identify_null start, identify_null working) { DelegateCombine1 delctor = new DelegateCombine1(); TestClass testinstance = new TestClass(); string sFlag = string.Empty; if (start == identify_null.c_Start_null_false) { delctor.starkWork = new booldelegate(testinstance.StartWork_Bool); } else { delctor.starkWork = null; } if (working == identify_null.c_Working_null_false) { delctor.working = new booldelegate(testinstance.Working_Bool); } else { delctor.working = null; } booldelegate combine = (booldelegate)Delegate.Combine(delctor.starkWork, delctor.working); if (combine == null) { return(string.Empty); } for (IEnumerator itr = combine.GetInvocationList().GetEnumerator(); itr.MoveNext();) { booldelegate bd = (booldelegate)itr.Current; if (bd.Equals(delctor.starkWork)) { sFlag += c_StartWrok; } if (bd.Equals(delctor.working)) { sFlag += c_Working; } } combine(); return(sFlag); }
//compare delegate's Type,target, method, and invocation list //two delegates have common Type,target, method, and invocation list //return true.otherwise return false private bool GetCompareResult(booldelegate del1, booldelegate del2) { if (!del1.GetType().Equals(del2.GetType())) { return(false); } if (!del1.Equals(del2)) { return(false); } return(true); }
// Returns true if the expected result is right // Returns false if the expected result is wrong public bool PosTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest2: Use the same instance's same instance method to create two different delegate ,then use equals method to compare"); try { DelegateEquals delctor = new DelegateEquals(); TestClass tcInstance = new TestClass(2); delctor.starkWork = new booldelegate(tcInstance.StartWork_Bool); booldelegate workDelegate = new booldelegate(tcInstance.StartWork_Bool); if (GetCompareResult(workDelegate, (booldelegate)delctor.starkWork)) { if (!workDelegate.Equals((booldelegate)delctor.starkWork)) { TestLibrary.TestFramework.LogError("004", "Equals method return error "); retVal = false; } } else { TestLibrary.TestFramework.LogError("005", "compare condition is error "); retVal = false; } workDelegate(); ((booldelegate)delctor.starkWork)(); } catch (Exception e) { TestLibrary.TestFramework.LogError("006", "Unexpected exception: " + e); retVal = false; } return(retVal); }
// Returns true if the expected result is right // Returns false if the expected result is wrong public bool PosTest1() { bool retVal = true; //Type,target, method, and invocation list TestLibrary.TestFramework.BeginScenario("PosTest1: Use one delegate object to instance the other delegate object,then use equals method to compare"); try { DelegateEquals delctor = new DelegateEquals(); delctor.starkWork = new booldelegate(new TestClass(1).StartWork_Bool); booldelegate workDelegate = (booldelegate)delctor.starkWork; if (GetCompareResult(workDelegate, (booldelegate)delctor.starkWork)) { if (!workDelegate.Equals((booldelegate)delctor.starkWork)) { TestLibrary.TestFramework.LogError("001", "Equals method return error "); retVal = false; } } else { TestLibrary.TestFramework.LogError("002", "compare condition is error "); retVal = false; } workDelegate(); ((booldelegate)delctor.starkWork)(); } catch (Exception e) { TestLibrary.TestFramework.LogError("003", "Unexpected exception: " + e); retVal = false; } return(retVal); }
// Returns true if the expected result is right // Returns false if the expected result is wrong public bool PosTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest2: Use the same instance's same instance method to create two different delegate ,then use equals method to compare"); try { DelegateEquals delctor = new DelegateEquals(); TestClass tcInstance = new TestClass(2); delctor.starkWork = new booldelegate(tcInstance.StartWork_Bool); booldelegate workDelegate = new booldelegate(tcInstance.StartWork_Bool); if (GetCompareResult(workDelegate, (booldelegate)delctor.starkWork)) { if (!workDelegate.Equals((booldelegate)delctor.starkWork)) { TestLibrary.TestFramework.LogError("004", "Equals method return error "); retVal = false; } } else { TestLibrary.TestFramework.LogError("005", "compare condition is error "); retVal = false; } workDelegate(); ((booldelegate)delctor.starkWork)(); } catch (Exception e) { TestLibrary.TestFramework.LogError("006", "Unexpected exception: " + e); retVal = false; } return retVal; }
private bool CombineImpl(booldelegate delegatesrc, identify_null start) { DelegateCombineImpl delctor = new DelegateCombineImpl(); TestClass testinstance = new TestClass(); string sFlag = string.Empty; string sFlagAdd = string.Empty; booldelegate combineImpl = delegatesrc; if (start == identify_null.c_Start_null_false) { delctor.starkWork = new booldelegate(testinstance.StartWork_Bool); combineImpl += (booldelegate)delctor.starkWork; sFlagAdd = c_StartWork; } else if (start == identify_null.c_Start_null_false_duplicate) { delctor.starkWork = new booldelegate(testinstance.StartWork_Bool); combineImpl += (booldelegate)delctor.starkWork; sFlagAdd = c_StartWork; //The invocation list can contain duplicate entries; that is, entries that refer to the same method on the same object. combineImpl += (booldelegate)delctor.starkWork; sFlagAdd += sFlagAdd; } else if (start == identify_null.c_Start_null_true) { delctor.starkWork = null; combineImpl += (booldelegate)delctor.starkWork; } else if (start == identify_null.c_Working_null_false) { delctor.working = new booldelegate(testinstance.Working_Bool); combineImpl += (booldelegate)delctor.working; sFlagAdd = c_Working; } else { delctor.working = null; combineImpl += (booldelegate)delctor.working; } if (combineImpl == null) { return(true); } for (IEnumerator itr = combineImpl.GetInvocationList().GetEnumerator(); itr.MoveNext();) { booldelegate bd = (booldelegate)itr.Current; //the filter is to get the delegate which is appended through equals method. if (bd.Equals(delctor.starkWork)) { sFlag += c_StartWork; } if (bd.Equals(delctor.working)) { sFlag += c_Working; } } combineImpl(); //judge delegate is appended to the end of the invocation list of the current if (sFlag == sFlagAdd) { return(true); } else { return(false); } }
//compare delegate's Type,target, method, and invocation list //two delegates have common Type,target, method, and invocation list //return true.otherwise return false private bool GetCompareResult(booldelegate del1, booldelegate del2) { if (!del1.GetType().Equals(del2.GetType())) { return false; } if (!del1.Equals(del2)) { return false; } return true; }
// Returns true if the expected result is right // Returns false if the expected result is wrong public bool PosTest7() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest7: Use the different instance's same instance method to create two delegate ,then use equals method to compare"); try { DelegateEquals delctor = new DelegateEquals(); booldelegate workDelegate = new booldelegate(new TestClass(1).StartWork_Bool); booldelegate workDelegate1 = new booldelegate(new TestClass1(2).StartWork_Bool ); if (workDelegate.Equals(workDelegate1)) { TestLibrary.TestFramework.LogError("016", "Equals method return error "); retVal = false; } workDelegate(); workDelegate1(); } catch (Exception e) { TestLibrary.TestFramework.LogError("017", "Unexpected exception: " + e); retVal = false; } return retVal; }
// Returns true if the expected result is right // Returns false if the expected result is wrong public bool PosTest6() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest6: Use the different type's same static method to create two delegate ,then use equals method to compare"); try { DelegateEquals delctor = new DelegateEquals(); booldelegate workDelegate = new booldelegate(TestClass.Completed_Bool); booldelegate workDelegate1 = new booldelegate(TestClass1.Completed_Bool); if (workDelegate.Equals(workDelegate1)) { TestLibrary.TestFramework.LogError("014", "Equals method return error "); retVal = false; } workDelegate(); workDelegate1(); } catch (Exception e) { TestLibrary.TestFramework.LogError("015", "Unexpected exception: " + e); retVal = false; } return retVal; }
// Returns true if the expected result is right // Returns false if the expected result is wrong public bool PosTest4() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest4: Use the same type's different static method to create two delegate ,then use equals method to compare"); try { DelegateEquals delctor = new DelegateEquals(); delctor.starkWork = new booldelegate(TestClass.Working_Bool); booldelegate workDelegate = new booldelegate(TestClass.Completed_Bool); if (workDelegate.Equals((booldelegate)delctor.starkWork)) { TestLibrary.TestFramework.LogError("010", "Equals method return error "); retVal = false; } workDelegate(); ((booldelegate)delctor.starkWork)(); } catch (Exception e) { TestLibrary.TestFramework.LogError("011", "Unexpected exception: " + e); retVal = false; } return retVal; }
// Returns true if the expected result is right // Returns false if the expected result is wrong public bool PosTest3() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest3: Use the same type's same static method to create two delegate ,then use equals method to compare"); try { DelegateEquals delctor = new DelegateEquals(); delctor.starkWork = new booldelegate(TestClass.Working_Bool); booldelegate workDelegate = new booldelegate(TestClass.Working_Bool); if (GetCompareResult(workDelegate, (booldelegate)delctor.starkWork)) { if (!workDelegate.Equals((booldelegate)delctor.starkWork)) { TestLibrary.TestFramework.LogError("007", "Equals method return error "); retVal = false; } } else { TestLibrary.TestFramework.LogError("008", "compare condition is error "); retVal = false; } workDelegate(); ((booldelegate)delctor.starkWork)(); } catch (Exception e) { TestLibrary.TestFramework.LogError("009", "Unexpected exception: " + e); retVal = false; } return retVal; }