Example #1
0
        // 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;
        }
Example #2
0
        // 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;
        }
Example #3
0
        // 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;
        }
Example #4
0
        // 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
        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);
        }
Example #6
0
        // Returns true if the expected result is right
        // Returns false if the expected result is wrong
        public bool PosTest1()
        {
            bool retVal = true;

            TestLibrary.TestFramework.BeginScenario("PosTest1: Call GetInvocationList against a delegate with one function");
            try
            {
                DelegateGetInvocationList delctor = new DelegateGetInvocationList();
                booldelegate dStartWork_Bool      = new booldelegate(new TestClass().StartWork_Bool);
                delctor.starkWork = dStartWork_Bool;
                Delegate[] invocationList = delctor.starkWork.GetInvocationList();
                if (invocationList.Length != 1)
                {
                    TestLibrary.TestFramework.LogError("001", "Call GetInvocationList against a delegate with one function returns wrong result: " + invocationList.Length);
                    retVal = false;
                }
                if (!delctor.starkWork.GetInvocationList()[0].Equals(dStartWork_Bool))
                {
                    TestLibrary.TestFramework.LogError("002", " GetInvocationList return error method  ");
                    retVal = false;
                }
                delctor.starkWork();
            }
            catch (Exception e)
            {
                TestLibrary.TestFramework.LogError("003", "Unexpected exception: " + e);
                retVal = false;
            }

            return(retVal);
        }
Example #7
0
        // 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);
        }
Example #8
0
        // 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
        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);
        }
Example #10
0
        // 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);
        }
Example #11
0
        // 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 PosTest1()
        {
            bool retVal = true;

            TestLibrary.TestFramework.BeginScenario("PosTest1: Call GetInvocationList against a delegate with one function");
            try
            {
                DelegateGetInvocationList delctor = new DelegateGetInvocationList();
                booldelegate dStartWork_Bool = new booldelegate(new TestClass().StartWork_Bool);
                delctor.starkWork = dStartWork_Bool;
                Delegate[] invocationList = delctor.starkWork.GetInvocationList();
                if (invocationList.Length != 1)
                {
                    TestLibrary.TestFramework.LogError("001", "Call GetInvocationList against a delegate with one function returns wrong result: " + invocationList.Length);
                    retVal = false;
                }
                if (!delctor.starkWork.GetInvocationList()[0].Equals(dStartWork_Bool))
                {
                    TestLibrary.TestFramework.LogError("002", " GetInvocationList return error method  ");
                    retVal = false;
                }
                delctor.starkWork();
            }
            catch (Exception e)
            {
                TestLibrary.TestFramework.LogError("003", "Unexpected exception: " + e);
                retVal = false;
            }

            return retVal;
        }
Example #13
0
        // Returns true if the expected result is right
        // Returns false if the expected result is wrong
        public bool NegTest1()
        {
            bool retVal = true;

            TestLibrary.TestFramework.BeginScenario("NegTest1: The delegate types do not match. ");

            try
            {
                DelegateRemove delctor         = new DelegateRemove();
                TestClass      tcInstance      = new TestClass();
                booldelegate   bStartWork_Bool = new booldelegate(tcInstance.StartWork_Bool);
                booldelegate   bWorking_Bool   = new booldelegate(tcInstance.Working_Bool);
                booldelegate   bCompleted_Bool = new booldelegate(tcInstance.Completed_Bool);

                delctor.starkWork += bStartWork_Bool;
                delctor.starkWork += bWorking_Bool;
                delctor.starkWork += bCompleted_Bool;
                delctor.starkWork  = (booldelegate)Delegate.Remove(delctor.starkWork, new voiddelegate(tcInstance.StartWork_Void));

                TestLibrary.TestFramework.LogError("015", "delegate remove error ");
                retVal = false;
            }
            catch (ArgumentException)
            {
            }
            catch (Exception e)
            {
                TestLibrary.TestFramework.LogError("016", "Unexpected exception: " + e);
                retVal = false;
            }

            return(retVal);
        }
Example #14
0
        // 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;
        }
Example #15
0
        //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);
        }
