1 | /* $Id: tstClipboardServiceHost.cpp 78155 2019-04-17 13:06:05Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Shared Clipboard host service test case.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2019 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 | #include "../VBoxClipboard.h"
|
---|
19 |
|
---|
20 | #include <VBox/HostServices/VBoxClipboardSvc.h>
|
---|
21 |
|
---|
22 | #include <iprt/assert.h>
|
---|
23 | #include <iprt/string.h>
|
---|
24 | #include <iprt/test.h>
|
---|
25 |
|
---|
26 | extern "C" DECLCALLBACK(DECLEXPORT(int)) VBoxHGCMSvcLoad (VBOXHGCMSVCFNTABLE *ptable);
|
---|
27 |
|
---|
28 | static VBOXCLIPBOARDCLIENTDATA g_Client;
|
---|
29 | static VBOXHGCMSVCHELPERS g_Helpers = { NULL };
|
---|
30 |
|
---|
31 | /** Simple call handle structure for the guest call completion callback */
|
---|
32 | struct VBOXHGCMCALLHANDLE_TYPEDEF
|
---|
33 | {
|
---|
34 | /** Where to store the result code */
|
---|
35 | int32_t rc;
|
---|
36 | };
|
---|
37 |
|
---|
38 | /** Call completion callback for guest calls. */
|
---|
39 | static DECLCALLBACK(int) callComplete(VBOXHGCMCALLHANDLE callHandle, int32_t rc)
|
---|
40 | {
|
---|
41 | callHandle->rc = rc;
|
---|
42 | return VINF_SUCCESS;
|
---|
43 | }
|
---|
44 |
|
---|
45 | static int setupTable(VBOXHGCMSVCFNTABLE *pTable)
|
---|
46 | {
|
---|
47 | pTable->cbSize = sizeof(*pTable);
|
---|
48 | pTable->u32Version = VBOX_HGCM_SVC_VERSION;
|
---|
49 | g_Helpers.pfnCallComplete = callComplete;
|
---|
50 | pTable->pHelpers = &g_Helpers;
|
---|
51 | return VBoxHGCMSvcLoad(pTable);
|
---|
52 | }
|
---|
53 |
|
---|
54 | static void testSetMode(void)
|
---|
55 | {
|
---|
56 | struct VBOXHGCMSVCPARM parms[2];
|
---|
57 | VBOXHGCMSVCFNTABLE table;
|
---|
58 | uint32_t u32Mode;
|
---|
59 | int rc;
|
---|
60 |
|
---|
61 | RTTestISub("Testing HOST_FN_SET_MODE");
|
---|
62 | rc = setupTable(&table);
|
---|
63 | RTTESTI_CHECK_MSG_RETV(RT_SUCCESS(rc), ("rc=%Rrc\n", rc));
|
---|
64 | /* Reset global variable which doesn't reset itself. */
|
---|
65 | HGCMSvcSetU32(&parms[0], VBOX_SHARED_CLIPBOARD_MODE_OFF);
|
---|
66 | rc = table.pfnHostCall(NULL, VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE,
|
---|
67 | 1, parms);
|
---|
68 | RTTESTI_CHECK_RC_OK(rc);
|
---|
69 | u32Mode = TestClipSvcGetMode();
|
---|
70 | RTTESTI_CHECK_MSG(u32Mode == VBOX_SHARED_CLIPBOARD_MODE_OFF,
|
---|
71 | ("u32Mode=%u\n", (unsigned) u32Mode));
|
---|
72 | rc = table.pfnHostCall(NULL, VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE,
|
---|
73 | 0, parms);
|
---|
74 | RTTESTI_CHECK_RC(rc, VERR_INVALID_PARAMETER);
|
---|
75 | rc = table.pfnHostCall(NULL, VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE,
|
---|
76 | 2, parms);
|
---|
77 | RTTESTI_CHECK_RC(rc, VERR_INVALID_PARAMETER);
|
---|
78 | HGCMSvcSetU64(&parms[0], 99);
|
---|
79 | rc = table.pfnHostCall(NULL, VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE,
|
---|
80 | 1, parms);
|
---|
81 | RTTESTI_CHECK_RC(rc, VERR_INVALID_PARAMETER);
|
---|
82 | HGCMSvcSetU32(&parms[0], VBOX_SHARED_CLIPBOARD_MODE_HOST_TO_GUEST);
|
---|
83 | rc = table.pfnHostCall(NULL, VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE,
|
---|
84 | 1, parms);
|
---|
85 | RTTESTI_CHECK_RC_OK(rc);
|
---|
86 | u32Mode = TestClipSvcGetMode();
|
---|
87 | RTTESTI_CHECK_MSG(u32Mode == VBOX_SHARED_CLIPBOARD_MODE_HOST_TO_GUEST,
|
---|
88 | ("u32Mode=%u\n", (unsigned) u32Mode));
|
---|
89 | HGCMSvcSetU32(&parms[0], 99);
|
---|
90 | rc = table.pfnHostCall(NULL, VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE,
|
---|
91 | 1, parms);
|
---|
92 | RTTESTI_CHECK_RC_OK(rc);
|
---|
93 | u32Mode = TestClipSvcGetMode();
|
---|
94 | RTTESTI_CHECK_MSG(u32Mode == VBOX_SHARED_CLIPBOARD_MODE_OFF,
|
---|
95 | ("u32Mode=%u\n", (unsigned) u32Mode));
|
---|
96 | table.pfnUnload(NULL);
|
---|
97 | }
|
---|
98 |
|
---|
99 | static void testGetHostMsg(void)
|
---|
100 | {
|
---|
101 | struct VBOXHGCMSVCPARM parms[2];
|
---|
102 | VBOXHGCMSVCFNTABLE table;
|
---|
103 | VBOXHGCMCALLHANDLE_TYPEDEF call;
|
---|
104 | int rc;
|
---|
105 |
|
---|
106 | RTTestISub("Setting up VBOX_SHARED_CLIPBOARD_FN_GET_HOST_MSG test");
|
---|
107 | rc = setupTable(&table);
|
---|
108 | RTTESTI_CHECK_MSG_RETV(RT_SUCCESS(rc), ("rc=%Rrc\n", rc));
|
---|
109 | /* Unless we are bidirectional the host message requests will be dropped. */
|
---|
110 | HGCMSvcSetU32(&parms[0], VBOX_SHARED_CLIPBOARD_MODE_BIDIRECTIONAL);
|
---|
111 | rc = table.pfnHostCall(NULL, VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE,
|
---|
112 | 1, parms);
|
---|
113 | RTTESTI_CHECK_RC_OK(rc);
|
---|
114 |
|
---|
115 | RTTestISub("Testing FN_GET_HOST_MSG, one format, waiting guest call.");
|
---|
116 | RT_ZERO(g_Client);
|
---|
117 | HGCMSvcSetU32(&parms[0], 0);
|
---|
118 | HGCMSvcSetU32(&parms[1], 0);
|
---|
119 | call.rc = VERR_TRY_AGAIN;
|
---|
120 | table.pfnCall(NULL, &call, 1 /* clientId */, &g_Client, VBOX_SHARED_CLIPBOARD_FN_GET_HOST_MSG,
|
---|
121 | 2, parms, 0);
|
---|
122 | RTTESTI_CHECK_RC(call.rc, VERR_TRY_AGAIN); /* This should get updated only when the guest call completes. */
|
---|
123 | vboxSvcClipboardReportMsg (&g_Client, VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA,
|
---|
124 | VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT);
|
---|
125 | RTTESTI_CHECK(parms[0].u.uint32 == VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA);
|
---|
126 | RTTESTI_CHECK(parms[1].u.uint32 == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT);
|
---|
127 | RTTESTI_CHECK_RC_OK(call.rc);
|
---|
128 | call.rc = VERR_TRY_AGAIN;
|
---|
129 | table.pfnCall(NULL, &call, 1 /* clientId */, &g_Client, VBOX_SHARED_CLIPBOARD_FN_GET_HOST_MSG,
|
---|
130 | 2, parms, 0);
|
---|
131 | RTTESTI_CHECK_RC(call.rc, VERR_TRY_AGAIN); /* This call should not complete yet. */
|
---|
132 |
|
---|
133 | RTTestISub("Testing FN_GET_HOST_MSG, one format, no waiting guest calls.");
|
---|
134 | RT_ZERO(g_Client);
|
---|
135 | vboxSvcClipboardReportMsg (&g_Client, VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA,
|
---|
136 | VBOX_SHARED_CLIPBOARD_FMT_HTML);
|
---|
137 | HGCMSvcSetU32(&parms[0], 0);
|
---|
138 | HGCMSvcSetU32(&parms[1], 0);
|
---|
139 | call.rc = VERR_TRY_AGAIN;
|
---|
140 | table.pfnCall(NULL, &call, 1 /* clientId */, &g_Client, VBOX_SHARED_CLIPBOARD_FN_GET_HOST_MSG,
|
---|
141 | 2, parms, 0);
|
---|
142 | RTTESTI_CHECK(parms[0].u.uint32 == VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA);
|
---|
143 | RTTESTI_CHECK(parms[1].u.uint32 == VBOX_SHARED_CLIPBOARD_FMT_HTML);
|
---|
144 | RTTESTI_CHECK_RC_OK(call.rc);
|
---|
145 | call.rc = VERR_TRY_AGAIN;
|
---|
146 | table.pfnCall(NULL, &call, 1 /* clientId */, &g_Client, VBOX_SHARED_CLIPBOARD_FN_GET_HOST_MSG,
|
---|
147 | 2, parms, 0);
|
---|
148 | RTTESTI_CHECK_RC(call.rc, VERR_TRY_AGAIN); /* This call should not complete yet. */
|
---|
149 |
|
---|
150 | RTTestISub("Testing FN_GET_HOST_MSG, two formats, waiting guest call.");
|
---|
151 | RT_ZERO(g_Client);
|
---|
152 | HGCMSvcSetU32(&parms[0], 0);
|
---|
153 | HGCMSvcSetU32(&parms[1], 0);
|
---|
154 | call.rc = VERR_TRY_AGAIN;
|
---|
155 | table.pfnCall(NULL, &call, 1 /* clientId */, &g_Client, VBOX_SHARED_CLIPBOARD_FN_GET_HOST_MSG,
|
---|
156 | 2, parms, 0);
|
---|
157 | RTTESTI_CHECK_RC(call.rc, VERR_TRY_AGAIN); /* This should get updated only when the guest call completes. */
|
---|
158 | vboxSvcClipboardReportMsg (&g_Client, VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA,
|
---|
159 | VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT | VBOX_SHARED_CLIPBOARD_FMT_HTML);
|
---|
160 | RTTESTI_CHECK(parms[0].u.uint32 == VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA);
|
---|
161 | RTTESTI_CHECK(parms[1].u.uint32 == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT);
|
---|
162 | RTTESTI_CHECK_RC_OK(call.rc);
|
---|
163 | call.rc = VERR_TRY_AGAIN;
|
---|
164 | table.pfnCall(NULL, &call, 1 /* clientId */, &g_Client, VBOX_SHARED_CLIPBOARD_FN_GET_HOST_MSG,
|
---|
165 | 2, parms, 0);
|
---|
166 | RTTESTI_CHECK(parms[0].u.uint32 == VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA);
|
---|
167 | RTTESTI_CHECK(parms[1].u.uint32 == VBOX_SHARED_CLIPBOARD_FMT_HTML);
|
---|
168 | RTTESTI_CHECK_RC_OK(call.rc);
|
---|
169 | call.rc = VERR_TRY_AGAIN;
|
---|
170 | table.pfnCall(NULL, &call, 1 /* clientId */, &g_Client, VBOX_SHARED_CLIPBOARD_FN_GET_HOST_MSG,
|
---|
171 | 2, parms, 0);
|
---|
172 | RTTESTI_CHECK_RC(call.rc, VERR_TRY_AGAIN); /* This call should not complete yet. */
|
---|
173 |
|
---|
174 | RTTestISub("Testing FN_GET_HOST_MSG, two formats, no waiting guest calls.");
|
---|
175 | RT_ZERO(g_Client);
|
---|
176 | vboxSvcClipboardReportMsg (&g_Client, VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA,
|
---|
177 | VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT | VBOX_SHARED_CLIPBOARD_FMT_HTML);
|
---|
178 | HGCMSvcSetU32(&parms[0], 0);
|
---|
179 | HGCMSvcSetU32(&parms[1], 0);
|
---|
180 | call.rc = VERR_TRY_AGAIN;
|
---|
181 | table.pfnCall(NULL, &call, 1 /* clientId */, &g_Client, VBOX_SHARED_CLIPBOARD_FN_GET_HOST_MSG,
|
---|
182 | 2, parms, 0);
|
---|
183 | RTTESTI_CHECK(parms[0].u.uint32 == VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA);
|
---|
184 | RTTESTI_CHECK(parms[1].u.uint32 == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT);
|
---|
185 | RTTESTI_CHECK_RC_OK(call.rc);
|
---|
186 | call.rc = VERR_TRY_AGAIN;
|
---|
187 | table.pfnCall(NULL, &call, 1 /* clientId */, &g_Client, VBOX_SHARED_CLIPBOARD_FN_GET_HOST_MSG,
|
---|
188 | 2, parms, 0);
|
---|
189 | RTTESTI_CHECK(parms[0].u.uint32 == VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA);
|
---|
190 | RTTESTI_CHECK(parms[1].u.uint32 == VBOX_SHARED_CLIPBOARD_FMT_HTML);
|
---|
191 | RTTESTI_CHECK_RC_OK(call.rc);
|
---|
192 | call.rc = VERR_TRY_AGAIN;
|
---|
193 | table.pfnCall(NULL, &call, 1 /* clientId */, &g_Client, VBOX_SHARED_CLIPBOARD_FN_GET_HOST_MSG,
|
---|
194 | 2, parms, 0);
|
---|
195 | RTTESTI_CHECK_RC(call.rc, VERR_TRY_AGAIN); /* This call should not complete yet. */
|
---|
196 | table.pfnUnload(NULL);
|
---|
197 | }
|
---|
198 |
|
---|
199 | static void testSetHeadless(void)
|
---|
200 | {
|
---|
201 | struct VBOXHGCMSVCPARM parms[2];
|
---|
202 | VBOXHGCMSVCFNTABLE table;
|
---|
203 | bool fHeadless;
|
---|
204 | int rc;
|
---|
205 |
|
---|
206 | RTTestISub("Testing HOST_FN_SET_HEADLESS");
|
---|
207 | rc = setupTable(&table);
|
---|
208 | RTTESTI_CHECK_MSG_RETV(RT_SUCCESS(rc), ("rc=%Rrc\n", rc));
|
---|
209 | /* Reset global variable which doesn't reset itself. */
|
---|
210 | HGCMSvcSetU32(&parms[0], false);
|
---|
211 | rc = table.pfnHostCall(NULL, VBOX_SHARED_CLIPBOARD_HOST_FN_SET_HEADLESS,
|
---|
212 | 1, parms);
|
---|
213 | RTTESTI_CHECK_RC_OK(rc);
|
---|
214 | fHeadless = VBoxSvcClipboardGetHeadless();
|
---|
215 | RTTESTI_CHECK_MSG(fHeadless == false, ("fHeadless=%RTbool\n", fHeadless));
|
---|
216 | rc = table.pfnHostCall(NULL, VBOX_SHARED_CLIPBOARD_HOST_FN_SET_HEADLESS,
|
---|
217 | 0, parms);
|
---|
218 | RTTESTI_CHECK_RC(rc, VERR_INVALID_PARAMETER);
|
---|
219 | rc = table.pfnHostCall(NULL, VBOX_SHARED_CLIPBOARD_HOST_FN_SET_HEADLESS,
|
---|
220 | 2, parms);
|
---|
221 | RTTESTI_CHECK_RC(rc, VERR_INVALID_PARAMETER);
|
---|
222 | HGCMSvcSetU64(&parms[0], 99);
|
---|
223 | rc = table.pfnHostCall(NULL, VBOX_SHARED_CLIPBOARD_HOST_FN_SET_HEADLESS,
|
---|
224 | 1, parms);
|
---|
225 | RTTESTI_CHECK_RC(rc, VERR_INVALID_PARAMETER);
|
---|
226 | HGCMSvcSetU32(&parms[0], true);
|
---|
227 | rc = table.pfnHostCall(NULL, VBOX_SHARED_CLIPBOARD_HOST_FN_SET_HEADLESS,
|
---|
228 | 1, parms);
|
---|
229 | RTTESTI_CHECK_RC_OK(rc);
|
---|
230 | fHeadless = VBoxSvcClipboardGetHeadless();
|
---|
231 | RTTESTI_CHECK_MSG(fHeadless == true, ("fHeadless=%RTbool\n", fHeadless));
|
---|
232 | HGCMSvcSetU32(&parms[0], 99);
|
---|
233 | rc = table.pfnHostCall(NULL, VBOX_SHARED_CLIPBOARD_HOST_FN_SET_HEADLESS,
|
---|
234 | 1, parms);
|
---|
235 | RTTESTI_CHECK_RC_OK(rc);
|
---|
236 | fHeadless = VBoxSvcClipboardGetHeadless();
|
---|
237 | RTTESTI_CHECK_MSG(fHeadless == true, ("fHeadless=%RTbool\n", fHeadless));
|
---|
238 | table.pfnUnload(NULL);
|
---|
239 | }
|
---|
240 |
|
---|
241 | static void testHostCall(void)
|
---|
242 | {
|
---|
243 | testSetMode();
|
---|
244 | testSetHeadless();
|
---|
245 | }
|
---|
246 |
|
---|
247 |
|
---|
248 | int main(int argc, char *argv[])
|
---|
249 | {
|
---|
250 | /*
|
---|
251 | * Init the runtime, test and say hello.
|
---|
252 | */
|
---|
253 | const char *pcszExecName;
|
---|
254 | NOREF(argc);
|
---|
255 | pcszExecName = strrchr(argv[0], '/');
|
---|
256 | pcszExecName = pcszExecName ? pcszExecName + 1 : argv[0];
|
---|
257 | RTTEST hTest;
|
---|
258 | RTEXITCODE rcExit = RTTestInitAndCreate(pcszExecName, &hTest);
|
---|
259 | if (rcExit != RTEXITCODE_SUCCESS)
|
---|
260 | return rcExit;
|
---|
261 | RTTestBanner(hTest);
|
---|
262 |
|
---|
263 | /*
|
---|
264 | * Run the tests.
|
---|
265 | */
|
---|
266 | testHostCall();
|
---|
267 | testGetHostMsg();
|
---|
268 |
|
---|
269 | /*
|
---|
270 | * Summary
|
---|
271 | */
|
---|
272 | return RTTestSummaryAndDestroy(hTest);
|
---|
273 | }
|
---|
274 |
|
---|
275 | int vboxClipboardInit() { return VINF_SUCCESS; }
|
---|
276 | void vboxClipboardDestroy() {}
|
---|
277 | void vboxClipboardDisconnect(_VBOXCLIPBOARDCLIENTDATA*) { AssertFailed(); }
|
---|
278 | int vboxClipboardConnect(_VBOXCLIPBOARDCLIENTDATA*, bool)
|
---|
279 | { AssertFailed(); return VERR_WRONG_ORDER; }
|
---|
280 | void vboxClipboardFormatAnnounce(_VBOXCLIPBOARDCLIENTDATA*, unsigned int)
|
---|
281 | { AssertFailed(); }
|
---|
282 | int vboxClipboardReadData(_VBOXCLIPBOARDCLIENTDATA*, unsigned int, void*, unsigned int, unsigned int*)
|
---|
283 | { AssertFailed(); return VERR_WRONG_ORDER; }
|
---|
284 | void vboxClipboardWriteData(_VBOXCLIPBOARDCLIENTDATA*, void*, unsigned int, unsigned int) { AssertFailed(); }
|
---|
285 | int vboxClipboardSync(_VBOXCLIPBOARDCLIENTDATA*)
|
---|
286 | { AssertFailed(); return VERR_WRONG_ORDER; }
|
---|