// Returns true if the expected result is right // Returns false if the expected result is wrong // one delegate object is booldelegate // the other is voiddelegate public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1: hash code of two different delegate object is not equal,the two delegate callback different function. "); try { DelegateGetHashCode delctor = new DelegateGetHashCode(); booldelegate workDelegate = new booldelegate(new TestClass(1).StartWork_Bool ); voiddelegate workDelegate1 = new voiddelegate(new TestClass(1).StartWork_Void); if (workDelegate.GetHashCode() == workDelegate1.GetHashCode()) { TestLibrary.TestFramework.LogError("001", "HashCode is not excepted "); retVal = false; } workDelegate(); workDelegate1(); } catch (Exception e) { TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e); retVal = false; } return retVal; }
// Returns true if the expected result is right // Returns false if the expected result is wrong // one delegate object is booldelegate // the other is booldelegate1 public bool PosTest2() { bool retVal = true; //Type,target, method, and invocation list TestLibrary.TestFramework.BeginScenario("PosTest2: hash code of two different delegate object even though they invoke the same function is not equal "); try { DelegateGetHashCode delctor = new DelegateGetHashCode(); booldelegate workDelegate = new booldelegate(new TestClass(1).StartWork_Bool); booldelegate1 workDelegate1 = new booldelegate1(new TestClass(1).StartWork_Bool); if (workDelegate.GetHashCode() == workDelegate1.GetHashCode()) { TestLibrary.TestFramework.LogError("003", "HashCode is not excepted "); retVal = false; } workDelegate(); workDelegate1(); } catch (Exception e) { TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e); retVal = false; } return retVal; }
// Returns true if the expected result is right // Returns false if the expected result is wrong // the same delegate object is booldelegate public bool PosTest7() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest7: Use the different instance's same instance method to create two delegate which delegate object is the same, their hashcode is different"); try { DelegateGetHashCode delctor = new DelegateGetHashCode(); booldelegate workDelegate = new booldelegate(new TestClass(1).StartWork_Bool); booldelegate workDelegate1 = new booldelegate(new TestClass1(2).StartWork_Bool ); if (workDelegate.GetHashCode()==workDelegate1.GetHashCode()) { TestLibrary.TestFramework.LogError("013", "HashCode is not excepted "); retVal = false; } workDelegate(); workDelegate1(); } catch (Exception e) { TestLibrary.TestFramework.LogError("014", "Unexpected exception: " + e); retVal = false; } return retVal; }
// Returns true if the expected result is right // Returns false if the expected result is wrong // one delegate object is booldelegate // the other is booldelegate2 public bool PosTest8() { bool retVal = true; //Type,target, method, and invocation list TestLibrary.TestFramework.BeginScenario("PosTest8: hash code of two delegate object is not equal,the two delegate callback different function. "); try { DelegateGetHashCode delctor = new DelegateGetHashCode(); booldelegate workDelegate = new booldelegate(new TestClass(1).StartWork_Bool); booldelegate2 workDelegate1 = new booldelegate2(new TestClass(1).StartWork_Bool); if (workDelegate.GetHashCode() == workDelegate1.GetHashCode()) { TestLibrary.TestFramework.LogError("015", "HashCode is not excepted "); retVal = false; } workDelegate(); workDelegate1("hello"); } catch (Exception e) { TestLibrary.TestFramework.LogError("016", "Unexpected exception: " + e); retVal = false; } return retVal; }
// Returns true if the expected result is right // Returns false if the expected result is wrong // the same delegate object is booldelegate public bool PosTest3() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest3: Use the same type's same method to create two delegate which delegate object is the same,their hashcode is equal"); try { DelegateGetHashCode delctor = new DelegateGetHashCode(); booldelegate workDelegate = new booldelegate(TestClass.Working_Bool); booldelegate workDelegate1 = new booldelegate(TestClass.Working_Bool); if (workDelegate.GetHashCode() != workDelegate1.GetHashCode()) { TestLibrary.TestFramework.LogError("005", "HashCode is not excepted "); retVal = false; } workDelegate(); workDelegate1(); } 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 // the same delegate object is booldelegate public bool PosTest6() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest6: Use the different type's same static method to create two delegate ,which delegate object is the same,their hashcode is equal"); try { DelegateGetHashCode delctor = new DelegateGetHashCode(); booldelegate workDelegate = new booldelegate(TestClass.Completed_Bool); booldelegate workDelegate1 = new booldelegate(TestClass1.Completed_Bool); if (workDelegate.GetHashCode()!=workDelegate1.GetHashCode()) { TestLibrary.TestFramework.LogError("011", "HashCode is not excepted"); retVal = false; } workDelegate(); workDelegate1(); } catch (Exception e) { TestLibrary.TestFramework.LogError("012", "Unexpected exception: " + e); retVal = false; } return retVal; }
// Returns true if the expected result is right // Returns false if the expected result is wrong // one delegate object is booldelegate // the other is voiddelegate public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1: hash code of two different delegate object is not equal,the two delegate callback different function. "); try { DelegateGetHashCode delctor = new DelegateGetHashCode(); booldelegate workDelegate = new booldelegate(new TestClass(1).StartWork_Bool ); voiddelegate workDelegate1 = new voiddelegate(new TestClass(1).StartWork_Void); if (workDelegate.GetHashCode() == workDelegate1.GetHashCode()) { TestLibrary.TestFramework.LogError("001", "HashCode is not excepted "); retVal = false; } workDelegate(); workDelegate1(); } catch (Exception e) { TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e); retVal = false; } return retVal; }
// Returns true if the expected result is right // Returns false if the expected result is wrong // one delegate object is booldelegate // the other is booldelegate1 public bool PosTest2() { bool retVal = true; //Type,target, method, and invocation list TestLibrary.TestFramework.BeginScenario("PosTest2: hash code of two different delegate object even though they invoke the same function is not equal "); try { DelegateGetHashCode delctor = new DelegateGetHashCode(); booldelegate workDelegate = new booldelegate(new TestClass(1).StartWork_Bool); booldelegate1 workDelegate1 = new booldelegate1(new TestClass(1).StartWork_Bool); if (workDelegate.GetHashCode() == workDelegate1.GetHashCode()) { TestLibrary.TestFramework.LogError("003", "HashCode is not excepted "); retVal = false; } workDelegate(); workDelegate1(); } catch (Exception e) { TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e); retVal = false; } return retVal; }
// Returns true if the expected result is right // Returns false if the expected result is wrong // one delegate object is booldelegate // the other is booldelegate2 public bool PosTest8() { bool retVal = true; //Type,target, method, and invocation list TestLibrary.TestFramework.BeginScenario("PosTest8: hash code of two delegate object is not equal,the two delegate callback different function. "); try { DelegateGetHashCode delctor = new DelegateGetHashCode(); booldelegate workDelegate = new booldelegate(new TestClass(1).StartWork_Bool); booldelegate2 workDelegate1 = new booldelegate2(new TestClass(1).StartWork_Bool); if (workDelegate.GetHashCode() == workDelegate1.GetHashCode()) { TestLibrary.TestFramework.LogError("015", "HashCode is not excepted "); retVal = false; } workDelegate(); workDelegate1("hello"); } catch (Exception e) { TestLibrary.TestFramework.LogError("016", "Unexpected exception: " + e); retVal = false; } return retVal; }
// Returns true if the expected result is right // Returns false if the expected result is wrong // the same delegate object is booldelegate public bool PosTest7() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest7: Use the different instance's same instance method to create two delegate which delegate object is the same,their hashcode is equal"); try { DelegateGetHashCode delctor = new DelegateGetHashCode(); booldelegate workDelegate = new booldelegate(new TestClass(1).StartWork_Bool); booldelegate workDelegate1 = new booldelegate(new TestClass1(2).StartWork_Bool ); if (workDelegate.GetHashCode()!=workDelegate1.GetHashCode()) { TestLibrary.TestFramework.LogError("013", "HashCode is not excepted "); retVal = false; } workDelegate(); workDelegate1(); } catch (Exception e) { TestLibrary.TestFramework.LogError("014", "Unexpected exception: " + e); retVal = false; } return retVal; }
// Returns true if the expected result is right // Returns false if the expected result is wrong // the same delegate object is booldelegate public bool PosTest6() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest6: Use the different type's same static method to create two delegate ,which delegate object is the same,their hashcode is equal"); try { DelegateGetHashCode delctor = new DelegateGetHashCode(); booldelegate workDelegate = new booldelegate(TestClass.Completed_Bool); booldelegate workDelegate1 = new booldelegate(TestClass1.Completed_Bool); if (workDelegate.GetHashCode()!=workDelegate1.GetHashCode()) { TestLibrary.TestFramework.LogError("011", "HashCode is not excepted"); retVal = false; } workDelegate(); workDelegate1(); } catch (Exception e) { TestLibrary.TestFramework.LogError("012", "Unexpected exception: " + e); retVal = false; } return retVal; }