VirtualBox

source: vbox/trunk/src/VBox/Devices/Input/testcase/tstUsbMouse.cpp@ 46932

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

Devices/Input/UsbMouse: add multi-touch mode to pfnReportModes in PDM.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.2 KB
Line 
1/* $Id: tstUsbMouse.cpp 46932 2013-07-03 13:02:28Z vboxsync $ */
2/** @file
3 * tstUsbMouse.cpp - testcase USB mouse and tablet devices.
4 */
5
6/*
7 * Copyright (C) 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 "VBoxDD.h"
22#include <VBox/vmm/pdmdrv.h>
23#include <iprt/alloc.h>
24#include <iprt/stream.h>
25#include <iprt/test.h>
26#include <iprt/uuid.h>
27
28/** Test mouse driver structure. */
29typedef struct DRVTSTMOUSE
30{
31 /** The USBHID structure. */
32 struct USBHID *pUsbHid;
33 /** The base interface for the mouse driver. */
34 PDMIBASE IBase;
35 /** Our mouse connector interface. */
36 PDMIMOUSECONNECTOR IConnector;
37 /** The base interface of the attached mouse port. */
38 PPDMIBASE pDrvBase;
39 /** The mouse port interface of the attached mouse port. */
40 PPDMIMOUSEPORT pDrv;
41 /** Is relative mode currently supported? */
42 bool fRel;
43 /** Is absolute mode currently supported? */
44 bool fAbs;
45 /** Is multi-touch mode currently supported? */
46 bool fMT;
47} DRVTSTMOUSE, *PDRVTSTMOUSE;
48
49
50/** Global mouse driver variable.
51 * @todo To be improved some time. */
52static DRVTSTMOUSE s_drvTstMouse;
53
54
55/** @interface_method_impl{PDMUSBHLPR3,pfnVMSetErrorV} */
56static DECLCALLBACK(int) tstVMSetErrorV(PPDMUSBINS pUsbIns, int rc,
57 RT_SRC_POS_DECL, const char *pszFormat,
58 va_list va)
59{
60 NOREF(pUsbIns);
61 RTPrintf("Error: %s:%u:%s:", RT_SRC_POS_ARGS);
62 RTPrintfV(pszFormat, va);
63 return rc;
64}
65
66/** @interface_method_impl{PDMUSBHLPR3,pfnDriverAttach} */
67/** @todo We currently just take the driver interface from the global
68 * variable. This is sufficient for a unit test but still a bit sad. */
69static DECLCALLBACK(int) tstDriverAttach(PPDMUSBINS pUsbIns, RTUINT iLun,
70 PPDMIBASE pBaseInterface,
71 PPDMIBASE *ppBaseInterface,
72 const char *pszDesc)
73{
74 NOREF(iLun);
75 NOREF(pszDesc);
76 s_drvTstMouse.pDrvBase = pBaseInterface;
77 s_drvTstMouse.pDrv = PDMIBASE_QUERY_INTERFACE(pBaseInterface,
78 PDMIMOUSEPORT);
79 *ppBaseInterface = &s_drvTstMouse.IBase;
80 return VINF_SUCCESS;
81}
82
83
84static PDMUSBHLP s_tstUsbHlp;
85
86
87/**
88 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
89 */
90static DECLCALLBACK(void *) tstMouseQueryInterface(PPDMIBASE pInterface,
91 const char *pszIID)
92{
93 PDRVTSTMOUSE pThis = RT_FROM_MEMBER(pInterface, DRVTSTMOUSE, IBase);
94 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThis->IBase);
95 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMOUSECONNECTOR, &pThis->IConnector);
96 return NULL;
97}
98
99
100/**
101 * @interface_method_impl{PDMIMOUSECONNECTOR,pfnReportModes}
102 */
103static DECLCALLBACK(void) tstMouseReportModes(PPDMIMOUSECONNECTOR pInterface,
104 bool fRel, bool fAbs, bool fMT)
105{
106 PDRVTSTMOUSE pDrv = RT_FROM_MEMBER(pInterface, DRVTSTMOUSE, IConnector);
107 pDrv->fRel = fRel;
108 pDrv->fAbs = fAbs;
109 pDrv->fMT = fMT;
110}
111
112
113static int tstMouseConstruct(int iInstance, bool isAbsolute, uint8_t u8CoordShift,
114 PPDMUSBINS *ppThis)
115{
116 int rc = VERR_NO_MEMORY;
117 PPDMUSBINS pThis = (PPDMUSBINS)RTMemAllocZ( sizeof(*pThis)
118 + g_UsbHidMou.cbInstance);
119 PCFGMNODE pCfg = NULL;
120 if (pThis)
121 pCfg = CFGMR3CreateTree(NULL);
122 if (pCfg)
123 rc = CFGMR3InsertInteger(pCfg, "Absolute", isAbsolute);
124 if (RT_SUCCESS(rc))
125 rc = CFGMR3InsertInteger(pCfg, "CoordShift", u8CoordShift);
126 if (RT_SUCCESS(rc))
127 {
128 s_drvTstMouse.pDrv = NULL;
129 s_drvTstMouse.pDrvBase = NULL;
130 pThis->iInstance = iInstance;
131 pThis->pHlpR3 = &s_tstUsbHlp;
132 rc = g_UsbHidMou.pfnConstruct(pThis, iInstance, pCfg, NULL);
133 if (RT_SUCCESS(rc))
134 {
135 *ppThis = pThis;
136 return rc;
137 }
138 }
139 /* Failure */
140 if (pCfg)
141 CFGMR3DestroyTree(pCfg);
142 if (pThis)
143 RTMemFree(pThis);
144 return rc;
145}
146
147
148static void testConstructAndDestruct(RTTEST hTest)
149{
150 PPDMUSBINS pThis;
151 RTTestSub(hTest, "simple construction and destruction");
152 int rc = tstMouseConstruct(0, false, 1, &pThis);
153 RTTEST_CHECK_RC_OK(hTest, rc);
154 if (pThis)
155 g_UsbHidMou.pfnDestruct(pThis);
156}
157
158
159static void testSendPosition(RTTEST hTest)
160{
161 PPDMUSBINS pThis = NULL;
162 VUSBURB Urb = { 0 };
163 RTTestSub(hTest, "sending a position event");
164 int rc = tstMouseConstruct(0, true, 1, &pThis);
165 if (RT_SUCCESS(rc))
166 {
167 rc = g_UsbHidMou.pfnUsbReset(pThis, false);
168 }
169 if (RT_SUCCESS(rc))
170 {
171 if (s_drvTstMouse.pDrv)
172 s_drvTstMouse.pDrv->pfnPutEventAbs(s_drvTstMouse.pDrv, 300, 200, 1,
173 0, 3);
174 else
175 rc = VERR_PDM_MISSING_INTERFACE;
176 }
177 if (RT_SUCCESS(rc))
178 {
179 Urb.EndPt = 0x01;
180 rc = g_UsbHidMou.pfnUrbQueue(pThis, &Urb);
181 }
182 if (RT_SUCCESS(rc))
183 {
184 PVUSBURB pUrb = g_UsbHidMou.pfnUrbReap(pThis, 0);
185 if (pUrb)
186 {
187 if (pUrb == &Urb)
188 {
189 if ( Urb.abData[0] != 1 /* Report ID */
190 || Urb.abData[1] != 3 /* Buttons */
191 || (int8_t)Urb.abData[2] != -1 /* Wheel, inverted */
192 || *(uint16_t *)&Urb.abData[4] != 150 /* x >> 1 */
193 || *(uint16_t *)&Urb.abData[6] != 100 /* y >> 1 */)
194 rc = VERR_GENERAL_FAILURE;
195 }
196 else
197 rc = VERR_GENERAL_FAILURE;
198 }
199 else
200 rc = VERR_GENERAL_FAILURE;
201 }
202 RTTEST_CHECK_RC_OK(hTest, rc);
203 if (pThis)
204 g_UsbHidMou.pfnDestruct(pThis);
205}
206
207
208int main()
209{
210 /*
211 * Init the runtime, test and say hello.
212 */
213 RTTEST hTest;
214 PDRVTSTMOUSE pThis;
215 int rc = RTTestInitAndCreate("tstUsbMouse", &hTest);
216 if (rc)
217 return rc;
218 RTTestBanner(hTest);
219 /* Set up our faked PDMUSBHLP interface. */
220 s_tstUsbHlp.pfnVMSetErrorV = tstVMSetErrorV;
221 s_tstUsbHlp.pfnDriverAttach = tstDriverAttach;
222 /* Set up our global mouse driver */
223 s_drvTstMouse.IBase.pfnQueryInterface = tstMouseQueryInterface;
224 s_drvTstMouse.IConnector.pfnReportModes = tstMouseReportModes;
225
226 /*
227 * Run the tests.
228 */
229 testConstructAndDestruct(hTest);
230 testSendPosition(hTest);
231 return RTTestSummaryAndDestroy(hTest);
232}
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