VirtualBox

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

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

Main/MouseImpl: use real CFGM in test case instead of faking APIs.

  • 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 47746 2013-08-15 07:44:17Z 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
255/******************************************************************************
256* Main test code *
257******************************************************************************/
258
259static int setup(void)
260{
261 PCFGMNODE pCfg = NULL;
262 Mouse *pMouse2;
263 int rc;
264 VMMDevPort.pfnSetAbsoluteMouse = setAbsoluteMouse;
265 VMMDevPort.pfnUpdateMouseCapabilities = updateMouseCapabilities;
266 HRESULT hrc = pMouse.createObject();
267 AssertComRC(hrc);
268 if (FAILED(hrc))
269 return VERR_GENERAL_FAILURE;
270 pConsole = new TestConsole;
271 pMouse->init(pConsole);
272 ppdmdrvIns = (struct PDMDRVINS *) RTMemAllocZ( sizeof(struct PDMDRVINS)
273 + Mouse::DrvReg.cbInstance);
274 *ppdmdrvIns = pdmdrvInsCore;
275 pMouse2 = pMouse;
276 pCfg = CFGMR3CreateTree(NULL);
277 if (pCfg)
278 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pMouse2);
279 if (RT_SUCCESS(rc))
280 Mouse::DrvReg.pfnConstruct(ppdmdrvIns, pCfg, 0);
281 return rc;
282}
283
284static void teardown(void)
285{
286 pMouse.setNull();
287 if (pConsole)
288 delete pConsole;
289 if (ppdmdrvIns)
290 RTMemFree(ppdmdrvIns);
291}
292
293static bool approxEq(int a, int b, int prec)
294{
295 return a - b < prec && b - a < prec;
296}
297
298/** @test testAbsToVMMDevNewProtocol */
299static void testAbsToVMMDevNewProtocol(RTTEST hTest)
300{
301 PPDMIBASE pBase;
302 PPDMIMOUSECONNECTOR pConnector;
303
304 RTTestSub(hTest, "Absolute event to VMMDev, new protocol");
305 pBase = &ppdmdrvIns->IBase;
306 pConnector = (PPDMIMOUSECONNECTOR)pBase->pfnQueryInterface(pBase,
307 PDMIMOUSECONNECTOR_IID);
308 pConnector->pfnReportModes(pConnector, true, false, false);
309 pMouse->onVMMDevGuestCapsChange( VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE
310 | VMMDEV_MOUSE_NEW_PROTOCOL);
311 pMouse->PutMouseEventAbsolute(0, 0, 0, 0, 0);
312 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0x8000, 200),
313 ("absoluteMouse.x=%d\n", absoluteMouse.x));
314 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0x8000, 200),
315 ("absoluteMouse.y=%d\n", absoluteMouse.y));
316 pMouse->PutMouseEventAbsolute(-319, -239, 0, 0, 0);
317 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0, 200),
318 ("absoluteMouse.x=%d\n", absoluteMouse.x));
319 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0, 200),
320 ("absoluteMouse.y=%d\n", absoluteMouse.y));
321 pMouse->PutMouseEventAbsolute(320, 240, 0, 0, 0);
322 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0xffff, 200),
323 ("absoluteMouse.x=%d\n", absoluteMouse.x));
324 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0xffff, 200),
325 ("absoluteMouse.y=%d\n", absoluteMouse.y));
326 RTTestSubDone(hTest);
327}
328
329/** @test testAbsToVMMDevOldProtocol */
330static void testAbsToVMMDevOldProtocol(RTTEST hTest)
331{
332 PPDMIBASE pBase;
333 PPDMIMOUSECONNECTOR pConnector;
334
335 RTTestSub(hTest, "Absolute event to VMMDev, old protocol");
336 pBase = &ppdmdrvIns->IBase;
337 pConnector = (PPDMIMOUSECONNECTOR)pBase->pfnQueryInterface(pBase,
338 PDMIMOUSECONNECTOR_IID);
339 pConnector->pfnReportModes(pConnector, true, false, false);
340 pMouse->onVMMDevGuestCapsChange(VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE);
341 pMouse->PutMouseEventAbsolute(320, 240, 0, 0, 0);
342 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0x8000, 200),
343 ("absoluteMouse.x=%d\n", absoluteMouse.x));
344 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0x8000, 200),
345 ("absoluteMouse.y=%d\n", absoluteMouse.y));
346 pMouse->PutMouseEventAbsolute(0, 0, 0, 0, 0);
347 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0, 200),
348 ("absoluteMouse.x=%d\n", absoluteMouse.x));
349 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0, 200),
350 ("absoluteMouse.y=%d\n", absoluteMouse.y));
351 pMouse->PutMouseEventAbsolute(-319, -239, 0, 0, 0);
352 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, -0x8000, 200),
353 ("absoluteMouse.x=%d\n", absoluteMouse.x));
354 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, -0x8000, 200),
355 ("absoluteMouse.y=%d\n", absoluteMouse.y));
356 RTTestSubDone(hTest);
357}
358
359/** @test testAbsToAbsDev */
360static void testAbsToAbsDev(RTTEST hTest)
361{
362 PPDMIBASE pBase;
363 PPDMIMOUSECONNECTOR pConnector;
364
365 RTTestSub(hTest, "Absolute event to absolute device");
366 pBase = &ppdmdrvIns->IBase;
367 pConnector = (PPDMIMOUSECONNECTOR)pBase->pfnQueryInterface(pBase,
368 PDMIMOUSECONNECTOR_IID);
369 pConnector->pfnReportModes(pConnector, false, true, false);
370 pMouse->onVMMDevGuestCapsChange( VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE
371 | VMMDEV_MOUSE_NEW_PROTOCOL);
372 pMouse->PutMouseEventAbsolute(0, 0, 0, 0, 0);
373 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.x, 0x8000, 200),
374 ("mouseEventAbs.x=%d\n", mouseEventAbs.x));
375 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.y, 0x8000, 200),
376 ("mouseEventAbs.y=%d\n", mouseEventAbs.y));
377 pMouse->PutMouseEventAbsolute(-319, -239, 0, 0, 0);
378 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.x, 0, 200),
379 ("mouseEventAbs.x=%d\n", mouseEventAbs.x));
380 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.y, 0, 200),
381 ("mouseEventAbs.y=%d\n", mouseEventAbs.y));
382 pMouse->PutMouseEventAbsolute(320, 240, 0, 0, 0);
383 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.x, 0xffff, 200),
384 ("mouseEventAbs.x=%d\n", mouseEventAbs.x));
385 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.y, 0xffff, 200),
386 ("mouseEventAbs.y=%d\n", mouseEventAbs.y));
387 mouseEventAbs.x = mouseEventAbs.y = 0xffff;
388 pMouse->PutMouseEventAbsolute(-640, -480, 0, 0, 0);
389 RTTESTI_CHECK_MSG(mouseEventAbs.x = 0xffff,
390 ("mouseEventAbs.x=%d\n", mouseEventAbs.x));
391 RTTESTI_CHECK_MSG(mouseEventAbs.y == 0xffff,
392 ("mouseEventAbs.y=%d\n", mouseEventAbs.y));
393 RTTestSubDone(hTest);
394}
395
396/** @todo generate this using the @test blocks above */
397typedef void (*PFNTEST)(RTTEST);
398static PFNTEST g_tests[] =
399{
400 testAbsToVMMDevNewProtocol,
401 testAbsToVMMDevOldProtocol,
402 testAbsToAbsDev,
403 NULL
404};
405
406int main(void)
407{
408 /*
409 * Init the runtime, test and say hello.
410 */
411 RTTEST hTest;
412 RTEXITCODE rcExit = RTTestInitAndCreate("tstMouseImpl", &hTest);
413 if (rcExit != RTEXITCODE_SUCCESS)
414 return rcExit;
415 RTTestBanner(hTest);
416
417 /*
418 * Run the tests.
419 */
420 for (unsigned i = 0; g_tests[i]; ++i)
421 {
422 int rc = setup();
423 AssertRC(rc);
424 if (RT_SUCCESS(rc))
425 g_tests[i](hTest);
426 teardown();
427 }
428
429 /*
430 * Summary
431 */
432 return RTTestSummaryAndDestroy(hTest);
433}
434
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