Example #16
0
        // 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: Remove a function which is not in the InvocationList");
            try
            {
                DelegateRemoveImpl delctor         = new DelegateRemoveImpl();
                booldelegate       bStartWork_Bool = new booldelegate(new TestClass().StartWork_Bool);
                booldelegate       bWorking_Bool   = new booldelegate(new TestClass().Working_Bool);
                booldelegate       bCompleted_Bool = new booldelegate(new TestClass().Completed_Bool);
                booldelegate       bOther_bool     = new booldelegate(TestClass1.Other_Bool);

                delctor.starkWork += bStartWork_Bool;
                delctor.starkWork += bWorking_Bool;
                delctor.starkWork += bCompleted_Bool;
                Delegate[] beforeList = delctor.starkWork.GetInvocationList();
                delctor.starkWork -= bOther_bool;
                Delegate[] afterList = delctor.starkWork.GetInvocationList();
                if (beforeList.Length != afterList.Length)
                {
                    TestLibrary.TestFramework.LogError("006",
                                                       String.Format("Remove changed invocation list length from {0} to {1}", beforeList.Length,
                                                                     afterList.Length));
                    retVal = false;
                }
                else
                {
                    for (int i = 0; i < beforeList.Length; i++)
                    {
                        if (!beforeList[i].Equals(afterList[i]))
                        {
                            TestLibrary.TestFramework.LogError("006a", String.Format(
                                                                   "Invocation lists differ at element {0}", i));
                            retVal = false;
                        }
                    }
                }
                delctor.starkWork();
            }
            catch (Exception e)
            {
                TestLibrary.TestFramework.LogError("008", "Unexpected exception: " + e);
                retVal = false;
            }

            return(retVal);
        }
Example #17
0
        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);
        }
Example #18
0
        // 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: Remove a function which is in the InvocationList and not only one method");
            try
            {
                DelegateRemoveImpl delctor         = new DelegateRemoveImpl();
                TestClass          tcInstance      = new TestClass();
                booldelegate       bStartWork_Bool = new booldelegate(tcInstance.StartWork_Bool);
                booldelegate       bWorking_Bool   = new booldelegate(tcInstance.Working_Bool);
                booldelegate       bCompleted_Bool = new booldelegate(tcInstance.Completed_Bool);

                delctor.starkWork += bStartWork_Bool;
                delctor.starkWork += bStartWork_Bool;
                delctor.starkWork += bWorking_Bool;
                delctor.starkWork += bCompleted_Bool;
                delctor.starkWork -= bStartWork_Bool;
                Delegate[] invocationList = delctor.starkWork.GetInvocationList();
                if (invocationList.Length != 3)
                {
                    TestLibrary.TestFramework.LogError("009", "remove failure: " + invocationList.Length);
                    retVal = false;
                }
                if (!delctor.starkWork.GetInvocationList()[0].Equals(bStartWork_Bool) ||
                    !delctor.starkWork.GetInvocationList()[1].Equals(bWorking_Bool) ||
                    !delctor.starkWork.GetInvocationList()[2].Equals(bCompleted_Bool))
                {
                    TestLibrary.TestFramework.LogError("010", " remove failure ");
                    retVal = false;
                }
                delctor.starkWork();
            }
            catch (Exception e)
            {
                TestLibrary.TestFramework.LogError("011", "Unexpected exception: " + e);
                retVal = false;
            }

            return(retVal);
        }
Example #19
0
        // 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: Call GetInvocationList against a delegate with muti functions ,some of these are the same");
            try
            {
                DelegateGetInvocationList delctor = new DelegateGetInvocationList();
                booldelegate bStartWork_Bool      = new booldelegate(new TestClass().StartWork_Bool);
                booldelegate bWorking_Bool        = new booldelegate(new TestClass().Working_Bool);
                booldelegate bCompleted_Bool      = new booldelegate(new TestClass().Completed_Bool);

                delctor.starkWork += bStartWork_Bool;
                delctor.starkWork += bStartWork_Bool;
                delctor.starkWork += bWorking_Bool;
                delctor.starkWork += bCompleted_Bool;
                Delegate[] invocationList = delctor.starkWork.GetInvocationList();
                if (invocationList.Length != 4)
                {
                    TestLibrary.TestFramework.LogError("010", "Call GetInvocationList against a delegate with one function returns wrong result: " + invocationList.Length);
                    retVal = false;
                }
                if (!delctor.starkWork.GetInvocationList()[0].Equals(bStartWork_Bool) ||
                    !delctor.starkWork.GetInvocationList()[1].Equals(bStartWork_Bool) ||
                    !delctor.starkWork.GetInvocationList()[2].Equals(bWorking_Bool) ||
                    !delctor.starkWork.GetInvocationList()[3].Equals(bCompleted_Bool))
                {
                    TestLibrary.TestFramework.LogError("011", " GetInvocationList return error method  ");
                    retVal = false;
                }
                delctor.starkWork();
            }
            catch (Exception e)
            {
                TestLibrary.TestFramework.LogError("012", "Unexpected exception: " + e);
                retVal = false;
            }

            return(retVal);
        }
