Esempio n. 1
0
    public bool NegTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("NegTest1: ArgumentException should be thrown when Type T does not implement either the System.IComparable generic interface or the System.IComparable interface.");

        try
        {
            TestGenericComparer <ComparerCompare2> comparer = new TestGenericComparer <ComparerCompare2>();
            IComparer icompare = comparer as IComparer;
            icompare.Compare(new ComparerCompare2(), new ComparerCompare2());

            TestLibrary.TestFramework.LogError("101.1", "ArgumentException is not thrown when Type T does not implement either the System.IComparable generic interface or the System.IComparable interface.");
            retVal = false;
        }
        catch (ArgumentException)
        {
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("101.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
Esempio n. 2
0
    public bool NegTest3()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("NegTest3: ArgumentException should be thrown when y is of a type that cannot be cast to type T");

        try
        {
            TestGenericComparer <TestClass1> comparer = new TestGenericComparer <TestClass1>();
            IComparer icompare = comparer as IComparer;
            icompare.Compare(new TestClass1(1), 'a');

            TestLibrary.TestFramework.LogError("103.1", "ArgumentException is not thrown when y is of a type that cannot be cast to type T");
            retVal = false;
        }
        catch (ArgumentException)
        {
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("103.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
Esempio n. 3
0
    public bool PosTest4()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest4: Call Compare when T implements IComparable");

        try
        {
            IComparer comparer = new TestGenericComparer <TestClass1>() as IComparer;
            retVal = VerificationHelper(comparer, new TestClass1(0), new TestClass1(1), -1, "004.1") && retVal;
            retVal = VerificationHelper(comparer, new TestClass1(1), new TestClass1(0), 1, "004.2") && retVal;
            retVal = VerificationHelper(comparer, new TestClass1(1), new TestClass1(1), 0, "004.3") && retVal;

            comparer = new TestGenericComparer <Object>() as IComparer;
            retVal   = VerificationHelper(comparer, new TestClass1(0), 1, -1, "004.4") && retVal;
            retVal   = VerificationHelper(comparer, new TestClass1(1), 0, 1, "004.5") && retVal;
            retVal   = VerificationHelper(comparer, new TestClass1(1), 1, 0, "004.6") && retVal;
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
Esempio n. 4
0
    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: Call Compare to compare two value type instance");

        try
        {
            IComparer comparer = new TestGenericComparer <ValueType>() as IComparer;
            retVal = VerificationHelper(comparer, 1, 2, -1, "001.1") && retVal;
            retVal = VerificationHelper(comparer, 2, 1, 1, "001.2") && retVal;
            retVal = VerificationHelper(comparer, 1, 1, 0, "001.3") && retVal;
            retVal = VerificationHelper(comparer, 1.0, 2.0, -1, "001.4") && retVal;
            retVal = VerificationHelper(comparer, 1, (int)TestEnum.VALUE_0, 1, "001.5") && retVal;
            retVal = VerificationHelper(comparer, 1, (int)TestEnum.VALUE_1, 0, "001.6") && retVal;
            retVal = VerificationHelper(comparer, 'a', 'A', 32, "001.7") && retVal;
            retVal = VerificationHelper(comparer, 'a', 'a', 0, "001.8") && retVal;
            retVal = VerificationHelper(comparer, 'A', 'a', -32, "001.9") && retVal;

            comparer = new TestGenericComparer <int>() as IComparer;
            retVal   = VerificationHelper(comparer, 1, 2, -1, "001.10") && retVal;
            retVal   = VerificationHelper(comparer, 2, 1, 1, "001.11") && retVal;
            retVal   = VerificationHelper(comparer, 1, 1, 0, "001.12") && retVal;
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
Esempio n. 5
0
    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: Call protected ctor to create a new instance of sub class");

        try
        {
            TestGenericComparer <int> comparer1 = new TestGenericComparer <int>();

            if (comparer1 == null)
            {
                TestLibrary.TestFramework.LogError("001.1", "Calling protected ctor to create a new instance of sub class returns null reference");
                retVal = false;
            }

            TestGenericComparer <string> comparer2 = new TestGenericComparer <string>();

            if (comparer2 == null)
            {
                TestLibrary.TestFramework.LogError("001.2", "Calling protected ctor to create a new instance of sub class returns null reference");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
Esempio n. 6
0
    public bool PosTest2()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest2: Call Compare with one or both parameters are null reference");

        try
        {
            IComparer comparer = new TestGenericComparer <TestClass>() as IComparer;
            retVal = VerificationHelper(comparer, null, new TestClass(1), -1, "002.1") && retVal;
            retVal = VerificationHelper(comparer, new TestClass(1), null, 1, "002.2") && retVal;
            retVal = VerificationHelper(comparer, null, null, 0, "002.3") && retVal;
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
Esempio n. 7
0
    public bool PosTest3()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest3: Call Compare when T implements IComparable<T>");

        try
        {
            Comparer <TestClass> comparer = new TestGenericComparer <TestClass>();
            retVal = VerificationHelper <TestClass>(comparer, new TestClass(0), new TestClass(1), -1, "003.1") && retVal;
            retVal = VerificationHelper <TestClass>(comparer, new TestClass(1), new TestClass(0), 1, "003.2") && retVal;
            retVal = VerificationHelper <TestClass>(comparer, new TestClass(1), new TestClass(1), 0, "003.3") && retVal;
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("003.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }