예제 #1
0
    public static void SafeHandle_invalid()
    {
        MySafeHandle mch = new MySafeHandle();

        Assert.Equal(false, mch.IsClosed);
        Assert.Equal(true, mch.IsInvalid);
    }
예제 #2
0
    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: Verify ctor can set correct handle value");

        try
        {
            MySafeHandle msf = new MySafeHandle();

            if (msf.Handle != IntPtr.Zero)
            {
                TestLibrary.TestFramework.LogError("001.1", "Ctor can not set correct handle value");
                TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] msf.Handle = " + msf.Handle.ToString());
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

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

        TestLibrary.TestFramework.BeginScenario("PosTest2: Check IsClosed return false when SetHandleAsInvalid method is not called and don't excute any close handle operation  ");
        try
        {
            MySafeHandle msh    = new MySafeHandle();
            IntPtr       myIptr = new IntPtr(1000);
            msh.MySetHandle(myIptr);
            if (msh.IsClosed)
            {
                TestLibrary.TestFramework.LogError("002.1", "IsClosed should return false ");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

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

        TestLibrary.TestFramework.BeginScenario("PosTest2: Verify the handle is a protected value, and can set a value");

        try
        {
            int          randValue = TestLibrary.Generator.GetInt32(-55);
            IntPtr       value     = new IntPtr(randValue);
            MySafeHandle msf       = new MySafeHandle(value);

            if (null == msf)
            {
                TestLibrary.TestFramework.LogError("002.1", "Failed to allocate a new safe handle instance");
                TestLibrary.TestFramework.LogInformation("[LOCAL VARIABLES] randValue = " + randValue);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

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

        TestLibrary.TestFramework.BeginScenario("PosTest1: Check IsClosed return true when SetHandleAsInvalid method is called  ");
        try
        {
            MySafeHandle msh = new MySafeHandle();
            IntPtr myIptr = new IntPtr(1000);
            msh.MySetHandle(myIptr);
            msh.SetHandleAsInvalid();
            if (!msh.IsClosed )
            {
                TestLibrary.TestFramework.LogError("001.1", "IsClosed should return true");
                retVal = false;
            }

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

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

        TestLibrary.TestFramework.BeginScenario("PosTest2: Check IsInvalid return false when  the handle value is Released. ");
        try
        {
            MySafeHandle msh    = new MySafeHandle();
            IntPtr       myIptr = new IntPtr(1000);
            msh.MySetHandle(myIptr);
            msh.MyReleaseInvoke();
            if (msh.IsInvalid)
            {
                TestLibrary.TestFramework.LogError("002.1", "IsInvalid should return false ");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

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

        TestLibrary.TestFramework.BeginScenario("PosTest2: Check IsClosed return false when SetHandleAsInvalid method is not called and don't excute any close handle operation  ");
        try
        {
            MySafeHandle msh = new MySafeHandle();
            IntPtr myIptr = new IntPtr(1000);
            msh.MySetHandle(myIptr);
            if (msh.IsClosed)
            {
                TestLibrary.TestFramework.LogError("002.1", "IsClosed should return false ");
                retVal = false;
            }

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

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

        TestLibrary.TestFramework.BeginScenario("PosTest1: Verify the handle is a protected value");

        try
        {
            MySafeHandle msf = new MySafeHandle();

            if (null == msf)
            {
                TestLibrary.TestFramework.LogError("001.1", "Failed to allocate a new safe handle instance");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
예제 #9
0
    public bool PosTest2()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest2: Check IsInvalid return false when  the handle value is Released. ");
        try
        {
            MySafeHandle msh = new MySafeHandle();
            IntPtr myIptr = new IntPtr(1000);
            msh.MySetHandle(myIptr);
            msh.MyReleaseInvoke();
            if (msh.IsInvalid)
            {
                TestLibrary.TestFramework.LogError("002.1", "IsInvalid should return false ");
                retVal = false;
            }

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

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

        TestLibrary.TestFramework.BeginScenario("PosTest1: Call SafeHandle.SetHandleAsInvalid ");
        try
        {
            MySafeHandle msh    = new MySafeHandle();
            IntPtr       myIptr = new IntPtr(1000);
            msh.MySetHandle(myIptr);
            msh.SetHandleAsInvalid();
            if (!msh.IsClosed || msh.GetHandle() != myIptr)
            {
                TestLibrary.TestFramework.LogError("001.1", "SetHandleAsInvalid has error ");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
예제 #11
0
    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: Verify ctor can set correct handle value");

        try
        {
            MySafeHandle msf = new MySafeHandle();

            if (msf.Handle != IntPtr.Zero)
            {
                TestLibrary.TestFramework.LogError("001.1", "Ctor can not set correct handle value");
                TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] msf.Handle = " + msf.Handle.ToString());
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
예제 #12
0
    public static void SafeHandle_valid()
    {
        MySafeHandle mch = new MySafeHandle(new IntPtr(1));

        Assert.Equal(false, mch.IsClosed);
        Assert.Equal(false, mch.IsInvalid);
    }
예제 #13
0
    public bool PosTest2()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest2: Verify ctor can set correct handle value for constructor with parameters");

        try
        {
            IntPtr       ptr = new IntPtr(TestLibrary.Generator.GetInt32(-55));
            MySafeHandle msf = new MySafeHandle(ptr);

            if (msf.Handle != ptr)
            {
                TestLibrary.TestFramework.LogError("002.1", "Ctor can not set correct handle value");
                TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] msf.Handle = " + msf.Handle.ToString() +
                                                         ", desiredValue = " + ptr.ToString());
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

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

        TestLibrary.TestFramework.BeginScenario("PosTest1: Call SafeHandle.SetHandleAsInvalid ");
        try
        {
            MySafeHandle msh = new MySafeHandle();
            IntPtr myIptr = new IntPtr(1000);
            msh.MySetHandle(myIptr);
            msh.SetHandleAsInvalid();
            if (!msh.IsClosed || msh.GetHandle()!=myIptr )
            {
                TestLibrary.TestFramework.LogError("001.1", "SetHandleAsInvalid has error ");
                retVal = false;
            }

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

        return retVal;
    }
예제 #15
0
    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: Verify the handle is a protected value");

        try
        {
            MySafeHandle msf = new MySafeHandle();

            if (null == msf)
            {
                TestLibrary.TestFramework.LogError("001.1", "Failed to allocate a new safe handle instance");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
예제 #16
0
 public static void SafeHandle_valid_close()
 {
     MySafeHandle mch = new MySafeHandle(new IntPtr(1));
     mch.Close();
     Assert.True(mch.IsClosed);
     Assert.False(mch.IsInvalid);
     Assert.True(mch.IsReleased);
 }
예제 #17
0
    public static void SafeHandle_valid_close()
    {
        MySafeHandle mch = new MySafeHandle(new IntPtr(1));

        mch.Close();
        Assert.True(mch.IsClosed);
        Assert.False(mch.IsInvalid);
        Assert.True(mch.IsReleased);
    }
예제 #18
0
파일: SafeHandle.cs 프로젝트: z77ma/runtime
    public static void SafeHandle_SetHandleAsInvalid()
    {
        IntPtr       ptr    = new IntPtr(1);
        MySafeHandle handle = new MySafeHandle(ptr);

        handle.SetHandleAsInvalid();
        Assert.True(handle.IsClosed);
        Assert.False(handle.IsInvalid);
        Assert.False(handle.IsReleased);
        Assert.Equal(ptr, handle.DangerousGetHandle());
    }
예제 #19
0
파일: SafeHandle.cs 프로젝트: dotnet/corefx
    public static void SafeHandle_invalid()
    {
        MySafeHandle mch = new MySafeHandle();
        Assert.False(mch.IsClosed);
        Assert.True(mch.IsInvalid);
        Assert.False(mch.IsReleased);

        mch.Dispose();
        Assert.True(mch.IsClosed);
        Assert.True(mch.IsInvalid);
        Assert.False(mch.IsReleased);
    }
예제 #20
0
    public static void SafeHandle_invalid()
    {
        MySafeHandle mch = new MySafeHandle();

        Assert.False(mch.IsClosed);
        Assert.True(mch.IsInvalid);
        Assert.False(mch.IsReleased);

        mch.Dispose();
        Assert.True(mch.IsClosed);
        Assert.True(mch.IsInvalid);
        Assert.False(mch.IsReleased);
    }
예제 #21
0
        public MySafeHandle AllocateHandle()
        {
            // Allocate SafeHandle first to avoid failure later.
            MySafeHandle sh = new MySafeHandle();

            RuntimeHelpers.PrepareConstrainedRegions();
            try { }
            finally
            {
                MyStruct myStruct = new MyStruct();
                NativeAllocateHandle(ref myStruct);
                sh.SetHandle(myStruct.m_outputHandle);
            }

            return sh;
        }
예제 #22
0
파일: SafeHandle.cs 프로젝트: z77ma/runtime
    public static void SafeHandle_invalid()
    {
        MySafeHandle mch = new MySafeHandle();

        Assert.False(mch.IsClosed);
        Assert.True(mch.IsInvalid);
        Assert.False(mch.IsReleased);
        Assert.Equal(IntPtr.Zero, mch.DangerousGetHandle());

        mch.Dispose();
        Assert.True(mch.IsClosed);
        Assert.True(mch.IsInvalid);
        Assert.False(mch.IsReleased);

        // Make sure we can dispose multiple times
        mch.Dispose();
        Assert.True(mch.IsClosed);
        Assert.True(mch.IsInvalid);
        Assert.False(mch.IsReleased);
    }
예제 #23
0
 public void MethodWithSafeHandleDangerousGetHandleCall()
 {
     MySafeHandle myHandle  = new MySafeHandle();
     IntPtr       handlePtr = myHandle.DangerousGetHandle();
 }
예제 #24
0
 internal static extern int GetModuleFileNameEx(
     MySafeHandle hProcess,
     IntPtr hModule,
     StringBuilder lpFilename,
     int nSize);
예제 #25
0
    public bool PosTest2()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest2: Verify the handle is a protected value, and can set a value");

        try
        {
            int randValue = TestLibrary.Generator.GetInt32(-55);
            IntPtr value = new IntPtr(randValue);
            MySafeHandle msf = new MySafeHandle(value);

            if (null == msf)
            {
                TestLibrary.TestFramework.LogError("002.1", "Failed to allocate a new safe handle instance");
                TestLibrary.TestFramework.LogInformation("[LOCAL VARIABLES] randValue = " + randValue);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
예제 #26
0
 internal static extern bool IsWow64Process(
     MySafeHandle hProcess,
     ref bool Wow64Process);
예제 #27
0
 internal static extern bool OpenProcessToken(MySafeHandle ProcessHandle, UInt32 DesiredAccess, out MySafeHandle TokenHandle);
예제 #28
0
 internal static extern bool GetTokenInformation(
     MySafeHandle TokenHandle,
     TOKEN_INFORMATION_CLASS TokenInformationClass,
     IntPtr TokenInformation,
     uint TokenInformationLength,
     out uint ReturnLength);
예제 #29
0
 internal static extern bool Process32Next(
     MySafeHandle hSnapshot,
     [MarshalAs(UnmanagedType.Struct)][In][Out] ref ProcessEntry32 lppe);
예제 #30
0
 internal static extern bool Module32Next(
     MySafeHandle hSnapshot,
     [MarshalAs(UnmanagedType.Struct)][In][Out] ref MODULEENTRY32 lppe);
예제 #31
0
 public static extern bool QueryFullProcessImageName([In] MySafeHandle hProcess, [In] int dwFlags, [Out] StringBuilder lpExeName, ref int lpdwSize);
예제 #32
0
 internal static extern bool EnumProcessModulesEx(
     MySafeHandle hProcess,
     [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U4)][Out] IntPtr[] lphModule,
     uint cb,
     [MarshalAs(UnmanagedType.U4)] out uint lpcbNeeded,
     uint dwFilterFlag);
 public void Hook(HookType hookType, HookReceived hookReceivedCallback)
 {
     _hookReceivedCallback = hookReceivedCallback;
     _hookId = new MySafeHandle(NativeMethods.SetWindowsHookEx((int)hookType, _hookedProc, IntPtr.Zero, 0));
 }
예제 #34
0
 internal static extern uint GetModuleBaseName(
     MySafeHandle hProcess,
     IntPtr hModule,
     [Out] StringBuilder lpBaseName,
     [In][MarshalAs(UnmanagedType.U4)] int nSize);
예제 #35
0
 public static void SafeHandle_valid()
 {
     MySafeHandle mch = new MySafeHandle(new IntPtr(1));
     Assert.Equal(false, mch.IsClosed);
     Assert.Equal(false, mch.IsInvalid);
 }
예제 #36
0
    public bool PosTest2()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest2: Verify ctor can set correct handle value for constructor with parameters");

        try
        {
            IntPtr ptr = new IntPtr(TestLibrary.Generator.GetInt32(-55));
            MySafeHandle msf = new MySafeHandle(ptr);

            if (msf.Handle != ptr)
            {
                TestLibrary.TestFramework.LogError("002.1", "Ctor can not set correct handle value");
                TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] msf.Handle = " + msf.Handle.ToString() +
                                                                                                                   ", desiredValue = " + ptr.ToString());
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
예제 #37
0
 public static void SafeHandle_invalid()
 {
     MySafeHandle mch = new MySafeHandle();
     Assert.Equal(false, mch.IsClosed);
     Assert.Equal(true, mch.IsInvalid);
 }