FreeRDP
Loading...
Searching...
No Matches
TestClientTouch.c
1
18#include <stdio.h>
19#include <winpr/crt.h>
20#include <freerdp/client.h>
21#include <freerdp/input.h>
22
23#include "../../../libfreerdp/core/connection.h"
24
25static UINT16 g_events[16];
26static size_t g_count = 0;
27
28static BOOL record_mouse(WINPR_ATTR_UNUSED rdpInput* input, UINT16 flags,
29 WINPR_ATTR_UNUSED UINT16 x, WINPR_ATTR_UNUSED UINT16 y)
30{
31 if (g_count < ARRAYSIZE(g_events))
32 g_events[g_count] = flags;
33 g_count++;
34 return TRUE;
35}
36
37/* the button flags of every recorded event, the pointer move bit aside */
38static BOOL expect(const char* what, const UINT16* want, size_t count)
39{
40 const UINT16 mask = PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON1 | PTR_FLAGS_BUTTON2 | PTR_FLAGS_BUTTON3;
41 BOOL ok = (g_count == count);
42 for (size_t x = 0; ok && (x < count); x++)
43 ok = ((g_events[x] & mask) == want[x]);
44 if (!ok)
45 {
46 (void)fprintf(stderr, "%s: got %" PRIuz " events:", what, g_count);
47 for (size_t x = 0; (x < g_count) && (x < ARRAYSIZE(g_events)); x++)
48 (void)fprintf(stderr, " 0x%04" PRIx16, (UINT16)(g_events[x] & mask));
49 (void)fprintf(stderr, ", wanted %" PRIuz ":", count);
50 for (size_t x = 0; x < count; x++)
51 (void)fprintf(stderr, " 0x%04" PRIx16, want[x]);
52 (void)fprintf(stderr, "\n");
53 }
54 g_count = 0;
55 return ok;
56}
57
58int TestClientTouch(int argc, char* argv[])
59{
60 WINPR_UNUSED(argc);
61 WINPR_UNUSED(argv);
62
63 int rc = -1;
64 RDP_CLIENT_ENTRY_POINTS entry = WINPR_C_ARRAY_INIT;
65 entry.Version = RDP_CLIENT_INTERFACE_VERSION;
66 entry.Size = sizeof(entry);
67 entry.ContextSize = sizeof(rdpClientContext);
68
69 rdpContext* context = freerdp_client_context_new(&entry);
70 if (!context)
71 goto fail;
72 rdpClientContext* cctx = (rdpClientContext*)context;
73
74 /* a connected session without the RDPEI channel: touch is sent as mouse buttons */
75 if (!rdp_client_transition_to_state(context->rdp, CONNECTION_STATE_ACTIVE))
76 goto fail;
77 context->input->MouseEvent = record_mouse;
78
79 {
80 /* one finger: a tap is a left click */
81 const UINT16 tap[] = { PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON1, PTR_FLAGS_BUTTON1 };
82 if (!freerdp_client_handle_touch(cctx, FREERDP_TOUCH_DOWN, 1, 0, 100, 200) ||
83 !freerdp_client_handle_touch(cctx, FREERDP_TOUCH_UP, 1, 0, 100, 200) ||
84 !expect("one finger", tap, ARRAYSIZE(tap)))
85 goto fail;
86 }
87
88 {
89 /* a second finger down while the first is held is the second button */
90 const UINT16 two[] = { PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON1,
91 PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON2, PTR_FLAGS_BUTTON2,
92 PTR_FLAGS_BUTTON1 };
93 if (!freerdp_client_handle_touch(cctx, FREERDP_TOUCH_DOWN, 1, 0, 100, 200) ||
94 !freerdp_client_handle_touch(cctx, FREERDP_TOUCH_DOWN, 2, 0, 150, 200) ||
95 !freerdp_client_handle_touch(cctx, FREERDP_TOUCH_UP, 2, 0, 150, 200) ||
96 !freerdp_client_handle_touch(cctx, FREERDP_TOUCH_UP, 1, 0, 100, 200) ||
97 !expect("two fingers", two, ARRAYSIZE(two)))
98 goto fail;
99 }
100
101 rc = 0;
102fail:
103 freerdp_client_context_free(context);
104 return rc;
105}