2011-07-12 13:06:14 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-07-12 13:06:14 +04:00
|
|
|
* Clipboard Virtual Channel Unit Tests
|
|
|
|
*
|
|
|
|
* Copyright 2011 Vic Lee
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <freerdp/freerdp.h>
|
|
|
|
#include <freerdp/constants.h>
|
2011-10-16 22:57:15 +04:00
|
|
|
#include <freerdp/channels/channels.h>
|
2011-07-12 13:06:14 +04:00
|
|
|
#include <freerdp/utils/event.h>
|
2012-12-14 08:54:54 +04:00
|
|
|
#include <winpr/print.h>
|
2012-10-09 04:33:58 +04:00
|
|
|
#include <freerdp/client/cliprdr.h>
|
2011-07-12 13:06:14 +04:00
|
|
|
|
|
|
|
#include "test_cliprdr.h"
|
|
|
|
|
|
|
|
int init_cliprdr_suite(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int clean_cliprdr_suite(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int add_cliprdr_suite(void)
|
|
|
|
{
|
|
|
|
add_test_suite(cliprdr);
|
|
|
|
|
|
|
|
add_test_function(cliprdr);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static const BYTE test_clip_caps_data[] =
|
2011-07-12 13:06:14 +04:00
|
|
|
{
|
|
|
|
"\x07\x00\x00\x00\x10\x00\x00\x00\x01\x00\x00\x00\x01\x00\x0C\x00"
|
|
|
|
"\x02\x00\x00\x00\x0E\x00\x00\x00"
|
|
|
|
};
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static const BYTE test_monitor_ready_data[] =
|
2011-07-12 13:06:14 +04:00
|
|
|
{
|
|
|
|
"\x01\x00\x00\x00\x00\x00\x00\x00"
|
|
|
|
};
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static const BYTE test_format_list_data[] =
|
2011-07-12 19:53:54 +04:00
|
|
|
{
|
|
|
|
"\x02\x00\x00\x00\x48\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00"
|
|
|
|
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
|
|
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\xd0\x00\x00"
|
|
|
|
"\x48\x00\x54\x00\x4D\x00\x4C\x00\x20\x00\x46\x00\x6F\x00\x72\x00"
|
|
|
|
"\x6D\x00\x61\x00\x74\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
|
|
};
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static const BYTE test_format_list_response_data[] =
|
2011-07-12 20:01:50 +04:00
|
|
|
{
|
|
|
|
"\x03\x00\x01\x00\x00\x00\x00\x00"
|
|
|
|
};
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static const BYTE test_data_request_data[] =
|
2011-07-12 20:30:25 +04:00
|
|
|
{
|
|
|
|
"\x04\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00"
|
|
|
|
};
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static const BYTE test_data_response_data[] =
|
2011-07-12 20:30:25 +04:00
|
|
|
{
|
|
|
|
"\x05\x00\x01\x00\x18\x00\x00\x00\x68\x00\x65\x00\x6C\x00\x6C\x00"
|
|
|
|
"\x6F\x00\x20\x00\x77\x00\x6F\x00\x72\x00\x6c\x00\x64\x00\x00\x00"
|
|
|
|
};
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static int test_rdp_channel_data(freerdp* instance, int chan_id, BYTE* data, int data_size)
|
2011-07-12 13:06:14 +04:00
|
|
|
{
|
|
|
|
printf("chan_id %d data_size %d\n", chan_id, data_size);
|
2012-12-14 08:54:54 +04:00
|
|
|
winpr_HexDump(data, data_size);
|
2011-08-07 22:37:26 +04:00
|
|
|
return 0;
|
2011-07-12 19:06:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int event_processed;
|
|
|
|
|
2013-03-29 05:13:56 +04:00
|
|
|
static void event_process_callback(wMessage* event)
|
2011-07-12 19:06:39 +04:00
|
|
|
{
|
|
|
|
printf("Event %d processed.\n", event->event_type);
|
|
|
|
event_processed = 1;
|
2011-07-12 13:06:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_cliprdr(void)
|
|
|
|
{
|
2011-07-28 09:04:01 +04:00
|
|
|
int i;
|
2011-11-01 03:15:27 +04:00
|
|
|
rdpChannels* channels;
|
2011-07-12 13:06:14 +04:00
|
|
|
rdpSettings settings = { 0 };
|
2011-07-28 09:04:01 +04:00
|
|
|
freerdp instance = { 0 };
|
2013-03-29 05:13:56 +04:00
|
|
|
wMessage* event;
|
2011-08-18 01:28:26 +04:00
|
|
|
RDP_CB_FORMAT_LIST_EVENT* format_list_event;
|
|
|
|
RDP_CB_DATA_REQUEST_EVENT* data_request_event;
|
|
|
|
RDP_CB_DATA_RESPONSE_EVENT* data_response_event;
|
2011-07-12 13:06:14 +04:00
|
|
|
|
2012-11-08 00:13:14 +04:00
|
|
|
settings.Hostname = "testhost";
|
2011-07-28 09:04:01 +04:00
|
|
|
instance.settings = &settings;
|
2011-08-02 22:12:08 +04:00
|
|
|
instance.SendChannelData = test_rdp_channel_data;
|
2011-07-12 13:06:14 +04:00
|
|
|
|
2011-11-01 03:15:27 +04:00
|
|
|
channels = freerdp_channels_new();
|
2011-07-12 13:06:14 +04:00
|
|
|
|
2011-11-01 03:15:27 +04:00
|
|
|
freerdp_channels_load_plugin(channels, &settings, "../channels/cliprdr/cliprdr.so", NULL);
|
|
|
|
freerdp_channels_pre_connect(channels, &instance);
|
|
|
|
freerdp_channels_post_connect(channels, &instance);
|
2011-07-12 13:06:14 +04:00
|
|
|
|
2011-07-12 19:53:54 +04:00
|
|
|
/* server sends cliprdr capabilities and monitor ready PDU */
|
2011-10-16 22:57:15 +04:00
|
|
|
freerdp_channels_data(&instance, 0, (char*)test_clip_caps_data, sizeof(test_clip_caps_data) - 1,
|
2011-07-12 13:06:14 +04:00
|
|
|
CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST, sizeof(test_clip_caps_data) - 1);
|
|
|
|
|
2011-10-16 22:57:15 +04:00
|
|
|
freerdp_channels_data(&instance, 0, (char*)test_monitor_ready_data, sizeof(test_monitor_ready_data) - 1,
|
2011-07-12 13:06:14 +04:00
|
|
|
CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST, sizeof(test_monitor_ready_data) - 1);
|
|
|
|
|
2011-07-12 19:53:54 +04:00
|
|
|
/* cliprdr sends clipboard_sync event to UI */
|
2011-11-01 03:15:27 +04:00
|
|
|
while ((event = freerdp_channels_pop_event(channels)) == NULL)
|
2011-07-12 18:09:56 +04:00
|
|
|
{
|
2011-11-01 03:15:27 +04:00
|
|
|
freerdp_channels_check_fds(channels, &instance);
|
2011-07-12 18:09:56 +04:00
|
|
|
}
|
|
|
|
printf("Got event %d\n", event->event_type);
|
2011-11-01 03:15:27 +04:00
|
|
|
CU_ASSERT(event->event_type == RDP_EVENT_TYPE_CB_MONITOR_READY);
|
2011-07-12 18:09:56 +04:00
|
|
|
freerdp_event_free(event);
|
2011-07-12 13:06:14 +04:00
|
|
|
|
2011-07-12 19:53:54 +04:00
|
|
|
/* UI sends format_list event to cliprdr */
|
2011-08-18 01:28:26 +04:00
|
|
|
event = freerdp_event_new(RDP_EVENT_CLASS_CLIPRDR, RDP_EVENT_TYPE_CB_FORMAT_LIST, event_process_callback, NULL);
|
2011-11-01 03:15:27 +04:00
|
|
|
format_list_event = (RDP_CB_FORMAT_LIST_EVENT*) event;
|
2011-07-12 19:06:39 +04:00
|
|
|
format_list_event->num_formats = 2;
|
2012-10-09 11:26:39 +04:00
|
|
|
format_list_event->formats = (UINT32*) malloc(sizeof(UINT32) * 2);
|
2011-07-12 19:06:39 +04:00
|
|
|
format_list_event->formats[0] = CB_FORMAT_TEXT;
|
|
|
|
format_list_event->formats[1] = CB_FORMAT_HTML;
|
|
|
|
event_processed = 0;
|
2011-11-01 03:15:27 +04:00
|
|
|
freerdp_channels_send_event(channels, event);
|
2011-07-12 20:01:50 +04:00
|
|
|
|
|
|
|
/* cliprdr sends format list PDU to server */
|
2011-07-12 19:06:39 +04:00
|
|
|
while (!event_processed)
|
|
|
|
{
|
2011-11-01 03:15:27 +04:00
|
|
|
freerdp_channels_check_fds(channels, &instance);
|
2011-07-12 19:06:39 +04:00
|
|
|
}
|
|
|
|
|
2011-07-12 20:01:50 +04:00
|
|
|
/* server sends format list response PDU to cliprdr */
|
2011-10-16 22:57:15 +04:00
|
|
|
freerdp_channels_data(&instance, 0, (char*)test_format_list_response_data, sizeof(test_format_list_response_data) - 1,
|
2011-07-12 20:01:50 +04:00
|
|
|
CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST, sizeof(test_format_list_response_data) - 1);
|
|
|
|
|
2011-07-12 19:53:54 +04:00
|
|
|
/* server sends format list PDU to cliprdr */
|
2011-10-16 22:57:15 +04:00
|
|
|
freerdp_channels_data(&instance, 0, (char*)test_format_list_data, sizeof(test_format_list_data) - 1,
|
2011-07-12 19:53:54 +04:00
|
|
|
CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST, sizeof(test_format_list_data) - 1);
|
|
|
|
|
|
|
|
/* cliprdr sends format_list event to UI */
|
2011-11-01 03:15:27 +04:00
|
|
|
while ((event = freerdp_channels_pop_event(channels)) == NULL)
|
2011-07-12 19:53:54 +04:00
|
|
|
{
|
2011-11-01 03:15:27 +04:00
|
|
|
freerdp_channels_check_fds(channels, &instance);
|
2011-07-12 19:53:54 +04:00
|
|
|
}
|
|
|
|
printf("Got event %d\n", event->event_type);
|
2011-08-18 01:28:26 +04:00
|
|
|
CU_ASSERT(event->event_type == RDP_EVENT_TYPE_CB_FORMAT_LIST);
|
|
|
|
if (event->event_type == RDP_EVENT_TYPE_CB_FORMAT_LIST)
|
2011-07-12 19:53:54 +04:00
|
|
|
{
|
2011-08-18 01:28:26 +04:00
|
|
|
format_list_event = (RDP_CB_FORMAT_LIST_EVENT*)event;
|
2011-07-12 19:53:54 +04:00
|
|
|
for (i = 0; i < format_list_event->num_formats; i++)
|
|
|
|
printf("Format: 0x%X\n", format_list_event->formats[i]);
|
|
|
|
}
|
|
|
|
freerdp_event_free(event);
|
|
|
|
|
2011-07-12 20:30:25 +04:00
|
|
|
/* server sends data request PDU to cliprdr */
|
2011-10-16 22:57:15 +04:00
|
|
|
freerdp_channels_data(&instance, 0, (char*)test_data_request_data, sizeof(test_data_request_data) - 1,
|
2011-07-12 20:30:25 +04:00
|
|
|
CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST, sizeof(test_data_request_data) - 1);
|
|
|
|
|
|
|
|
/* cliprdr sends data request event to UI */
|
2011-11-01 03:15:27 +04:00
|
|
|
while ((event = freerdp_channels_pop_event(channels)) == NULL)
|
2011-07-12 20:30:25 +04:00
|
|
|
{
|
2011-11-01 03:15:27 +04:00
|
|
|
freerdp_channels_check_fds(channels, &instance);
|
2011-07-12 20:30:25 +04:00
|
|
|
}
|
|
|
|
printf("Got event %d\n", event->event_type);
|
2011-08-18 01:28:26 +04:00
|
|
|
CU_ASSERT(event->event_type == RDP_EVENT_TYPE_CB_DATA_REQUEST);
|
|
|
|
if (event->event_type == RDP_EVENT_TYPE_CB_DATA_REQUEST)
|
2011-07-12 20:30:25 +04:00
|
|
|
{
|
2011-08-18 01:28:26 +04:00
|
|
|
data_request_event = (RDP_CB_DATA_REQUEST_EVENT*)event;
|
2011-07-12 20:30:25 +04:00
|
|
|
printf("Requested format: 0x%X\n", data_request_event->format);
|
|
|
|
}
|
|
|
|
freerdp_event_free(event);
|
|
|
|
|
|
|
|
/* UI sends data response event to cliprdr */
|
2011-08-18 01:28:26 +04:00
|
|
|
event = freerdp_event_new(RDP_EVENT_CLASS_CLIPRDR, RDP_EVENT_TYPE_CB_DATA_RESPONSE, event_process_callback, NULL);
|
|
|
|
data_response_event = (RDP_CB_DATA_RESPONSE_EVENT*)event;
|
2012-10-09 11:01:37 +04:00
|
|
|
data_response_event->data = (BYTE*)malloc(6);
|
2011-07-27 03:14:11 +04:00
|
|
|
strcpy((char*)data_response_event->data, "hello");
|
2011-07-12 20:30:25 +04:00
|
|
|
data_response_event->size = 6;
|
|
|
|
event_processed = 0;
|
2011-11-01 03:15:27 +04:00
|
|
|
freerdp_channels_send_event(channels, event);
|
2011-07-12 20:30:25 +04:00
|
|
|
|
|
|
|
/* cliprdr sends data response PDU to server */
|
|
|
|
while (!event_processed)
|
|
|
|
{
|
2011-11-01 03:15:27 +04:00
|
|
|
freerdp_channels_check_fds(channels, &instance);
|
2011-07-12 20:30:25 +04:00
|
|
|
}
|
|
|
|
|
2011-07-12 20:50:00 +04:00
|
|
|
/* UI sends data request event to cliprdr */
|
2011-08-18 01:28:26 +04:00
|
|
|
event = freerdp_event_new(RDP_EVENT_CLASS_CLIPRDR, RDP_EVENT_TYPE_CB_DATA_REQUEST, event_process_callback, NULL);
|
|
|
|
data_request_event = (RDP_CB_DATA_REQUEST_EVENT*)event;
|
2011-07-12 20:50:00 +04:00
|
|
|
data_request_event->format = CB_FORMAT_UNICODETEXT;
|
|
|
|
event_processed = 0;
|
2011-11-01 03:15:27 +04:00
|
|
|
freerdp_channels_send_event(channels, event);
|
2011-07-12 20:50:00 +04:00
|
|
|
|
|
|
|
/* cliprdr sends data request PDU to server */
|
|
|
|
while (!event_processed)
|
|
|
|
{
|
2011-11-01 03:15:27 +04:00
|
|
|
freerdp_channels_check_fds(channels, &instance);
|
2011-07-12 20:50:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* server sends data response PDU to cliprdr */
|
2011-10-16 22:57:15 +04:00
|
|
|
freerdp_channels_data(&instance, 0, (char*)test_data_response_data, sizeof(test_data_response_data) - 1,
|
2011-07-12 20:50:00 +04:00
|
|
|
CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST, sizeof(test_data_response_data) - 1);
|
|
|
|
|
|
|
|
/* cliprdr sends data response event to UI */
|
2011-11-01 03:15:27 +04:00
|
|
|
while ((event = freerdp_channels_pop_event(channels)) == NULL)
|
2011-07-12 20:50:00 +04:00
|
|
|
{
|
2011-11-01 03:15:27 +04:00
|
|
|
freerdp_channels_check_fds(channels, &instance);
|
2011-07-12 20:50:00 +04:00
|
|
|
}
|
|
|
|
printf("Got event %d\n", event->event_type);
|
2011-08-18 01:28:26 +04:00
|
|
|
CU_ASSERT(event->event_type == RDP_EVENT_TYPE_CB_DATA_RESPONSE);
|
|
|
|
if (event->event_type == RDP_EVENT_TYPE_CB_DATA_RESPONSE)
|
2011-07-12 20:50:00 +04:00
|
|
|
{
|
2011-08-18 01:28:26 +04:00
|
|
|
data_response_event = (RDP_CB_DATA_RESPONSE_EVENT*)event;
|
2011-07-12 20:50:00 +04:00
|
|
|
printf("Data response size: %d\n", data_response_event->size);
|
2012-12-14 08:54:54 +04:00
|
|
|
winpr_HexDump(data_response_event->data, data_response_event->size);
|
2011-07-12 20:50:00 +04:00
|
|
|
}
|
|
|
|
freerdp_event_free(event);
|
|
|
|
|
2011-11-01 03:15:27 +04:00
|
|
|
freerdp_channels_close(channels, &instance);
|
|
|
|
freerdp_channels_free(channels);
|
2011-07-12 13:06:14 +04:00
|
|
|
}
|