VirtualBox

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

Last change on this file since 51615 was 51615, checked in by vboxsync, 11 years ago

repaired tstMouseImpl

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