VirtualBox

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

Last change on this file since 47497 was 47428, checked in by vboxsync, 12 years ago

Addressed some warnings.

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