VirtualBox

source: vbox/trunk/src/VBox/HostServices/GuestControl/testcase/tstGuestControlMockHGCM.cpp@ 99040

Last change on this file since 99040 was 98578, checked in by vboxsync, 21 months ago

HGCMMock*.h: Moved to HostServices as it chiefly tests the HGCM services, not so much shared guest/host code is the previous location would indicate.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.9 KB
Line 
1/* $Id: tstGuestControlMockHGCM.cpp 98578 2023-02-15 02:00:05Z vboxsync $ */
2/** @file
3 * Guest Control host service test case.
4 */
5
6/*
7 * Copyright (C) 2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#include <VBox/HostServices/GuestControlSvc.h>
33#include <VBox/VBoxGuestLib.h>
34
35#include <VBox/HostServices/TstHGCMMock.h>
36#include <VBox/HostServices/TstHGCMMockUtils.h>
37
38#include <iprt/assert.h>
39#include <iprt/initterm.h>
40#include <iprt/mem.h>
41#include <iprt/rand.h>
42#include <iprt/stream.h>
43#include <iprt/string.h>
44#include <iprt/test.h>
45#include <iprt/utf16.h>
46
47
48/*********************************************************************************************************************************
49* Static globals *
50*********************************************************************************************************************************/
51static RTTEST g_hTest;
52
53
54/*********************************************************************************************************************************
55* Shared Clipboard testing *
56*********************************************************************************************************************************/
57/** @todo r=bird: Clipboard? */
58
59struct CLIPBOARDTESTDESC;
60/** Pointer to a test description. */
61typedef CLIPBOARDTESTDESC *PTESTDESC;
62
63struct CLIPBOARDTESTCTX;
64/** Pointer to a test context. */
65typedef CLIPBOARDTESTCTX *PCLIPBOARDTESTCTX;
66
67/** Pointer a test descriptor. */
68typedef CLIPBOARDTESTDESC *PTESTDESC;
69
70typedef DECLCALLBACKTYPE(int, FNTESTSETUP,(PCLIPBOARDTESTCTX pTstCtx, void **ppvCtx));
71/** Pointer to a test setup callback. */
72typedef FNTESTSETUP *PFNTESTSETUP;
73
74typedef DECLCALLBACKTYPE(int, FNTESTEXEC,(PCLIPBOARDTESTCTX pTstCtx, void *pvCtx));
75/** Pointer to a test exec callback. */
76typedef FNTESTEXEC *PFNTESTEXEC;
77
78typedef DECLCALLBACKTYPE(int, FNTESTDESTROY,(PCLIPBOARDTESTCTX pTstCtx, void *pvCtx));
79/** Pointer to a test destroy callback. */
80typedef FNTESTDESTROY *PFNTESTDESTROY;
81
82
83/**
84 * Structure for keeping a clipboard test task.
85 */
86typedef struct CLIPBOARDTESTTASK
87{
88
89} CLIPBOARDTESTTASK;
90typedef CLIPBOARDTESTTASK *PCLIPBOARDTESTTASK;
91
92/**
93 * Structure for keeping a clipboard test context.
94 */
95typedef struct CLIPBOARDTESTCTX
96{
97 /** The HGCM Mock utils context. */
98 TSTHGCMUTILSCTX HGCM;
99 /** Clipboard-specific task data. */
100 CLIPBOARDTESTTASK Task;
101 struct
102 {
103 /** The VbglR3 Guest Control context to work on. */
104 VBGLR3GUESTCTRLCMDCTX CmdCtx;
105 } Guest;
106} CLIPBOARDTESTCTX;
107
108/** The one and only clipboard test context. One at a time. */
109CLIPBOARDTESTCTX g_TstCtx;
110
111#if 0 /** @todo r=bird: Clipboard? This times out and asserts and doesn't seems to do anything sensible. */
112
113/**
114 * Structure for keeping a clipboard test description.
115 */
116typedef struct CLIPBOARDTESTDESC
117{
118 /** The setup callback. */
119 PFNTESTSETUP pfnSetup;
120 /** The exec callback. */
121 PFNTESTEXEC pfnExec;
122 /** The destruction callback. */
123 PFNTESTDESTROY pfnDestroy;
124} CLIPBOARDTESTDESC;
125
126typedef struct SHCLCONTEXT
127{
128} SHCLCONTEXT;
129
130#endif
131
132
133static void testGuestSimple(void)
134{
135 RTTestISub("Testing client (guest) API - Simple");
136
137 PTSTHGCMMOCKSVC pSvc = TstHgcmMockSvcInst(); RT_NOREF(pSvc);
138
139 /* Preparations. */
140 VBGLR3GUESTCTRLCMDCTX Ctx;
141 RT_ZERO(Ctx);
142
143 /*
144 * Multiple connects / disconnects.
145 */
146 RTTESTI_CHECK_RC_OK(VbglR3GuestCtrlConnect(&Ctx.uClientID));
147 RTTESTI_CHECK_RC_OK(VbglR3GuestCtrlDisconnect(Ctx.uClientID));
148
149 /*
150 * Feature tests.
151 */
152 RTTESTI_CHECK_RC_OK(VbglR3GuestCtrlConnect(&Ctx.uClientID));
153 RTTESTI_CHECK_RC_OK(VbglR3GuestCtrlReportFeatures(Ctx.uClientID, 0x0, NULL /* pfHostFeatures */));
154 /* Report bogus features to the host. */
155 RTTESTI_CHECK_RC_OK(VbglR3GuestCtrlReportFeatures(Ctx.uClientID, 0xdeadb33f, NULL /* pfHostFeatures */));
156 RTTESTI_CHECK_RC_OK(VbglR3GuestCtrlDisconnect(Ctx.uClientID));
157}
158
159static void testHostCall(void)
160{
161}
162
163
164/*********************************************************************************************************************************
165 * Test: Guest reading from host *
166 ********************************************************************************************************************************/
167/** @todo r=bird: Reading from the host? WTF? Doesn't seem to work, so I've disabled it till it can be rewritten and
168 * made to do something useful rather than asserting. */
169#if 0
170typedef struct TSTUSERMOCK
171{
172} TSTUSERMOCK;
173typedef TSTUSERMOCK *PTSTUSERMOCK;
174
175static void tstTestReadFromHost_MockInit(PTSTUSERMOCK pUsrMock, const char *pszName)
176{
177 RT_NOREF(pUsrMock, pszName);
178}
179
180static void tstTestReadFromHost_MockDestroy(PTSTUSERMOCK pUsrMock)
181{
182 RT_NOREF(pUsrMock);
183}
184
185static DECLCALLBACK(int) tstTestReadFromHost_ThreadGuest(PTSTHGCMUTILSCTX pCtx, void *pvCtx)
186{
187 RTThreadSleep(1000); /* Fudge; wait until the host has prepared the data for the clipboard. */
188
189 PCLIPBOARDTESTCTX pTstCtx = (PCLIPBOARDTESTCTX)pvCtx;
190 AssertPtr(pTstCtx);
191
192 RT_ZERO(pTstCtx->Guest.CmdCtx);
193 RTTEST_CHECK_RC_OK(g_hTest, VbglR3GuestCtrlConnect(&pTstCtx->Guest.CmdCtx.uClientID));
194
195 RTThreadSleep(1000); /* Fudge; wait until the host has prepared the data for the clipboard. */
196
197 /* Signal that the task ended. */
198 TstHGCMUtilsTaskSignal(&pCtx->Task, VINF_SUCCESS);
199
200 RTTEST_CHECK_RC_OK(g_hTest, VbglR3GuestCtrlDisconnect(pTstCtx->Guest.CmdCtx.uClientID));
201
202 return VINF_SUCCESS;
203}
204
205static DECLCALLBACK(int) tstTestReadFromHostSetup(PCLIPBOARDTESTCTX pTstCtx, void **ppvCtx)
206{
207 RT_NOREF(pTstCtx, ppvCtx);
208 return VINF_SUCCESS;
209}
210
211static DECLCALLBACK(int) tstTestReadFromHostExec(PCLIPBOARDTESTCTX pTstCtx, void *pvCtx)
212{
213 RT_NOREF(pvCtx);
214
215 TstHGCMUtilsGuestThreadStart(&pTstCtx->HGCM, tstTestReadFromHost_ThreadGuest, pTstCtx);
216
217 PTSTHGCMUTILSTASK pTask = (PTSTHGCMUTILSTASK)TstHGCMUtilsTaskGetCurrent(&pTstCtx->HGCM);
218
219 bool fUseMock = false;
220 TSTUSERMOCK UsrMock;
221 if (fUseMock)
222 tstTestReadFromHost_MockInit(&UsrMock, "tstX11Hst");
223
224 /* Wait until the task has been finished. */
225 TstHGCMUtilsTaskWait(pTask, RT_MS_30SEC);
226
227 if (fUseMock)
228 tstTestReadFromHost_MockDestroy(&UsrMock);
229
230 return VINF_SUCCESS;
231}
232
233static DECLCALLBACK(int) tstTestReadFromHostDestroy(PCLIPBOARDTESTCTX pTstCtx, void *pvCtx)
234{
235 RT_NOREF(pvCtx);
236
237 int vrc = TstHGCMUtilsGuestThreadStop(&pTstCtx->HGCM);
238 AssertRC(vrc);
239 vrc = TstHGCMUtilsHostThreadStop(&pTstCtx->HGCM);
240 AssertRC(vrc);
241
242 return vrc;
243}
244
245#endif
246
247
248/*********************************************************************************************************************************
249 * Main *
250 ********************************************************************************************************************************/
251#if 0 /** @todo r=bird: Same as above. */
252
253/** Test definition table. */
254CLIPBOARDTESTDESC g_aTests[] =
255{
256 /* Tests guest reading clipboard data from the host. */
257 { tstTestReadFromHostSetup, tstTestReadFromHostExec, tstTestReadFromHostDestroy }
258};
259/** Number of tests defined. */
260unsigned g_cTests = RT_ELEMENTS(g_aTests);
261
262static int tstOne(PTESTDESC pTstDesc)
263{
264 PCLIPBOARDTESTCTX pTstCtx = &g_TstCtx;
265
266 void *pvCtx;
267 int rc = pTstDesc->pfnSetup(pTstCtx, &pvCtx);
268 if (RT_SUCCESS(rc))
269 {
270 rc = pTstDesc->pfnExec(pTstCtx, pvCtx);
271
272 int rc2 = pTstDesc->pfnDestroy(pTstCtx, pvCtx);
273 if (RT_SUCCESS(rc))
274 rc = rc2;
275 }
276
277 return rc;
278}
279
280#endif
281
282int main()
283{
284 /*
285 * Init the runtime, test and say hello.
286 */
287 RTEXITCODE rcExit = RTTestInitAndCreate("tstGuestControlMockHGCM", &g_hTest);
288 if (rcExit != RTEXITCODE_SUCCESS)
289 return rcExit;
290 RTTestBanner(g_hTest);
291
292 PTSTHGCMMOCKSVC const pSvc = TstHgcmMockSvcInst();
293 TstHgcmMockSvcCreate(pSvc);
294 TstHgcmMockSvcStart(pSvc);
295
296 /*
297 * Run the tests.
298 */
299 if (1)
300 {
301 testGuestSimple();
302 testHostCall();
303 }
304
305#if 0 /** @todo r=bird: Clipboard? This times out and asserts and doesn't seems to do anything sensible. */
306 RT_ZERO(g_TstCtx);
307
308 PTSTHGCMUTILSCTX pCtx = &g_TstCtx.HGCM;
309 TstHGCMUtilsCtxInit(pCtx, pSvc);
310
311 PTSTHGCMUTILSTASK pTask = (PTSTHGCMUTILSTASK)TstHGCMUtilsTaskGetCurrent(pCtx);
312 TstHGCMUtilsTaskInit(pTask);
313 pTask->pvUser = &g_TstCtx.Task;
314
315 for (unsigned i = 0; i < RT_ELEMENTS(g_aTests); i++)
316 tstOne(&g_aTests[i]);
317
318 TstHGCMUtilsTaskDestroy(pTask);
319#endif
320
321 TstHgcmMockSvcStop(pSvc);
322 TstHgcmMockSvcDestroy(pSvc);
323
324 /*
325 * Summary
326 */
327 return RTTestSummaryAndDestroy(g_hTest);
328}
329
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