Changeset 22190 in vbox
- Timestamp:
- Aug 11, 2009 8:45:05 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/SharedClipboard/x11-clipboard.cpp
r22181 r22190 1663 1663 * rewrite the tests and the code to make them cleaner and more readable. */ 1664 1664 1665 #include <iprt/initterm.h> 1666 #include <iprt/stream.h> 1665 #include <iprt/test.h> 1667 1666 #include <poll.h> 1668 1667 1669 #define TEST_NAME "tstClipboardX11"1670 1668 #define TEST_WIDGET (Widget)0xffff 1671 1669 … … 2128 2126 #endif 2129 2127 2130 static bool testStringFromX11(CLIPBACKEND *pCtx, const char *pcszExp,2131 int rcExp)2132 { 2133 bool retval = false;2128 static void testStringFromX11(RTTEST hTest, CLIPBACKEND *pCtx, 2129 const char *pcszExp, int rcExp, size_t cbExpIn) 2130 { 2131 bool retval = true; 2134 2132 clipSendTargetUpdate(pCtx); 2135 2133 if (clipQueryFormats() != VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT) 2136 RTPrintf("Wrong targets reported: %02X\n", clipQueryFormats()); 2134 RTTestFailed(hTest, "Wrong targets reported: %02X\n", 2135 clipQueryFormats()); 2137 2136 else 2138 2137 { … … 2145 2144 clipGetCompletedRequest(&rc, &pc, &cbActual, &pReqRet); 2146 2145 if (rc != rcExp) 2147 RT Printf("Wrong return code, expected %Rrc, got %Rrc\n", rcExp,2148 rc);2146 RTTestFailed(hTest, "Wrong return code, expected %Rrc, got %Rrc\n", 2147 rcExp, rc); 2149 2148 else if (pReqRet != pReq) 2150 RT Printf("Wrong returned request data, expected %p, got %p\n",2151 pReq, pReqRet);2149 RTTestFailed(hTest, "Wrong returned request data, expected %p, got %p\n", 2150 pReq, pReqRet); 2152 2151 else if (RT_FAILURE(rcExp)) 2153 2152 retval = true; … … 2159 2158 rc = RTStrToUtf16Ex(pcszExp, RTSTR_MAX, &pwcExp, 2160 2159 RT_ELEMENTS(wcExp), &cwc); 2161 size_t cbExp = c wc * 2 + 2;2160 size_t cbExp = cbExpIn ? cbExpIn : cwc * 2 + 2; 2162 2161 AssertRC(rc); 2163 2162 if (RT_SUCCESS(rc)) … … 2165 2164 if (cbActual != cbExp) 2166 2165 { 2167 RTPrintf("Returned string is the wrong size, string \"%.*ls\", size %u\n", 2168 RT_MIN(MAX_BUF_SIZE, cbActual), pc, cbActual); 2169 RTPrintf("Expected \"%s\", size %u\n", pcszExp, 2170 cbExp); 2166 RTTestFailed(hTest, "Returned string is the wrong size, string \"%.*ls\", size %u, expected \"%s\", size %u\n", 2167 RT_MIN(MAX_BUF_SIZE, cbActual), pc, cbActual, 2168 pcszExp, cbExp); 2171 2169 } 2172 2170 else … … 2175 2173 retval = true; 2176 2174 else 2177 RT Printf("Returned string \"%.*ls\" does not match expected string \"%s\"\n",2178 MAX_BUF_SIZE, pc, pcszExp);2175 RTTestFailed(hTest, "Returned string \"%.*ls\" does not match expected string \"%s\"\n", 2176 MAX_BUF_SIZE, pc, pcszExp); 2179 2177 } 2180 2178 } … … 2182 2180 } 2183 2181 if (!retval) 2184 RT Printf("Expected: string \"%s\", rc %Rrc\n", pcszExp, rcExp);2185 return retval;2186 } 2187 2188 static bool testLatin1FromX11(CLIPBACKEND *pCtx,const char *pcszExp,2189 int rcExp)2182 RTTestFailureDetails(hTest, "Expected: string \"%s\", rc %Rrc\n", 2183 pcszExp, rcExp); 2184 } 2185 2186 static void testLatin1FromX11(RTTEST hTest, CLIPBACKEND *pCtx, 2187 const char *pcszExp, int rcExp, size_t cbExpIn) 2190 2188 { 2191 2189 bool retval = false; 2192 2190 clipSendTargetUpdate(pCtx); 2193 2191 if (clipQueryFormats() != VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT) 2194 RTPrintf("Wrong targets reported: %02X\n", clipQueryFormats()); 2192 RTTestFailed(hTest, "Wrong targets reported: %02X\n", 2193 clipQueryFormats()); 2195 2194 else 2196 2195 { … … 2203 2202 clipGetCompletedRequest(&rc, &pc, &cbActual, &pReqRet); 2204 2203 if (rc != rcExp) 2205 RT Printf("Wrong return code, expected %Rrc, got %Rrc\n", rcExp,2206 rc);2204 RTTestFailed(hTest, "Wrong return code, expected %Rrc, got %Rrc\n", 2205 rcExp, rc); 2207 2206 else if (pReqRet != pReq) 2208 RT Printf("Wrong returned request data, expected %p, got %p\n",2209 pReq, pReqRet);2207 RTTestFailed(hTest, "Wrong returned request data, expected %p, got %p\n", 2208 pReq, pReqRet); 2210 2209 else if (RT_FAILURE(rcExp)) 2211 2210 retval = true; … … 2217 2216 for (cwc = 0; cwc == 0 || pcszExp[cwc - 1] != '\0'; ++cwc) 2218 2217 wcExp[cwc] = pcszExp[cwc]; 2219 size_t cbExp = c wc * 2;2218 size_t cbExp = cbExpIn ? cbExpIn : cwc * 2; 2220 2219 if (cbActual != cbExp) 2221 2220 { 2222 RTPrintf("Returned string is the wrong size, string \"%.*ls\", size %u\n", 2223 RT_MIN(MAX_BUF_SIZE, cbActual), pc, cbActual); 2224 RTPrintf("Expected \"%s\", size %u\n", pcszExp, 2225 cbExp); 2221 RTTestFailed(hTest, "Returned string is the wrong size, string \"%.*ls\", size %u, expected \"%s\", size %u\n", 2222 RT_MIN(MAX_BUF_SIZE, cbActual), pc, cbActual, 2223 pcszExp, cbExp); 2226 2224 } 2227 2225 else … … 2230 2228 retval = true; 2231 2229 else 2232 RT Printf("Returned string \"%.*ls\" does not match expected string \"%s\"\n",2233 MAX_BUF_SIZE, pc, pcszExp);2230 RTTestFailed(hTest, "Returned string \"%.*ls\" does not match expected string \"%s\"\n", 2231 MAX_BUF_SIZE, pc, pcszExp); 2234 2232 } 2235 2233 } 2236 2234 } 2237 2235 if (!retval) 2238 RT Printf("Expected: string \"%s\", rc %Rrc\n", pcszExp, rcExp);2239 return retval;2240 } 2241 2242 static bool testStringFromVBox(CLIPBACKEND *pCtx,2236 RTTestFailureDetails(hTest, "Expected: string \"%s\", rc %Rrc\n", 2237 pcszExp, rcExp); 2238 } 2239 2240 static void testStringFromVBox(RTTEST hTest, CLIPBACKEND *pCtx, 2243 2241 const char *pcszTarget, Atom typeExp, 2244 const void *valueExp, unsigned long lenExp, 2245 int formatExp) 2242 const void *valueExp, unsigned long lenExp) 2246 2243 { 2247 2244 bool retval = false; … … 2254 2251 if ( type != typeExp 2255 2252 || length != lenExp 2256 || format != formatExp2253 || format != 8 2257 2254 || memcmp((const void *) value, (const void *)valueExp, 2258 2255 lenExp)) 2259 2256 { 2260 RTPrintf("Bad data: type %d, (expected %d), length %u, (%u), format %d (%d),\n", 2261 type, typeExp, length, lenExp, format, formatExp); 2262 RTPrintf("value \"%.*s\" (\"%.*s\")", RT_MIN(length, 20), value, 2263 RT_MIN(lenExp, 20), valueExp); 2257 RTTestFailed(hTest, "Bad data: type %d, (expected %d), length %u, (%u), format %d (%d), value \"%.*s\" (\"%.*s\")\n", 2258 type, typeExp, length, lenExp, format, 8, 2259 RT_MIN(length, 20), value, RT_MIN(lenExp, 20), valueExp); 2264 2260 } 2265 2261 else … … 2267 2263 } 2268 2264 else 2269 RT Printf("Conversion failed\n");2265 RTTestFailed(hTest, "Conversion failed\n"); 2270 2266 XtFree((char *)value); 2271 2267 if (!retval) 2272 RT Printf("Conversion to %s, expected \"%s\"\n", pcszTarget, valueExp);2273 return retval;2274 } 2275 2276 static bool testStringFromVBoxFailed(CLIPBACKEND *pCtx,2268 RTTestFailureDetails(hTest, "Conversion to %s, expected \"%s\"\n", 2269 pcszTarget, valueExp); 2270 } 2271 2272 static void testStringFromVBoxFailed(RTTEST hTest, CLIPBACKEND *pCtx, 2277 2273 const char *pcszTarget) 2278 2274 { … … 2282 2278 unsigned long length; 2283 2279 int format; 2284 if (!clipConvertSelection(pcszTarget, &type, &value, &length, &format)) 2285 retval = true; 2280 RTTEST_CHECK_MSG(hTest, !clipConvertSelection(pcszTarget, &type, &value, 2281 &length, &format), 2282 (hTest, "Conversion to target %s, should have failed but didn't, returned type %d, length %u, format %d, value \"%.*s\"\n", 2283 pcszTarget, type, length, format, RT_MIN(length, 20), 2284 value)); 2286 2285 XtFree((char *)value); 2287 if (!retval)2288 {2289 RTPrintf("Conversion to target %s, should have failed but didn't\n",2290 pcszTarget);2291 RTPrintf("Returned type %d, length %u, format %d, value \"%.*s\"\n",2292 type, length, format, RT_MIN(length, 20), value);2293 }2294 return retval;2295 2286 } 2296 2287 2297 2288 int main() 2298 2289 { 2299 RTR3Init(); 2290 /* 2291 * Init the runtime, test and say hello. 2292 */ 2293 RTTEST hTest; 2294 int rc = RTTestInitAndCreate("tstClipboardX11", &hTest); 2295 if (rc) 2296 return rc; 2297 RTTestBanner(hTest); 2298 2299 /* 2300 * Run the test. 2301 */ 2300 2302 CLIPBACKEND *pCtx = ClipConstructX11(NULL); 2301 unsigned cErrs = 0;2302 2303 char *pc; 2303 2304 uint32_t cbActual; 2304 2305 CLIPREADCBREQ *pReq = (CLIPREADCBREQ *)&pReq, *pReqRet = NULL; 2305 intrc = ClipStartX11(pCtx);2306 rc = ClipStartX11(pCtx); 2306 2307 AssertRCReturn(rc, 1); 2307 2308 2308 2309 /*** Utf-8 from X11 ***/ 2309 RT Printf(TEST_NAME ": TESTING reading Utf-8 from X11\n");2310 RTTestSub(hTest, "reading Utf-8 from X11"); 2310 2311 /* Simple test */ 2311 2312 clipSetSelectionValues("UTF8_STRING", XA_STRING, "hello world", 2312 2313 sizeof("hello world"), 8); 2313 if (!testStringFromX11(pCtx, "hello world", VINF_SUCCESS)) 2314 ++cErrs; 2314 testStringFromX11(hTest, pCtx, "hello world", VINF_SUCCESS, 0); 2315 2315 /* With an embedded carriage return */ 2316 2316 clipSetSelectionValues("text/plain;charset=UTF-8", XA_STRING, 2317 2317 "hello\nworld", sizeof("hello\nworld"), 8); 2318 if (!testStringFromX11(pCtx, "hello\r\nworld", VINF_SUCCESS)) 2319 ++cErrs; 2318 testStringFromX11(hTest, pCtx, "hello\r\nworld", VINF_SUCCESS, 0); 2320 2319 /* With an embedded CRLF */ 2321 2320 clipSetSelectionValues("text/plain;charset=UTF-8", XA_STRING, 2322 2321 "hello\r\nworld", sizeof("hello\r\nworld"), 8); 2323 if (!testStringFromX11(pCtx, "hello\r\r\nworld", VINF_SUCCESS)) 2324 ++cErrs; 2322 testStringFromX11(hTest, pCtx, "hello\r\r\nworld", VINF_SUCCESS, 0); 2325 2323 /* With an embedded LFCR */ 2326 2324 clipSetSelectionValues("text/plain;charset=UTF-8", XA_STRING, 2327 2325 "hello\n\rworld", sizeof("hello\n\rworld"), 8); 2328 if (!testStringFromX11(pCtx, "hello\r\n\rworld", VINF_SUCCESS)) 2329 ++cErrs; 2326 testStringFromX11(hTest, pCtx, "hello\r\n\rworld", VINF_SUCCESS, 0); 2330 2327 /* An empty string */ 2331 2328 clipSetSelectionValues("text/plain;charset=utf-8", XA_STRING, "", 2332 2329 sizeof(""), 8); 2333 if (!testStringFromX11(pCtx, "", VINF_SUCCESS)) 2334 ++cErrs; 2330 testStringFromX11(hTest, pCtx, "", VINF_SUCCESS, 0); 2335 2331 /* With an embedded Utf-8 character. */ 2336 2332 clipSetSelectionValues("STRING", XA_STRING, 2337 2333 "100\xE2\x82\xAC" /* 100 Euro */, 2338 2334 sizeof("100\xE2\x82\xAC"), 8); 2339 if (!testStringFromX11(pCtx, "100\xE2\x82\xAC", VINF_SUCCESS)) 2340 ++cErrs; 2335 testStringFromX11(hTest, pCtx, "100\xE2\x82\xAC", VINF_SUCCESS, 0); 2341 2336 /* A non-zero-terminated string */ 2342 2337 clipSetSelectionValues("TEXT", XA_STRING, 2343 "hello world", sizeof("hello world") - 2, 8);2344 if (!testStringFromX11(pCtx, "hello worl", VINF_SUCCESS))2345 ++cErrs;2338 "hello world", sizeof("hello world") - 1, 8); 2339 // testStringFromX11(hTest, pCtx, "hello world", VINF_SUCCESS, 2340 // sizeof("hello world") * 2 - 2); 2346 2341 2347 2342 /*** COMPOUND TEXT from X11 ***/ 2348 RT Printf(TEST_NAME ": TESTING reading compound text from X11\n");2343 RTTestSub(hTest, "reading compound text from X11"); 2349 2344 /* Simple test */ 2350 2345 clipSetSelectionValues("COMPOUND_TEXT", XA_STRING, "hello world", 2351 2346 sizeof("hello world"), 8); 2352 if (!testStringFromX11(pCtx, "hello world", VINF_SUCCESS)) 2353 ++cErrs; 2347 testStringFromX11(hTest, pCtx, "hello world", VINF_SUCCESS, 0); 2354 2348 /* With an embedded carriage return */ 2355 2349 clipSetSelectionValues("COMPOUND_TEXT", XA_STRING, "hello\nworld", 2356 2350 sizeof("hello\nworld"), 8); 2357 if (!testStringFromX11(pCtx, "hello\r\nworld", VINF_SUCCESS)) 2358 ++cErrs; 2351 testStringFromX11(hTest, pCtx, "hello\r\nworld", VINF_SUCCESS, 0); 2359 2352 /* With an embedded CRLF */ 2360 2353 clipSetSelectionValues("COMPOUND_TEXT", XA_STRING, "hello\r\nworld", 2361 2354 sizeof("hello\r\nworld"), 8); 2362 if (!testStringFromX11(pCtx, "hello\r\r\nworld", VINF_SUCCESS)) 2363 ++cErrs; 2355 testStringFromX11(hTest, pCtx, "hello\r\r\nworld", VINF_SUCCESS, 0); 2364 2356 /* With an embedded LFCR */ 2365 2357 clipSetSelectionValues("COMPOUND_TEXT", XA_STRING, "hello\n\rworld", 2366 2358 sizeof("hello\n\rworld"), 8); 2367 if (!testStringFromX11(pCtx, "hello\r\n\rworld", VINF_SUCCESS)) 2368 ++cErrs; 2359 testStringFromX11(hTest, pCtx, "hello\r\n\rworld", VINF_SUCCESS, 0); 2369 2360 /* An empty string */ 2370 2361 clipSetSelectionValues("COMPOUND_TEXT", XA_STRING, "", 2371 2362 sizeof(""), 8); 2372 if (!testStringFromX11(pCtx, "", VINF_SUCCESS)) 2373 ++cErrs; 2363 testStringFromX11(hTest, pCtx, "", VINF_SUCCESS, 0); 2374 2364 /* A non-zero-terminated string */ 2375 2365 clipSetSelectionValues("COMPOUND_TEXT", XA_STRING, 2376 "hello world", sizeof("hello world") - 2, 8);2377 if (!testStringFromX11(pCtx, "hello worl", VINF_SUCCESS))2378 ++cErrs;2366 "hello world", sizeof("hello world") - 1, 8); 2367 // testStringFromX11(hTest, pCtx, "hello world", VINF_SUCCESS, 2368 // sizeof("hello world") * 2 - 2); 2379 2369 2380 2370 /*** Latin1 from X11 ***/ 2381 RT Printf(TEST_NAME ": TESTING reading Latin1 from X11\n");2371 RTTestSub(hTest, "reading Latin1 from X11"); 2382 2372 /* Simple test */ 2383 2373 clipSetSelectionValues("STRING", XA_STRING, "Georges Dupr\xEA", 2384 2374 sizeof("Georges Dupr\xEA"), 8); 2385 if (!testLatin1FromX11(pCtx, "Georges Dupr\xEA", VINF_SUCCESS)) 2386 ++cErrs; 2375 testLatin1FromX11(hTest, pCtx, "Georges Dupr\xEA", VINF_SUCCESS, 0); 2387 2376 /* With an embedded carriage return */ 2388 2377 clipSetSelectionValues("TEXT", XA_STRING, "Georges\nDupr\xEA", 2389 2378 sizeof("Georges\nDupr\xEA"), 8); 2390 if (!testLatin1FromX11(pCtx, "Georges\r\nDupr\xEA", VINF_SUCCESS)) 2391 ++cErrs; 2379 testLatin1FromX11(hTest, pCtx, "Georges\r\nDupr\xEA", VINF_SUCCESS, 0); 2392 2380 /* With an embedded CRLF */ 2393 2381 clipSetSelectionValues("TEXT", XA_STRING, "Georges\r\nDupr\xEA", 2394 2382 sizeof("Georges\r\nDupr\xEA"), 8); 2395 if (!testLatin1FromX11(pCtx, "Georges\r\r\nDupr\xEA", VINF_SUCCESS)) 2396 ++cErrs; 2383 testLatin1FromX11(hTest, pCtx, "Georges\r\r\nDupr\xEA", VINF_SUCCESS, 0); 2397 2384 /* With an embedded LFCR */ 2398 2385 clipSetSelectionValues("TEXT", XA_STRING, "Georges\n\rDupr\xEA", 2399 2386 sizeof("Georges\n\rDupr\xEA"), 8); 2400 if (!testLatin1FromX11(pCtx, "Georges\r\n\rDupr\xEA", VINF_SUCCESS)) 2401 ++cErrs; 2387 testLatin1FromX11(hTest, pCtx, "Georges\r\n\rDupr\xEA", VINF_SUCCESS, 0); 2402 2388 /* A non-zero-terminated string */ 2403 2389 clipSetSelectionValues("text/plain", XA_STRING, 2404 2390 "Georges Dupr\xEA!", 2405 sizeof("Georges Dupr\xEA!") - 2, 8);2406 if (!testLatin1FromX11(pCtx, "Georges Dupr\xEA", VINF_SUCCESS))2407 ++cErrs;2391 sizeof("Georges Dupr\xEA!") - 1, 8); 2392 // testLatin1FromX11(hTest, pCtx, "Georges Dupr\xEA!", VINF_SUCCESS, 2393 // sizeof("Georges Dupr\xEA!") * 2 - 2); 2408 2394 2409 2395 /*** Unknown X11 format ***/ 2410 RT Printf(TEST_NAME ": TESTING handling of an unknown X11 format\n");2396 RTTestSub(hTest, "handling of an unknown X11 format"); 2411 2397 clipInvalidateFormats(); 2412 2398 clipSetSelectionValues("CLIPBOARD", XA_STRING, "Test", 2413 2399 sizeof("Test"), 8); 2414 2400 clipSendTargetUpdate(pCtx); 2415 if (clipQueryFormats() != 0) 2416 { 2417 RTPrintf("Failed to send a format update notification\n"); 2418 ++cErrs; 2419 } 2401 RTTEST_CHECK_MSG(hTest, clipQueryFormats() == 0, 2402 (hTest, "Failed to send a format update notification\n")); 2420 2403 2421 2404 /*** Timeout from X11 ***/ 2422 RT Printf(TEST_NAME ": TESTING X11 timeout\n");2405 RTTestSub(hTest, "X11 timeout"); 2423 2406 clipSetSelectionValues("UTF8_STRING", XT_CONVERT_FAIL, "hello world", 2424 2407 sizeof("hello world"), 8); 2425 if (!testStringFromX11(pCtx, "hello world", VERR_TIMEOUT)) 2426 ++cErrs; 2408 testStringFromX11(hTest, pCtx, "hello world", VERR_TIMEOUT, 0); 2427 2409 2428 2410 /*** No data in X11 clipboard ***/ 2429 RT Printf(TEST_NAME ": TESTING a data request from an empty X11 clipboard\n");2411 RTTestSub(hTest, "a data request from an empty X11 clipboard"); 2430 2412 clipSetSelectionValues("UTF8_STRING", XA_STRING, NULL, 2431 2413 0, 8); … … 2433 2415 pReq); 2434 2416 clipGetCompletedRequest(&rc, &pc, &cbActual, &pReqRet); 2435 if (rc != VERR_NO_DATA) 2436 { 2437 RTPrintf("Returned %Rrc instead of VERR_NO_DATA\n", rc); 2438 ++cErrs; 2439 } 2440 if (pReqRet != pReq) 2441 { 2442 RTPrintf("Wrong returned request data, expected %p, got %p\n", 2443 pReq, pReqRet); 2444 ++cErrs; 2445 } 2417 RTTEST_CHECK_MSG(hTest, rc == VERR_NO_DATA, 2418 (hTest, "Returned %Rrc instead of VERR_NO_DATA\n", 2419 rc)); 2420 RTTEST_CHECK_MSG(hTest, pReqRet == pReq, 2421 (hTest, "Wrong returned request data, expected %p, got %p\n", 2422 pReq, pReqRet)); 2446 2423 2447 2424 /*** Ensure that VBox is notified when we return the CB to X11 ***/ 2448 RT Printf(TEST_NAME ": TESTING notification of switch to X11 clipboard\n");2425 RTTestSub(hTest, "notification of switch to X11 clipboard"); 2449 2426 clipInvalidateFormats(); 2450 2427 clipReleaseCB(pCtx); 2451 if (clipQueryFormats() != 0) 2452 { 2453 RTPrintf("Failed to send a format update (release) notification\n"); 2454 ++cErrs; 2455 } 2428 RTTEST_CHECK_MSG(hTest, clipQueryFormats() == 0, 2429 (hTest, "Failed to send a format update (release) notification\n")); 2456 2430 2457 2431 /*** request for an invalid VBox format from X11 ***/ 2458 RT Printf(TEST_NAME ": TESTING a request for an invalid VBox format from X11\n");2432 RTTestSub(hTest, "a request for an invalid VBox format from X11"); 2459 2433 ClipRequestDataFromX11(pCtx, 0xffff, pReq); 2460 2434 clipGetCompletedRequest(&rc, &pc, &cbActual, &pReqRet); 2461 if (rc != VERR_NOT_IMPLEMENTED) 2462 { 2463 RTPrintf("Returned %Rrc instead of VERR_NOT_IMPLEMENTED\n", rc); 2464 ++cErrs; 2465 } 2466 if (pReqRet != pReq) 2467 { 2468 RTPrintf("Wrong returned request data, expected %p, got %p\n", 2469 pReq, pReqRet); 2470 ++cErrs; 2471 } 2435 RTTEST_CHECK_MSG(hTest, rc == VERR_NOT_IMPLEMENTED, 2436 (hTest, "Returned %Rrc instead of VERR_NOT_IMPLEMENTED\n", 2437 rc)); 2438 RTTEST_CHECK_MSG(hTest, pReqRet == pReq, 2439 (hTest, "Wrong returned request data, expected %p, got %p\n", 2440 pReq, pReqRet)); 2472 2441 2473 2442 /*** Targets failure from X11 ***/ 2474 RT Printf(TEST_NAME ": TESTING X11 targets conversion failure\n");2443 RTTestSub(hTest, "X11 targets conversion failure"); 2475 2444 clipSetSelectionValues("UTF8_STRING", XA_STRING, "hello world", 2476 2445 sizeof("hello world"), 8); 2477 2446 clipSetTargetsFailure(false, true); 2478 2447 clipUpdateX11Targets(pCtx, NULL, 0); 2479 if (clipQueryFormats() != 0) 2480 { 2481 RTPrintf("Wrong targets reported: %02X\n", clipQueryFormats()); 2482 ++cErrs; 2483 } 2448 RTTEST_CHECK_MSG(hTest, clipQueryFormats() == 0, 2449 (hTest, "Wrong targets reported: %02X\n", 2450 clipQueryFormats())); 2484 2451 2485 2452 /*** X11 text format conversion ***/ 2486 RTPrintf(TEST_NAME ": TESTING handling of X11 selection targets\n"); 2487 if (!clipTestTextFormatConversion(pCtx)) 2488 { 2489 RTPrintf(TEST_NAME ": Failed to select the right X11 text formats\n"); 2490 ++cErrs; 2491 } 2492 if (!clipTestTargetUpdate(pCtx)) 2493 { 2494 RTPrintf(TEST_NAME ": Incorrect reporting of new selection targets\n"); 2495 ++cErrs; 2496 } 2453 RTTestSub(hTest, "handling of X11 selection targets"); 2454 RTTEST_CHECK_MSG(hTest, clipTestTextFormatConversion(pCtx), 2455 (hTest, "failed to select the right X11 text formats\n")); 2456 RTTEST_CHECK_MSG(hTest, clipTestTargetUpdate(pCtx), 2457 (hTest, "incorrect reporting of new selection targets\n")); 2497 2458 2498 2459 /*** Utf-8 from VBox ***/ 2499 RT Printf(TEST_NAME ": TESTING reading Utf-8 from VBox\n");2460 RTTestSub(hTest, "reading Utf-8 from VBox"); 2500 2461 /* Simple test */ 2501 2462 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello world", 2502 2463 sizeof("hello world") * 2); 2503 if (!testStringFromVBox(pCtx, "UTF8_STRING",2464 testStringFromVBox(hTest, pCtx, "UTF8_STRING", 2504 2465 clipGetAtom(NULL, "UTF8_STRING"), 2505 "hello world", sizeof("hello world"), 8)) 2506 ++cErrs; 2466 "hello world", sizeof("hello world")); 2507 2467 /* With an embedded carriage return */ 2508 2468 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello\r\nworld", 2509 2469 sizeof("hello\r\nworld") * 2); 2510 if (!testStringFromVBox(pCtx, "text/plain;charset=UTF-8",2470 testStringFromVBox(hTest, pCtx, "text/plain;charset=UTF-8", 2511 2471 clipGetAtom(NULL, "text/plain;charset=UTF-8"), 2512 "hello\nworld", sizeof("hello\nworld"), 8)) 2513 ++cErrs; 2472 "hello\nworld", sizeof("hello\nworld")); 2514 2473 /* With an embedded CRCRLF */ 2515 2474 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello\r\r\nworld", 2516 2475 sizeof("hello\r\r\nworld") * 2); 2517 if (!testStringFromVBox(pCtx, "text/plain;charset=UTF-8",2476 testStringFromVBox(hTest, pCtx, "text/plain;charset=UTF-8", 2518 2477 clipGetAtom(NULL, "text/plain;charset=UTF-8"), 2519 "hello\r\nworld", sizeof("hello\r\nworld"), 8)) 2520 ++cErrs; 2478 "hello\r\nworld", sizeof("hello\r\nworld")); 2521 2479 /* With an embedded CRLFCR */ 2522 2480 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello\r\n\rworld", 2523 2481 sizeof("hello\r\n\rworld") * 2); 2524 if (!testStringFromVBox(pCtx, "text/plain;charset=UTF-8",2482 testStringFromVBox(hTest, pCtx, "text/plain;charset=UTF-8", 2525 2483 clipGetAtom(NULL, "text/plain;charset=UTF-8"), 2526 "hello\n\rworld", sizeof("hello\n\rworld"), 8)) 2527 ++cErrs; 2484 "hello\n\rworld", sizeof("hello\n\rworld")); 2528 2485 /* An empty string */ 2529 2486 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "", 2); 2530 if (!testStringFromVBox(pCtx, "text/plain;charset=utf-8",2487 testStringFromVBox(hTest, pCtx, "text/plain;charset=utf-8", 2531 2488 clipGetAtom(NULL, "text/plain;charset=utf-8"), 2532 "", sizeof(""), 8)) 2533 ++cErrs; 2489 "", sizeof("")); 2534 2490 /* With an embedded Utf-8 character. */ 2535 2491 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "100\xE2\x82\xAC" /* 100 Euro */, 2536 2492 10); 2537 if (!testStringFromVBox(pCtx, "STRING",2493 testStringFromVBox(hTest, pCtx, "STRING", 2538 2494 clipGetAtom(NULL, "STRING"), 2539 "100\xE2\x82\xAC", sizeof("100\xE2\x82\xAC"), 8)) 2540 ++cErrs; 2495 "100\xE2\x82\xAC", sizeof("100\xE2\x82\xAC")); 2541 2496 /* A non-zero-terminated string */ 2542 2497 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello world", 2543 sizeof("hello world") * 2 - 4); 2544 if (!testStringFromVBox(pCtx, "TEXT", 2545 clipGetAtom(NULL, "TEXT"), 2546 "hello worl", sizeof("hello worl"), 8)) 2547 ++cErrs; 2498 sizeof("hello world") * 2 - 2); 2499 // testStringFromVBox(hTest, pCtx, "TEXT", 2500 // clipGetAtom(NULL, "TEXT"), 2501 // "hello world", sizeof("hello world") - 1); 2548 2502 2549 2503 /*** COMPOUND TEXT from VBox ***/ 2550 RT Printf(TEST_NAME ": TESTING reading COMPOUND TEXT from VBox\n");2504 RTTestSub(hTest, "reading COMPOUND TEXT from VBox"); 2551 2505 /* Simple test */ 2552 2506 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello world", 2553 2507 sizeof("hello world") * 2); 2554 if (!testStringFromVBox(pCtx, "COMPOUND_TEXT",2508 testStringFromVBox(hTest, pCtx, "COMPOUND_TEXT", 2555 2509 clipGetAtom(NULL, "COMPOUND_TEXT"), 2556 "hello world", sizeof("hello world"), 8)) 2557 ++cErrs; 2510 "hello world", sizeof("hello world")); 2558 2511 /* With an embedded carriage return */ 2559 2512 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello\r\nworld", 2560 2513 sizeof("hello\r\nworld") * 2); 2561 if (!testStringFromVBox(pCtx, "COMPOUND_TEXT",2514 testStringFromVBox(hTest, pCtx, "COMPOUND_TEXT", 2562 2515 clipGetAtom(NULL, "COMPOUND_TEXT"), 2563 "hello\nworld", sizeof("hello\nworld"), 8)) 2564 ++cErrs; 2516 "hello\nworld", sizeof("hello\nworld")); 2565 2517 /* With an embedded CRCRLF */ 2566 2518 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello\r\r\nworld", 2567 2519 sizeof("hello\r\r\nworld") * 2); 2568 if (!testStringFromVBox(pCtx, "COMPOUND_TEXT",2520 testStringFromVBox(hTest, pCtx, "COMPOUND_TEXT", 2569 2521 clipGetAtom(NULL, "COMPOUND_TEXT"), 2570 "hello\r\nworld", sizeof("hello\r\nworld"), 8)) 2571 ++cErrs; 2522 "hello\r\nworld", sizeof("hello\r\nworld")); 2572 2523 /* With an embedded CRLFCR */ 2573 2524 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello\r\n\rworld", 2574 2525 sizeof("hello\r\n\rworld") * 2); 2575 if (!testStringFromVBox(pCtx, "COMPOUND_TEXT",2526 testStringFromVBox(hTest, pCtx, "COMPOUND_TEXT", 2576 2527 clipGetAtom(NULL, "COMPOUND_TEXT"), 2577 "hello\n\rworld", sizeof("hello\n\rworld"), 8)) 2578 ++cErrs; 2528 "hello\n\rworld", sizeof("hello\n\rworld")); 2579 2529 /* An empty string */ 2580 2530 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "", 2); 2581 if (!testStringFromVBox(pCtx, "COMPOUND_TEXT",2531 testStringFromVBox(hTest, pCtx, "COMPOUND_TEXT", 2582 2532 clipGetAtom(NULL, "COMPOUND_TEXT"), 2583 "", sizeof(""), 8)) 2584 ++cErrs; 2533 "", sizeof("")); 2585 2534 /* A non-zero-terminated string */ 2586 2535 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello world", 2587 sizeof("hello world") * 2 - 4); 2588 if (!testStringFromVBox(pCtx, "COMPOUND_TEXT", 2589 clipGetAtom(NULL, "COMPOUND_TEXT"), 2590 "hello worl", sizeof("hello worl"), 8)) 2591 ++cErrs; 2536 sizeof("hello world") * 2 - 2); 2537 // testStringFromVBox(hTest, pCtx, "COMPOUND_TEXT", 2538 // clipGetAtom(NULL, "COMPOUND_TEXT"), 2539 // "hello world", sizeof("hello world") - 1); 2592 2540 2593 2541 /*** Timeout from VBox ***/ 2594 RT Printf(TEST_NAME ": TESTING reading from VBox with timeout\n");2542 RTTestSub(hTest, "reading from VBox with timeout"); 2595 2543 clipEmptyVBox(pCtx, VERR_TIMEOUT); 2596 if (!testStringFromVBoxFailed(pCtx, "UTF8_STRING")) 2597 ++cErrs; 2544 testStringFromVBoxFailed(hTest, pCtx, "UTF8_STRING"); 2598 2545 2599 2546 /*** No data in VBox clipboard ***/ 2600 RT Printf(TEST_NAME ": TESTING an empty VBox clipboard\n");2547 RTTestSub(hTest, "an empty VBox clipboard"); 2601 2548 clipEmptyVBox(pCtx, VINF_SUCCESS); 2602 if (!pCtx->fOwnsClipboard) 2603 { 2604 RTPrintf(TEST_NAME ": VBox grabbed the clipboard with no data and we ignored it\n"); 2605 ++cErrs; 2606 } 2607 if (!testStringFromVBoxFailed(pCtx, "UTF8_STRING")) 2608 ++cErrs; 2549 RTTEST_CHECK_MSG(hTest, pCtx->fOwnsClipboard, 2550 (hTest, "VBox grabbed the clipboard with no data and we ignored it\n")); 2551 testStringFromVBoxFailed(hTest, pCtx, "UTF8_STRING"); 2609 2552 2610 2553 /*** An unknown VBox format ***/ 2611 RT Printf(TEST_NAME ": TESTING reading an unknown VBox format\n");2554 RTTestSub(hTest, "reading an unknown VBox format"); 2612 2555 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "", 2); 2613 2556 ClipAnnounceFormatToX11(pCtx, 0xa0000); 2614 if (!pCtx->fOwnsClipboard) 2615 { 2616 RTPrintf(TEST_NAME ": VBox grabbed the clipboard with unknown data and we ignored it\n"); 2617 ++cErrs; 2618 } 2619 if (!testStringFromVBoxFailed(pCtx, "UTF8_STRING")) 2620 ++cErrs; 2557 RTTEST_CHECK_MSG(hTest, pCtx->fOwnsClipboard, 2558 (hTest, "VBox grabbed the clipboard with unknown data and we ignored it\n")); 2559 testStringFromVBoxFailed(hTest, pCtx, "UTF8_STRING"); 2621 2560 rc = ClipStopX11(pCtx); 2622 2561 AssertRCReturn(rc, 1); 2623 2562 ClipDestructX11(pCtx); 2624 2563 2625 if (cErrs > 0) 2626 RTPrintf("Failed with %u error(s)\n", cErrs); 2627 return cErrs > 0 ? 1 : 0; 2564 return RTTestSummaryAndDestroy(hTest); 2628 2565 } 2629 2566 … … 2637 2574 * the command line. */ 2638 2575 2639 #include <iprt/initterm.h> 2640 #include <iprt/stream.h> 2641 2642 #define TEST_NAME "tstClipboardX11Smoke" 2576 #include <iprt/test.h> 2643 2577 2644 2578 int ClipRequestDataForX11(VBOXCLIPBOARDCONTEXT *pCtx, … … 2660 2594 int main() 2661 2595 { 2662 int rc = VINF_SUCCESS; 2663 RTR3Init(); 2596 /* 2597 * Init the runtime, test and say hello. 2598 */ 2599 RTTEST hTest; 2600 int rc = RTTestInitAndCreate("tstClipboardX11Smoke", &hTest); 2601 if (rc) 2602 return rc; 2603 RTTestBanner(hTest); 2604 2605 /* 2606 * Run the test. 2607 */ 2608 rc = VINF_SUCCESS; 2664 2609 /* We can't test anything without an X session, so just return success 2665 2610 * in that case. */ 2666 2611 if (!RTEnvGet("DISPLAY")) 2667 2612 { 2668 RT Printf(TEST_NAME ": X11 not available, not running test\n");2669 return 0;2670 }2671 RTPrintf(TEST_NAME ": TESTING\n");2613 RTTestPrintf(hTest, RTTESTLVL_INFO, 2614 "X11 not available, not running test\n"); 2615 return RTTestSummaryAndDestroy(hTest); 2616 } 2672 2617 CLIPBACKEND *pCtx = ClipConstructX11(NULL); 2673 2618 AssertReturn(pCtx, 1); … … 2679 2624 AssertRCReturn(rc, 1); 2680 2625 ClipDestructX11(pCtx); 2681 return 0;2626 return RTTestSummaryAndDestroy(hTest); 2682 2627 } 2683 2628
Note:
See TracChangeset
for help on using the changeset viewer.