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

        TestLibrary.TestFramework.BeginScenario("PosTest1: Resource of the Enumerator should be released after Dispose().");

        try
        {
            Queue <string> TestQueue = new Queue <string>();
            TestQueue.Enqueue("one");
            TestQueue.Enqueue("two");
            TestQueue.Enqueue("three");
            Queue <string> .Enumerator TestEnumerator;
            TestEnumerator = TestQueue.GetEnumerator();
            TestEnumerator.MoveNext();
            TestEnumerator.Dispose();
            string TestString = TestEnumerator.Current;
            TestLibrary.TestFramework.LogError("P01.1", "Resource of the Enumerator have not been released after Dispose()!");
            retVal = false;
        }
        catch (InvalidOperationException)
        {
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("P01.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogVerbose(e.StackTrace);
            retVal = false;
        }

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

        TestLibrary.TestFramework.BeginScenario("NegTest1: InvalidOperationException should be thrown when the collection was modified after the enumerator was created.");

        try
        {
            Queue <string> TestQueue = new Queue <string>();
            TestQueue.Enqueue("one");
            TestQueue.Enqueue("two");
            TestQueue.Enqueue("three");
            Queue <string> .Enumerator TestEnumerator;
            TestEnumerator = TestQueue.GetEnumerator();
            TestQueue.Enqueue("four");
            TestEnumerator.MoveNext();
            TestLibrary.TestFramework.LogError("N01.1", "InvalidOperationException is not thrown when the collection was modified after the enumerator was created!");
            retVal = false;
        }
        catch (InvalidOperationException)
        {
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("N01.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogVerbose(e.StackTrace);
            retVal = false;
        }

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

        TestLibrary.TestFramework.BeginScenario("PosTest1: The enumerator should be positioned at the first element in the collection after MoveNext().");

        try
        {
            Queue <string> TestQueue = new Queue <string>();
            TestQueue.Enqueue("one");
            TestQueue.Enqueue("two");
            TestQueue.Enqueue("three");
            Queue <string> .Enumerator TestEnumerator;
            TestEnumerator = TestQueue.GetEnumerator();
            TestEnumerator.MoveNext();
            string TestString = TestEnumerator.Current;
            if (TestString != "one")
            {
                TestLibrary.TestFramework.LogError("P01.1", "The enumerator is not positioned at the first element in the collection after MoveNext()!");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("P01.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogVerbose(e.StackTrace);
            retVal = false;
        }

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

        TestLibrary.TestFramework.BeginScenario("NegTest2: InvalidOperationException should be thrown when the enumerator is positioned after the last element of the collection.");

        try
        {
            Queue <string> TestQueue = new Queue <string>();
            TestQueue.Enqueue("one");
            TestQueue.Enqueue("two");
            TestQueue.Enqueue("three");
            Queue <string> .Enumerator TestEnumerator;
            TestEnumerator = TestQueue.GetEnumerator();
            TestEnumerator.MoveNext();
            TestEnumerator.MoveNext();
            TestEnumerator.MoveNext();
            TestEnumerator.MoveNext();
            string TestString = TestEnumerator.Current;
            TestLibrary.TestFramework.LogError("N02.1", "InvalidOperationException is not thrown when the enumerator is positioned after the last element of the collection!");
            retVal = false;
        }
        catch (InvalidOperationException)
        {
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("N02.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogVerbose(e.StackTrace);
            retVal = false;
        }

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

        TestLibrary.TestFramework.BeginScenario("PosTest1: Test whether GetEnumerator() is successful when the queue is not empty.");

        try
        {
            Queue <string> TestQueue = new Queue <string>();
            TestQueue.Enqueue("one");
            TestQueue.Enqueue("two");
            TestQueue.Enqueue("three");
            Queue <string> .Enumerator TestEnumerator;
            TestEnumerator = TestQueue.GetEnumerator();
            TestEnumerator.MoveNext();
            for (int i = 0; i < TestQueue.Count; i++)
            {
                if (TestQueue.ToArray()[i] != TestEnumerator.Current)
                {
                    TestLibrary.TestFramework.LogError("P01.1", "GetEnumerator() failed when the queue is not empty!");
                    retVal = false;
                }
                TestEnumerator.MoveNext();
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("P01.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogVerbose(e.StackTrace);
            retVal = false;
        }

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

        TestLibrary.TestFramework.BeginScenario("PosTest2: Test whether GetEnumerator() is successful when the queue is empty.");

        try
        {
            Queue <string>             TestQueue = new Queue <string>();
            Queue <string> .Enumerator TestEnumerator;
            TestEnumerator = TestQueue.GetEnumerator();
            try
            {
                string CurrentElement = TestEnumerator.Current;
                TestLibrary.TestFramework.LogError("P02.1", "GetEnumerator() failed when the queue is empty!");
                retVal = false;
            }
            catch (InvalidOperationException)
            {
            }
            bool b = TestEnumerator.MoveNext();
            if (b != false)
            {
                TestLibrary.TestFramework.LogError("P02.2", "GetEnumerator() failed when the queue is empty!");
                retVal = false;
            }
            try
            {
                string CurrentElement = TestEnumerator.Current;
                TestLibrary.TestFramework.LogError("P02.3", "GetEnumerator() failed when the queue is empty!");
                retVal = false;
            }
            catch (InvalidOperationException)
            {
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("P02.4", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogVerbose(e.StackTrace);
            retVal = false;
        }

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

        TestLibrary.TestFramework.BeginScenario("PosTest4: With a Queue that contains three items, MoveNext returns true the first three times and returns false every time it is called after that.");

        try
        {
            bool           b;
            Queue <string> TestQueue = new Queue <string>();
            TestQueue.Enqueue("one");
            TestQueue.Enqueue("two");
            TestQueue.Enqueue("three");
            Queue <string> .Enumerator TestEnumerator;
            TestEnumerator = TestQueue.GetEnumerator();
            for (int i = 0; i < 3; i++)
            {
                b = TestEnumerator.MoveNext();
                if (!b)
                {
                    TestLibrary.TestFramework.LogError("P04.1", "MoveNext() failed!");
                    retVal = false;
                }
            }
            b = TestEnumerator.MoveNext();
            if (b)
            {
                TestLibrary.TestFramework.LogError("P04.1", "MoveNext() failed!");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("P04.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogVerbose(e.StackTrace);
            retVal = false;
        }

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

        TestLibrary.TestFramework.BeginScenario("PosTest3: The enumerator should be positioned after the last element in the collection after MoveNext() passed the end of collection.");

        try
        {
            Queue <string> TestQueue = new Queue <string>();
            TestQueue.Enqueue("one");
            TestQueue.Enqueue("two");
            TestQueue.Enqueue("three");
            Queue <string> .Enumerator TestEnumerator;
            TestEnumerator = TestQueue.GetEnumerator();
            bool bSuc;
            bSuc = TestEnumerator.MoveNext();
            bSuc = TestEnumerator.MoveNext();
            bSuc = TestEnumerator.MoveNext();
            bSuc = TestEnumerator.MoveNext();
            bSuc = TestEnumerator.MoveNext();
            bSuc = TestEnumerator.MoveNext();
            if (bSuc)
            {
                TestLibrary.TestFramework.LogError("P03.1", "The enumerator is not positioned after the last element in the collection after MoveNext() passed the end of collection!");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("P03.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogVerbose(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }