VirtualBox

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

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

Main/testcase: typo in tstMouseImpl

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