VirtualBox

Changeset 102929 in vbox for trunk/src


Ignore:
Timestamp:
Jan 17, 2024 3:30:48 PM (11 months ago)
Author:
vboxsync
Message:

Shared Clipboard: Better documented for what headless mode is and why we need it; improved testing here and there a bit, so we have better coverage there.

Location:
trunk/src/VBox/GuestHost/SharedClipboard
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/SharedClipboard/clipboard-x11.cpp

    r102826 r102929  
    334334
    335335    Widget pWidget = pCtx->pWidget;
    336     AssertPtrReturnVoid(pWidget);
     336    if (!pWidget)
     337        return;
    337338
    338339    bool fFound = false;
     
    11551156
    11561157/**
     1158 * Helper function for public X11 Shared Clipboard APIs to know whether we're running in headless mode or not.
     1159 *
     1160 * Headless mode either could mean that we don't want to touch the X11 clipboard, or that X simply isn't installed and/or
     1161 * isn't available (e.g. running on a pure server installation w/o any desktop environment).
     1162 *
     1163 * Goal here is to make the X11 API transparent for the caller whether X is available or not.
     1164 *
     1165 * @returns \c true if running in headless mode, or \c false if not.
     1166 * @param   pCtx                The X11 clipboard context to use.
     1167 */
     1168DECLINLINE(bool) shClX11HeadlessIsEnabled(PSHCLX11CTX pCtx)
     1169{
     1170    return pCtx->fHeadless;
     1171}
     1172
     1173/**
    11571174 * Sets the callback table, internal version.
    11581175 *
     
    11961213    LogFlowFunc(("pCtx=%p\n", pCtx));
    11971214
    1198     int rc = VINF_SUCCESS;
    1199 
    12001215    RT_BZERO(pCtx, sizeof(SHCLX11CTX));
    1201 
    1202     if (fHeadless)
    1203     {
    1204         /*
    1205          * If we don't find the DISPLAY environment variable we assume that
    1206          * we are not connected to an X11 server. Don't actually try to do
    1207          * this then, just fail silently and report success on every call.
    1208          * This is important for VBoxHeadless.
    1209          */
    1210         LogRel(("Shared Clipboard: X11 DISPLAY variable not set -- disabling clipboard sharing\n"));
    1211     }
    12121216
    12131217    /* Init clipboard cache. */
     
    12171221    shClX11SetCallbacksInternal(pCtx, pCallbacks);
    12181222
    1219     pCtx->fHaveX11       = !fHeadless;
     1223    pCtx->fHeadless      = fHeadless;
    12201224    pCtx->pFrontend      = pParent;
    12211225
     
    12251229#endif
    12261230
     1231    int rc = VINF_SUCCESS;
     1232
     1233    LogRel(("Shared Clipboard: Initializing X11 clipboard (%s mode)\n", fHeadless ? "headless" : "regular"));
     1234
     1235    if (!pCtx->fHeadless)
     1236    {
    12271237#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS_HTTP
    1228     ShClTransferHttpServerInit(&pCtx->HttpCtx.HttpServer);
     1238        rc = ShClTransferHttpServerInit(&pCtx->HttpCtx.HttpServer);
    12291239#endif
    12301240
    12311241#ifdef TESTCASE
    1232     if (RT_SUCCESS(rc))
    1233     {
    1234         /** @todo The testcases currently do not utilize the threading code. So init stuff here. */
    1235         rc = clipInitInternal(pCtx);
    12361242        if (RT_SUCCESS(rc))
    1237             rc = clipRegisterContext(pCtx);
    1238     }
    1239 #endif
     1243        {
     1244            /** @todo The testcases currently do not utilize the threading code. So init stuff here. */
     1245            rc = clipInitInternal(pCtx);
     1246            if (RT_SUCCESS(rc))
     1247                rc = clipRegisterContext(pCtx);
     1248        }
     1249#endif
     1250    }
     1251
     1252    if (RT_FAILURE(rc))
     1253        LogRel(("Shared Clipboard: Initializing X11 clipboard failed with %Rrc\n", rc));
    12401254
    12411255    LogFlowFuncLeaveRC(rc);
     
    12461260 * Destroys a Shared Clipboard X11 context.
    12471261 *
     1262 * @returns VBox status code.
    12481263 * @param   pCtx                The X11 clipboard context to destroy.
    12491264 */
    1250 void ShClX11Destroy(PSHCLX11CTX pCtx)
     1265int ShClX11Destroy(PSHCLX11CTX pCtx)
    12511266{
    12521267    if (!pCtx)
    1253         return;
     1268        return VINF_SUCCESS;
    12541269
    12551270    LogFlowFunc(("pCtx=%p\n", pCtx));
     
    12581273    ShClCacheDestroy(&pCtx->Cache);
    12591274
     1275    int rc = VINF_SUCCESS;
    12601276#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS_HTTP
    1261     ShClTransferHttpServerDestroy(&pCtx->HttpCtx.HttpServer);
     1277    rc = ShClTransferHttpServerDestroy(&pCtx->HttpCtx.HttpServer);
    12621278#endif
    12631279
     
    12681284#endif
    12691285
    1270     if (pCtx->fHaveX11)
     1286    if (!shClX11HeadlessIsEnabled(pCtx))
    12711287    {
    12721288        /* We set this to NULL when the event thread exits.  It really should
    12731289         * have exited at this point, when we are about to unload the code from
    12741290         * memory. */
    1275         Assert(pCtx->pWidget == NULL);
    1276     }
     1291        AssertStmt(pCtx->pWidget == NULL, rc = VERR_WRONG_ORDER);
     1292    }
     1293
     1294    return rc;
    12771295}
    12781296
     
    12901308    AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
    12911309
    1292     /*
    1293      * Immediately return if we are not connected to the X server.
    1294      */
    1295     if (!pCtx->fHaveX11)
     1310    if (shClX11HeadlessIsEnabled(pCtx))
    12961311        return VINF_SUCCESS;
    12971312
     
    13761391int ShClX11ThreadStop(PSHCLX11CTX pCtx)
    13771392{
    1378     int rc;
    1379     /*
    1380      * Immediately return if we are not connected to the X server.
    1381      */
    1382     if (!pCtx->fHaveX11)
     1393    if (shClX11HeadlessIsEnabled(pCtx))
    13831394        return VINF_SUCCESS;
    13841395
     
    13861397
    13871398    /* Write to the "stop" pipe. */
    1388     rc = clipThreadScheduleCall(pCtx, clipThreadSignalStop, (XtPointer)pCtx);
     1399    int rc = clipThreadScheduleCall(pCtx, clipThreadSignalStop, (XtPointer)pCtx);
    13891400    if (RT_FAILURE(rc))
    13901401    {
     
    19851996int ShClX11ReportFormatsToX11Async(PSHCLX11CTX pCtx, SHCLFORMATS uFormats)
    19861997{
    1987     /*
    1988      * Immediately return if we are not connected to the X server.
    1989      */
    1990     if (!pCtx->fHaveX11)
     1998    if (shClX11HeadlessIsEnabled(pCtx))
    19911999        return VINF_SUCCESS;
    19922000
     
    26322640{
    26332641    AssertPtrReturn(pEvent, VERR_INVALID_POINTER);
    2634     /*
    2635      * Immediately return if we are not connected to the X server.
    2636      */
    2637     if (!pCtx->fHaveX11)
     2642
     2643    if (shClX11HeadlessIsEnabled(pCtx))
    26382644        return VINF_SUCCESS;
    26392645
     
    26832689    AssertReturn(cbBuf, VERR_INVALID_PARAMETER);
    26842690    /* pcbRead is optional. */
     2691
     2692    if (shClX11HeadlessIsEnabled(pCtx))
     2693    {
     2694        if (pcbRead)
     2695            *pcbRead = 0;
     2696        return VINF_SUCCESS;
     2697    }
    26852698
    26862699    PSHCLEVENT pEvent;
     
    27502763    /* pEvent not used yet. */ RT_NOREF(pEvent);
    27512764
    2752     /*
    2753      * Immediately return if we are not connected to the X server.
    2754      */
    2755     if (!pCtx->fHaveX11)
     2765    if (shClX11HeadlessIsEnabled(pCtx))
    27562766        return VINF_SUCCESS;
    27572767
  • trunk/src/VBox/GuestHost/SharedClipboard/testcase/tstClipboardGH-X11.cpp

    r102466 r102929  
    589589        RTTestFailureDetails(hTest, "Conversion to %s, expected \"%s\"\n",
    590590                             pcszTarget, valueExp);
    591 }
    592 
    593 static void tstNoX11(PSHCLX11CTX pCtx, const char *pcszTestCtx)
    594 {
    595     uint32_t cbActual = 0;
    596     uint8_t  abBuf[TESTCASE_MAX_BUF_SIZE];
    597     int rc = ShClX11ReadDataFromX11(pCtx, &g_EventSource, g_msTimeout, VBOX_SHCL_FMT_UNICODETEXT, abBuf, sizeof(abBuf), &cbActual);
    598     RTTESTI_CHECK_MSG(rc == VERR_NO_DATA, ("context: %s\n", pcszTestCtx));
    599591}
    600592
     
    878870     * Headless clipboard tests
    879871     */
    880     rc = ShClX11Init(&X11Ctx, &Callbacks, NULL /* pParent */, true /* fHeadless */);
    881     AssertRCReturn(rc, RTEXITCODE_FAILURE);
     872    RTTEST_CHECK_RC_OK(hTest, ShClX11Init(&X11Ctx, &Callbacks, NULL /* pParent */, true /* fHeadless */));
    882873
    883874    /* Read from X11 */
    884875    RTTestSub(hTest, "reading from X11, headless clipboard");
     876
    885877    /* Simple test */
    886     tstClipSetVBoxUtf16(&X11Ctx, VINF_SUCCESS, "",
    887                         sizeof("") * 2);
    888     tstClipSetSelectionValues("UTF8_STRING", XA_STRING, "hello world",
    889                               sizeof("hello world"), 8);
    890     tstNoX11(&X11Ctx, "reading from X11, headless clipboard");
     878    tstClipSetVBoxUtf16(&X11Ctx, VINF_SUCCESS, "", sizeof("") * 2);
     879    tstClipSetSelectionValues("UTF8_STRING", XA_STRING, "hello world", sizeof("hello world"), 8);
     880    rc = ShClX11ReadDataFromX11(&X11Ctx, &g_EventSource, g_msTimeout, VBOX_SHCL_FMT_UNICODETEXT, abBuf, sizeof(abBuf), &cbActual);
     881    RTTESTI_CHECK_MSG(cbActual == 0, ("expected 0 but got %RU32\n", cbActual));
     882    RTTESTI_CHECK_MSG(rc == VINF_SUCCESS, ("expected VINF_SUCCESS but got %Rrc, context: %s\n", rc));
    891883
    892884    /* Read from VBox */
    893885    RTTestSub(hTest, "reading from VBox, headless clipboard");
     886
    894887    /* Simple test */
    895888    tstClipEmptyVBox(&X11Ctx, VERR_WRONG_ORDER);
     
    899892    tstNoSelectionOwnership(&X11Ctx, "reading from VBox, headless clipboard");
    900893
    901     ShClX11Destroy(&X11Ctx);
     894    RTTEST_CHECK_RC_OK(hTest, ShClX11Destroy(&X11Ctx));
    902895    ShClEventSourceDestroy(&g_EventSource);
    903896
  • trunk/src/VBox/GuestHost/SharedClipboard/testcase/tstClipboardGH-X11Smoke.cpp

    r98103 r102929  
    9090
    9191    SHCLX11CTX X11Ctx;
    92     rc = ShClX11Init(&X11Ctx, &Callbacks, NULL /* pParent */, false);
    93     AssertRCReturn(rc, 1);
    94     rc = ShClX11ThreadStart(&X11Ctx, false /* fGrab */);
    95     AssertRCReturn(rc, 1);
     92    RTTEST_CHECK_RC_OK(hTest, ShClX11Init(&X11Ctx, &Callbacks, NULL /* pParent */, false /* fHeadless */));
     93    RTTEST_CHECK_RC_OK(hTest, ShClX11ThreadStart(&X11Ctx, false /* fGrab */));
     94
    9695    /* Give the clipboard time to synchronise. */
    9796    RTThreadSleep(500);
    98     rc = ShClX11ThreadStop(&X11Ctx);
    99     AssertRCReturn(rc, 1);
    100     ShClX11Destroy(&X11Ctx);
     97
     98    RTTEST_CHECK_RC_OK(hTest, ShClX11ThreadStop(&X11Ctx));
     99    RTTEST_CHECK_RC_OK(hTest, ShClX11Destroy(&X11Ctx));
     100
    101101    return RTTestSummaryAndDestroy(hTest);
    102102}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette