VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxBFE/testcase/tstMouseImpl.cpp@ 36156

Last change on this file since 36156 was 36156, checked in by vboxsync, 14 years ago

FE/BFE: try the mouse testcase again

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.9 KB
Line 
1/* $Id: tstMouseImpl.cpp 36156 2011-03-03 19:52:32Z vboxsync $ */
2/** @file
3 * Main unit test - Mouse class.
4 */
5
6/*
7 * Copyright (C) 2011 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#include "MouseImpl.h"
22#include "VMMDev.h"
23#include "DisplayImpl.h"
24
25#include <VBox/vmm/cfgm.h>
26#include <VBox/vmm/pdmdrv.h>
27#include <VBox/VMMDev.h>
28#include <iprt/assert.h>
29#include <iprt/test.h>
30
31class TestConsole : public Console
32{
33public:
34 TestConsole() {}
35 ~TestConsole() {}
36
37 virtual void updateTitlebar() {}
38 virtual void updateTitlebarProgress(const char *, int) {}
39
40 virtual void inputGrabStart() {}
41 virtual void inputGrabEnd() {}
42
43 virtual void mouseSendEvent(int) {}
44 virtual void onMousePointerShapeChange(bool, bool, uint32_t,
45 uint32_t, uint32_t,
46 uint32_t, void *) {}
47 virtual void progressInfo(PVM, unsigned, void *) {}
48
49 virtual CONEVENT eventWait()
50 {
51 AssertFailedReturn(CONEVENT_QUIT);
52 }
53 virtual void eventQuit() {}
54 virtual void resetCursor() {}
55 virtual void resetKeys(void) {}
56 virtual VMMDev *getVMMDev()
57 {
58 return &mVMMDev;
59 }
60 virtual Display *getDisplay()
61 {
62 return &mDisplay;
63 }
64
65private:
66 VMMDev mVMMDev;
67 Display mDisplay;
68};
69
70static int pdmdrvhlpAttach(PPDMDRVINS pDrvIns, uint32_t fFlags,
71 PPDMIBASE *ppBaseInterface)
72{
73 return VERR_PDM_NO_ATTACHED_DRIVER;
74}
75
76static struct PDMDRVHLPR3 pdmHlpR3 =
77{
78 PDM_DRVHLPR3_VERSION,
79 pdmdrvhlpAttach
80};
81
82static struct
83{
84 int32_t cx;
85 int32_t cy;
86} mouseEvent;
87
88static int mousePutEvent(PPDMIMOUSEPORT pInterface, int32_t iDeltaX,
89 int32_t iDeltaY, int32_t iDeltaZ, int32_t iDeltaW,
90 uint32_t fButtonStates)
91{
92 mouseEvent.cx = iDeltaX;
93 mouseEvent.cy = iDeltaY;
94 return VINF_SUCCESS;
95}
96
97static struct
98{
99 int32_t x;
100 int32_t y;
101} mouseEventAbs;
102
103static int mousePutEventAbs(PPDMIMOUSEPORT pInterface, uint32_t uX,
104 uint32_t uY, int32_t iDeltaZ, int32_t iDeltaW,
105 uint32_t fButtonStates)
106{
107 mouseEventAbs.x = uX;
108 mouseEventAbs.y = uY;
109 return VINF_SUCCESS;
110}
111
112static struct PDMIMOUSEPORT pdmiMousePort =
113{
114 mousePutEvent,
115 mousePutEventAbs
116};
117
118static void *pdmiBaseQuery(struct PDMIBASE *pInterface, const char *pszIID)
119{
120 return &pdmiMousePort;
121}
122
123static struct PDMIBASE pdmiBase =
124{
125 pdmiBaseQuery
126};
127
128static struct PDMDRVINS pdmdrvInsCore =
129{
130 PDM_DRVINS_VERSION,
131 0,
132 NULL,
133 NULL,
134 NULL,
135 NULL,
136 &pdmHlpR3,
137 NULL,
138 NULL,
139 NULL,
140 &pdmiBase
141};
142
143static struct PDMDRVINS *ppdmdrvIns = NULL;
144
145PDMIVMMDEVPORT VMMDevPort;
146Mouse *pMouse;
147Console *pConsole;
148
149static struct
150{
151 int32_t x;
152 int32_t y;
153} absoluteMouse;
154
155static int setAbsoluteMouse(PPDMIVMMDEVPORT, int32_t x, int32_t y)
156{
157 absoluteMouse.x = x;
158 absoluteMouse.y = y;
159 return VINF_SUCCESS;
160}
161
162static int updateMouseCapabilities(PPDMIVMMDEVPORT, uint32_t, uint32_t)
163{
164 return VINF_SUCCESS;
165}
166
167PPDMIVMMDEVPORT VMMDev::getVMMDevPort(void)
168{
169 return &VMMDevPort;
170}
171
172VMMDev::VMMDev() {}
173
174VMMDev::~VMMDev() {}
175
176void Display::getFramebufferDimensions(int32_t *px1, int32_t *py1,
177 int32_t *px2, int32_t *py2)
178{
179 if (px1)
180 *px1 = -320;
181 if (py1)
182 *py1 = -240;
183 if (px2)
184 *px2 = 320;
185 if (py2)
186 *py2 = 240;
187}
188
189STDMETHODIMP Display::GetScreenResolution(ULONG aScreenId,
190 ULONG *aWidth,
191 ULONG *aHeight,
192 ULONG *aBitsPerPixel)
193{
194 if (aWidth)
195 *aWidth = 640;
196 if (aHeight)
197 *aHeight = 480;
198 if (aBitsPerPixel)
199 *aBitsPerPixel = 32;
200 return S_OK;
201}
202
203Display::Display() {}
204
205Display::~Display() {}
206
207DECLEXPORT(bool) CFGMR3AreValuesValid(PCFGMNODE, const char *)
208{
209 return true;
210}
211
212DECLEXPORT(int) CFGMR3QueryPtr(PCFGMNODE, const char *, void **pv)
213{
214 *pv = pMouse;
215 return VINF_SUCCESS;
216}
217
218static int setup(void)
219{
220 VMMDevPort.pfnSetAbsoluteMouse = setAbsoluteMouse;
221 VMMDevPort.pfnUpdateMouseCapabilities = updateMouseCapabilities;
222 pMouse = new Mouse;
223 Assert(SUCCEEDED(pMouse->FinalConstruct()));
224 pConsole = new TestConsole;
225 pMouse->init(pConsole);
226 ppdmdrvIns = (struct PDMDRVINS *) RTMemAllocZ( sizeof(struct PDMDRVINS)
227 + Mouse::DrvReg.cbInstance);
228 *ppdmdrvIns = pdmdrvInsCore;
229 Mouse::DrvReg.pfnConstruct(ppdmdrvIns, NULL, 0);
230 return VINF_SUCCESS;
231}
232
233static void teardown(void)
234{
235 delete pMouse;
236 delete pConsole;
237 RTMemFree(ppdmdrvIns);
238}
239
240static bool approxEq(int a, int b, int prec)
241{
242 return a - b < prec && b - a < prec;
243}
244
245/** @test testAbsToVMMDevNewProtocol */
246static void testAbsToVMMDevNewProtocol(RTTEST hTest)
247{
248 PPDMIBASE pBase;
249 PPDMIMOUSECONNECTOR pConnector;
250
251 RTTestSub(hTest, "Absolute event to VMMDev, new protocol");
252 pBase = &ppdmdrvIns->IBase;
253 pConnector = (PPDMIMOUSECONNECTOR)pBase->pfnQueryInterface(pBase,
254 PDMIMOUSECONNECTOR_IID);
255 pConnector->pfnReportModes(pConnector, true, false);
256 pMouse->onVMMDevGuestCapsChange( VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE
257 | VMMDEV_MOUSE_NEW_PROTOCOL);
258 pMouse->PutMouseEventAbsolute(0, 0, 0, 0, 0);
259 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0x8000, 200),
260 ("absoluteMouse.x=%d\n", absoluteMouse.x));
261 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0x8000, 200),
262 ("absoluteMouse.y=%d\n", absoluteMouse.y));
263 pMouse->PutMouseEventAbsolute(-319, -239, 0, 0, 0);
264 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0, 200),
265 ("absoluteMouse.x=%d\n", absoluteMouse.x));
266 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0, 200),
267 ("absoluteMouse.y=%d\n", absoluteMouse.y));
268 pMouse->PutMouseEventAbsolute(320, 240, 0, 0, 0);
269 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0xffff, 200),
270 ("absoluteMouse.x=%d\n", absoluteMouse.x));
271 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0xffff, 200),
272 ("absoluteMouse.y=%d\n", absoluteMouse.y));
273 RTTestSubDone(hTest);
274}
275
276/** @test testAbsToVMMDevOldProtocol */
277static void testAbsToVMMDevOldProtocol(RTTEST hTest)
278{
279 PPDMIBASE pBase;
280 PPDMIMOUSECONNECTOR pConnector;
281
282 RTTestSub(hTest, "Absolute event to VMMDev, old protocol");
283 pBase = &ppdmdrvIns->IBase;
284 pConnector = (PPDMIMOUSECONNECTOR)pBase->pfnQueryInterface(pBase,
285 PDMIMOUSECONNECTOR_IID);
286 pConnector->pfnReportModes(pConnector, true, false);
287 pMouse->onVMMDevGuestCapsChange(VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE);
288 pMouse->PutMouseEventAbsolute(320, 240, 0, 0, 0);
289 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0x8000, 200),
290 ("absoluteMouse.x=%d\n", absoluteMouse.x));
291 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0x8000, 200),
292 ("absoluteMouse.y=%d\n", absoluteMouse.y));
293 pMouse->PutMouseEventAbsolute(0, 0, 0, 0, 0);
294 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0, 200),
295 ("absoluteMouse.x=%d\n", absoluteMouse.x));
296 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0, 200),
297 ("absoluteMouse.y=%d\n", absoluteMouse.y));
298 pMouse->PutMouseEventAbsolute(-319, -239, 0, 0, 0);
299 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, -0x8000, 200),
300 ("absoluteMouse.x=%d\n", absoluteMouse.x));
301 RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, -0x8000, 200),
302 ("absoluteMouse.y=%d\n", absoluteMouse.y));
303 RTTestSubDone(hTest);
304}
305
306/** @test testAbsToAbsDev */
307static void testAbsToAbsDev(RTTEST hTest)
308{
309 PPDMIBASE pBase;
310 PPDMIMOUSECONNECTOR pConnector;
311
312 RTTestSub(hTest, "Absolute event to absolute device");
313 pBase = &ppdmdrvIns->IBase;
314 pConnector = (PPDMIMOUSECONNECTOR)pBase->pfnQueryInterface(pBase,
315 PDMIMOUSECONNECTOR_IID);
316 pConnector->pfnReportModes(pConnector, false, true);
317 pMouse->onVMMDevGuestCapsChange( VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE
318 | VMMDEV_MOUSE_NEW_PROTOCOL);
319 pMouse->PutMouseEventAbsolute(0, 0, 0, 0, 0);
320 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.x, 0x8000, 200),
321 ("mouseEventAbs.x=%d\n", mouseEventAbs.x));
322 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.y, 0x8000, 200),
323 ("mouseEventAbs.y=%d\n", mouseEventAbs.y));
324 pMouse->PutMouseEventAbsolute(-319, -239, 0, 0, 0);
325 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.x, 0, 200),
326 ("mouseEventAbs.x=%d\n", mouseEventAbs.x));
327 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.y, 0, 200),
328 ("mouseEventAbs.y=%d\n", mouseEventAbs.y));
329 pMouse->PutMouseEventAbsolute(320, 240, 0, 0, 0);
330 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.x, 0xffff, 200),
331 ("mouseEventAbs.x=%d\n", mouseEventAbs.x));
332 RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.y, 0xffff, 200),
333 ("mouseEventAbs.y=%d\n", mouseEventAbs.y));
334 mouseEventAbs.x = mouseEventAbs.y = 0xffff;
335 pMouse->PutMouseEventAbsolute(-640, -480, 0, 0, 0);
336 RTTESTI_CHECK_MSG(mouseEventAbs.x = 0xffff,
337 ("mouseEventAbs.x=%d\n", mouseEventAbs.x));
338 RTTESTI_CHECK_MSG(mouseEventAbs.y == 0xffff,
339 ("mouseEventAbs.y=%d\n", mouseEventAbs.y));
340 RTTestSubDone(hTest);
341}
342
343/** @todo generate this using the @test blocks above */
344typedef void (*PFNTEST)(RTTEST);
345static PFNTEST g_tests[] =
346{
347 testAbsToVMMDevNewProtocol,
348 testAbsToVMMDevOldProtocol,
349 testAbsToAbsDev,
350 NULL
351};
352
353int main(void)
354{
355 /*
356 * Init the runtime, test and say hello.
357 */
358 RTTEST hTest;
359 RTEXITCODE rcExit = RTTestInitAndCreate("tstMouseImpl", &hTest);
360 if (rcExit != RTEXITCODE_SUCCESS)
361 return rcExit;
362 RTTestBanner(hTest);
363
364 /*
365 * Run the tests.
366 */
367 for (unsigned i = 0; g_tests[i]; ++i)
368 {
369 AssertRC(setup());
370 g_tests[i](hTest);
371 teardown();
372 }
373
374 /*
375 * Summary
376 */
377 return RTTestSummaryAndDestroy(hTest);
378}
379
Note: See TracBrowser for help on using the repository browser.

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