public bool PosTest4()
    {
        bool retVal    = true;
        int  randValue = 0;

        TestLibrary.TestFramework.BeginScenario("PosTest4: Call DangerousRelease after call DangerousAddRef for invalid handle");

        try
        {
            randValue = TestLibrary.Generator.GetInt32(-55);
            SafeHandle handle  = new MySafeInValidHandle(new IntPtr(randValue));
            bool       success = false;

            handle.DangerousAddRef(ref success);
            if (!success)
            {
                TestLibrary.TestFramework.LogInformation("WARNING: Calling DangerousAddRef returns false");
            }

            handle.DangerousRelease();
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] randValue = " + randValue.ToString());
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
    public bool PosTest3()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest3: Call DangerousRelease after call DangerousAddRef for invalid handle");

        try
        {
            SafeHandle handle  = new MySafeInValidHandle();
            bool       success = false;

            handle.DangerousAddRef(ref success);
            if (!success)
            {
                TestLibrary.TestFramework.LogInformation("WARNING: Calling DangerousAddRef returns false");
            }

            handle.DangerousRelease();
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("003", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
예제 #3
0
    public bool PosTest4()
    {
        bool retVal    = true;
        int  randValue = 0;

        TestLibrary.TestFramework.BeginScenario("PosTest4: call Dispose on an invalid SafeHandle instance with false");

        try
        {
            MySafeInValidHandle handle = new MySafeInValidHandle();
            handle.DisposeWrap(false);

            randValue = TestLibrary.Generator.GetInt32(-55);
            handle    = new MySafeInValidHandle(new IntPtr(randValue));
            handle.DisposeWrap(false);
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] randValue = " + randValue);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
예제 #4
0
    public bool PosTest4()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest4: DangerousGetHandle should return handle value for valid safe handle");

        try
        {
            int        randValue    = TestLibrary.Generator.GetInt32(-55);
            IntPtr     desiredValue = new IntPtr(randValue);
            SafeHandle handle       = new MySafeInValidHandle(desiredValue);
            IntPtr     handleValue  = handle.DangerousGetHandle();

            if (handleValue != desiredValue)
            {
                TestLibrary.TestFramework.LogError("004.1", "DangerousGetHandle returns wrong handle value for valid safe handle");
                TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] handleValue = " + handleValue.ToString() + ", desiredValue = " + desiredValue.ToString());
                retVal = false;
            }

            handleValue = handle.DangerousGetHandle();

            if (handleValue != desiredValue)
            {
                TestLibrary.TestFramework.LogError("004.2", "DangerousGetHandle returns wrong handle value for valid safe handle");
                TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] handleValue = " + handleValue.ToString() + ", desiredValue = " + desiredValue.ToString());
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004.3", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
예제 #5
0
    public bool PosTest3()
    {
        bool retVal    = true;
        int  randValue = 0;

        TestLibrary.TestFramework.BeginScenario("PosTest3: call Dispose through IDispose interface");

        try
        {
            SafeHandle  handle = new MySafeInValidHandle();
            IDisposable idisp  = handle as IDisposable;
            idisp.Dispose();

            randValue = TestLibrary.Generator.GetInt32(-55);
            handle    = new MySafeInValidHandle(new IntPtr(randValue));
            idisp     = handle as IDisposable;
            idisp.Dispose();

            handle = new MySafeValidHandle();
            idisp  = handle as IDisposable;
            idisp.Dispose();

            randValue = TestLibrary.Generator.GetInt32(-55);
            handle    = new MySafeValidHandle(new IntPtr(randValue));
            idisp     = handle as IDisposable;
            idisp.Dispose();
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("003", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] randValue = " + randValue);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
예제 #6
0
    public bool PosTest3()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest3: DangerousGetHandle should return handle value for invalid safe handle");

        try
        {
            SafeHandle handle      = new MySafeInValidHandle();
            IntPtr     handleValue = handle.DangerousGetHandle();

            if (handleValue != IntPtr.Zero)
            {
                TestLibrary.TestFramework.LogError("003.1", "DangerousGetHandle returns wrong handle value for invalid safe handle");
                TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] handleValue = " + handleValue.ToString() + ", desiredValue = IntPtr.Zero");
                retVal = false;
            }

            handleValue = handle.DangerousGetHandle();

            if (handleValue != IntPtr.Zero)
            {
                TestLibrary.TestFramework.LogError("003.2", "DangerousGetHandle returns wrong handle value for invalid safe handle");
                TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] handleValue = " + handleValue.ToString() + ", desiredValue = IntPtr.Zero");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("003.3", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
예제 #7
0
    public bool PosTest4()
    {
        bool retVal = true;
        int randValue = 0;

        TestLibrary.TestFramework.BeginScenario("PosTest4: call Dispose on an invalid SafeHandle instance with false");

        try
        {
            MySafeInValidHandle handle = new MySafeInValidHandle();
            handle.DisposeWrap(false);

            randValue = TestLibrary.Generator.GetInt32(-55);
            handle = new MySafeInValidHandle(new IntPtr(randValue));
            handle.DisposeWrap(false);
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] randValue = " + randValue);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
예제 #8
0
    public bool PosTest3()
    {
        bool retVal = true;
        int randValue = 0;

        TestLibrary.TestFramework.BeginScenario("PosTest3: call Dispose through IDispose interface");

        try
        {
            SafeHandle handle = new MySafeInValidHandle();
            IDisposable idisp = handle as IDisposable;
            idisp.Dispose();

            randValue = TestLibrary.Generator.GetInt32(-55);
            handle = new MySafeInValidHandle(new IntPtr(randValue));
            idisp = handle as IDisposable;
            idisp.Dispose();

            handle = new MySafeValidHandle();
            idisp = handle as IDisposable;
            idisp.Dispose();

            randValue = TestLibrary.Generator.GetInt32(-55);
            handle = new MySafeValidHandle(new IntPtr(randValue));
            idisp = handle as IDisposable;
            idisp.Dispose();
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("003", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] randValue = " + randValue);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
    public bool PosTest6()
    {
        bool retVal = true;
        int randValue = 0;

        TestLibrary.TestFramework.BeginScenario("PosTest6: Call DangerousAddRef after call DangerousRelease for invalid handle");

        try
        {
            randValue = TestLibrary.Generator.GetInt32(-55);
            SafeHandle handle = new MySafeInValidHandle(new IntPtr(randValue));
            bool success = false;

            handle.DangerousAddRef(ref success);
            if (!success)
            {
                TestLibrary.TestFramework.LogInformation("WARNING: Calling DangerousAddRef returns false");
            }

            handle.DangerousRelease();

            handle.DangerousAddRef(ref success);
            if (!success)
            {
                TestLibrary.TestFramework.LogError("006.1", "Calling DangerousAddRef returns false after calling DangerousRelease");
            }

            handle.DangerousRelease();
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("006.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] randValue = " + randValue.ToString());
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
예제 #10
0
    public bool PosTest3()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest3: Call DangerousRelease after call DangerousAddRef for invalid handle");

        try
        {
            SafeHandle handle = new MySafeInValidHandle();
            bool success = false;

            handle.DangerousAddRef(ref success);
            if (!success)
            {
                TestLibrary.TestFramework.LogInformation("WARNING: Calling DangerousAddRef returns false");
            }

            handle.DangerousRelease();
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("003", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
    public bool PosTest4()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest4: DangerousGetHandle should return handle value for valid safe handle");

        try
        {
            int randValue = TestLibrary.Generator.GetInt32(-55);
            IntPtr desiredValue = new IntPtr(randValue);
            SafeHandle handle = new MySafeInValidHandle(desiredValue);
            IntPtr handleValue = handle.DangerousGetHandle();

            if (handleValue != desiredValue)
            {
                TestLibrary.TestFramework.LogError("004.1", "DangerousGetHandle returns wrong handle value for valid safe handle");
                TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] handleValue = " + handleValue.ToString() + ", desiredValue = " + desiredValue.ToString());
                retVal = false;
            }

            handleValue = handle.DangerousGetHandle();

            if (handleValue != desiredValue)
            {
                TestLibrary.TestFramework.LogError("004.2", "DangerousGetHandle returns wrong handle value for valid safe handle");
                TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] handleValue = " + handleValue.ToString() + ", desiredValue = " + desiredValue.ToString());
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004.3", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
    public bool PosTest3()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest3: DangerousGetHandle should return handle value for invalid safe handle");

        try
        {
            SafeHandle handle = new MySafeInValidHandle();
            IntPtr handleValue = handle.DangerousGetHandle();

            if (handleValue != IntPtr.Zero)
            {
                TestLibrary.TestFramework.LogError("003.1", "DangerousGetHandle returns wrong handle value for invalid safe handle");
                TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] handleValue = " + handleValue.ToString() + ", desiredValue = IntPtr.Zero");
                retVal = false;
            }

            handleValue = handle.DangerousGetHandle();

            if (handleValue != IntPtr.Zero)
            {
                TestLibrary.TestFramework.LogError("003.2", "DangerousGetHandle returns wrong handle value for invalid safe handle");
                TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] handleValue = " + handleValue.ToString() + ", desiredValue = IntPtr.Zero");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("003.3", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }