VirtualBox

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

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

Main/MouseImpl: restored Mouse test case, not yet building though; fix a burn.

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