Changeset 22237 in vbox for trunk/src/VBox/GuestHost
- Timestamp:
- Aug 13, 2009 1:43:54 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 51044
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/SharedClipboard/x11-clipboard.cpp
r22234 r22237 1083 1083 } 1084 1084 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 */ 1092 static 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 1085 1102 static int clipConvertVBoxCBForX11(CLIPBACKEND *pCtx, Atom *atomTarget, 1086 1103 Atom *atomTypeReturn, … … 1113 1130 atomTypeReturn, pValReturn, 1114 1131 pcLenReturn, piFormatReturn); 1132 if (RT_SUCCESS(rc)) 1133 clipTrimTrailingNul(*(XtPointer *)pValReturn, pcLenReturn, format); 1115 1134 RTMemFree(pv); 1116 1135 } … … 2071 2090 2072 2091 static void testStringFromX11(RTTEST hTest, CLIPBACKEND *pCtx, 2073 const char *pcszExp, int rcExp , size_t cbExpIn)2092 const char *pcszExp, int rcExp) 2074 2093 { 2075 2094 bool retval = true; … … 2102 2121 rc = RTStrToUtf16Ex(pcszExp, RTSTR_MAX, &pwcExp, 2103 2122 RT_ELEMENTS(wcExp), &cwc); 2104 size_t cbExp = c bExpIn ? cbExpIn : cwc * 2 + 2;2123 size_t cbExp = cwc * 2 + 2; 2105 2124 AssertRC(rc); 2106 2125 if (RT_SUCCESS(rc)) … … 2129 2148 2130 2149 static void testLatin1FromX11(RTTEST hTest, CLIPBACKEND *pCtx, 2131 const char *pcszExp, int rcExp , size_t cbExpIn)2150 const char *pcszExp, int rcExp) 2132 2151 { 2133 2152 bool retval = false; … … 2160 2179 for (cwc = 0; cwc == 0 || pcszExp[cwc - 1] != '\0'; ++cwc) 2161 2180 wcExp[cwc] = pcszExp[cwc]; 2162 size_t cbExp = c bExpIn ? cbExpIn : cwc * 2;2181 size_t cbExp = cwc * 2; 2163 2182 if (cbActual != cbExp) 2164 2183 { … … 2184 2203 static void testStringFromVBox(RTTEST hTest, CLIPBACKEND *pCtx, 2185 2204 const char *pcszTarget, Atom typeExp, 2186 const void *valueExp, unsigned long lenExp)2205 const char *valueExp) 2187 2206 { 2188 2207 bool retval = false; … … 2191 2210 unsigned long length; 2192 2211 int format; 2212 size_t lenExp = strlen(valueExp); 2193 2213 if (clipConvertSelection(pcszTarget, &type, &value, &length, &format)) 2194 2214 { … … 2256 2276 clipSetSelectionValues("UTF8_STRING", XA_STRING, "hello world", 2257 2277 sizeof("hello world"), 8); 2258 testStringFromX11(hTest, pCtx, "hello world", VINF_SUCCESS , 0);2278 testStringFromX11(hTest, pCtx, "hello world", VINF_SUCCESS); 2259 2279 /* With an embedded carriage return */ 2260 2280 clipSetSelectionValues("text/plain;charset=UTF-8", XA_STRING, 2261 2281 "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); 2263 2283 /* With an embedded CRLF */ 2264 2284 clipSetSelectionValues("text/plain;charset=UTF-8", XA_STRING, 2265 2285 "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); 2267 2287 /* With an embedded LFCR */ 2268 2288 clipSetSelectionValues("text/plain;charset=UTF-8", XA_STRING, 2269 2289 "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); 2271 2291 /* An empty string */ 2272 2292 clipSetSelectionValues("text/plain;charset=utf-8", XA_STRING, "", 2273 2293 sizeof(""), 8); 2274 testStringFromX11(hTest, pCtx, "", VINF_SUCCESS , 0);2294 testStringFromX11(hTest, pCtx, "", VINF_SUCCESS); 2275 2295 /* With an embedded Utf-8 character. */ 2276 2296 clipSetSelectionValues("STRING", XA_STRING, 2277 2297 "100\xE2\x82\xAC" /* 100 Euro */, 2278 2298 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); 2280 2300 /* A non-zero-terminated string */ 2281 2301 clipSetSelectionValues("TEXT", XA_STRING, 2282 2302 "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); 2285 2304 2286 2305 /*** COMPOUND TEXT from X11 ***/ … … 2289 2308 clipSetSelectionValues("COMPOUND_TEXT", XA_STRING, "hello world", 2290 2309 sizeof("hello world"), 8); 2291 testStringFromX11(hTest, pCtx, "hello world", VINF_SUCCESS , 0);2310 testStringFromX11(hTest, pCtx, "hello world", VINF_SUCCESS); 2292 2311 /* With an embedded carriage return */ 2293 2312 clipSetSelectionValues("COMPOUND_TEXT", XA_STRING, "hello\nworld", 2294 2313 sizeof("hello\nworld"), 8); 2295 testStringFromX11(hTest, pCtx, "hello\r\nworld", VINF_SUCCESS , 0);2314 testStringFromX11(hTest, pCtx, "hello\r\nworld", VINF_SUCCESS); 2296 2315 /* With an embedded CRLF */ 2297 2316 clipSetSelectionValues("COMPOUND_TEXT", XA_STRING, "hello\r\nworld", 2298 2317 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); 2300 2319 /* With an embedded LFCR */ 2301 2320 clipSetSelectionValues("COMPOUND_TEXT", XA_STRING, "hello\n\rworld", 2302 2321 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); 2304 2323 /* An empty string */ 2305 2324 clipSetSelectionValues("COMPOUND_TEXT", XA_STRING, "", 2306 2325 sizeof(""), 8); 2307 testStringFromX11(hTest, pCtx, "", VINF_SUCCESS , 0);2326 testStringFromX11(hTest, pCtx, "", VINF_SUCCESS); 2308 2327 /* A non-zero-terminated string */ 2309 2328 clipSetSelectionValues("COMPOUND_TEXT", XA_STRING, 2310 2329 "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); 2313 2331 2314 2332 /*** Latin1 from X11 ***/ … … 2317 2335 clipSetSelectionValues("STRING", XA_STRING, "Georges Dupr\xEA", 2318 2336 sizeof("Georges Dupr\xEA"), 8); 2319 testLatin1FromX11(hTest, pCtx, "Georges Dupr\xEA", VINF_SUCCESS , 0);2337 testLatin1FromX11(hTest, pCtx, "Georges Dupr\xEA", VINF_SUCCESS); 2320 2338 /* With an embedded carriage return */ 2321 2339 clipSetSelectionValues("TEXT", XA_STRING, "Georges\nDupr\xEA", 2322 2340 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); 2324 2342 /* With an embedded CRLF */ 2325 2343 clipSetSelectionValues("TEXT", XA_STRING, "Georges\r\nDupr\xEA", 2326 2344 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); 2328 2346 /* With an embedded LFCR */ 2329 2347 clipSetSelectionValues("TEXT", XA_STRING, "Georges\n\rDupr\xEA", 2330 2348 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); 2332 2350 /* A non-zero-terminated string */ 2333 2351 clipSetSelectionValues("text/plain", XA_STRING, 2334 2352 "Georges Dupr\xEA!", 2335 2353 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); 2338 2355 2339 2356 /*** Unknown X11 format ***/ … … 2350 2367 clipSetSelectionValues("UTF8_STRING", XT_CONVERT_FAIL, "hello world", 2351 2368 sizeof("hello world"), 8); 2352 testStringFromX11(hTest, pCtx, "hello world", VERR_TIMEOUT , 0);2369 testStringFromX11(hTest, pCtx, "hello world", VERR_TIMEOUT); 2353 2370 2354 2371 /*** No data in X11 clipboard ***/ … … 2409 2426 sizeof("hello world") * 2); 2410 2427 testStringFromVBox(hTest, pCtx, "UTF8_STRING", 2411 clipGetAtom(NULL, "UTF8_STRING"), 2412 "hello world", sizeof("hello world")); 2428 clipGetAtom(NULL, "UTF8_STRING"), "hello world"); 2413 2429 /* With an embedded carriage return */ 2414 2430 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello\r\nworld", 2415 2431 sizeof("hello\r\nworld") * 2); 2416 2432 testStringFromVBox(hTest, pCtx, "text/plain;charset=UTF-8", 2417 2418 "hello\nworld", sizeof("hello\nworld"));2433 clipGetAtom(NULL, "text/plain;charset=UTF-8"), 2434 "hello\nworld"); 2419 2435 /* With an embedded CRCRLF */ 2420 2436 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello\r\r\nworld", 2421 2437 sizeof("hello\r\r\nworld") * 2); 2422 2438 testStringFromVBox(hTest, pCtx, "text/plain;charset=UTF-8", 2423 2424 "hello\r\nworld", sizeof("hello\r\nworld"));2439 clipGetAtom(NULL, "text/plain;charset=UTF-8"), 2440 "hello\r\nworld"); 2425 2441 /* With an embedded CRLFCR */ 2426 2442 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello\r\n\rworld", 2427 2443 sizeof("hello\r\n\rworld") * 2); 2428 2444 testStringFromVBox(hTest, pCtx, "text/plain;charset=UTF-8", 2429 2430 "hello\n\rworld", sizeof("hello\n\rworld"));2445 clipGetAtom(NULL, "text/plain;charset=UTF-8"), 2446 "hello\n\rworld"); 2431 2447 /* An empty string */ 2432 2448 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "", 2); 2433 2449 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"), ""); 2436 2451 /* With an embedded Utf-8 character. */ 2437 2452 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "100\xE2\x82\xAC" /* 100 Euro */, 2438 2453 10); 2439 2454 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"); 2442 2456 /* A non-zero-terminated string */ 2443 2457 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello world", 2444 2458 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"); 2448 2461 2449 2462 /*** COMPOUND TEXT from VBox ***/ … … 2453 2466 sizeof("hello world") * 2); 2454 2467 testStringFromVBox(hTest, pCtx, "COMPOUND_TEXT", 2455 clipGetAtom(NULL, "COMPOUND_TEXT"), 2456 "hello world", sizeof("hello world")); 2468 clipGetAtom(NULL, "COMPOUND_TEXT"), "hello world"); 2457 2469 /* With an embedded carriage return */ 2458 2470 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello\r\nworld", 2459 2471 sizeof("hello\r\nworld") * 2); 2460 2472 testStringFromVBox(hTest, pCtx, "COMPOUND_TEXT", 2461 clipGetAtom(NULL, "COMPOUND_TEXT"), 2462 "hello\nworld", sizeof("hello\nworld")); 2473 clipGetAtom(NULL, "COMPOUND_TEXT"), "hello\nworld"); 2463 2474 /* With an embedded CRCRLF */ 2464 2475 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello\r\r\nworld", 2465 2476 sizeof("hello\r\r\nworld") * 2); 2466 2477 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"); 2469 2479 /* With an embedded CRLFCR */ 2470 2480 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello\r\n\rworld", 2471 2481 sizeof("hello\r\n\rworld") * 2); 2472 2482 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"); 2475 2484 /* An empty string */ 2476 2485 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "", 2); 2477 2486 testStringFromVBox(hTest, pCtx, "COMPOUND_TEXT", 2478 clipGetAtom(NULL, "COMPOUND_TEXT"), 2479 "", sizeof("")); 2487 clipGetAtom(NULL, "COMPOUND_TEXT"), ""); 2480 2488 /* A non-zero-terminated string */ 2481 2489 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello world", 2482 2490 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"); 2486 2493 2487 2494 /*** Timeout from VBox ***/
Note:
See TracChangeset
for help on using the changeset viewer.