Example #20
0
        // 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: Remove a function which is not in the InvocationList");
            try
            {
                DelegateRemove delctor         = new DelegateRemove();
                booldelegate   bStartWork_Bool = new booldelegate(new TestClass().StartWork_Bool);
                booldelegate   bWorking_Bool   = new booldelegate(new TestClass().Working_Bool);
                booldelegate   bCompleted_Bool = new booldelegate(new TestClass().Completed_Bool);

                delctor.starkWork += bStartWork_Bool;
                delctor.starkWork += null;
                delctor.starkWork += bWorking_Bool;
                delctor.starkWork += bCompleted_Bool;
                delctor.starkWork  = (booldelegate)Delegate.Remove(delctor.starkWork, new booldelegate(new TestClass().Completed_Bool));
                Delegate[] invocationList = delctor.starkWork.GetInvocationList();
                if (invocationList.Length != 3)
                {
                    TestLibrary.TestFramework.LogError("006", "Call GetInvocationList against a delegate with one function returns wrong result: " + invocationList.Length);
                    retVal = false;
                }
                if (!delctor.starkWork.GetInvocationList()[0].Equals(bStartWork_Bool) ||
                    !delctor.starkWork.GetInvocationList()[1].Equals(bWorking_Bool) ||
                    !delctor.starkWork.GetInvocationList()[2].Equals(bCompleted_Bool))
                {
                    TestLibrary.TestFramework.LogError("007", " remove failure ");
                    retVal = false;
                }
                delctor.starkWork();
            }
            catch (Exception e)
            {
                TestLibrary.TestFramework.LogError("008", "Unexpected exception: " + e);
                retVal = false;
            }

            return(retVal);
        }
Example #21
0
        // Returns true if the expected result is right
        // Returns false if the expected result is wrong
        public bool PosTest5()
        {
            bool retVal = true;

            TestLibrary.TestFramework.BeginScenario("PosTest5: Remove a function which is in the InvocationList and not only one method ,method is static method");
            try
            {
                DelegateRemove delctor         = new DelegateRemove();
                booldelegate   bStartWork_Bool = new booldelegate(TestClass1.StartWork_Bool);
                booldelegate   bWorking_Bool   = new booldelegate(TestClass1.Working_Bool);
                booldelegate   bCompleted_Bool = new booldelegate(TestClass1.Completed_Bool);

                delctor.starkWork += bStartWork_Bool;
                delctor.starkWork += bStartWork_Bool;
                delctor.starkWork += bWorking_Bool;
                delctor.starkWork += bCompleted_Bool;
                delctor.starkWork  = (booldelegate)Delegate.Remove(delctor.starkWork, new booldelegate(TestClass1.StartWork_Bool));
                Delegate[] invocationList = delctor.starkWork.GetInvocationList();
                if (invocationList.Length != 3)
                {
                    TestLibrary.TestFramework.LogError("012", "remove failure: " + invocationList.Length);
                    retVal = false;
                }
                if (!delctor.starkWork.GetInvocationList()[0].Equals(bStartWork_Bool) ||
                    !delctor.starkWork.GetInvocationList()[1].Equals(bWorking_Bool) ||
                    !delctor.starkWork.GetInvocationList()[2].Equals(bCompleted_Bool))
                {
                    TestLibrary.TestFramework.LogError("013", " remove failure ");
                    retVal = false;
                }
                delctor.starkWork();
            }
            catch (Exception e)
            {
                TestLibrary.TestFramework.LogError("014", "Unexpected exception: " + e);
                retVal = false;
            }

            return(retVal);
        }
