- Timestamp:
- May 8, 2009 3:31:09 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/SharedClipboard/x11-clipboard.cpp
r19506 r19534 20 20 * additional information or have any questions. 21 21 */ 22 23 /* Note: to automatically run regression tests on the shared clipboard, set 24 * the make variable VBOX_RUN_X11_CLIPBOARD_TEST=1 while building. If you 25 * often make changes to the clipboard code, setting this variable in 26 * LocalConfig.kmk will cause the tests to be run every time the code is 27 * changed. */ 22 28 23 29 #define LOG_GROUP LOG_GROUP_SHARED_CLIPBOARD … … 388 394 unsigned cb, uint32_t *pcbActual) 389 395 { 390 unsigned cwDestLen = cbSourceLen;391 396 char *pu8SourceText = reinterpret_cast<char *>(pValue); 392 397 PRTUTF16 pu16DestText = reinterpret_cast<PRTUTF16>(pv); … … 396 401 cbSourceLen, pu8SourceText)); 397 402 *pcbActual = 0; /* Only set this to the right value on success. */ 398 for (unsigned i = 0; i < cbSourceLen; i++) 403 unsigned cwDestLen = 0; 404 for (unsigned i = 0; i < cbSourceLen && pu8SourceText[i] != '\0'; i++) 405 { 406 ++cwDestLen; 399 407 if (pu8SourceText[i] == LINEFEED) 400 408 ++cwDestLen; 409 } 410 /* Leave space for the terminator */ 411 ++cwDestLen; 401 412 if (cb < cwDestLen * 2) 402 413 { … … 1058 1069 static Boolean vboxClipboardConvertToUtf8ForX11(VBOXCLIPBOARDCONTEXTX11 1059 1070 *pCtx, 1071 Atom *atomTarget, 1060 1072 Atom *atomTypeReturn, 1061 1073 XtPointer *pValReturn, … … 1138 1150 LogFlowFunc (("converted string is %.*s. Returning.\n", cbDestLen, pu8DestText)); 1139 1151 RTMemFree(pvVBox); 1140 *atomTypeReturn = clipGetAtom(pCtx->widget, "UTF8_STRING");1152 *atomTypeReturn = *atomTarget; 1141 1153 *pValReturn = reinterpret_cast<XtPointer>(pu8DestText); 1142 1154 *pcLenReturn = cbDestLen + 1; … … 1336 1348 piFormatReturn); 1337 1349 case UTF8: 1338 return vboxClipboardConvertToUtf8ForX11(pCtx, atomTypeReturn, 1350 return vboxClipboardConvertToUtf8ForX11(pCtx, atomTarget, 1351 atomTypeReturn, 1339 1352 pValReturn, pcLenReturn, 1340 1353 piFormatReturn); … … 1613 1626 /* Set the data in the simulated VBox clipboard. */ 1614 1627 static int clipSetVBoxUtf16(VBOXCLIPBOARDCONTEXTX11 *pCtx, int retval, 1615 const char *pcszData )1628 const char *pcszData, size_t cb) 1616 1629 { 1617 1630 PRTUTF16 pwszData = NULL; … … 1620 1633 if (RT_FAILURE(rc)) 1621 1634 return rc; 1622 size_t cb = cwData * 2 + 2;1635 AssertReturn(cb <= cwData * 2 + 2, VERR_BUFFER_OVERFLOW); 1623 1636 void *pv = RTMemDup(pwszData, cb); 1624 1637 RTUtf16Free(pwszData); … … 2144 2157 AssertRCReturn(rc, 1); 2145 2158 2146 /*** ********/2159 /*** Utf-8 from X11 ***/ 2147 2160 RTPrintf(TEST_NAME ": TESTING reading Utf-8 from X11\n"); 2161 /* Simple test */ 2148 2162 clipSetSelectionValues("UTF8_STRING", XA_STRING, "hello world", 2149 2163 sizeof("hello world"), 8); 2150 2164 if (!testStringFromX11(pCtx, 256, "hello world", VINF_SUCCESS)) 2151 2165 ++cErrs; 2166 /* Receiving buffer of the exact size needed */ 2152 2167 if (!testStringFromX11(pCtx, sizeof("hello world") * 2, "hello world", 2153 2168 VINF_SUCCESS)) 2154 2169 ++cErrs; 2170 /* Buffer one too small */ 2155 2171 if (!testStringFromX11(pCtx, sizeof("hello world") * 2 - 1, "hello world", 2156 2172 VERR_BUFFER_OVERFLOW)) 2157 2173 ++cErrs; 2174 /* Zero-size buffer */ 2158 2175 if (!testStringFromX11(pCtx, 0, "hello world", VERR_BUFFER_OVERFLOW)) 2159 2176 ++cErrs; 2160 clipSetSelectionValues("UTF8_STRING", XA_STRING, "hello world\n", 2161 sizeof("hello world\n"), 8); 2162 if (!testStringFromX11(pCtx, sizeof("hello world\r\n") * 2, 2163 "hello world\r\n", VINF_SUCCESS)) 2164 ++cErrs; 2165 clipSetSelectionValues("UTF8_STRING", XA_STRING, "", 2177 /* With an embedded carriage return */ 2178 clipSetSelectionValues("text/plain;charset=UTF-8", XA_STRING, 2179 "hello\nworld", sizeof("hello\nworld"), 8); 2180 if (!testStringFromX11(pCtx, sizeof("hello\r\nworld") * 2, 2181 "hello\r\nworld", VINF_SUCCESS)) 2182 ++cErrs; 2183 /* An empty string */ 2184 clipSetSelectionValues("text/plain;charset=utf-8", XA_STRING, "", 2166 2185 sizeof(""), 8); 2167 2186 if (!testStringFromX11(pCtx, sizeof("") * 2, "", VINF_SUCCESS)) 2168 2187 ++cErrs; 2169 /* This next one is Utf-8 only. */2170 clipSetSelectionValues(" UTF8_STRING", XA_STRING,2188 /* With an embedded Utf-8 character. */ 2189 clipSetSelectionValues("STRING", XA_STRING, 2171 2190 "100\xE2\x82\xAC" /* 100 Euro */, 2172 2191 sizeof("100\xE2\x82\xAC"), 8); … … 2174 2193 "100\xE2\x82\xAC", VINF_SUCCESS)) 2175 2194 ++cErrs; 2176 2177 /***********/ 2195 /* A non-zero-terminated string */ 2196 clipSetSelectionValues("TEXT", XA_STRING, 2197 "hello world", sizeof("hello world") - 2, 8); 2198 if (!testStringFromX11(pCtx, sizeof("hello world") * 2 - 2, 2199 "hello worl", VINF_SUCCESS)) 2200 ++cErrs; 2201 2202 /*** COMPOUND TEXT from X11 ***/ 2178 2203 RTPrintf(TEST_NAME ": TESTING reading compound text from X11\n"); 2204 /* Simple test */ 2179 2205 clipSetSelectionValues("COMPOUND_TEXT", XA_STRING, "hello world", 2180 2206 sizeof("hello world"), 8); 2181 2207 if (!testStringFromX11(pCtx, 256, "hello world", VINF_SUCCESS)) 2182 2208 ++cErrs; 2209 /* Receiving buffer of the exact size needed */ 2183 2210 if (!testStringFromX11(pCtx, sizeof("hello world") * 2, "hello world", 2184 2211 VINF_SUCCESS)) 2185 2212 ++cErrs; 2213 /* Buffer one too small */ 2186 2214 if (!testStringFromX11(pCtx, sizeof("hello world") * 2 - 1, "hello world", 2187 2215 VERR_BUFFER_OVERFLOW)) 2188 2216 ++cErrs; 2217 /* Zero-size buffer */ 2189 2218 if (!testStringFromX11(pCtx, 0, "hello world", VERR_BUFFER_OVERFLOW)) 2190 2219 ++cErrs; 2191 clipSetSelectionValues("COMPOUND_TEXT", XA_STRING, "hello world\n", 2192 sizeof("hello world\n"), 8); 2193 if (!testStringFromX11(pCtx, sizeof("hello world\r\n") * 2, 2194 "hello world\r\n", VINF_SUCCESS)) 2195 ++cErrs; 2220 /* With an embedded carriage return */ 2221 clipSetSelectionValues("COMPOUND_TEXT", XA_STRING, "hello\nworld", 2222 sizeof("hello\nworld"), 8); 2223 if (!testStringFromX11(pCtx, sizeof("hello\r\nworld") * 2, 2224 "hello\r\nworld", VINF_SUCCESS)) 2225 ++cErrs; 2226 /* An empty string */ 2196 2227 clipSetSelectionValues("COMPOUND_TEXT", XA_STRING, "", 2197 2228 sizeof(""), 8); 2198 2229 if (!testStringFromX11(pCtx, sizeof("") * 2, "", VINF_SUCCESS)) 2199 2230 ++cErrs; 2200 2201 /***********/ 2231 /* A non-zero-terminated string */ 2232 clipSetSelectionValues("COMPOUND_TEXT", XA_STRING, 2233 "hello world", sizeof("hello world") - 2, 8); 2234 if (!testStringFromX11(pCtx, sizeof("hello world") * 2 - 2, 2235 "hello worl", VINF_SUCCESS)) 2236 ++cErrs; 2237 2238 /*** Latin1 from X11 ***/ 2202 2239 RTPrintf(TEST_NAME ": TESTING reading Latin1 from X11\n"); 2240 /* Simple test */ 2203 2241 clipSetSelectionValues("STRING", XA_STRING, "Georges Dupr\xEA", 2204 2242 sizeof("Georges Dupr\xEA"), 8); 2205 2243 if (!testLatin1FromX11(pCtx, 256, "Georges Dupr\xEA", VINF_SUCCESS)) 2206 2244 ++cErrs; 2245 /* Receiving buffer of the exact size needed */ 2207 2246 if (!testLatin1FromX11(pCtx, sizeof("Georges Dupr\xEA") * 2, 2208 2247 "Georges Dupr\xEA", VINF_SUCCESS)) 2209 2248 ++cErrs; 2249 /* Buffer one too small */ 2210 2250 if (!testLatin1FromX11(pCtx, sizeof("Georges Dupr\xEA") * 2 - 1, 2211 2251 "Georges Dupr\xEA", VERR_BUFFER_OVERFLOW)) 2212 2252 ++cErrs; 2253 /* Zero-size buffer */ 2213 2254 if (!testLatin1FromX11(pCtx, 0, "Georges Dupr\xEA", VERR_BUFFER_OVERFLOW)) 2214 2255 ++cErrs; 2215 clipSetSelectionValues("TEXT", XA_STRING, "Georges Dupr\xEA\n", 2216 sizeof("Georges Dupr\xEA\n"), 8); 2217 if (!testLatin1FromX11(pCtx, sizeof("Georges Dupr\xEA\r\n") * 2, 2218 "Georges Dupr\xEA\r\n", VINF_SUCCESS)) 2219 ++cErrs; 2220 2221 /***********/ 2256 /* With an embedded carriage return */ 2257 clipSetSelectionValues("TEXT", XA_STRING, "Georges\nDupr\xEA", 2258 sizeof("Georges\nDupr\xEA"), 8); 2259 if (!testLatin1FromX11(pCtx, sizeof("Georges\r\nDupr\xEA") * 2, 2260 "Georges\r\nDupr\xEA", VINF_SUCCESS)) 2261 ++cErrs; 2262 /* A non-zero-terminated string */ 2263 clipSetSelectionValues("text/plain", XA_STRING, 2264 "Georges Dupr\xEA!", 2265 sizeof("Georges Dupr\xEA!") - 2, 8); 2266 if (!testLatin1FromX11(pCtx, sizeof("Georges Dupr\xEA!") * 2 - 2, 2267 "Georges Dupr\xEA", VINF_SUCCESS)) 2268 ++cErrs; 2269 2270 2271 /*** Timeout from X11 ***/ 2222 2272 RTPrintf(TEST_NAME ": TESTING X11 timeout\n"); 2223 2273 clipSetSelectionValues("UTF8_STRING", XT_CONVERT_FAIL, "hello world", … … 2226 2276 ++cErrs; 2227 2277 2228 /*** ********/2278 /*** No data in X11 clipboard ***/ 2229 2279 RTPrintf(TEST_NAME ": TESTING a data request from an empty X11 clipboard\n"); 2230 2280 clipSetSelectionValues("UTF8_STRING", XA_STRING, NULL, … … 2239 2289 } 2240 2290 2241 /*** ********/2291 /*** request for an invalid VBox format from X11 ***/ 2242 2292 RTPrintf(TEST_NAME ": TESTING a request for an invalid host format from X11\n"); 2243 2293 rc = VBoxX11ClipboardReadX11Data(pCtx, 0xffff, (void *) pc, … … 2249 2299 } 2250 2300 2251 /*** ********/2301 /*** Utf-8 from VBox ***/ 2252 2302 RTPrintf(TEST_NAME ": TESTING reading Utf-8 from VBox\n"); 2253 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello world"); 2303 /* Simple test */ 2304 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello world", 2305 sizeof("hello world") * 2); 2254 2306 if (!testStringFromVBox(pCtx, "UTF8_STRING", 2255 2307 clipGetAtom(NULL, "UTF8_STRING"), 2256 2308 "hello world", sizeof("hello world"), 8)) 2257 2309 ++cErrs; 2258 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello world\r\n"); 2259 if (!testStringFromVBox(pCtx, "UTF8_STRING", 2260 clipGetAtom(NULL, "UTF8_STRING"), 2261 "hello world\n", sizeof("hello world\n"), 8)) 2262 ++cErrs; 2263 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, ""); 2264 if (!testStringFromVBox(pCtx, "UTF8_STRING", 2265 clipGetAtom(NULL, "UTF8_STRING"), 2310 /* With an embedded carriage return */ 2311 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello\r\nworld", 2312 sizeof("hello\r\nworld") * 2); 2313 if (!testStringFromVBox(pCtx, "text/plain;charset=UTF-8", 2314 clipGetAtom(NULL, "text/plain;charset=UTF-8"), 2315 "hello\nworld", sizeof("hello\nworld"), 8)) 2316 ++cErrs; 2317 /* An empty string */ 2318 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "", 2); 2319 if (!testStringFromVBox(pCtx, "text/plain;charset=utf-8", 2320 clipGetAtom(NULL, "text/plain;charset=utf-8"), 2266 2321 "", sizeof(""), 8)) 2267 2322 ++cErrs; 2268 /* This next one is Utf-8 only. */ 2269 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "100\xE2\x82\xAC" /* 100 Euro */); 2270 if (!testStringFromVBox(pCtx, "UTF8_STRING", 2271 clipGetAtom(NULL, "UTF8_STRING"), 2323 /* With an embedded Utf-8 character. */ 2324 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "100\xE2\x82\xAC" /* 100 Euro */, 2325 10); 2326 if (!testStringFromVBox(pCtx, "STRING", 2327 clipGetAtom(NULL, "STRING"), 2272 2328 "100\xE2\x82\xAC", sizeof("100\xE2\x82\xAC"), 8)) 2273 2329 ++cErrs; 2274 2275 /***********/ 2330 /* A non-zero-terminated string */ 2331 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello world", 2332 sizeof("hello world") * 2 - 4); 2333 if (!testStringFromVBox(pCtx, "TEXT", 2334 clipGetAtom(NULL, "TEXT"), 2335 "hello worl", sizeof("hello worl"), 8)) 2336 ++cErrs; 2337 2338 /*** COMPOUND TEXT from VBox ***/ 2276 2339 RTPrintf(TEST_NAME ": TESTING reading COMPOUND TEXT from VBox\n"); 2277 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello world"); 2340 /* Simple test */ 2341 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello world", 2342 sizeof("hello world") * 2); 2278 2343 if (!testStringFromVBox(pCtx, "COMPOUND_TEXT", 2279 2344 clipGetAtom(NULL, "COMPOUND_TEXT"), 2280 2345 "hello world", sizeof("hello world"), 8)) 2281 2346 ++cErrs; 2282 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello world\r\n"); 2347 /* With an embedded carriage return */ 2348 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello\r\nworld", 2349 sizeof("hello\r\nworld") * 2); 2283 2350 if (!testStringFromVBox(pCtx, "COMPOUND_TEXT", 2284 2351 clipGetAtom(NULL, "COMPOUND_TEXT"), 2285 "hello world\n", sizeof("hello world\n"), 8)) 2286 ++cErrs; 2287 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, ""); 2352 "hello\nworld", sizeof("hello\nworld"), 8)) 2353 ++cErrs; 2354 /* An empty string */ 2355 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "", 2); 2288 2356 if (!testStringFromVBox(pCtx, "COMPOUND_TEXT", 2289 2357 clipGetAtom(NULL, "COMPOUND_TEXT"), 2290 2358 "", sizeof(""), 8)) 2291 2359 ++cErrs; 2292 2293 /***********/ 2360 /* A non-zero-terminated string */ 2361 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello world", 2362 sizeof("hello world") * 2 - 4); 2363 if (!testStringFromVBox(pCtx, "COMPOUND_TEXT", 2364 clipGetAtom(NULL, "COMPOUND_TEXT"), 2365 "hello worl", sizeof("hello worl"), 8)) 2366 ++cErrs; 2367 2368 /*** Timeout from VBox ***/ 2294 2369 RTPrintf(TEST_NAME ": TESTING reading from VBox with timeout\n"); 2295 2370 clipEmptyVBox(pCtx, VERR_TIMEOUT); … … 2297 2372 ++cErrs; 2298 2373 2299 /*** ********/2374 /*** No data in VBox clipboard ***/ 2300 2375 RTPrintf(TEST_NAME ": TESTING reading from VBox with no data\n"); 2301 2376 clipEmptyVBox(pCtx, VINF_SUCCESS);
Note:
See TracChangeset
for help on using the changeset viewer.