Initial commit - from Precise source
[freerdp-ubuntu-pcb-backport.git] / cunit / test_drdynvc.c
1 /**
2  * FreeRDP: A Remote Desktop Protocol Client
3  * Dynamic Virtual Channel Unit Tests
4  *
5  * Copyright 2011 Vic Lee
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #include <stdio.h>
21 #include <string.h>
22 #include <stdlib.h>
23 #include <freerdp/freerdp.h>
24 #include <freerdp/constants.h>
25 #include <freerdp/channels/channels.h>
26 #include <freerdp/utils/event.h>
27 #include <freerdp/utils/hexdump.h>
28 #include <freerdp/utils/memory.h>
29
30 #include "test_drdynvc.h"
31
32 int init_drdynvc_suite(void)
33 {
34         freerdp_channels_global_init();
35         return 0;
36 }
37
38 int clean_drdynvc_suite(void)
39 {
40         freerdp_channels_global_uninit();
41         return 0;
42 }
43
44 int add_drdynvc_suite(void)
45 {
46         add_test_suite(drdynvc);
47
48         add_test_function(drdynvc);
49
50         return 0;
51 }
52
53 static const uint8 test_capability_request_data[] =
54 {
55         "\x58\x00\x02\x00\x33\x33\x11\x11\x3D\x0A\xA7\x04"
56 };
57
58 static int data_received = 0;
59
60 static int test_rdp_channel_data(freerdp* instance, int chan_id, uint8* data, int data_size)
61 {
62         printf("chan_id %d data_size %d\n", chan_id, data_size);
63         freerdp_hexdump(data, data_size);
64         data_received = 1;
65         return 0;
66 }
67
68 void test_drdynvc(void)
69 {
70         rdpChannels* chan_man;
71         rdpSettings settings = { 0 };
72         freerdp instance = { 0 };
73
74         settings.hostname = "testhost";
75         instance.settings = &settings;
76         instance.SendChannelData = test_rdp_channel_data;
77
78         chan_man = freerdp_channels_new();
79
80         freerdp_channels_load_plugin(chan_man, &settings, "../channels/drdynvc/drdynvc.so", NULL);
81         freerdp_channels_pre_connect(chan_man, &instance);
82         freerdp_channels_post_connect(chan_man, &instance);
83
84         /* server sends capability request PDU */
85         freerdp_channels_data(&instance, 0, (char*)test_capability_request_data, sizeof(test_capability_request_data) - 1,
86                 CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST, sizeof(test_capability_request_data) - 1);
87
88         /* drdynvc sends capability response PDU to server */
89         data_received = 0;
90         while (!data_received)
91         {
92                 freerdp_channels_check_fds(chan_man, &instance);
93         }
94
95         freerdp_channels_close(chan_man, &instance);
96         freerdp_channels_free(chan_man);
97 }