1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
/* $Id: tstClipboardGH-X11Smoke.cpp $ */
/** @file
* Shared Clipboard guest/host X11 code smoke tests.
*/
/*
* Copyright (C) 2011-2022 Oracle and/or its affiliates.
*
* This file is part of VirtualBox base platform packages, as
* available from https://www.virtualbox.org.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, in version 3 of the
* License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <https://www.gnu.org/licenses>.
*
* SPDX-License-Identifier: GPL-3.0-only
*/
/* This is a simple test case that just starts a copy of the X11 clipboard
* backend, checks the X11 clipboard and exits. If ever needed I will add an
* interactive mode in which the user can read and copy to the clipboard from
* the command line. */
#include <iprt/assert.h>
#include <iprt/env.h>
#include <iprt/err.h>
#include <iprt/test.h>
#include <VBox/GuestHost/SharedClipboard.h>
#include <VBox/GuestHost/SharedClipboard-x11.h>
#include <VBox/GuestHost/clipboard-helper.h>
static DECLCALLBACK(int) tstShClReportFormatsCallback(PSHCLCONTEXT pCtx, uint32_t fFormats, void *pvUser)
{
RT_NOREF(pCtx, fFormats, pvUser);
return VINF_SUCCESS;
}
static DECLCALLBACK(int) tstShClOnRequestDataFromSourceCallback(PSHCLCONTEXT pCtx, SHCLFORMAT uFmt, void **ppv, uint32_t *pcb, void *pvUser)
{
RT_NOREF(pCtx, uFmt, ppv, pcb, pvUser);
return VERR_NO_DATA;
}
static DECLCALLBACK(int) tstShClOnSendDataToDest(PSHCLCONTEXT pCtx, void *pv, uint32_t cb, void *pvUser)
{
RT_NOREF(pCtx, pv, cb, pvUser);
return VINF_SUCCESS;
}
int main()
{
/*
* Init the runtime, test and say hello.
*/
RTTEST hTest;
int rc = RTTestInitAndCreate("tstClipboardGH-X11Smoke", &hTest);
if (rc)
return rc;
RTTestBanner(hTest);
/*
* Run the test.
*/
rc = VINF_SUCCESS;
/* We can't test anything without an X session, so just return success
* in that case. */
if (!RTEnvExist("DISPLAY"))
{
RTTestPrintf(hTest, RTTESTLVL_INFO,
"X11 not available, not running test\n");
return RTTestSummaryAndDestroy(hTest);
}
SHCLCALLBACKS Callbacks;
RT_ZERO(Callbacks);
Callbacks.pfnReportFormats = tstShClReportFormatsCallback;
Callbacks.pfnOnRequestDataFromSource = tstShClOnRequestDataFromSourceCallback;
Callbacks.pfnOnSendDataToDest = tstShClOnSendDataToDest;
SHCLX11CTX X11Ctx;
rc = ShClX11Init(&X11Ctx, &Callbacks, NULL /* pParent */, false);
AssertRCReturn(rc, 1);
rc = ShClX11ThreadStart(&X11Ctx, false /* fGrab */);
AssertRCReturn(rc, 1);
/* Give the clipboard time to synchronise. */
RTThreadSleep(500);
rc = ShClX11ThreadStop(&X11Ctx);
AssertRCReturn(rc, 1);
ShClX11Destroy(&X11Ctx);
return RTTestSummaryAndDestroy(hTest);
}
|