示例#1
0
        public static void ToString_InvalidFormat_ThrowsFormatException()
        {
            UIntPtr i = (UIntPtr)123;

            Assert.Throws <FormatException>(() => i.ToString("Y"));       // Invalid format
            Assert.Throws <FormatException>(() => i.ToString("Y", null)); // Invalid format
        }
示例#2
0
        public static void ToStringTest(UIntPtr i, string format, IFormatProvider provider, string expected)
        {
            // Format is case insensitive
            string upperFormat = format.ToUpperInvariant();
            string lowerFormat = format.ToLowerInvariant();

            string upperExpected = expected.ToUpperInvariant();
            string lowerExpected = expected.ToLowerInvariant();

            bool isDefaultProvider = (provider == null || provider == NumberFormatInfo.CurrentInfo);

            if (string.IsNullOrEmpty(format) || format.ToUpperInvariant() == "G")
            {
                if (isDefaultProvider)
                {
                    Assert.Equal(upperExpected, i.ToString());
                    Assert.Equal(upperExpected, i.ToString((IFormatProvider)null));
                }
                Assert.Equal(upperExpected, i.ToString(provider));
            }
            if (isDefaultProvider)
            {
                Assert.Equal(upperExpected, i.ToString(upperFormat));
                Assert.Equal(lowerExpected, i.ToString(lowerFormat));
                Assert.Equal(upperExpected, i.ToString(upperFormat, null));
                Assert.Equal(lowerExpected, i.ToString(lowerFormat, null));
            }
            Assert.Equal(upperExpected, i.ToString(upperFormat, provider));
            Assert.Equal(lowerExpected, i.ToString(lowerFormat, provider));
        }
示例#3
0
    private static void TestPointer(UIntPtr p, ulong expected)
    {
        ulong l = p.ToUInt64();

        Assert.Equal(expected, l);

        uint expected32 = (uint)expected;

        if (expected32 != expected)
        {
            Assert.Throws <OverflowException>(() => p.ToUInt32());
            return;
        }

        {
            uint i = p.ToUInt32();
            Assert.Equal(expected32, i);
        }

        string s         = p.ToString();
        string sExpected = expected.ToString();

        Assert.Equal(s, sExpected);

        Assert.True(p == new UIntPtr(expected));
        Assert.Equal(p, new UIntPtr(expected));
        Assert.False(p == new UIntPtr(expected + 1));
        Assert.NotEqual(p, new UIntPtr(expected + 1));
        Assert.False(p != new UIntPtr(expected));
        Assert.True(p != new UIntPtr(expected + 1));
    }
示例#4
0
    public virtual bool runTest()
    {
        Console.Error.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
        int     iCountErrors    = 0;
        int     iCountTestcases = 0;
        String  strLoc          = "Loc_000oo";
        UInt32  iValue;
        UIntPtr ip1;

        try {
            strLoc = "Loc_743wg";
            iValue = 16;
            ip1    = new UIntPtr(iValue);
            iCountTestcases++;
            if (ip1.ToString() != iValue.ToString())
            {
                iCountErrors++;
                Console.WriteLine("Err_2975sf! Wrong value returned");
            }
            strLoc = "Loc_0084wf";
            iValue = 0;
            ip1    = new UIntPtr(iValue);
            iCountTestcases++;
            if (ip1.ToString() != iValue.ToString())
            {
                iCountErrors++;
                Console.WriteLine("Err_974325sdg! Wrong value returned");
            }
            strLoc = "Loc_93476sdg";
            iValue = UInt32.MaxValue;
            ip1    = new UIntPtr(iValue);
            iCountTestcases++;
            if (ip1.ToString() != iValue.ToString())
            {
                iCountErrors++;
                Console.WriteLine("Err_07536tsg! Wrong value returned");
            }
            iValue = UInt32.MinValue;
            ip1    = new UIntPtr(iValue);
            if (ip1.ToString() != iValue.ToString())
            {
                iCountErrors++;
                Console.WriteLine("Err_9875wrsg! Wrong value returned");
            }
        } catch (Exception exc_general) {
            ++iCountErrors;
            Console.WriteLine(s_strTFAbbrev + " Error Err_8888yyy!  strLoc==" + strLoc + ", exc_general==" + exc_general);
        }
        if (iCountErrors == 0)
        {
            Console.Error.WriteLine("paSs.   " + s_strTFPath + " " + s_strTFName + " ,iCountTestcases==" + iCountTestcases);
            return(true);
        }
        else
        {
            Console.Error.WriteLine("FAiL!   " + s_strTFPath + " " + s_strTFName + " ,iCountErrors==" + iCountErrors + " , BugNums?: " + s_strActiveBugNums);
            return(false);
        }
    }
        public void UIntPtr_should_be_serialize_correct()
        {
            UIntPtr p    = new UIntPtr(0xC01E0001);
            var     json = JsonSerializer.ToJson(p);

            Assert.IsTrue(JsonValidator.IsValid(json));
            Assert.AreEqual(p.ToString(), json);
        }
