FreeRDP
Loading...
Searching...
No Matches
TestSDLWebClipOffers.cpp
1#include <tuple>
2
3#include "../../SDL3/sdl_web_clip_offers.hpp"
4
5int TestSDLWebClipOffers(int argc, char* argv[])
6{
7 (void)argc;
8 (void)argv;
9
10 const std::string local = "copied in the browser";
11 const std::string remote = "copied in the session";
12
13 {
14 SdlWebClipOffers offers;
15 if (!offers.offer(local, nullptr, 0))
16 return 1;
17 /* Without a server clipboard in between, offering the same data again is harmless. */
18 if (!offers.offer(local, nullptr, 0))
19 return 2;
20 }
21
22 {
23 /* The server copies files, which we don't fetch, or its text is still on the way. */
24 SdlWebClipOffers offers;
25 std::ignore = offers.offer(local, nullptr, 0);
26 offers.serverAnnounced();
27 if (offers.offer(local, nullptr, 0))
28 return 3;
29 /* A new local copy still takes the clipboard back. */
30 if (!offers.offer("copied again in the browser", nullptr, 0))
31 return 4;
32 }
33
34 {
35 /* The server's text reached the browser clipboard and is offered back on focus. */
36 SdlWebClipOffers offers;
37 std::ignore = offers.offer(local, nullptr, 0);
38 offers.serverAnnounced();
39 offers.serverSentText(remote);
40 if (offers.offer(remote, nullptr, 0))
41 return 5;
42 /* The page replaced our old offer, so copying it again is a new local copy. */
43 if (!offers.offer(local, nullptr, 0))
44 return 6;
45 }
46
47 {
48 /* An image offered with the server's text is new content. */
49 SdlWebClipOffers offers;
50 const BYTE image[] = { 1, 2, 3 };
51 offers.serverAnnounced();
52 offers.serverSentText(remote);
53 if (!offers.offer(remote, image, sizeof(image)))
54 return 7;
55 }
56
57 {
58 SdlWebClipOffers offers;
59 const BYTE image[] = { 1, 2, 3 };
60 std::ignore = offers.offer("", image, sizeof(image));
61 offers.serverAnnounced();
62 offers.serverSentImage();
63 if (!offers.offer("", image, sizeof(image)))
64 return 8;
65 }
66
67 return 0;
68}