Example #22
0
        // 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: Remove a function which is in the InvocationList");
            try
            {
                DelegateRemove delctor         = new DelegateRemove();
                TestClass      tcInstance      = new TestClass();
                booldelegate   bStartWork_Bool = new booldelegate(tcInstance.StartWork_Bool);
                booldelegate   bWorking_Bool   = new booldelegate(tcInstance.Working_Bool);
                booldelegate   bCompleted_Bool = new booldelegate(tcInstance.Completed_Bool);

                delctor.starkWork += bStartWork_Bool;
                delctor.starkWork += bWorking_Bool;
                delctor.starkWork += bCompleted_Bool;
                delctor.starkWork  = (booldelegate)Delegate.Remove(delctor.starkWork, new booldelegate(tcInstance.Working_Bool));
                Delegate[] invocationList = delctor.starkWork.GetInvocationList();
                if (invocationList.Length != 2)
                {
                    TestLibrary.TestFramework.LogError("003", "remove failure or remove method is not in the InvocationList");
                    retVal = false;
                }
                if (!delctor.starkWork.GetInvocationList()[0].Equals(bStartWork_Bool) ||
                    !delctor.starkWork.GetInvocationList()[1].Equals(bCompleted_Bool))
                {
                    TestLibrary.TestFramework.LogError("004", " remove failure ");
                    retVal = false;
                }
                delctor.starkWork();
            }
            catch (Exception e)
            {
                TestLibrary.TestFramework.LogError("005", "Unexpected exception: " + e);
                retVal = false;
            }

            return(retVal);
        }
Example #23
0
        // 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: Remove a function which is in the InvocationList");
            try
            {
                DelegateRemoveImpl delctor = new DelegateRemoveImpl();
                TestClass tcInstance = new TestClass();
		booldelegate bStartWork_Bool = new booldelegate(tcInstance.StartWork_Bool);
		booldelegate bWorking_Bool   = new booldelegate(tcInstance.Working_Bool);
		booldelegate bCompleted_Bool = new booldelegate(tcInstance.Completed_Bool);

                delctor.starkWork += bStartWork_Bool;
                delctor.starkWork += bWorking_Bool;
                delctor.starkWork += bCompleted_Bool;
                delctor.starkWork -= bWorking_Bool;
                Delegate[] invocationList = delctor.starkWork.GetInvocationList();
                if (invocationList.Length != 2)
                {
                    TestLibrary.TestFramework.LogError("003", "remove failure or remove method is not in the InvocationList");
                    retVal = false;
                }
                if (!delctor.starkWork.GetInvocationList()[0].Equals(bStartWork_Bool)
                    || !delctor.starkWork.GetInvocationList()[1].Equals(bCompleted_Bool))
                {
                    TestLibrary.TestFramework.LogError("004", " remove failure ");
                    retVal = false;
                }
                delctor.starkWork();
            }
            catch (Exception e)
            {
                TestLibrary.TestFramework.LogError("005", "Unexpected exception: " + e);
                retVal = false;
            }
            
            return retVal;
        }
Example #24
0
        // 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: combine two delegate ,first is not null,second is  null");

            try
            {
                booldelegate delgate = new booldelegate(new TestClass().StartWork_Bool);
                if (!CombineImpl(delgate, identify_null.c_Working_null_true))
                {
                    TestLibrary.TestFramework.LogError("005", "delegate combine is not successful ");
                    retVal = false;
                }
            }
            catch (Exception e)
            {
                TestLibrary.TestFramework.LogError("006", "Unexpected exception: " + e);
                retVal = false;
            }

            return(retVal);
        }
Example #25
0
        // Returns true if the expected result is right
        // Returns false if the expected result is wrong
        public bool PosTest5()
        {
            bool retVal = true;

            TestLibrary.TestFramework.BeginScenario("PosTest5: combine three delegate ,first is  not null and the two others  entry that refer to the same method on the same object");

            try
            {
                booldelegate delegate1 = new booldelegate(new TestClass().Working_Bool);
                if (!CombineImpl(delegate1, identify_null.c_Start_null_false_duplicate))
                {
                    TestLibrary.TestFramework.LogError("009", "delegate combine is not successful ");
                    retVal = false;
                }
            }
            catch (Exception e)
            {
                TestLibrary.TestFramework.LogError("010", "Unexpected exception: " + e);
                retVal = false;
            }

            return(retVal);
        }
