Example #1
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:Copies a range of elements from an Array starting at the Sourceindex element and pastes them into another Array starting at the Target index element,the two array can upcast.");
        try
        {
            Array           myOriginalArray = Array.CreateInstance(typeof(TestDeriveClass), c_MaxValue);
            Array           myTargetArray   = Array.CreateInstance(typeof(TestBaseClass), c_MaxValue * 2);
            TestDeriveClass generator1;
            TestBaseClass   generator2;
            for (int i = 0; i < c_MaxValue; i++)
            {
                generator1 = new TestDeriveClass(i);
                generator2 = new TestDeriveClass(i + c_MaxValue);
                myOriginalArray.SetValue(generator1, i);
                myTargetArray.SetValue(generator2, i);
            }
            Array.Copy(myOriginalArray, c_MinValue, myTargetArray, c_MaxValue, c_MaxValue);
            int index = c_MaxValue;
            for (IEnumerator itr = myOriginalArray.GetEnumerator(); itr.MoveNext();)
            {
                object current = itr.Current;
                if (!current.Equals(myTargetArray.GetValue(index)))
                {
                    TestLibrary.TestFramework.LogError("005", "Copy error");
                    retVal = false;
                    break;
                }
                index++;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("006", "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
    public bool NegTest5()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("NegTest5:At least one element in sourceArray cannot be cast to the type of destinationArray.");
        try
        {
            Array            myOriginalArray = Array.CreateInstance(typeof(ITestInterface), c_MaxValue);
            Array            myTargetArray   = Array.CreateInstance(typeof(TestBaseClass), c_MaxValue * 2);
            TestDeriveClass  generator1;
            TestBaseClass    generator2;
            TestDeriveClass1 generator3 = new TestDeriveClass1(100);
            for (int i = 0; i < c_MaxValue; i++)
            {
                generator1 = new TestDeriveClass(i);
                generator2 = new TestDeriveClass(i + c_MaxValue);
                myOriginalArray.SetValue(generator1, i);
                myTargetArray.SetValue(generator2, i);
            }

            myOriginalArray.SetValue(generator3, c_MaxValue - 1);
            Array.Copy(myOriginalArray, c_MinValue, myTargetArray, c_MaxValue, c_MaxValue);
            TestLibrary.TestFramework.LogError("017", "Copy error");
            retVal = false;
        }
        catch (InvalidCastException)
        {
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("018", "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
    public bool NegTest5()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("NegTest5:At least one element in sourceArray cannot be cast to the type of destinationArray.");
        try
        {
            Array myOriginalArray = Array.CreateInstance(typeof(ITestInterface), c_MaxValue);
            Array myTargetArray = Array.CreateInstance(typeof(TestBaseClass), c_MaxValue * 2);
            TestDeriveClass generator1;
            TestBaseClass generator2;
            TestDeriveClass1 generator3=new TestDeriveClass1(100);
            for (int i = 0; i < c_MaxValue; i++)
            {
                generator1 = new TestDeriveClass(i);
                generator2 = new TestDeriveClass(i + c_MaxValue);
                myOriginalArray.SetValue(generator1, i);
                myTargetArray.SetValue(generator2, i);
            }

            myOriginalArray.SetValue(generator3, c_MaxValue - 1);
            Array.Copy(myOriginalArray, myTargetArray, c_MaxValue);
            TestLibrary.TestFramework.LogError("017", "Copy error");
            retVal = false;
        }
        catch (InvalidCastException)
        {
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("018", "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
    public bool PosTest3()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest3:Copies a range of elements from an Array starting at the first element and pastes them into another Array starting at the first element,the two array can upcast.");
        try
        {
            Array myOriginalArray = Array.CreateInstance(typeof(TestDeriveClass), c_MaxValue);
            Array myTargetArray = Array.CreateInstance(typeof(TestBaseClass), c_MaxValue * 2);
            TestDeriveClass generator1;
            TestBaseClass generator2 ;
            for (int i = 0; i < c_MaxValue; i++)
            {
                generator1 = new TestDeriveClass(i);
                generator2 = new TestDeriveClass(i + c_MaxValue);
                myOriginalArray.SetValue(generator1, i);
                myTargetArray.SetValue(generator2, i);
            }
            Array.Copy(myOriginalArray, myTargetArray, c_MaxValue);
            int index = 0;
            for (IEnumerator itr = myOriginalArray.GetEnumerator(); itr.MoveNext(); )
            {
                object current = itr.Current;
                if (!current.Equals(myTargetArray.GetValue(index)))
                {
                    TestLibrary.TestFramework.LogError("005", "Copy error");
                    retVal = false;
                    break;
                }
                index++;
            }

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

        return retVal;
    }