1 | /* $Id: tstClipboardServiceImpl.cpp 90238 2021-07-19 13:48:09Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Shared Clipboard host service implementation (backend) test case.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2020 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 "../VBoxSharedClipboardSvc-internal.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 SHCLCLIENT 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 | int ShClBackendInit(VBOXHGCMSVCFNTABLE *) { return VINF_SUCCESS; }
|
---|
55 | void ShClBackendDestroy(void) { }
|
---|
56 | int ShClBackendDisconnect(PSHCLCLIENT) { return VINF_SUCCESS; }
|
---|
57 | int ShClBackendConnect(PSHCLCLIENT, bool) { return VINF_SUCCESS; }
|
---|
58 | int ShClBackendFormatAnnounce(PSHCLCLIENT, SHCLFORMATS) { AssertFailed(); return VINF_SUCCESS; }
|
---|
59 | int ShClBackendReadData(PSHCLCLIENT, PSHCLCLIENTCMDCTX, SHCLFORMAT, void *, uint32_t, unsigned int *) { AssertFailed(); return VERR_WRONG_ORDER; }
|
---|
60 | int ShClBackendWriteData(PSHCLCLIENT, PSHCLCLIENTCMDCTX, SHCLFORMAT, void *, uint32_t) { AssertFailed(); return VINF_SUCCESS; }
|
---|
61 | int ShClBackendSync(PSHCLCLIENT) { return VINF_SUCCESS; }
|
---|
62 |
|
---|
63 | static void testAnnounceAndReadData(void)
|
---|
64 | {
|
---|
65 | struct VBOXHGCMSVCPARM parms[2];
|
---|
66 | VBOXHGCMSVCFNTABLE table;
|
---|
67 | int rc;
|
---|
68 |
|
---|
69 | RTTestISub("Setting up client ...");
|
---|
70 | rc = setupTable(&table);
|
---|
71 | RTTESTI_CHECK_MSG_RETV(RT_SUCCESS(rc), ("rc=%Rrc\n", rc));
|
---|
72 | /* Unless we are bidirectional the host message requests will be dropped. */
|
---|
73 | HGCMSvcSetU32(&parms[0], VBOX_SHCL_MODE_BIDIRECTIONAL);
|
---|
74 | rc = table.pfnHostCall(NULL, VBOX_SHCL_HOST_FN_SET_MODE, 1, parms);
|
---|
75 | RTTESTI_CHECK_RC_OK(rc);
|
---|
76 | rc = shClSvcClientInit(&g_Client, 1 /* clientId */);
|
---|
77 | RTTESTI_CHECK_RC_OK(rc);
|
---|
78 | }
|
---|
79 |
|
---|
80 | int main(int argc, char *argv[])
|
---|
81 | {
|
---|
82 | /*
|
---|
83 | * Init the runtime, test and say hello.
|
---|
84 | */
|
---|
85 | const char *pcszExecName;
|
---|
86 | NOREF(argc);
|
---|
87 | pcszExecName = strrchr(argv[0], '/');
|
---|
88 | pcszExecName = pcszExecName ? pcszExecName + 1 : argv[0];
|
---|
89 | RTTEST hTest;
|
---|
90 | RTEXITCODE rcExit = RTTestInitAndCreate(pcszExecName, &hTest);
|
---|
91 | if (rcExit != RTEXITCODE_SUCCESS)
|
---|
92 | return rcExit;
|
---|
93 | RTTestBanner(hTest);
|
---|
94 |
|
---|
95 | /* Don't let assertions in the host service panic (core dump) the test cases. */
|
---|
96 | RTAssertSetMayPanic(false);
|
---|
97 |
|
---|
98 | /*
|
---|
99 | * Run the tests.
|
---|
100 | */
|
---|
101 | testAnnounceAndReadData();
|
---|
102 |
|
---|
103 | /*
|
---|
104 | * Summary
|
---|
105 | */
|
---|
106 | return RTTestSummaryAndDestroy(hTest);
|
---|
107 | }
|
---|
108 |
|
---|