示例#6
0
 public virtual bool runTest()
   {
   Console.Error.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
   int iCountErrors = 0;
   int iCountTestcases = 0;
   String strLoc = "Loc_000oo";
   UInt32 iValue;
   UIntPtr ip1;
   try {
   strLoc = "Loc_743wg";
   iValue = 16;
   ip1 = new UIntPtr(iValue);
   iCountTestcases++;
   if(ip1.ToString() != iValue.ToString()){
   iCountErrors++;
   Console.WriteLine("Err_2975sf! Wrong value returned");
   }
   strLoc = "Loc_0084wf";
   iValue = 0;
   ip1 = new UIntPtr(iValue);
   iCountTestcases++;
   if(ip1.ToString() != iValue.ToString()){
   iCountErrors++;
   Console.WriteLine("Err_974325sdg! Wrong value returned");
   }
   strLoc = "Loc_93476sdg";
   iValue = UInt32.MaxValue;
   ip1 = new UIntPtr(iValue);
   iCountTestcases++;
   if(ip1.ToString() != iValue.ToString()){
   iCountErrors++;
   Console.WriteLine("Err_07536tsg! Wrong value returned");
   }
   iValue = UInt32.MinValue;
   ip1 = new UIntPtr(iValue);
   if(ip1.ToString() != iValue.ToString()){
   iCountErrors++;
   Console.WriteLine("Err_9875wrsg! Wrong value returned");
   }
   } catch (Exception exc_general ) {
   ++iCountErrors;
   Console.WriteLine(s_strTFAbbrev +" Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general);
   }
   if ( iCountErrors == 0 )
     {
     Console.Error.WriteLine( "paSs.   "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
     return true;
     }
   else
     {
     Console.Error.WriteLine("FAiL!   "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
     return false;
     }
   }
示例#7
0
        public void UIntPtr_should_be_deserialize_correct()
        {
            UIntPtr p    = new UIntPtr(0xC01E0001);
            var     json = JsonSerializer.ToJson(p);

            Assert.AreEqual(p.ToString(), json);

            var res = JsonSerializer.ToObject <UIntPtr>(json);

            Assert.AreEqual(p, res);
        }
示例#8
0
        /// <summary>
        /// Returns the optimizer used.
        /// </summary>
        /// <returns>The optimizer used is returned.</returns>
        public OrtTrainingOptimizer GetTrainingOptimizer()
        {
            UIntPtr val = UIntPtr.Zero;

            NativeApiStatus.VerifySuccess(NativeMethodsTraining.OrtGetTrainingOptimizer(_nativeHandle, out val));

            switch (((OrtTrainingOptimizer)(int)val))
            {
            case OrtTrainingOptimizer.ORT_TRAINING_OPTIMIZER_SGD:
                return(OrtTrainingOptimizer.ORT_TRAINING_OPTIMIZER_SGD);

            default:
                throw new Exception("Unknown optimizer '" + val.ToString() + "'!");
            }
        }
示例#9
0
        /// <summary>
        /// Returns the loss function used.
        /// </summary>
        /// <returns>The loss function used is returned.</returns>
        public OrtTrainingLossFunction GetTrainingLossFunction()
        {
            UIntPtr val = UIntPtr.Zero;

            NativeApiStatus.VerifySuccess(NativeMethodsTraining.OrtGetTrainingLossFunction(_nativeHandle, out val));

            switch (((OrtTrainingLossFunction)(int)val))
            {
            case OrtTrainingLossFunction.ORT_TRAINING_LOSS_FUNCTION_SOFTMAXCROSSENTROPY:
                return(OrtTrainingLossFunction.ORT_TRAINING_LOSS_FUNCTION_SOFTMAXCROSSENTROPY);

            default:
                throw new Exception("Unknown loss function '" + val.ToString() + "'!");
            }
        }
示例#10
0
    private static void TestPointer(UIntPtr p, ulong expected)
    {
        ulong l = p.ToUInt64();

        Assert.Equal(l, expected);

        uint expected32 = (uint)expected;

        if (expected32 != expected)
        {
            try
            {
                uint i = p.ToUInt32();
                Assert.True(false, "ToUInt32() should have thrown.");
            }
            catch (OverflowException)
            {
            }
            return;
        }

        {
            uint i = p.ToUInt32();
            Assert.Equal(i, expected32);
        }

        String s         = p.ToString();
        String sExpected = expected.ToString();

        Assert.Equal(s, sExpected);

        bool b;

        b = (p == new UIntPtr(expected));
        Assert.True(b);

        b = (p == new UIntPtr(expected + 1));
        Assert.False(b);

        b = (p != new UIntPtr(expected));
        Assert.False(b);

        b = (p != new UIntPtr(expected + 1));
        Assert.True(b);
    }
示例#11
0
        public static ClipboardData GetClipboardDatas() // Gets all clipboard datas, but only text-based datas supported...
        {
            var cd = new ClipboardData()
            {
                data   = new List <byte[]>(),
                format = new List <uint>()
            };

            OpenClipboard(IntPtr.Zero);
            foreach (var fmt in (uint[])Enum.GetValues(typeof(uFormat)))
            {
                IntPtr pos = GetClipboardData(fmt);
                if (pos == IntPtr.Zero)
                {
                    continue;
                }
                UIntPtr lenght = GlobalSize(pos);
                IntPtr  gLock  = GlobalLock(pos);
                //Console.WriteLine(fmt + " is awaible in clipboard!!");
                byte[] data;
                if ((uint)lenght > 0)
                {
                    //Init a buffer which will contain the clipboard data
                    data = new byte[(uint)lenght];
                    //Console.WriteLine(lenght);
                    int l = Convert.ToInt32(lenght.ToString());
                    //Copy data from clipboard to our byte[] buffer
                    Marshal.Copy(gLock, data, 0, l);
                }
                else
                {
                    data = new byte[0];
                }
                cd.data.Add(data);
                cd.format.Add(fmt);
            }
            CloseClipboard();
            return(cd);
        }
示例#12
0
        public static string GetClipboardText()
        {
            if (!OpenClipboard(IntPtr.Zero))
            {
                return(string.Empty);
            }

            IntPtr pos = GetClipboardData(CF_UNICODETEXT);

            if (pos != IntPtr.Zero)
            {
                CloseClipboard();
                return(string.Empty);
            }

            UIntPtr lenght = GlobalSize(pos);
            IntPtr  gLock  = GlobalLock(pos);

            byte[] buffer = null;
            if ((int)lenght > 0)
            {
                //Init a buffer which will contain the clipboard data
                buffer = new byte[(int)lenght];
                int l = Convert.ToInt32(lenght.ToString());
                //Copy data from clipboard to our byte[] buffer
                Marshal.Copy(gLock, buffer, 0, l);
            }
            string text = string.Empty;

            if (buffer != null)
            {
                //text = System.Text.Encoding.ASCII.GetString(buffer);
                text = System.Text.Encoding.Unicode.GetString(buffer);
            }
            CloseClipboard();

            return(text);
        }
示例#13
0
    public bool PosTest4()
    {
        bool retVal = true;

        const string c_TEST_ID = "P004";
        string       testDesc  = string.Format("PosTest4: value is max {0}-bit pointer: UInt{0}.MaxValue",
                                               8 * UIntPtr.Size);
        string errorDesc;

        string  actualStr, expectedStr;
        UIntPtr uiPtr;
        bool    actualResult;

        TestLibrary.TestFramework.BeginScenario(testDesc);
        try
        {
            UInt64 ui = (UIntPtr.Size == 4) ? UInt32.MaxValue : UInt64.MaxValue;
            expectedStr = (UIntPtr.Size == 4) ? ((UInt32)ui).ToString() : ui.ToString();
            uiPtr       = new UIntPtr(ui);
            actualStr   = uiPtr.ToString();

            actualResult = actualStr == expectedStr;
            if (!actualResult)
            {
                errorDesc = "Actual hash code is not " + expectedStr + " as expected: Actual(" + actualStr + ")";
                TestLibrary.TestFramework.LogError("007" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e;
            TestLibrary.TestFramework.LogError("008" + " TestId-" + c_TEST_ID, errorDesc);
            retVal = false;
        }

        return(retVal);
    }
示例#14
0
    public bool PosTest2()
    {
        bool retVal = true;

        const string c_TEST_ID   = "P002";
        const string c_TEST_DESC = "PosTest2: UIntPtr with a random Int32 value ";
        string       errorDesc;

        string  actualStr, expectedStr;
        UIntPtr uiPtr;
        bool    actualResult;

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
        try
        {
            UInt32 ui = (UInt32)TestLibrary.Generator.GetInt32(-55);
            expectedStr = (UIntPtr.Size == 4) ? ui.ToString() : ((UInt64)ui).ToString();
            uiPtr       = new UIntPtr(ui);
            actualStr   = uiPtr.ToString();

            actualResult = actualStr == expectedStr;
            if (!actualResult)
            {
                errorDesc = "Actual string from UIntPtr is not " + expectedStr + " as expected: Actual(" + actualStr + ")";
                TestLibrary.TestFramework.LogError("003" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e;
            TestLibrary.TestFramework.LogError("004" + " TestId-" + c_TEST_ID, errorDesc);
            retVal = false;
        }

        return(retVal);
    }
示例#15
0
    private static void VerifyPointer(UIntPtr ptr, ulong expected)
    {
        Assert.Equal(expected, ptr.ToUInt64());

        uint expected32 = (uint)expected;

        if (expected32 != expected)
        {
            Assert.Throws <OverflowException>(() => ptr.ToUInt32());
            return;
        }

        Assert.Equal(expected32, ptr.ToUInt32());

        Assert.Equal(expected.ToString(), ptr.ToString());

        Assert.Equal(ptr, new UIntPtr(expected));
        Assert.True(ptr == new UIntPtr(expected));
        Assert.False(ptr != new UIntPtr(expected));

        Assert.NotEqual(ptr, new UIntPtr(expected + 1));
        Assert.False(ptr == new UIntPtr(expected + 1));
        Assert.True(ptr != new UIntPtr(expected + 1));
    }
示例#16
0
 // AttemptToTerminateServer() will check to see if the objects count and the server
 // lock count have both dropped to zero.
 //
 // If so, and if we were started by COM, we post a WM_QUIT message to the main thread's
 // message loop. This will cause the message loop to exit and hence the termination
 // of this application. If hand-started, then just trace that it WOULD exit now.
 //
 public static void ExitIf()
 {
     lock (lockObject)
     {
         OCSimulator.TL.LogMessage("ExitIf", "Object Count: " + +ObjectsCount + ", Server Lock Count: " + ServerLockCount + ", Started by COM: " + StartedByCOM);
         if ((ObjectsCount <= 0) && (ServerLockCount <= 0))
         {
             if (StartedByCOM)
             {
                 UIntPtr wParam = new UIntPtr(0);
                 IntPtr  lParam = new IntPtr(0);
                 OCSimulator.TL.LogMessage("ExitIf", "Posting WM_QUIT to Main Thread. Thread ID:" + MainThreadId.ToString() + ", wParam: " + wParam.ToString() + ", lParam: " + lParam.ToString());
                 bool success    = PostThreadMessage(MainThreadId, WM_QUIT, wParam, lParam);
                 int  returnCode = Marshal.GetLastWin32Error();
                 OCSimulator.TL.LogMessage("ExitIf", "WM_QUIT outcome. Success: " + success + ", return code: " + returnCode.ToString("X"));
             }
         }
     }
 }
示例#17
0
 /// <inheritdoc/>
 public override string ToString() => _value.ToString();
示例#18
0
 public override string ToString()
 {
     return("[rmw_qos_profile_t: history: " + history.ToString() + " depth: " + depth.ToString() + " reliability: " + reliability.ToString() + " durability: " + durability.ToString() + " ]");
 }
示例#19
0
 private static void Update(IntPtr RGBA32GPUPtr, UIntPtr RGBA32Ptr, UIntPtr width, UIntPtr height, UIntPtr size)
 {
     //Dispatch on main thread
     Dispatch.Dispatch(() => {
         Ext.LogVerbose("Received native update: " + string.Format("ptr<{0}>, ptr<{1}>, {2}, {3}, {4}", RGBA32GPUPtr.ToInt32().ToString(), RGBA32Ptr.ToUInt32().ToString(), width.ToString(), height.ToString(), size.ToString()));
         //Initialization
         Preview = Preview ?? Texture2D.CreateExternalTexture((int)width, (int)height, TextureFormat.RGBA32, false, false, RGBA32GPUPtr);
         //Size checking
         if (Preview.width != (int)width || Preview.height != (int)height)
         {
             Preview.Resize((int)width, (int)height, Preview.format, false);
         }
         //Update
         Preview.UpdateExternalTexture(RGBA32GPUPtr);
         //Propagation
         if (OnNativePreviewUpdate != null)
         {
             OnNativePreviewUpdate(ComponentBuffer.RGBA32GPU, unchecked ((UIntPtr)(ulong)(long)RGBA32GPUPtr), (int)width, (int)height, (int)size);
             if (mReadablePreview)
             {
                 OnNativePreviewUpdate(ComponentBuffer.RGBA32, RGBA32Ptr, (int)width, (int)height, (int)size);
             }
         }
         //OpenCV
         #if OPENCV_DEVELOPER_MODE
         if (mReadablePreview)
         {
             PreviewMatrix = PreviewMatrix ?? new Mat(new Size((int)width, (int)height), CvType.CV_8UC4);
             if (PreviewMatrix.cols() != (int)width || PreviewMatrix.rows() != (int)height)
             {
                 Imgproc.resize(PreviewMatrix, PreviewMatrix, new Size((int)width, (int)height));
             }
             Utils.copyToMat(unchecked ((IntPtr)(long)(ulong)RGBA32Ptr), PreviewMatrix);
             //Core.flip (PreviewMatrix, PreviewMatrix, 0); //Dev should do this themselves
         }
         #endif
         //Propagation
         if (
             !FirstFrameReceived
             #if UNITY_ANDROID
             && !A.Get <bool>("orientationDirty") //In NCNA, this flag is bound to active camera state
             #endif
             )
         {
             PropagateStart(); FirstFrameReceived = isPlaying = true;
         }
         if (FirstFrameReceived)
         {
             PropagateUpdate();
         }
     });
 }
示例#20
0
文件: UIntPtr.cs 项目: kkurni/corefx
    private static void VerifyPointer(UIntPtr ptr, ulong expected)
    {
        Assert.Equal(expected, ptr.ToUInt64());

        uint expected32 = (uint)expected;
        if (expected32 != expected)
        {
            Assert.Throws<OverflowException>(() => ptr.ToUInt32());
            return;
        }

        Assert.Equal(expected32, ptr.ToUInt32());

        Assert.Equal(expected.ToString(), ptr.ToString());

        Assert.Equal(ptr, new UIntPtr(expected));
        Assert.True(ptr == new UIntPtr(expected));
        Assert.False(ptr != new UIntPtr(expected));

        Assert.NotEqual(ptr, new UIntPtr(expected + 1));
        Assert.False(ptr == new UIntPtr(expected + 1));
        Assert.True(ptr != new UIntPtr(expected + 1));
    }
示例#21
0
    public bool PosTest4()
    {
        bool retVal = true;

        const string c_TEST_ID = "P004";
        string testDesc = string.Format("PosTest4: value is max {0}-bit pointer: UInt{0}.MaxValue",
                                                      8 * UIntPtr.Size);
        string errorDesc;

        string actualStr, expectedStr;
        UIntPtr uiPtr;
        bool actualResult;

        TestLibrary.TestFramework.BeginScenario(testDesc);
        try
        {
            UInt64 ui = (UIntPtr.Size == 4) ? UInt32.MaxValue : UInt64.MaxValue;
            expectedStr = (UIntPtr.Size == 4) ? ((UInt32)ui).ToString() : ui.ToString();
            uiPtr = new UIntPtr(ui);
            actualStr = uiPtr.ToString();

            actualResult = actualStr == expectedStr;
            if (!actualResult)
            {
                errorDesc = "Actual hash code is not " + expectedStr + " as expected: Actual(" + actualStr + ")";
                TestLibrary.TestFramework.LogError("007" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e;
            TestLibrary.TestFramework.LogError("008" + " TestId-" + c_TEST_ID, errorDesc);
            retVal = false;
        }

        return retVal;
    }
示例#22
0
 /// <summary>
 /// изменяем Hwnd окна и записываем в файл
 /// </summary>
 /// <param name="hwnd"></param>
 public void SetHwnd(UIntPtr hwnd)
 {
     databot.Hwnd = hwnd;
     File.WriteAllText(globalParam.DirectoryOfMyProgram + this.numberOfWindow + "\\HWND.txt", hwnd.ToString());
 }
示例#23
0
 // AttemptToTerminateServer() will check to see if the objects count and the server
 // lock count have both dropped to zero.
 //
 // If so, and if we were started by COM, we post a WM_QUIT message to the main thread's
 // message loop. This will cause the message loop to exit and hence the termination
 // of this application. If hand-started, then just trace that it WOULD exit now.
 //
 public static void ExitIf()
 {
     lock (lockObj)
     {
         TelescopeHardware.TL.LogMessage("ExitIf", "Object Count: " + +ObjectsCount + ", Server Lock Count: " + ServerLockCount + ", Started by COM: " + m_bComStart);
         if ((ObjectsCount <= 0) && (ServerLockCount <= 0))
         {
             if (m_bComStart)
             {
                 UIntPtr wParam = new UIntPtr(0);
                 IntPtr  lParam = new IntPtr(0);
                 TelescopeHardware.TL.LogMessage("ExitIf", "Posting WM_QUIT to Main Thread. Thread ID:" + MainThreadId.ToString() + ", wParam: " + wParam.ToString() + ", lParam: " + lParam.ToString());
                 bool success    = PostThreadMessage(MainThreadId, 0x0012, wParam, lParam);
                 int  returnCode = Marshal.GetLastWin32Error();
                 TelescopeHardware.TL.LogMessage("ExitIf", "WM_QUIT outcome. Succcess: " + success + ", return code: " + returnCode.ToString("X"));
                 global::TelescopeSimulator.Alpaca.Program.Shutdown();
             }
         }
     }
 }
示例#24
0
 public override string ToString()
 {
     return(_value.ToString());
 }
 /// <summary>
 /// изменяем Hwnd окна и записываем в файл
 /// </summary>
 /// <param name="hwnd"></param>
 public void SetHwnd(UIntPtr hwnd)
 {
     databot.hwnd = hwnd;
     File.WriteAllText(KATALOG_MY_PROGRAM + numberOfWindow + "\\HWND.txt", hwnd.ToString());
 }
示例#26
0
        public void ParseWparam(UIntPtr wParam)
        {
            switch ((int)wParam)
            {
            case NativeMethodsMouse.WM_MOUSEMOVE:
                Event  = MouseEventType.MOUSEMOVE;
                Button = MouseButton.None;
                Action = MouseAction.Move;
                break;

            case NativeMethodsMouse.WM_LBUTTONDOWN:
                Event  = MouseEventType.LBUTTONDOWN;
                Button = MouseButton.LButton;
                Action = MouseAction.Down;
                break;

            case NativeMethodsMouse.WM_LBUTTONUP:
                Event  = MouseEventType.LBUTTONUP;
                Button = MouseButton.LButton;
                Action = MouseAction.Up;
                break;

            case NativeMethodsMouse.WM_LBUTTONDBLCLK:
                Event  = MouseEventType.LBUTTONDBLCLK;
                Button = MouseButton.LButton;
                Action = MouseAction.DblClk;
                break;

            case NativeMethodsMouse.WM_RBUTTONDOWN:
                Event  = MouseEventType.RBUTTONDOWN;
                Button = MouseButton.RButton;
                Action = MouseAction.Down;
                break;

            case NativeMethodsMouse.WM_RBUTTONUP:
                Event  = MouseEventType.RBUTTONUP;
                Button = MouseButton.RButton;
                Action = MouseAction.Up;
                break;

            case NativeMethodsMouse.WM_RBUTTONDBLCLK:
                Event  = MouseEventType.RBUTTONDBLCLK;
                Button = MouseButton.RButton;
                Action = MouseAction.DblClk;
                break;

            case NativeMethodsMouse.WM_MBUTTONDOWN:
                Event  = MouseEventType.MBUTTONDOWN;
                Button = MouseButton.MButton;
                Action = MouseAction.Down;
                break;

            case NativeMethodsMouse.WM_MBUTTONUP:
                Event  = MouseEventType.MBUTTONUP;
                Button = MouseButton.MButton;
                Action = MouseAction.Up;
                break;

            case NativeMethodsMouse.WM_MBUTTONDBLCLK:
                Event  = MouseEventType.MBUTTONDBLCLK;
                Button = MouseButton.MButton;
                Action = MouseAction.DblClk;
                break;

            case NativeMethodsMouse.WM_XBUTTONDOWN:
                Event  = MouseEventType.XBUTTONDOWN;
                Button = MouseButton.XButton;
                Action = MouseAction.Down;
                break;

            case NativeMethodsMouse.WM_XBUTTONUP:
                Event  = MouseEventType.XBUTTONUP;
                Button = MouseButton.XButton;
                Action = MouseAction.Up;
                break;

            case NativeMethodsMouse.WM_XBUTTONDBLCLK:
                Event  = MouseEventType.XBUTTONDBLCLK;
                Button = MouseButton.XButton;
                Action = MouseAction.DblClk;
                break;

            case NativeMethodsMouse.WM_MOUSEWHEEL1:
                Event  = MouseEventType.MOUSEWHEEL1;
                Button = MouseButton.None;
                Action = MouseAction.Wheel;

                unchecked {
                    wheelDelta = BitConverter.ToInt16(BitConverter.GetBytes(Msllhookstruct.mouseData), 2);
                }
                break;

            case NativeMethodsMouse.WM_MOUSEHWHEEL2:
                Event  = MouseEventType.MOUSEHWHEEL2;
                Button = MouseButton.None;
                Action = MouseAction.Wheel;
                unchecked {
                    wheelDelta = BitConverter.ToInt16(BitConverter.GetBytes(Msllhookstruct.mouseData), 2);
                }
                break;

            default:
                Log.e("ME", "Unknown Mouse Event: " + wParam.ToString());
                break;
            }
        }
示例#27
0
        /// <summary>
        /// Convert to a DataClip collection all data present in the clipboard
        /// </summary>
        /// <returns></returns>
        public static ReadOnlyCollection <DataClip> GetClipboard()
        {
            //Init a list of ClipData, which will contain each Clipboard Data
            List <DataClip> clipData = new List <DataClip>();

            //Open Clipboard to allow us to read from it
            if (!NativeMethods.OpenClipboard(IntPtr.Zero))
            {
                return(new ReadOnlyCollection <DataClip>(clipData));
            }

            //Loop for each clipboard data type
            int format = 0;

            while ((format = (int)NativeMethods.EnumClipboardFormats((uint)format)) != 0)
            {
                //Check if clipboard data type is recognized, and get its name
                string   formatName = "0";
                DataClip cd;
                if (format > 14)
                {
                    StringBuilder res = new StringBuilder();
                    if (NativeMethods.GetClipboardFormatName((uint)format, res, 100) > 0)
                    {
                        formatName = res.ToString();
                    }
                }
                //Get the pointer for the current Clipboard Data
                IntPtr pos = NativeMethods.GetClipboardData((uint)format);
                //Goto next if it's unreachable
                if (pos == IntPtr.Zero)
                {
                    continue;
                }
                //Get the clipboard buffer data properties
                UIntPtr lenght = NativeMethods.GlobalSize(pos);
                IntPtr  gLock  = NativeMethods.GlobalLock(pos);
                byte[]  buffer;
                if ((int)lenght > 0)
                {
                    //Init a buffer which will contain the clipboard data
                    buffer = new byte[(int)lenght];
                    int l = Convert.ToInt32(lenght.ToString());
                    //Copy data from clipboard to our byte[] buffer
                    Marshal.Copy(gLock, buffer, 0, l);
                }
                else
                {
                    buffer = new byte[0];
                }
                //Create a ClipData object that represtens current clipboard data
                cd            = new DataClip(format, formatName, buffer);
                cd.FormatName = formatName;
                //Add current Clipboard Data to the list


                clipData.Add(cd);
            }
            //Close the clipboard and realese unused resources
            NativeMethods.CloseClipboard();
            //Returns the list of Clipboard Datas as a ReadOnlyCollection of ClipData
            return(new ReadOnlyCollection <DataClip>(clipData));
        }
示例#28
0
    private static void TestPointer(UIntPtr p, ulong expected)
    {
        ulong l = p.ToUInt64();
        Assert.Equal(expected, l);

        uint expected32 = (uint)expected;
        if (expected32 != expected)
        {
            Assert.Throws<OverflowException>(() => p.ToUInt32());
            return;
        }

        {
            uint i = p.ToUInt32();
            Assert.Equal(expected32, i);
        }

        string s = p.ToString();
        string sExpected = expected.ToString();
        Assert.Equal(s, sExpected);

        Assert.True(p == new UIntPtr(expected));
        Assert.Equal(p, new UIntPtr(expected));
        Assert.False(p == new UIntPtr(expected + 1));
        Assert.NotEqual(p, new UIntPtr(expected + 1));
        Assert.False(p != new UIntPtr(expected));
        Assert.True(p != new UIntPtr(expected + 1));
    }
示例#29
0
    public bool PosTest2()
    {
        bool retVal = true;

        const string c_TEST_ID = "P002";
        const string c_TEST_DESC = "PosTest2: UIntPtr with a random Int32 value ";
        string errorDesc;

        string actualStr, expectedStr;
        UIntPtr uiPtr;
        bool actualResult;

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
        try
        {
            UInt32 ui = (UInt32)TestLibrary.Generator.GetInt32(-55);
            expectedStr = (UIntPtr.Size == 4) ? ui.ToString() : ((UInt64)ui).ToString();
            uiPtr = new UIntPtr(ui);
            actualStr = uiPtr.ToString();

            actualResult = actualStr == expectedStr;
            if (!actualResult)
            {
                errorDesc = "Actual string from UIntPtr is not " + expectedStr + " as expected: Actual(" + actualStr + ")";
                TestLibrary.TestFramework.LogError("003" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e;
            TestLibrary.TestFramework.LogError("004" + " TestId-" + c_TEST_ID, errorDesc);
            retVal = false;
        }

        return retVal;
    }
示例#30
0
文件: UIntPtr.cs 项目: johnhhm/corefx
    private static void TestPointer(UIntPtr p, ulong expected)
    {
        ulong l = p.ToUInt64();
        Assert.Equal(l, expected);

        uint expected32 = (uint)expected;
        if (expected32 != expected)
        {
            try
            {
                uint i = p.ToUInt32();
                Assert.True(false, "ToUInt32() should have thrown.");
            }
            catch (OverflowException)
            {
            }
            return;
        }

        {
            uint i = p.ToUInt32();
            Assert.Equal(i, expected32);
        }

        String s = p.ToString();
        String sExpected = expected.ToString();
        Assert.Equal(s, sExpected);

        bool b;

        b = (p == new UIntPtr(expected));
        Assert.True(b);

        b = (p == new UIntPtr(expected + 1));
        Assert.False(b);

        b = (p != new UIntPtr(expected));
        Assert.False(b);

        b = (p != new UIntPtr(expected + 1));
        Assert.True(b);
    }
示例#31
0
 public static string ToString(UIntPtr value)
 {
     return(value.ToString());
 }