Example #26
0
        // Returns true if the expected result is right
        // Returns false if the expected result is wrong
        public bool PosTest1()
        {
            bool retVal = true;

            TestLibrary.TestFramework.BeginScenario("PosTest1: combine two  delegates which are not null");

            try
            {
                booldelegate delegate1 = new booldelegate(new TestClass().Working_Bool);
                if (!CombineImpl(delegate1, identify_null.c_Start_null_false))
                {
                    TestLibrary.TestFramework.LogError("001", "delegate combineimpl is not successful ");
                    retVal = false;
                }
            }
            catch (Exception e)
            {
                TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
                retVal = false;
            }

            return(retVal);
        }
Example #27
0
        // 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: combine two delegate ,first is null,second is not null");

            try
            {
                booldelegate delegate1 = null;
                if (!CombineImpl(delegate1, identify_null.c_Working_null_false))
                {
                    TestLibrary.TestFramework.LogError("003", "delegate combine is not successful ");
                    retVal = false;
                }
            }
            catch (Exception e)
            {
                TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e);
                retVal = false;
            }

            return(retVal);
        }
Example #28
0
        // 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;

            TestLibrary.TestFramework.BeginScenario("PosTest1: combine two  delegates which are not null");

            try
            {
                booldelegate delgate = new booldelegate(new TestClass().Working_Bool);
                if (!CombineImpl(delgate,identify_null.c_Start_null_false))
                {
                    TestLibrary.TestFramework.LogError("001", "delegate combineimpl is not successful ");
                    retVal = false;
                }
              
            }
            catch (Exception e)
            {
                TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
                retVal = false;
            }

            return retVal;
        }
Example #30
0
        // 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 PosTest5()
        {
            bool retVal = true;

            TestLibrary.TestFramework.BeginScenario("PosTest5: combine three delegate ,first is  not null and the two others  entry that refer to the same method on the same object");

            try
            {
                booldelegate delgate = new booldelegate(new TestClass().Working_Bool);
                if (!CombineImpl(delgate, identify_null.c_Start_null_false_duplicate ))
                {
                    TestLibrary.TestFramework.LogError("009", "delegate combine is not successful ");
                    retVal = false;
                }

            }
            catch (Exception e)
            {
                TestLibrary.TestFramework.LogError("010", "Unexpected exception: " + e);
                retVal = false;
            }

            return retVal;
        }
Example #32
0
        // 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;
        }
Example #33
0
        // 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;
        }
Example #34
0
        // 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;
        }
Example #35
0
        // 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;
        }
