VirtualBox

source: vbox/trunk/src/VBox/Main/testcase/tstMouseImpl.cpp@ 47310

最後變更 在這個檔案從47310是 47277,由 vboxsync 提交於 12 年 前

windows warnings.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
  • 屬性 svn:mergeinfo 設為 (切換已刪除的分支)
檔案大小: 11.2 KB
 
1/* $Id: tstMouseImpl.cpp 47277 2013-07-19 17:49:34Z vboxsync $ */
2/** @file
3 * Main unit test - Mouse class.
4 */
5
6/*
7 * Copyright (C) 2011-2013 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18/******************************************************************************
19* Header Files *
20******************************************************************************/
21#define IN_VMM_R3 /* Kill most Windows warnings on CFGMR3* implementations. */
22#include "MouseImpl.h"
23#include "VMMDev.h"
24#include "DisplayImpl.h"
25
26#include <VBox/vmm/cfgm.h>
27#include <VBox/vmm/pdmdrv.h>
28#include <VBox/VMMDev.h>
29#include <iprt/assert.h>
30#include <iprt/test.h>
31
32#ifndef RT_OS_WINDOWS
33NS_DECL_CLASSINFO(Mouse)
34NS_IMPL_THREADSAFE_ISUPPORTS1_CI(Mouse, IMouse)
35#endif
36
37PDMIVMMDEVPORT VMMDevPort;
38
39class TestVMMDev : public VMMDevMouseInterface
40{
41 PPDMIVMMDEVPORT getVMMDevPort(void) { return &VMMDevPort; }
42};
43
44class TestDisplay : public DisplayMouseInterface
45{
46 void getFramebufferDimensions(int32_t *px1, int32_t *py1,
47 int32_t *px2, int32_t *py2);
48 int getScreenResolution(uint32_t cScreen, ULONG *pcx, ULONG *pcy,
49 ULONG *pcBPP);
50};
51
52class TestConsole : public ConsoleMouseInterface
53{
54public:
55 VMMDevMouseInterface *getVMMDevMouseInterface() { return &mVMMDev; }
56 DisplayMouseInterface *getDisplayMouseInterface() { return &mDisplay; }
57 /** @todo why on earth is this not implemented? */
58 void onMouseCapabilityChange(BOOL supportsAbsolute, BOOL supportsRelative,
59 BOOL supportsMT, BOOL needsHostCursor) {}
60
61private:
62 TestVMMDev mVMMDev;
63 TestDisplay mDisplay;
64};
65
66static int pdmdrvhlpAttach(PPDMDRVINS pDrvIns, uint32_t fFlags,
67 PPDMIBASE *ppBaseInterface)
68{
69 return VERR_PDM_NO_ATTACHED_DRIVER;
70}
71
72static struct PDMDRVHLPR3 pdmHlpR3 =
73{
74 PDM_DRVHLPR3_VERSION,
75 pdmdrvhlpAttach
76};
77
78static struct
79{
80 int32_t cx;
81 int32_t cy;
82} mouseEvent;
83
84static int mousePutEvent(PPDMIMOUSEPORT pInterface, int32_t iDeltaX,
85 int32_t iDeltaY, int32_t iDeltaZ, int32_t iDeltaW,
86 uint32_t fButtonStates)
87{
88 mouseEvent.cx = iDeltaX;
89 mouseEvent.cy = iDeltaY;
90 return VINF_SUCCESS;
91}
92
93static struct
94{
95 int32_t x;
96 int32_t y;
97} mouseEventAbs;
98
99static int mousePutEventAbs(PPDMIMOUSEPORT pInterface, uint32_t uX,
100 uint32_t uY, int32_t iDeltaZ, int32_t iDeltaW,
101 uint32_t fButtonStates)
102{
103 mouseEventAbs.x = uX;
104 mouseEventAbs.y = uY;
105 return VINF_SUCCESS;
106}
107
108static struct PDMIMOUSEPORT pdmiMousePort =
109{
110 mousePutEvent,
111 mousePutEventAbs
112};
113
114static void *pdmiBaseQuery(struct PDMIBASE *pInterface, const char *pszIID)
115{
116 return &pdmiMousePort;
117}
118
119static struct PDMIBASE pdmiBase =
120{
121 pdmiBaseQuery
122};
123
124static struct PDMDRVINS pdmdrvInsCore =
125{
126 PDM_DRVINS_VERSION,
127 0,
128 NIL_RTRCPTR,
129 NIL_RTRCPTR,
130 NIL_RTR0PTR,
131 NIL_RTR0PTR,
132 &pdmHlpR3,
133 NULL,
134 NULL,
135 NULL,
136 &pdmiBase
137};
138
139static struct PDMDRVINS *ppdmdrvIns = NULL;
140
141ComObjPtr<Mouse> pMouse;
142ConsoleMouseInterface *pConsole = NULL;
143
144static struct
145{
146 int32_t x;
147 int32_t y;
148} absoluteMouse;
149
150static int setAbsoluteMouse(PPDMIVMMDEVPORT, int32_t x, int32_t y)
151{
152 absoluteMouse.x = x;
153 absoluteMouse.y = y;
154 return VINF_SUCCESS;
155}
156
157static int updateMouseCapabilities(PPDMIVMMDEVPORT, uint32_t, uint32_t)
158{
159 return VINF_SUCCESS;
160}
161
162void TestDisplay::getFramebufferDimensions(int32_t *px1, int32_t *py1,
163 int32_t *px2, int32_t *py2)
164{
165 if (px1)
166 *px1 = -320;
167 if (py1)
168 *py1 = -240;
169 if (px2)
170 *px2 = 320;
171 if (py2)
172 *py2 = 240;
173}
174
175int TestDisplay::getScreenResolution(uint32_t cScreen, ULONG *pcx,
176 ULONG *pcy, ULONG *pcBPP)
177{
178 NOREF(cScreen);
179 if (pcx)
180 *pcx = 640;
181 if (pcy)
182 *pcy = 480;
183 if (pcBPP)
184 *pcBPP = 32;
185 return S_OK;
186}
187
188DECLEXPORT(bool) CFGMR3AreValuesValid(PCFGMNODE, const char *)
189{
190 return true;
191}
192
193DECLEXPORT(int) CFGMR3QueryPtr(PCFGMNODE, const char *, void **pv)
194{
195 *pv = pMouse;
196 return VINF_SUCCESS;
197}
198
199/******************************************************************************
200* Main test code *
201******************************************************************************/
202
203static int setup(void)
204{
205 VMMDevPort.pfnSetAbsoluteMouse = setAbsoluteMouse;
206 VMMDevPort.pfnUpdateMouseCapabilities = updateMouseCapabilities;
207 HRESULT hrc = pMouse.createObject();
208 AssertComRC(hrc);
209 if (FAILED(hrc))
210 return VERR_GENERAL_FAILURE;
211 pConsole = new TestConsole;
212 pMouse->init(pConsole);
213 ppdmdrvIns = (struct PDMDRVINS *) RTMemAllocZ( sizeof(struct PDMDRVINS)
214 + Mouse::DrvReg.cbInstance);
215 *ppdmdrvIns = pdmdrvInsCore;
216 Mouse::DrvReg.pfnConstruct(ppdmdrvIns, NULL, 0);
217 return VINF_SUCCESS;
218}
219
220static void teardown(void)
221{
222 pMouse.setNull();
223 if (pConsole)
224 delete pConsole;
225 if (ppdmdrvIns)
226 RTMemFree(ppdmdrvIns);
227}
228
229static bool approxEq(int a, int b, int prec)
230{
231 return a - b < prec && b - a < prec;
232}
233
234/** @test testAbsToVMMDevNewProtocol */
235static void testAbsToVMMDevNewProtocol(RTTEST hTest)
236{
237 PPDMIBASE pBase;
238 PPDMIMOUSECONNECTOR pConnector;
239
240 RTTestSub(hTest, "Absolute event to VMMDev, new protocol");
241 pBase = &ppdmdrvIns->IBase;
242 pConnector = (PPDMIMOUSECONNECTOR)pBase->pfnQueryInterface(pBase,
243 PDMIMOUSECONNECTOR_IID);
244 pConnector->pfnReportModes(pConnector, true, false, false);
245 pMouse->onVMMDevGuestCapsChange( VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE
246 | VMMDEV_MOUSE_NEW_PROTOCOL);
247 pMouse->PutMouseEventAbsolute(0, 0, 0, 0, 0);
248 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0x8000, 200),
249 ("absoluteMouse.x=%d\n", absoluteMouse.x));
250 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0x8000, 200),
251 ("absoluteMouse.y=%d\n", absoluteMouse.y));
252 pMouse->PutMouseEventAbsolute(-319, -239, 0, 0, 0);
253 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0, 200),
254 ("absoluteMouse.x=%d\n", absoluteMouse.x));
255 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0, 200),
256 ("absoluteMouse.y=%d\n", absoluteMouse.y));
257 pMouse->PutMouseEventAbsolute(320, 240, 0, 0, 0);
258 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0xffff, 200),
259 ("absoluteMouse.x=%d\n", absoluteMouse.x));
260 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0xffff, 200),
261 ("absoluteMouse.y=%d\n", absoluteMouse.y));
262 RTTestSubDone(hTest);
263}
264
265/** @test testAbsToVMMDevOldProtocol */
266static void testAbsToVMMDevOldProtocol(RTTEST hTest)
267{
268 PPDMIBASE pBase;
269 PPDMIMOUSECONNECTOR pConnector;
270
271 RTTestSub(hTest, "Absolute event to VMMDev, old protocol");
272 pBase = &ppdmdrvIns->IBase;
273 pConnector = (PPDMIMOUSECONNECTOR)pBase->pfnQueryInterface(pBase,
274 PDMIMOUSECONNECTOR_IID);
275 pConnector->pfnReportModes(pConnector, true, false, false);
276 pMouse->onVMMDevGuestCapsChange(VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE);
277 pMouse->PutMouseEventAbsolute(320, 240, 0, 0, 0);
278 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0x8000, 200),
279 ("absoluteMouse.x=%d\n", absoluteMouse.x));
280 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0x8000, 200),
281 ("absoluteMouse.y=%d\n", absoluteMouse.y));
282 pMouse->PutMouseEventAbsolute(0, 0, 0, 0, 0);
283 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0, 200),
284 ("absoluteMouse.x=%d\n", absoluteMouse.x));
285 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0, 200),
286 ("absoluteMouse.y=%d\n", absoluteMouse.y));
287 pMouse->PutMouseEventAbsolute(-319, -239, 0, 0, 0);
288 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, -0x8000, 200),
289 ("absoluteMouse.x=%d\n", absoluteMouse.x));
290 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, -0x8000, 200),
291 ("absoluteMouse.y=%d\n", absoluteMouse.y));
292 RTTestSubDone(hTest);
293}
294
295/** @test testAbsToAbsDev */
296static void testAbsToAbsDev(RTTEST hTest)
297{
298 PPDMIBASE pBase;
299 PPDMIMOUSECONNECTOR pConnector;
300
301 RTTestSub(hTest, "Absolute event to absolute device");
302 pBase = &ppdmdrvIns->IBase;
303 pConnector = (PPDMIMOUSECONNECTOR)pBase->pfnQueryInterface(pBase,
304 PDMIMOUSECONNECTOR_IID);
305 pConnector->pfnReportModes(pConnector, false, true, false);
306 pMouse->onVMMDevGuestCapsChange( VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE
307 | VMMDEV_MOUSE_NEW_PROTOCOL);
308 pMouse->PutMouseEventAbsolute(0, 0, 0, 0, 0);
309 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.x, 0x8000, 200),
310 ("mouseEventAbs.x=%d\n", mouseEventAbs.x));
311 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.y, 0x8000, 200),
312 ("mouseEventAbs.y=%d\n", mouseEventAbs.y));
313 pMouse->PutMouseEventAbsolute(-319, -239, 0, 0, 0);
314 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.x, 0, 200),
315 ("mouseEventAbs.x=%d\n", mouseEventAbs.x));
316 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.y, 0, 200),
317 ("mouseEventAbs.y=%d\n", mouseEventAbs.y));
318 pMouse->PutMouseEventAbsolute(320, 240, 0, 0, 0);
319 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.x, 0xffff, 200),
320 ("mouseEventAbs.x=%d\n", mouseEventAbs.x));
321 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.y, 0xffff, 200),
322 ("mouseEventAbs.y=%d\n", mouseEventAbs.y));
323 mouseEventAbs.x = mouseEventAbs.y = 0xffff;
324 pMouse->PutMouseEventAbsolute(-640, -480, 0, 0, 0);
325 RTTESTI_CHECK_MSG(mouseEventAbs.x = 0xffff,
326 ("mouseEventAbs.x=%d\n", mouseEventAbs.x));
327 RTTESTI_CHECK_MSG(mouseEventAbs.y == 0xffff,
328 ("mouseEventAbs.y=%d\n", mouseEventAbs.y));
329 RTTestSubDone(hTest);
330}
331
332/** @todo generate this using the @test blocks above */
333typedef void (*PFNTEST)(RTTEST);
334static PFNTEST g_tests[] =
335{
336 testAbsToVMMDevNewProtocol,
337 testAbsToVMMDevOldProtocol,
338 testAbsToAbsDev,
339 NULL
340};
341
342int main(void)
343{
344 /*
345 * Init the runtime, test and say hello.
346 */
347 RTTEST hTest;
348 RTEXITCODE rcExit = RTTestInitAndCreate("tstMouseImpl", &hTest);
349 if (rcExit != RTEXITCODE_SUCCESS)
350 return rcExit;
351 RTTestBanner(hTest);
352
353 /*
354 * Run the tests.
355 */
356 for (unsigned i = 0; g_tests[i]; ++i)
357 {
358 int rc = setup();
359 AssertRC(rc);
360 if (RT_SUCCESS(rc))
361 g_tests[i](hTest);
362 teardown();
363 }
364
365 /*
366 * Summary
367 */
368 return RTTestSummaryAndDestroy(hTest);
369}
370
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette