VirtualBox

Changeset 22237 in vbox for trunk/src/VBox/GuestHost


Ignore:
Timestamp:
Aug 13, 2009 1:43:54 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
51044
Message:

GuestHost/SharedClipboard/x11: always send nul-terminated text to VBox, always send non-nul-terminated text to X11

File:
1 edited

Legend:

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

    r22234 r22237  
    10831083}
    10841084
     1085/**
     1086 * Remove a trailing nul character from a string by adjusting the string
     1087 * length.  Some X11 applications don't like zero-terminated text...
     1088 * @param  pText   the text in question
     1089 * @param  pcText  the length of the text, adjusted on return
     1090 * @param  format  the format of the text
     1091 */
     1092static void clipTrimTrailingNul(XtPointer pText, unsigned long *pcText,
     1093                                CLIPFORMAT format)
     1094{
     1095    AssertPtrReturnVoid(pText);
     1096    AssertPtrReturnVoid(pcText);
     1097    AssertReturnVoid((format == UTF8) || (format == CTEXT) || (format == TEXT));
     1098    if (((char *)pText)[*pcText - 1] == '\0')
     1099       --(*pcText);
     1100}
     1101
    10851102static int clipConvertVBoxCBForX11(CLIPBACKEND *pCtx, Atom *atomTarget,
    10861103                                   Atom *atomTypeReturn,
     
    11131130                                           atomTypeReturn, pValReturn,
    11141131                                           pcLenReturn, piFormatReturn);
     1132        if (RT_SUCCESS(rc))
     1133            clipTrimTrailingNul(*(XtPointer *)pValReturn, pcLenReturn, format);
    11151134        RTMemFree(pv);
    11161135    }
     
    20712090
    20722091static void testStringFromX11(RTTEST hTest, CLIPBACKEND *pCtx,
    2073                               const char *pcszExp, int rcExp, size_t cbExpIn)
     2092                              const char *pcszExp, int rcExp)
    20742093{
    20752094    bool retval = true;
     
    21022121            rc = RTStrToUtf16Ex(pcszExp, RTSTR_MAX, &pwcExp,
    21032122                                RT_ELEMENTS(wcExp), &cwc);
    2104             size_t cbExp = cbExpIn ? cbExpIn : cwc * 2 + 2;
     2123            size_t cbExp = cwc * 2 + 2;
    21052124            AssertRC(rc);
    21062125            if (RT_SUCCESS(rc))
     
    21292148
    21302149static void testLatin1FromX11(RTTEST hTest, CLIPBACKEND *pCtx,
    2131                               const char *pcszExp, int rcExp, size_t cbExpIn)
     2150                              const char *pcszExp, int rcExp)
    21322151{
    21332152    bool retval = false;
     
    21602179            for (cwc = 0; cwc == 0 || pcszExp[cwc - 1] != '\0'; ++cwc)
    21612180                wcExp[cwc] = pcszExp[cwc];
    2162             size_t cbExp = cbExpIn ? cbExpIn : cwc * 2;
     2181            size_t cbExp = cwc * 2;
    21632182            if (cbActual != cbExp)
    21642183            {
     
    21842203static void testStringFromVBox(RTTEST hTest, CLIPBACKEND *pCtx,
    21852204                               const char *pcszTarget, Atom typeExp,
    2186                                const void *valueExp, unsigned long lenExp)
     2205                               const char *valueExp)
    21872206{
    21882207    bool retval = false;
     
    21912210    unsigned long length;
    21922211    int format;
     2212    size_t lenExp = strlen(valueExp);
    21932213    if (clipConvertSelection(pcszTarget, &type, &value, &length, &format))
    21942214    {
     
    22562276    clipSetSelectionValues("UTF8_STRING", XA_STRING, "hello world",
    22572277                           sizeof("hello world"), 8);
    2258     testStringFromX11(hTest, pCtx, "hello world", VINF_SUCCESS, 0);
     2278    testStringFromX11(hTest, pCtx, "hello world", VINF_SUCCESS);
    22592279    /* With an embedded carriage return */
    22602280    clipSetSelectionValues("text/plain;charset=UTF-8", XA_STRING,
    22612281                           "hello\nworld", sizeof("hello\nworld"), 8);
    2262     testStringFromX11(hTest, pCtx, "hello\r\nworld", VINF_SUCCESS, 0);
     2282    testStringFromX11(hTest, pCtx, "hello\r\nworld", VINF_SUCCESS);
    22632283    /* With an embedded CRLF */
    22642284    clipSetSelectionValues("text/plain;charset=UTF-8", XA_STRING,
    22652285                           "hello\r\nworld", sizeof("hello\r\nworld"), 8);
    2266     testStringFromX11(hTest, pCtx, "hello\r\r\nworld", VINF_SUCCESS, 0);
     2286    testStringFromX11(hTest, pCtx, "hello\r\r\nworld", VINF_SUCCESS);
    22672287    /* With an embedded LFCR */
    22682288    clipSetSelectionValues("text/plain;charset=UTF-8", XA_STRING,
    22692289                           "hello\n\rworld", sizeof("hello\n\rworld"), 8);
    2270     testStringFromX11(hTest, pCtx, "hello\r\n\rworld", VINF_SUCCESS, 0);
     2290    testStringFromX11(hTest, pCtx, "hello\r\n\rworld", VINF_SUCCESS);
    22712291    /* An empty string */
    22722292    clipSetSelectionValues("text/plain;charset=utf-8", XA_STRING, "",
    22732293                           sizeof(""), 8);
    2274     testStringFromX11(hTest, pCtx, "", VINF_SUCCESS, 0);
     2294    testStringFromX11(hTest, pCtx, "", VINF_SUCCESS);
    22752295    /* With an embedded Utf-8 character. */
    22762296    clipSetSelectionValues("STRING", XA_STRING,
    22772297                           "100\xE2\x82\xAC" /* 100 Euro */,
    22782298                           sizeof("100\xE2\x82\xAC"), 8);
    2279     testStringFromX11(hTest, pCtx, "100\xE2\x82\xAC", VINF_SUCCESS, 0);
     2299    testStringFromX11(hTest, pCtx, "100\xE2\x82\xAC", VINF_SUCCESS);
    22802300    /* A non-zero-terminated string */
    22812301    clipSetSelectionValues("TEXT", XA_STRING,
    22822302                           "hello world", sizeof("hello world") - 1, 8);
    2283     // testStringFromX11(hTest, pCtx, "hello world", VINF_SUCCESS,
    2284     //                   sizeof("hello world") * 2 - 2);
     2303    testStringFromX11(hTest, pCtx, "hello world", VINF_SUCCESS);
    22852304
    22862305    /*** COMPOUND TEXT from X11 ***/
     
    22892308    clipSetSelectionValues("COMPOUND_TEXT", XA_STRING, "hello world",
    22902309                           sizeof("hello world"), 8);
    2291     testStringFromX11(hTest, pCtx, "hello world", VINF_SUCCESS, 0);
     2310    testStringFromX11(hTest, pCtx, "hello world", VINF_SUCCESS);
    22922311    /* With an embedded carriage return */
    22932312    clipSetSelectionValues("COMPOUND_TEXT", XA_STRING, "hello\nworld",
    22942313                           sizeof("hello\nworld"), 8);
    2295     testStringFromX11(hTest, pCtx, "hello\r\nworld", VINF_SUCCESS, 0);
     2314    testStringFromX11(hTest, pCtx, "hello\r\nworld", VINF_SUCCESS);
    22962315    /* With an embedded CRLF */
    22972316    clipSetSelectionValues("COMPOUND_TEXT", XA_STRING, "hello\r\nworld",
    22982317                           sizeof("hello\r\nworld"), 8);
    2299     testStringFromX11(hTest, pCtx, "hello\r\r\nworld", VINF_SUCCESS, 0);
     2318    testStringFromX11(hTest, pCtx, "hello\r\r\nworld", VINF_SUCCESS);
    23002319    /* With an embedded LFCR */
    23012320    clipSetSelectionValues("COMPOUND_TEXT", XA_STRING, "hello\n\rworld",
    23022321                           sizeof("hello\n\rworld"), 8);
    2303     testStringFromX11(hTest, pCtx, "hello\r\n\rworld", VINF_SUCCESS, 0);
     2322    testStringFromX11(hTest, pCtx, "hello\r\n\rworld", VINF_SUCCESS);
    23042323    /* An empty string */
    23052324    clipSetSelectionValues("COMPOUND_TEXT", XA_STRING, "",
    23062325                           sizeof(""), 8);
    2307     testStringFromX11(hTest, pCtx, "", VINF_SUCCESS, 0);
     2326    testStringFromX11(hTest, pCtx, "", VINF_SUCCESS);
    23082327    /* A non-zero-terminated string */
    23092328    clipSetSelectionValues("COMPOUND_TEXT", XA_STRING,
    23102329                           "hello world", sizeof("hello world") - 1, 8);
    2311     // testStringFromX11(hTest, pCtx, "hello world", VINF_SUCCESS,
    2312     //                   sizeof("hello world") * 2 - 2);
     2330    testStringFromX11(hTest, pCtx, "hello world", VINF_SUCCESS);
    23132331
    23142332    /*** Latin1 from X11 ***/
     
    23172335    clipSetSelectionValues("STRING", XA_STRING, "Georges Dupr\xEA",
    23182336                           sizeof("Georges Dupr\xEA"), 8);
    2319     testLatin1FromX11(hTest, pCtx, "Georges Dupr\xEA", VINF_SUCCESS, 0);
     2337    testLatin1FromX11(hTest, pCtx, "Georges Dupr\xEA", VINF_SUCCESS);
    23202338    /* With an embedded carriage return */
    23212339    clipSetSelectionValues("TEXT", XA_STRING, "Georges\nDupr\xEA",
    23222340                           sizeof("Georges\nDupr\xEA"), 8);
    2323     testLatin1FromX11(hTest, pCtx, "Georges\r\nDupr\xEA", VINF_SUCCESS, 0);
     2341    testLatin1FromX11(hTest, pCtx, "Georges\r\nDupr\xEA", VINF_SUCCESS);
    23242342    /* With an embedded CRLF */
    23252343    clipSetSelectionValues("TEXT", XA_STRING, "Georges\r\nDupr\xEA",
    23262344                           sizeof("Georges\r\nDupr\xEA"), 8);
    2327     testLatin1FromX11(hTest, pCtx, "Georges\r\r\nDupr\xEA", VINF_SUCCESS, 0);
     2345    testLatin1FromX11(hTest, pCtx, "Georges\r\r\nDupr\xEA", VINF_SUCCESS);
    23282346    /* With an embedded LFCR */
    23292347    clipSetSelectionValues("TEXT", XA_STRING, "Georges\n\rDupr\xEA",
    23302348                           sizeof("Georges\n\rDupr\xEA"), 8);
    2331     testLatin1FromX11(hTest, pCtx, "Georges\r\n\rDupr\xEA", VINF_SUCCESS, 0);
     2349    testLatin1FromX11(hTest, pCtx, "Georges\r\n\rDupr\xEA", VINF_SUCCESS);
    23322350    /* A non-zero-terminated string */
    23332351    clipSetSelectionValues("text/plain", XA_STRING,
    23342352                           "Georges Dupr\xEA!",
    23352353                           sizeof("Georges Dupr\xEA!") - 1, 8);
    2336     // testLatin1FromX11(hTest, pCtx, "Georges Dupr\xEA!", VINF_SUCCESS,
    2337     //                   sizeof("Georges Dupr\xEA!") * 2 - 2);
     2354    testLatin1FromX11(hTest, pCtx, "Georges Dupr\xEA!", VINF_SUCCESS);
    23382355
    23392356    /*** Unknown X11 format ***/
     
    23502367    clipSetSelectionValues("UTF8_STRING", XT_CONVERT_FAIL, "hello world",
    23512368                           sizeof("hello world"), 8);
    2352     testStringFromX11(hTest, pCtx, "hello world", VERR_TIMEOUT, 0);
     2369    testStringFromX11(hTest, pCtx, "hello world", VERR_TIMEOUT);
    23532370
    23542371    /*** No data in X11 clipboard ***/
     
    24092426                     sizeof("hello world") * 2);
    24102427    testStringFromVBox(hTest, pCtx, "UTF8_STRING",
    2411                             clipGetAtom(NULL, "UTF8_STRING"),
    2412                             "hello world", sizeof("hello world"));
     2428                       clipGetAtom(NULL, "UTF8_STRING"), "hello world");
    24132429    /* With an embedded carriage return */
    24142430    clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello\r\nworld",
    24152431                     sizeof("hello\r\nworld") * 2);
    24162432    testStringFromVBox(hTest, pCtx, "text/plain;charset=UTF-8",
    2417                             clipGetAtom(NULL, "text/plain;charset=UTF-8"),
    2418                             "hello\nworld", sizeof("hello\nworld"));
     2433                       clipGetAtom(NULL, "text/plain;charset=UTF-8"),
     2434                       "hello\nworld");
    24192435    /* With an embedded CRCRLF */
    24202436    clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello\r\r\nworld",
    24212437                     sizeof("hello\r\r\nworld") * 2);
    24222438    testStringFromVBox(hTest, pCtx, "text/plain;charset=UTF-8",
    2423                             clipGetAtom(NULL, "text/plain;charset=UTF-8"),
    2424                             "hello\r\nworld", sizeof("hello\r\nworld"));
     2439                       clipGetAtom(NULL, "text/plain;charset=UTF-8"),
     2440                       "hello\r\nworld");
    24252441    /* With an embedded CRLFCR */
    24262442    clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello\r\n\rworld",
    24272443                     sizeof("hello\r\n\rworld") * 2);
    24282444    testStringFromVBox(hTest, pCtx, "text/plain;charset=UTF-8",
    2429                             clipGetAtom(NULL, "text/plain;charset=UTF-8"),
    2430                             "hello\n\rworld", sizeof("hello\n\rworld"));
     2445                       clipGetAtom(NULL, "text/plain;charset=UTF-8"),
     2446                       "hello\n\rworld");
    24312447    /* An empty string */
    24322448    clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "", 2);
    24332449    testStringFromVBox(hTest, pCtx, "text/plain;charset=utf-8",
    2434                             clipGetAtom(NULL, "text/plain;charset=utf-8"),
    2435                             "", sizeof(""));
     2450                       clipGetAtom(NULL, "text/plain;charset=utf-8"), "");
    24362451    /* With an embedded Utf-8 character. */
    24372452    clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "100\xE2\x82\xAC" /* 100 Euro */,
    24382453                     10);
    24392454    testStringFromVBox(hTest, pCtx, "STRING",
    2440                             clipGetAtom(NULL, "STRING"),
    2441                             "100\xE2\x82\xAC", sizeof("100\xE2\x82\xAC"));
     2455                       clipGetAtom(NULL, "STRING"), "100\xE2\x82\xAC");
    24422456    /* A non-zero-terminated string */
    24432457    clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello world",
    24442458                     sizeof("hello world") * 2 - 2);
    2445     // testStringFromVBox(hTest, pCtx, "TEXT",
    2446     //                         clipGetAtom(NULL, "TEXT"),
    2447     //                         "hello world", sizeof("hello world") - 1);
     2459    testStringFromVBox(hTest, pCtx, "TEXT", clipGetAtom(NULL, "TEXT"),
     2460                       "hello world");
    24482461
    24492462    /*** COMPOUND TEXT from VBox ***/
     
    24532466                     sizeof("hello world") * 2);
    24542467    testStringFromVBox(hTest, pCtx, "COMPOUND_TEXT",
    2455                             clipGetAtom(NULL, "COMPOUND_TEXT"),
    2456                             "hello world", sizeof("hello world"));
     2468                       clipGetAtom(NULL, "COMPOUND_TEXT"), "hello world");
    24572469    /* With an embedded carriage return */
    24582470    clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello\r\nworld",
    24592471                     sizeof("hello\r\nworld") * 2);
    24602472    testStringFromVBox(hTest, pCtx, "COMPOUND_TEXT",
    2461                             clipGetAtom(NULL, "COMPOUND_TEXT"),
    2462                             "hello\nworld", sizeof("hello\nworld"));
     2473                       clipGetAtom(NULL, "COMPOUND_TEXT"), "hello\nworld");
    24632474    /* With an embedded CRCRLF */
    24642475    clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello\r\r\nworld",
    24652476                     sizeof("hello\r\r\nworld") * 2);
    24662477    testStringFromVBox(hTest, pCtx, "COMPOUND_TEXT",
    2467                             clipGetAtom(NULL, "COMPOUND_TEXT"),
    2468                             "hello\r\nworld", sizeof("hello\r\nworld"));
     2478                       clipGetAtom(NULL, "COMPOUND_TEXT"), "hello\r\nworld");
    24692479    /* With an embedded CRLFCR */
    24702480    clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello\r\n\rworld",
    24712481                     sizeof("hello\r\n\rworld") * 2);
    24722482    testStringFromVBox(hTest, pCtx, "COMPOUND_TEXT",
    2473                             clipGetAtom(NULL, "COMPOUND_TEXT"),
    2474                             "hello\n\rworld", sizeof("hello\n\rworld"));
     2483                       clipGetAtom(NULL, "COMPOUND_TEXT"), "hello\n\rworld");
    24752484    /* An empty string */
    24762485    clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "", 2);
    24772486    testStringFromVBox(hTest, pCtx, "COMPOUND_TEXT",
    2478                             clipGetAtom(NULL, "COMPOUND_TEXT"),
    2479                             "", sizeof(""));
     2487                       clipGetAtom(NULL, "COMPOUND_TEXT"), "");
    24802488    /* A non-zero-terminated string */
    24812489    clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello world",
    24822490                     sizeof("hello world") * 2 - 2);
    2483     // testStringFromVBox(hTest, pCtx, "COMPOUND_TEXT",
    2484     //                         clipGetAtom(NULL, "COMPOUND_TEXT"),
    2485     //                         "hello world", sizeof("hello world") - 1);
     2491    testStringFromVBox(hTest, pCtx, "COMPOUND_TEXT",
     2492                       clipGetAtom(NULL, "COMPOUND_TEXT"), "hello world");
    24862493
    24872494    /*** Timeout from VBox ***/
Note: See TracChangeset for help on using the changeset viewer.

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