VirtualBox

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

Last change on this file since 47389 was 47384, checked in by vboxsync, 12 years ago

Main/testcase/tstMouseImpl: 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.5 KB
Line 
1/* $Id: tstMouseImpl.cpp 47384 2013-07-25 09:17:50Z 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 NULL, /* IBase */
193 0, /* fTracing */
194 0, /* idTracing */
195#if HC_ARCH_BITS == 32
196 0, /* au32Padding */
197#endif
198 {
199 0 /* Padding */
200 }, /* Internal */
201 0 /* achInstanceData */
202};
203
204static struct PDMDRVINS *ppdmdrvIns = NULL;
205
206ComObjPtr<Mouse> pMouse;
207ConsoleMouseInterface *pConsole = NULL;
208
209static struct
210{
211 int32_t x;
212 int32_t y;
213} absoluteMouse;
214
215static int setAbsoluteMouse(PPDMIVMMDEVPORT, int32_t x, int32_t y)
216{
217 absoluteMouse.x = x;
218 absoluteMouse.y = y;
219 return VINF_SUCCESS;
220}
221
222static int updateMouseCapabilities(PPDMIVMMDEVPORT, uint32_t, uint32_t)
223{
224 return VINF_SUCCESS;
225}
226
227void TestDisplay::getFramebufferDimensions(int32_t *px1, int32_t *py1,
228 int32_t *px2, int32_t *py2)
229{
230 if (px1)
231 *px1 = -320;
232 if (py1)
233 *py1 = -240;
234 if (px2)
235 *px2 = 320;
236 if (py2)
237 *py2 = 240;
238}
239
240int TestDisplay::getScreenResolution(uint32_t cScreen, ULONG *pcx,
241 ULONG *pcy, ULONG *pcBPP)
242{
243 NOREF(cScreen);
244 if (pcx)
245 *pcx = 640;
246 if (pcy)
247 *pcy = 480;
248 if (pcBPP)
249 *pcBPP = 32;
250 return S_OK;
251}
252
253DECLEXPORT(bool) CFGMR3AreValuesValid(PCFGMNODE, const char *)
254{
255 return true;
256}
257
258DECLEXPORT(int) CFGMR3QueryPtr(PCFGMNODE, const char *, void **pv)
259{
260 *pv = pMouse;
261 return VINF_SUCCESS;
262}
263
264/******************************************************************************
265* Main test code *
266******************************************************************************/
267
268static int setup(void)
269{
270 VMMDevPort.pfnSetAbsoluteMouse = setAbsoluteMouse;
271 VMMDevPort.pfnUpdateMouseCapabilities = updateMouseCapabilities;
272 HRESULT hrc = pMouse.createObject();
273 AssertComRC(hrc);
274 if (FAILED(hrc))
275 return VERR_GENERAL_FAILURE;
276 pConsole = new TestConsole;
277 pMouse->init(pConsole);
278 ppdmdrvIns = (struct PDMDRVINS *) RTMemAllocZ( sizeof(struct PDMDRVINS)
279 + Mouse::DrvReg.cbInstance);
280 *ppdmdrvIns = pdmdrvInsCore;
281 Mouse::DrvReg.pfnConstruct(ppdmdrvIns, NULL, 0);
282 return VINF_SUCCESS;
283}
284
285static void teardown(void)
286{
287 pMouse.setNull();
288 if (pConsole)
289 delete pConsole;
290 if (ppdmdrvIns)
291 RTMemFree(ppdmdrvIns);
292}
293
294static bool approxEq(int a, int b, int prec)
295{
296 return a - b < prec && b - a < prec;
297}
298
299/** @test testAbsToVMMDevNewProtocol */
300static void testAbsToVMMDevNewProtocol(RTTEST hTest)
301{
302 PPDMIBASE pBase;
303 PPDMIMOUSECONNECTOR pConnector;
304
305 RTTestSub(hTest, "Absolute event to VMMDev, new protocol");
306 pBase = &ppdmdrvIns->IBase;
307 pConnector = (PPDMIMOUSECONNECTOR)pBase->pfnQueryInterface(pBase,
308 PDMIMOUSECONNECTOR_IID);
309 pConnector->pfnReportModes(pConnector, true, false, false);
310 pMouse->onVMMDevGuestCapsChange( VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE
311 | VMMDEV_MOUSE_NEW_PROTOCOL);
312 pMouse->PutMouseEventAbsolute(0, 0, 0, 0, 0);
313 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0x8000, 200),
314 ("absoluteMouse.x=%d\n", absoluteMouse.x));
315 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0x8000, 200),
316 ("absoluteMouse.y=%d\n", absoluteMouse.y));
317 pMouse->PutMouseEventAbsolute(-319, -239, 0, 0, 0);
318 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0, 200),
319 ("absoluteMouse.x=%d\n", absoluteMouse.x));
320 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0, 200),
321 ("absoluteMouse.y=%d\n", absoluteMouse.y));
322 pMouse->PutMouseEventAbsolute(320, 240, 0, 0, 0);
323 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0xffff, 200),
324 ("absoluteMouse.x=%d\n", absoluteMouse.x));
325 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0xffff, 200),
326 ("absoluteMouse.y=%d\n", absoluteMouse.y));
327 RTTestSubDone(hTest);
328}
329
330/** @test testAbsToVMMDevOldProtocol */
331static void testAbsToVMMDevOldProtocol(RTTEST hTest)
332{
333 PPDMIBASE pBase;
334 PPDMIMOUSECONNECTOR pConnector;
335
336 RTTestSub(hTest, "Absolute event to VMMDev, old protocol");
337 pBase = &ppdmdrvIns->IBase;
338 pConnector = (PPDMIMOUSECONNECTOR)pBase->pfnQueryInterface(pBase,
339 PDMIMOUSECONNECTOR_IID);
340 pConnector->pfnReportModes(pConnector, true, false, false);
341 pMouse->onVMMDevGuestCapsChange(VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE);
342 pMouse->PutMouseEventAbsolute(320, 240, 0, 0, 0);
343 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0x8000, 200),
344 ("absoluteMouse.x=%d\n", absoluteMouse.x));
345 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0x8000, 200),
346 ("absoluteMouse.y=%d\n", absoluteMouse.y));
347 pMouse->PutMouseEventAbsolute(0, 0, 0, 0, 0);
348 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0, 200),
349 ("absoluteMouse.x=%d\n", absoluteMouse.x));
350 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0, 200),
351 ("absoluteMouse.y=%d\n", absoluteMouse.y));
352 pMouse->PutMouseEventAbsolute(-319, -239, 0, 0, 0);
353 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, -0x8000, 200),
354 ("absoluteMouse.x=%d\n", absoluteMouse.x));
355 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, -0x8000, 200),
356 ("absoluteMouse.y=%d\n", absoluteMouse.y));
357 RTTestSubDone(hTest);
358}
359
360/** @test testAbsToAbsDev */
361static void testAbsToAbsDev(RTTEST hTest)
362{
363 PPDMIBASE pBase;
364 PPDMIMOUSECONNECTOR pConnector;
365
366 RTTestSub(hTest, "Absolute event to absolute device");
367 pBase = &ppdmdrvIns->IBase;
368 pConnector = (PPDMIMOUSECONNECTOR)pBase->pfnQueryInterface(pBase,
369 PDMIMOUSECONNECTOR_IID);
370 pConnector->pfnReportModes(pConnector, false, true, false);
371 pMouse->onVMMDevGuestCapsChange( VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE
372 | VMMDEV_MOUSE_NEW_PROTOCOL);
373 pMouse->PutMouseEventAbsolute(0, 0, 0, 0, 0);
374 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.x, 0x8000, 200),
375 ("mouseEventAbs.x=%d\n", mouseEventAbs.x));
376 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.y, 0x8000, 200),
377 ("mouseEventAbs.y=%d\n", mouseEventAbs.y));
378 pMouse->PutMouseEventAbsolute(-319, -239, 0, 0, 0);
379 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.x, 0, 200),
380 ("mouseEventAbs.x=%d\n", mouseEventAbs.x));
381 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.y, 0, 200),
382 ("mouseEventAbs.y=%d\n", mouseEventAbs.y));
383 pMouse->PutMouseEventAbsolute(320, 240, 0, 0, 0);
384 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.x, 0xffff, 200),
385 ("mouseEventAbs.x=%d\n", mouseEventAbs.x));
386 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.y, 0xffff, 200),
387 ("mouseEventAbs.y=%d\n", mouseEventAbs.y));
388 mouseEventAbs.x = mouseEventAbs.y = 0xffff;
389 pMouse->PutMouseEventAbsolute(-640, -480, 0, 0, 0);
390 RTTESTI_CHECK_MSG(mouseEventAbs.x = 0xffff,
391 ("mouseEventAbs.x=%d\n", mouseEventAbs.x));
392 RTTESTI_CHECK_MSG(mouseEventAbs.y == 0xffff,
393 ("mouseEventAbs.y=%d\n", mouseEventAbs.y));
394 RTTestSubDone(hTest);
395}
396
397/** @todo generate this using the @test blocks above */
398typedef void (*PFNTEST)(RTTEST);
399static PFNTEST g_tests[] =
400{
401 testAbsToVMMDevNewProtocol,
402 testAbsToVMMDevOldProtocol,
403 testAbsToAbsDev,
404 NULL
405};
406
407int main(void)
408{
409 /*
410 * Init the runtime, test and say hello.
411 */
412 RTTEST hTest;
413 RTEXITCODE rcExit = RTTestInitAndCreate("tstMouseImpl", &hTest);
414 if (rcExit != RTEXITCODE_SUCCESS)
415 return rcExit;
416 RTTestBanner(hTest);
417
418 /*
419 * Run the tests.
420 */
421 for (unsigned i = 0; g_tests[i]; ++i)
422 {
423 int rc = setup();
424 AssertRC(rc);
425 if (RT_SUCCESS(rc))
426 g_tests[i](hTest);
427 teardown();
428 }
429
430 /*
431 * Summary
432 */
433 return RTTestSummaryAndDestroy(hTest);
434}
435
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