VirtualBox

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

Last change on this file since 53969 was 53969, checked in by vboxsync, 10 years ago

Devices/Graphics, Main: optionally send cursor integration toggle and guest cursor position information through the graphics device. Small test case fix.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
  • Property svn:mergeinfo set to (toggle deleted branches)
    /branches/VBox-3.0/src/VBox/Frontends/VBoxBFE/testcase/tstMouseImpl.cpp58652,​70973
    /branches/VBox-3.2/src/VBox/Frontends/VBoxBFE/testcase/tstMouseImpl.cpp66309,​66318
    /branches/VBox-4.0/src/VBox/Frontends/VBoxBFE/testcase/tstMouseImpl.cpp70873
    /branches/VBox-4.1/src/VBox/Frontends/VBoxBFE/testcase/tstMouseImpl.cpp74233,​78414,​78691,​81841,​82127
    /branches/VBox-4.1/src/VBox/Frontends/VBoxHeadless/VBoxBFE/testcase/tstMouseImpl.cpp82454
    /branches/VBox-4.2/src/VBox/Main/testcase/tstMouseImpl.cpp91503-91504,​91506-91508,​91510,​91514-91515,​91521
    /branches/VBox-4.3/src/VBox/Main/testcase/tstMouseImpl.cpp91223
    /branches/VBox-4.3/trunk/src/VBox/Main/testcase/tstMouseImpl.cpp91223
    /branches/andy/guestctrl20/src/VBox/Frontends/VBoxBFE/testcase/tstMouseImpl.cpp78916,​78930
    /branches/dsen/gui/src/VBox/Frontends/VBoxBFE/testcase/tstMouseImpl.cpp79076-79078,​79089,​79109-79110,​79112-79113,​79127-79130,​79134,​79141,​79151,​79155,​79157-79159,​79193,​79197
    /branches/dsen/gui2/src/VBox/Frontends/VBoxBFE/testcase/tstMouseImpl.cpp79224,​79228,​79233,​79235,​79258,​79262-79263,​79273,​79341,​79345,​79354,​79357,​79387-79388,​79559-79569,​79572-79573,​79578,​79581-79582,​79590-79591,​79598-79599,​79602-79603,​79605-79606,​79632,​79635,​79637,​79644
    /branches/dsen/gui3/src/VBox/Frontends/VBoxBFE/testcase/tstMouseImpl.cpp79645-79692