Example #36
0
        // 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: Remove a function which is not in the InvocationList");
            try
            {
                DelegateRemove delctor = new DelegateRemove();
		booldelegate bStartWork_Bool = new booldelegate(new TestClass().StartWork_Bool);
		booldelegate bWorking_Bool   = new booldelegate(new TestClass().Working_Bool);
		booldelegate bCompleted_Bool = new booldelegate(new TestClass().Completed_Bool);

                delctor.starkWork += bStartWork_Bool;
                delctor.starkWork += null;
                delctor.starkWork += bWorking_Bool;
                delctor.starkWork += bCompleted_Bool;
                delctor.starkWork = (booldelegate)Delegate.Remove(delctor.starkWork, new booldelegate(new TestClass().Completed_Bool));
                Delegate[] invocationList = delctor.starkWork.GetInvocationList();
                if (invocationList.Length != 3)
                {
                    TestLibrary.TestFramework.LogError("006", "Call GetInvocationList against a delegate with one function returns wrong result: " + invocationList.Length);
                    retVal = false;
                }
                if (!delctor.starkWork.GetInvocationList()[0].Equals(bStartWork_Bool)
                    || !delctor.starkWork.GetInvocationList()[1].Equals(bWorking_Bool)
                    || !delctor.starkWork.GetInvocationList()[2].Equals(bCompleted_Bool))
                {
                    TestLibrary.TestFramework.LogError("007", " remove failure ");
                    retVal = false;
                }
                delctor.starkWork();
            }
            catch (Exception e)
            {
                TestLibrary.TestFramework.LogError("008", "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: combine two delegate ,first is not null,second is  null");

            try
            {

                booldelegate delgate = new booldelegate(new TestClass().StartWork_Bool);
                if (!CombineImpl(delgate, identify_null.c_Working_null_true   ))
                {
                    TestLibrary.TestFramework.LogError("005", "delegate combine is not successful ");
                    retVal = false;
                }
             

            }
            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 PosTest2()
        {
            bool retVal = true;

            TestLibrary.TestFramework.BeginScenario("PosTest2: Call GetInvocationList against a delegate with muti different functions ");
            try
            {
                DelegateGetInvocationList delctor = new DelegateGetInvocationList();
		booldelegate bStartWork_Bool = new booldelegate(new TestClass().StartWork_Bool);
		booldelegate bWorking_Bool   = new booldelegate(new TestClass().Working_Bool);
		booldelegate bCompleted_Bool = new booldelegate(new TestClass().Completed_Bool);

                delctor.starkWork += bStartWork_Bool;
                delctor.starkWork += bWorking_Bool;
                delctor.starkWork += bCompleted_Bool;
                Delegate[] invocationList = delctor.starkWork.GetInvocationList();
                if (invocationList.Length != 3)
                {
                    TestLibrary.TestFramework.LogError("004", "Call GetInvocationList against a delegate with one function returns wrong result: " + invocationList.Length);
                    retVal = false;
                }
                if (!delctor.starkWork.GetInvocationList()[0].Equals(bStartWork_Bool)
                    || !delctor.starkWork.GetInvocationList()[1].Equals(bWorking_Bool)
                    || !delctor.starkWork.GetInvocationList()[2].Equals(bCompleted_Bool))
                {
                    TestLibrary.TestFramework.LogError("005", " GetInvocationList return error method  ");
                    retVal = false;
                }
                delctor.starkWork();
            }
            catch (Exception e)
            {
                TestLibrary.TestFramework.LogError("006", "Unexpected exception: " + e);
                retVal = false;
            }

            return retVal;
        }
Example #39
0
        // Returns true if the expected result is right
        // Returns false if the expected result is wrong
        public bool PosTest5()
        {
            bool retVal = true;

            TestLibrary.TestFramework.BeginScenario("PosTest5: Remove a function which is in the InvocationList and not only one method ,method is static method");
            try
            {
                DelegateRemoveImpl delctor = new DelegateRemoveImpl();
		booldelegate bStartWork_Bool = new booldelegate(TestClass1.StartWork_Bool);
		booldelegate bWorking_Bool   = new booldelegate(TestClass1.Working_Bool);
		booldelegate bCompleted_Bool = new booldelegate(TestClass1.Completed_Bool);

                delctor.starkWork += bStartWork_Bool;
                delctor.starkWork += bStartWork_Bool;
                delctor.starkWork += bWorking_Bool;
                delctor.starkWork += bCompleted_Bool;
                delctor.starkWork -= bStartWork_Bool;
                Delegate[] invocationList = delctor.starkWork.GetInvocationList();
                if (invocationList.Length != 3)
                {
                    TestLibrary.TestFramework.LogError("012", "remove failure: " + invocationList.Length);
                    retVal = false;
                }
                if (!delctor.starkWork.GetInvocationList()[0].Equals(bStartWork_Bool)
                    || !delctor.starkWork.GetInvocationList()[1].Equals(bWorking_Bool)
                    || !delctor.starkWork.GetInvocationList()[2].Equals(bCompleted_Bool))
                {
                    TestLibrary.TestFramework.LogError("013", " remove failure ");
                    retVal = false;
                }
                delctor.starkWork();
            }
            catch (Exception e)
            {
                TestLibrary.TestFramework.LogError("014", "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_StartWrok;
               
            }
            else if (start == identify_null.c_Start_null_false_duplicate )
            {
                delctor.starkWork = new booldelegate(testinstance.StartWork_Bool);
                combineImpl += (booldelegate)delctor.starkWork;
                sFlagAdd = c_StartWrok;
                //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_StartWrok;
                }
                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;
            
        }
Example #41
0
        // Returns true if the expected result is right
        // Returns false if the expected result is wrong
        public bool NegTest1()
        {
            bool retVal = true;
            TestLibrary.TestFramework.BeginScenario("NegTest1: The delegate types do not match. ");

            try
            {
                DelegateRemove delctor = new DelegateRemove();
                TestClass tcInstance = new TestClass();
		booldelegate bStartWork_Bool = new booldelegate(tcInstance.StartWork_Bool);
		booldelegate bWorking_Bool   = new booldelegate(tcInstance.Working_Bool);
		booldelegate bCompleted_Bool = new booldelegate(tcInstance.Completed_Bool);

                delctor.starkWork += bStartWork_Bool;
                delctor.starkWork += bWorking_Bool;
                delctor.starkWork += bCompleted_Bool;
                delctor.starkWork = (booldelegate)Delegate.Remove(delctor.starkWork, new voiddelegate(tcInstance.StartWork_Void));
                
                TestLibrary.TestFramework.LogError("015", "delegate remove error ");
                retVal = false;
            }
            catch (ArgumentException)
            {

            }
            catch (Exception e)
            {
                TestLibrary.TestFramework.LogError("016", "Unexpected exception: " + e);
                retVal = false;
            }

            return retVal;
        }
Example #42
0
        // 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: Remove a function which is in the InvocationList and not only one method");
            try
            {
                DelegateRemove delctor = new DelegateRemove();
                TestClass tcInstance = new TestClass();
		booldelegate bStartWork_Bool = new booldelegate(tcInstance.StartWork_Bool);
		booldelegate bWorking_Bool   = new booldelegate(tcInstance.Working_Bool);
		booldelegate bCompleted_Bool = new booldelegate(tcInstance.Completed_Bool);

                delctor.starkWork += bStartWork_Bool;
                delctor.starkWork += bStartWork_Bool;
                delctor.starkWork += bWorking_Bool;
                delctor.starkWork += bCompleted_Bool;
                delctor.starkWork = (booldelegate)Delegate.Remove(delctor.starkWork, new booldelegate(tcInstance.StartWork_Bool));
                Delegate[] invocationList = delctor.starkWork.GetInvocationList();
                if (invocationList.Length !=3)
                {
                    TestLibrary.TestFramework.LogError("009", "remove failure: " + invocationList.Length);
                    retVal = false;
                }
                if (!delctor.starkWork.GetInvocationList()[0].Equals(bStartWork_Bool)
                    || !delctor.starkWork.GetInvocationList()[1].Equals(bWorking_Bool)
                    || !delctor.starkWork.GetInvocationList()[2].Equals(bCompleted_Bool))
                {
                    TestLibrary.TestFramework.LogError("010", " remove failure ");
                    retVal = false;
                }
                delctor.starkWork();
            }
            catch (Exception e)
            {
                TestLibrary.TestFramework.LogError("011", "Unexpected exception: " + e);
                retVal = false;
            }

            return retVal;
        }
Example #43
0
        // 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: Remove a function which is not in the InvocationList");
            try
            {
                DelegateRemoveImpl delctor = new DelegateRemoveImpl();
		booldelegate bStartWork_Bool = new booldelegate(new TestClass().StartWork_Bool);
		booldelegate bWorking_Bool   = new booldelegate(new TestClass().Working_Bool);
		booldelegate bCompleted_Bool = new booldelegate(new TestClass().Completed_Bool);
		booldelegate bOther_bool = new booldelegate(TestClass1.Other_Bool);

                delctor.starkWork += bStartWork_Bool;
                delctor.starkWork += bWorking_Bool;
                delctor.starkWork += bCompleted_Bool;
		Delegate[] beforeList = delctor.starkWork.GetInvocationList();
                delctor.starkWork -= bOther_bool;
		Delegate[] afterList = delctor.starkWork.GetInvocationList();
		if (beforeList.Length != afterList.Length)
                 {
                    TestLibrary.TestFramework.LogError("006", 
		String.Format("Remove changed invocation list length from {0} to {1}", beforeList.Length,
		afterList.Length));
                    retVal = false;
                } else {
		for (int i=0; i<beforeList.Length; i++)
			if (!beforeList[i].Equals(afterList[i]))
			{
			TestLibrary.TestFramework.LogError("006a", String.Format(
			 "Invocation lists differ at element {0}", i));
			retVal=false;
			}
		}
                delctor.starkWork();
            }
            catch (Exception e)
            {
                TestLibrary.TestFramework.LogError("008", "Unexpected exception: " + e);
                retVal = false;
            }
            
            return retVal;
        }
Example #44
0
        // 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;
        }
Example #45
0
        // 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;
        }
Example #46
0
 //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;
 }
Example #47
0
        // 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;
        }
Example #48
0
        // 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;
        }
Example #49
0
        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);
            }
        }
Example #50
0
        // 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;
        }