File size: 15.8 KB
Line 
1/* $Id: tstMouseImpl.cpp 53969 2015-01-26 21:14:57Z vboxsync $ */
2/** @file
3 * Main unit test - Mouse class.
4 */
5
6/*
7 * Copyright (C) 2011-2014 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.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
33PDMIVMMDEVPORT VMMDevPort;
34
35class TestVMMDev : public VMMDevMouseInterface
36{
37 PPDMIVMMDEVPORT getVMMDevPort(void) { return &VMMDevPort; }
38};
39
40class TestDisplay : public DisplayMouseInterface
41{
42 virtual HRESULT i_getScreenResolution(ULONG cScreen, ULONG *pcx, ULONG *pcy,
43 ULONG *pcBPP, LONG *pXOrigin, LONG *pYOrigin);
44 virtual void i_getFramebufferDimensions(int32_t *px1, int32_t *py1,
45 int32_t *px2, int32_t *py2);
46 virtual HRESULT i_reportHostCursorCapabilities(uint32_t fCapabilitiesAdded, uint32_t fCapabilitiesRemoved)
47 { return S_OK; }
48 virtual HRESULT i_reportHostCursorPosition(int32_t x, int32_t y) { return S_OK; }
49};
50
51class TestConsole : public ConsoleMouseInterface
52{
53public:
54 VMMDevMouseInterface *i_getVMMDevMouseInterface() { return &mVMMDev; }
55 DisplayMouseInterface *i_getDisplayMouseInterface() { return &mDisplay; }
56 /** @todo why on earth is this not implemented? */
57 void i_onMouseCapabilityChange(BOOL supportsAbsolute, BOOL supportsRelative,
58 BOOL supportsMT, BOOL needsHostCursor) {}
59
60private:
61 TestVMMDev mVMMDev;
62 TestDisplay mDisplay;
63};
64
65static int pdmdrvhlpAttach(PPDMDRVINS pDrvIns, uint32_t fFlags,
66 PPDMIBASE *ppBaseInterface)
67{
68 return VERR_PDM_NO_ATTACHED_DRIVER;
69}
70
71static struct PDMDRVHLPR3 pdmHlpR3 =
72{
73 PDM_DRVHLPR3_VERSION,
74 pdmdrvhlpAttach,
75 NULL, /* pfnDetach */
76 NULL, /* pfnDetachSelf */
77 NULL, /* pfnMountPrepare */
78 NULL, /* pfnAssertEMT */
79 NULL, /* pfnAssertOther */
80 NULL, /* pfnVMSetError */
81 NULL, /* pfnVMSetErrorV */
82 NULL, /* pfnVMSetRuntimeError */
83 NULL, /* pfnVMSetRuntimeErrorV */
84 NULL, /* pfnVMState */
85 NULL, /* pfnVMTeleportedAndNotFullyResumedYet */
86 NULL, /* pfnGetSupDrvSession */
87 NULL, /* pfnQueueCreate */
88 NULL, /* pfnTMGetVirtualFreq */
89 NULL, /* pfnTMGetVirtualTime */
90 NULL, /* pfnTMTimerCreate */
91 NULL, /* pfnSSMRegister */
92 NULL, /* pfnSSMDeregister */
93 NULL, /* pfnDBGFInfoRegister */
94 NULL, /* pfnDBGFInfoDeregister */
95 NULL, /* pfnSTAMRegister */
96 NULL, /* pfnSTAMRegisterF */
97 NULL, /* pfnSTAMRegisterV */
98 NULL, /* pfnSTAMDeregister */
99 NULL, /* pfnSUPCallVMMR0Ex */
100 NULL, /* pfnUSBRegisterHub */
101 NULL, /* pfnSetAsyncNotification */
102 NULL, /* pfnAsyncNotificationCompleted */
103 NULL, /* pfnThreadCreate */
104 NULL, /* pfnAsyncCompletionTemplateCreate */
105#ifdef VBOX_WITH_NETSHAPER
106 NULL, /* pfnNetShaperAttach */
107 NULL, /* pfnNetShaperDetach */
108#endif
109 NULL, /* pfnLdrGetRCInterfaceSymbols */
110 NULL, /* pfnLdrGetR0InterfaceSymbols */
111 NULL, /* pfnCritSectInit */
112 NULL, /* pfnCallR0 */
113 NULL, /* pfnFTSetCheckpoint */
114 NULL, /* pfnBlkCacheRetain */
115 NULL, /* pfnVMGetSuspendReason */
116 NULL, /* pfnVMGetResumeReason */
117 NULL, /* pfnReserved0 */
118 NULL, /* pfnReserved1 */
119 NULL, /* pfnReserved2 */
120 NULL, /* pfnReserved3 */
121 NULL, /* pfnReserved4 */
122 NULL, /* pfnReserved5 */
123 NULL, /* pfnReserved6 */
124 NULL, /* pfnReserved7 */
125 NULL, /* pfnReserved8 */
126 NULL, /* pfnReserved9 */
127 PDM_DRVHLPR3_VERSION /* u32TheEnd */
128};
129
130static struct
131{
132 int32_t dx;
133 int32_t dy;
134 int32_t dz;
135 int32_t dw;
136} mouseEvent;
137
138static int mousePutEvent(PPDMIMOUSEPORT pInterface, int32_t iDeltaX,
139 int32_t iDeltaY, int32_t iDeltaZ, int32_t iDeltaW,
140 uint32_t fButtonStates)
141{
142 mouseEvent.dx = iDeltaX;
143 mouseEvent.dy = iDeltaY;
144 mouseEvent.dz = iDeltaZ;
145 mouseEvent.dw = iDeltaW;
146 return VINF_SUCCESS;
147}
148
149static struct
150{
151 uint32_t cx;
152 uint32_t cy;
153 int32_t dz;
154 int32_t dw;
155 uint32_t fButtonStates;
156} mouseEventAbs;
157
158static int mousePutEventAbs(PPDMIMOUSEPORT pInterface, uint32_t uX,
159 uint32_t uY, int32_t iDeltaZ, int32_t iDeltaW,
160 uint32_t fButtonStates)
161{
162 mouseEventAbs.cx = uX;
163 mouseEventAbs.cy = uY;
164 mouseEventAbs.dz = iDeltaZ;
165 mouseEventAbs.dw = iDeltaW;
166 mouseEventAbs.fButtonStates = fButtonStates;
167 return VINF_SUCCESS;
168}
169
170static struct PDMIMOUSEPORT pdmiMousePort =
171{
172 mousePutEvent,
173 mousePutEventAbs,
174 NULL /* pfnPutEventMT */
175};
176
177static void *pdmiBaseQuery(struct PDMIBASE *pInterface, const char *pszIID)
178{
179 return &pdmiMousePort;
180}
181
182static struct PDMIBASE pdmiBase =
183{
184 pdmiBaseQuery
185};
186
187static struct PDMDRVINS pdmdrvInsCore =
188{
189 PDM_DRVINS_VERSION,
190 0, /* iInstance */
191 NIL_RTRCPTR, /* pHlpRC */
192 NIL_RTRCPTR, /* pvInstanceDataRC */
193 NIL_RTR0PTR, /* pHelpR0 */
194 NIL_RTR0PTR, /* pvInstanceDataR0 */
195 &pdmHlpR3,
196 NULL, /* pvInstanceDataR3 */
197 NIL_RTR3PTR, /* pReg */
198 NIL_RTR3PTR, /* pCfg */
199 &pdmiBase,
200 NULL, /* pDownBase */
201 { /* IBase */
202 NULL /* pfnQueryInterface */
203 },
204 0, /* fTracing */
205 0, /* idTracing */
206#if HC_ARCH_BITS == 32
207 { 0 }, /* au32Padding */
208#endif
209 {
210 { 0 } /* padding */
211 }, /* Internal */
212 { 0 } /* achInstanceData */
213};
214
215static struct PDMDRVINS *ppdmdrvIns = NULL;
216
217ComObjPtr<Mouse> pMouse;
218ConsoleMouseInterface *pConsole = NULL;
219
220static struct
221{
222 int32_t x;
223 int32_t y;
224} absoluteMouse;
225
226static int setAbsoluteMouse(PPDMIVMMDEVPORT, int32_t x, int32_t y)
227{
228 absoluteMouse.x = x;
229 absoluteMouse.y = y;
230 return VINF_SUCCESS;
231}
232
233static int updateMouseCapabilities(PPDMIVMMDEVPORT, uint32_t, uint32_t)
234{
235 return VINF_SUCCESS;
236}
237
238void TestDisplay::i_getFramebufferDimensions(int32_t *px1, int32_t *py1,
239 int32_t *px2, int32_t *py2)
240{
241 if (px1)
242 *px1 = -320;
243 if (py1)
244 *py1 = -240;
245 if (px2)
246 *px2 = 320;
247 if (py2)
248 *py2 = 240;
249}
250
251HRESULT TestDisplay::i_getScreenResolution(ULONG cScreen, ULONG *pcx,
252 ULONG *pcy, ULONG *pcBPP, LONG *pXOrigin, LONG *pYOrigin)
253{
254 NOREF(cScreen);
255 if (pcx)
256 *pcx = 640;
257 if (pcy)
258 *pcy = 480;
259 if (pcBPP)
260 *pcBPP = 32;
261 if (pXOrigin)
262 *pXOrigin = 0;
263 if (pYOrigin)
264 *pYOrigin = 0;
265 return S_OK;
266}
267
268/******************************************************************************
269* Main test code *
270******************************************************************************/
271
272static int setup(void)
273{
274 PCFGMNODE pCfg = NULL;
275 Mouse *pMouse2;
276 int rc = VERR_NO_MEMORY;
277 VMMDevPort.pfnSetAbsoluteMouse = setAbsoluteMouse;
278 VMMDevPort.pfnUpdateMouseCapabilities = updateMouseCapabilities;
279 HRESULT hrc = pMouse.createObject();
280 AssertComRC(hrc);
281 if (FAILED(hrc))
282 return VERR_GENERAL_FAILURE;
283 pConsole = new TestConsole;
284 pMouse->init(pConsole);
285 ppdmdrvIns = (struct PDMDRVINS *) RTMemAllocZ( sizeof(struct PDMDRVINS)
286 + Mouse::DrvReg.cbInstance);
287 *ppdmdrvIns = pdmdrvInsCore;
288 pMouse2 = pMouse;
289 pCfg = CFGMR3CreateTree(NULL);
290 if (pCfg)
291 {
292 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pMouse2);
293 if (RT_SUCCESS(rc))
294 Mouse::DrvReg.pfnConstruct(ppdmdrvIns, pCfg, 0);
295 }
296 return rc;
297}
298
299static void teardown(void)
300{
301 pMouse.setNull();
302 if (pConsole)
303 delete pConsole;
304 if (ppdmdrvIns)
305 RTMemFree(ppdmdrvIns);
306}
307
308static bool approxEq(int a, int b, int prec)
309{
310 return a - b < prec && b - a < prec;
311}
312
313/** @test testAbsToVMMDevNewProtocol */
314static void testAbsToVMMDevNewProtocol(RTTEST hTest)
315{
316 PPDMIBASE pBase;
317 PPDMIMOUSECONNECTOR pConnector;
318
319 RTTestSub(hTest, "Absolute event to VMMDev, new protocol");
320 pBase = &ppdmdrvIns->IBase;
321 pConnector = (PPDMIMOUSECONNECTOR)pBase->pfnQueryInterface(pBase,
322 PDMIMOUSECONNECTOR_IID);
323 pConnector->pfnReportModes(pConnector, true, false, false);
324 pMouse->i_onVMMDevGuestCapsChange( VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE
325 | VMMDEV_MOUSE_NEW_PROTOCOL);
326 pMouse->PutMouseEventAbsolute(0, 0, 0, 0, 0);
327 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0x8000, 200),
328 ("absoluteMouse.x=%d\n", absoluteMouse.x));
329 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0x8000, 200),
330 ("absoluteMouse.y=%d\n", absoluteMouse.y));
331 pMouse->PutMouseEventAbsolute(-319, -239, 0, 0, 0);
332 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0, 200),
333 ("absoluteMouse.x=%d\n", absoluteMouse.x));
334 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0, 200),
335 ("absoluteMouse.y=%d\n", absoluteMouse.y));
336 pMouse->PutMouseEventAbsolute(320, 240, 0, 0, 0);
337 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0xffff, 200),
338 ("absoluteMouse.x=%d\n", absoluteMouse.x));
339 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0xffff, 200),
340 ("absoluteMouse.y=%d\n", absoluteMouse.y));
341 RTTestSubDone(hTest);
342}
343
344/** @test testAbsToVMMDevOldProtocol */
345static void testAbsToVMMDevOldProtocol(RTTEST hTest)
346{
347 PPDMIBASE pBase;
348 PPDMIMOUSECONNECTOR pConnector;
349
350 RTTestSub(hTest, "Absolute event to VMMDev, old protocol");
351 pBase = &ppdmdrvIns->IBase;
352 pConnector = (PPDMIMOUSECONNECTOR)pBase->pfnQueryInterface(pBase,
353 PDMIMOUSECONNECTOR_IID);
354 pConnector->pfnReportModes(pConnector, true, false, false);
355 pMouse->i_onVMMDevGuestCapsChange(VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE);
356 pMouse->PutMouseEventAbsolute(320, 240, 0, 0, 0);
357 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0x8000, 200),
358 ("absoluteMouse.x=%d\n", absoluteMouse.x));
359 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0x8000, 200),
360 ("absoluteMouse.y=%d\n", absoluteMouse.y));
361 pMouse->PutMouseEventAbsolute(0, 0, 0, 0, 0);
362 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0, 200),
363 ("absoluteMouse.x=%d\n", absoluteMouse.x));
364 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0, 200),
365 ("absoluteMouse.y=%d\n", absoluteMouse.y));
366 pMouse->PutMouseEventAbsolute(-319, -239, 0, 0, 0);
367 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, -0x8000, 200),
368 ("absoluteMouse.x=%d\n", absoluteMouse.x));
369 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, -0x8000, 200),
370 ("absoluteMouse.y=%d\n", absoluteMouse.y));
371 RTTestSubDone(hTest);
372}
373
374/** @test testAbsToAbsDev */
375static void testAbsToAbsDev(RTTEST hTest)
376{
377 PPDMIBASE pBase;
378 PPDMIMOUSECONNECTOR pConnector;
379
380 RTTestSub(hTest, "Absolute event to absolute device");
381 pBase = &ppdmdrvIns->IBase;
382 pConnector = (PPDMIMOUSECONNECTOR)pBase->pfnQueryInterface(pBase,
383 PDMIMOUSECONNECTOR_IID);
384 pConnector->pfnReportModes(pConnector, false, true, false);
385 pMouse->i_onVMMDevGuestCapsChange(VMMDEV_MOUSE_NEW_PROTOCOL);
386 pMouse->PutMouseEventAbsolute(0, 0, 0, 0, 0);
387 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.cx, 0x8000, 200),
388 ("mouseEventAbs.cx=%d\n", mouseEventAbs.cx));
389 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.cy, 0x8000, 200),
390 ("mouseEventAbs.cy=%d\n", mouseEventAbs.cy));
391 pMouse->PutMouseEventAbsolute(-319, -239, 0, 0, 3);
392 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.cx, 0, 200),
393 ("mouseEventAbs.cx=%d\n", mouseEventAbs.cx));
394 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.cy, 0, 200),
395 ("mouseEventAbs.cy=%d\n", mouseEventAbs.cy));
396 RTTESTI_CHECK_MSG(mouseEventAbs.fButtonStates == 3,
397 ("mouseEventAbs.fButtonStates=%u\n",
398 (unsigned) mouseEventAbs.fButtonStates));
399 pMouse->PutMouseEventAbsolute(320, 240, -3, 2, 1);
400 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.cx, 0xffff, 200),
401 ("mouseEventAbs.cx=%d\n", mouseEventAbs.cx));
402 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.cy, 0xffff, 200),
403 ("mouseEventAbs.cy=%d\n", mouseEventAbs.cy));
404 RTTESTI_CHECK_MSG(mouseEventAbs.fButtonStates == 1,
405 ("mouseEventAbs.fButtonStates=%u\n",
406 (unsigned) mouseEventAbs.fButtonStates));
407 RTTESTI_CHECK_MSG(mouseEventAbs.dz == -3,
408 ("mouseEventAbs.dz=%d\n", (int) mouseEvent.dz));
409 RTTESTI_CHECK_MSG(mouseEventAbs.dw == 2,
410 ("mouseEventAbs.dw=%d\n", (int) mouseEvent.dw));
411 mouseEventAbs.cx = mouseEventAbs.cy = 0xffff;
412 pMouse->PutMouseEventAbsolute(-640, -480, 0, 0, 0);
413 RTTESTI_CHECK_MSG(mouseEventAbs.cx == 0xffff,
414 ("mouseEventAbs.cx=%d\n", mouseEventAbs.cx));
415 RTTESTI_CHECK_MSG(mouseEventAbs.cy == 0xffff,
416 ("mouseEventAbs.cy=%d\n", mouseEventAbs.cy));
417 RTTestSubDone(hTest);
418}
419
420/** @todo generate this using the @test blocks above */
421typedef void (*PFNTEST)(RTTEST);
422static PFNTEST g_tests[] =
423{
424 testAbsToVMMDevNewProtocol,
425 testAbsToVMMDevOldProtocol,
426 testAbsToAbsDev,
427 NULL
428};
429
430int main(void)
431{
432 /*
433 * Init the runtime, test and say hello.
434 */
435 RTTEST hTest;
436 RTEXITCODE rcExit = RTTestInitAndCreate("tstMouseImpl", &hTest);
437 if (rcExit != RTEXITCODE_SUCCESS)
438 return rcExit;
439 RTTestBanner(hTest);
440
441 /*
442 * Run the tests.
443 */
444 for (unsigned i = 0; g_tests[i]; ++i)
445 {
446 int rc = setup();
447 AssertRC(rc);
448 if (RT_SUCCESS(rc))
449 g_tests[i](hTest);
450 teardown();
451 }
452
453 /*
454 * Summary
455 */
456 return RTTestSummaryAndDestroy(hTest);
457}
458
Note: See TracBrowser for help on using the repository browser.

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