~ubuntu-branches/ubuntu/vivid/freerdp/vivid

« back to all changes in this revision

Viewing changes to cunit/test_rail.c

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2014-11-11 12:20:50 UTC
  • mfrom: (1.1.9) (9.1.17 sid)
  • Revision ID: package-import@ubuntu.com-20141111122050-wyr8hrnwco9fcmum
Tags: 1.1.0~git20140921.1.440916e+dfsg1-2ubuntu1
* Merge with Debian unstable, remaining changes
  - Disable ffmpeg support
* Disable gstreamer support, this relies on gstreamer 0.10 and we don't want
  to add any more deps on that.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
   FreeRDP: A Remote Desktop Protocol client.
 
2
   FreeRDP: A Remote Desktop Protocol Implementation
3
3
   RAIL(TS RemoteApp) Virtual Channel Unit Tests
4
4
 
5
5
   Copyright 2011 Vic Lee
28
28
#include <freerdp/constants.h>
29
29
#include <freerdp/channels/channels.h>
30
30
#include <freerdp/utils/event.h>
31
 
#include <freerdp/utils/hexdump.h>
32
 
#include <freerdp/utils/memory.h>
 
31
#include <winpr/print.h>
33
32
#include <freerdp/utils/rail.h>
34
33
#include <freerdp/rail.h>
35
34
 
67
66
}
68
67
 
69
68
 
70
 
static uint8 client_handshake[] =
 
69
static BYTE client_handshake[] =
71
70
{
72
71
0x05, 0x00, 0x08, 0x00, 0xb0, 0x1d, 0x00, 0x00
73
72
};
74
73
 
75
 
static uint8 client_info_pdu[] =
 
74
static BYTE client_info_pdu[] =
76
75
{
77
76
0x0b, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00
78
77
};
82
81
// WorkingDir: f:\windows\system32
83
82
// Arguments: www.bing.com
84
83
 
85
 
static uint8 client_execute_pdu[] =
 
84
static BYTE client_execute_pdu[] =
86
85
{
87
86
0x01,0x00,0x5e,0x00,0x08,0x00,0x14,0x00,0x26,0x00,0x18,0x00,0x7c,0x00,
88
87
0x7c,0x00,0x69,0x00,0x65,0x00,0x78,0x00,0x70,0x00,0x6c,0x00,0x6f,0x00,
93
92
0x67,0x00,0x2e,0x00,0x63,0x00,0x6f,0x00,0x6d,0x00
94
93
};
95
94
 
96
 
static uint8 client_activate_pdu[] =
 
95
static BYTE client_activate_pdu[] =
97
96
{
98
97
0x02,0x00,
99
98
0x09,0x00,
103
102
 
104
103
 
105
104
 
106
 
static uint8 client_sysparam_highcontrast_pdu[] =
 
105
static BYTE client_sysparam_highcontrast_pdu[] =
107
106
{
108
107
0x03,0x00,
109
108
0x12,0x00,
115
114
};
116
115
 
117
116
 
118
 
static uint8 client_sysparam_taskbarpos_pdu[] =
 
117
static BYTE client_sysparam_taskbarpos_pdu[] =
119
118
{
120
119
0x03,0x00,
121
120
0x10,0x00,
126
125
0xc2,0x03  // 0x03c2
127
126
};
128
127
 
129
 
static uint8 client_sysparam_mousebuttonswap_pdu[] =
 
128
static BYTE client_sysparam_mousebuttonswap_pdu[] =
130
129
{
131
130
0x03,0x00,
132
131
0x09,0x00,
133
132
0x21,0x00,0x00,0x00, // SPI_SETMOUSEBUTTONSWAP
134
 
0x00 // false
 
133
0x00 // FALSE
135
134
};
136
135
 
137
136
 
138
 
static uint8 client_sysparam_keyboardpref_pdu[] =
 
137
static BYTE client_sysparam_keyboardpref_pdu[] =
139
138
{
140
139
0x03,0x00,
141
140
0x09,0x00,
142
141
0x45,0x00,0x00,0x00, // SPI_SETKEYBOARDPREF
143
 
0x00 // false
 
142
0x00 // FALSE
144
143
};
145
144
 
146
145
 
147
 
static uint8 client_sysparam_dragfullwindow_pdu[] =
 
146
static BYTE client_sysparam_dragfullwindow_pdu[] =
148
147
{
149
148
0x03,0x00,
150
149
0x09,0x00,
151
150
0x25,0x00,0x00,0x00, // SPI_SETDRAGFULLWINDOWS
152
 
0x01 // true
 
151
0x01 // TRUE
153
152
};
154
153
 
155
154
 
156
 
static uint8 client_sysparam_keyboardcues_pdu[] =
 
155
static BYTE client_sysparam_keyboardcues_pdu[] =
157
156
{
158
157
0x03,0x00,
159
158
0x09,0x00,
160
159
0x0b,0x10,0x00,0x00, //SPI_SETKEYBOARDCUES
161
 
0x00 // false
 
160
0x00 // FALSE
162
161
};
163
162
 
164
 
static uint8 client_sysparam_setworkarea_pdu[] =
 
163
static BYTE client_sysparam_setworkarea_pdu[] =
165
164
{
166
165
0x03,0x00,
167
166
0x10,0x00,
172
171
0x9a,0x03  // 0x039a
173
172
};
174
173
 
175
 
static uint8 client_syscommand_pdu[] =
 
174
static BYTE client_syscommand_pdu[] =
176
175
{
177
176
0x04,0x00,
178
177
0x0a,0x00,
180
179
0x20,0xf0
181
180
};
182
181
 
183
 
static uint8 client_notify_pdu[] =
 
182
static BYTE client_notify_pdu[] =
184
183
{
185
184
0x06,0x00,
186
185
0x10,0x00,
189
188
0x04,0x02,0x00,0x00
190
189
};
191
190
 
192
 
static uint8 client_windowmove_pdu[] =
 
191
static BYTE client_windowmove_pdu[] =
193
192
{
194
193
0x08,0x00,
195
194
0x10,0x00,
200
199
0x88,0x01
201
200
};
202
201
 
203
 
static uint8 client_system_menu_pdu[] =
 
202
static BYTE client_system_menu_pdu[] =
204
203
{
205
204
0x0c,0x00,
206
205
0x0c,0x00,
209
208
0x4a,0x02
210
209
};
211
210
 
212
 
static uint8 client_langbar_pdu[] =
 
211
static BYTE client_langbar_pdu[] =
213
212
{
214
213
0x0D,0x00,0x08,0x00,0x01,0x00,0x00,0x00
215
214
};
216
215
 
217
 
static uint8 client_get_app_id_req_pdu[] =
 
216
static BYTE client_get_app_id_req_pdu[] =
218
217
{
219
218
0x0E,0x00,0x08,0x00,0x52,0x00,0x02,0x00
220
219
};
221
220
 
222
 
static uint8 server_handshake[] =
 
221
static BYTE server_handshake[] =
223
222
{
224
223
        0x05, 0x00, 0x08, 0x00, 0xb0, 0x1d, 0x00, 0x00
225
224
};
226
225
 
227
 
static uint8 server_exec_result_pdu[] =
 
226
static BYTE server_exec_result_pdu[] =
228
227
{
229
228
0x80,0x00,0x24,0x00,0x08,0x00,0x03,0x00,0x15,0x00,0x00,0x00,0x00,0x00,
230
229
0x14,0x00,0x7c,0x00,0x7c,0x00,0x57,0x00,0x72,0x00,0x6f,0x00,0x6e,0x00,
231
230
0x67,0x00,0x41,0x00,0x70,0x00,0x70,0x00
232
231
};
233
232
 
234
 
static uint8 server_exec_result_exe_or_file[] =
 
233
static BYTE server_exec_result_exe_or_file[] =
235
234
{
236
235
0x7c,0x00,0x7c,0x00,0x57,0x00,0x72,0x00,0x6f,0x00,0x6e,0x00,
237
236
0x67,0x00,0x41,0x00,0x70,0x00,0x70,0x00
238
237
};
239
238
 
240
 
static uint8 server_sysparam1_pdu[] =
 
239
static BYTE server_sysparam1_pdu[] =
241
240
{
242
241
0x03,0x00,
243
242
0x09,0x00,
245
244
0x00
246
245
};
247
246
 
248
 
static uint8 server_sysparam2_pdu[] =
 
247
static BYTE server_sysparam2_pdu[] =
249
248
{
250
249
0x03,0x00,
251
250
0x09,0x00,
253
252
0x00
254
253
};
255
254
 
256
 
static uint8 server_localmovesize_start_pdu[] =
 
255
static BYTE server_localmovesize_start_pdu[] =
257
256
{
258
257
0x09,0x00,0x10,0x00,0x8e,0x00,0x07,0x00,0x01,0x00,0x09,0x00,0x7e,0x01,
259
258
0x0a,0x00
260
259
};
261
260
 
262
 
static uint8 server_localmovesize_stop_pdu[] =
 
261
static BYTE server_localmovesize_stop_pdu[] =
263
262
{
264
263
0x09,0x00,0x10,0x00,0x8e,0x00,0x07,0x00,0x00,0x00,0x09,0x00,0xa6,0x00,
265
264
0x44,0x00
266
265
};
267
266
 
268
 
static uint8 server_minmaxinfo_pdu[] =
 
267
static BYTE server_minmaxinfo_pdu[] =
269
268
{
270
269
0x0a,0x00,0x18,0x00,0x8e,0x00,0x07,0x00,0x08,0x04,0xd6,0x02,0x00,0x00,
271
270
0x00,0x00,0x70,0x00,0x1b,0x00,0x0c,0x04,0x0c,0x03
272
271
};
273
272
 
274
 
static uint8 server_langbar_pdu[] =
 
273
static BYTE server_langbar_pdu[] =
275
274
{
276
275
0x0D,0x00,0x08,0x00,0x01,0x00,0x00,0x00
277
276
};
278
277
 
279
278
 
280
 
static uint8 server_app_get_resp_pdu[] =
 
279
static BYTE server_app_get_resp_pdu[] =
281
280
{
282
281
0x0F,0x00,0x08,0x02,0x52,0x00,0x02,0x00,0x6d,0x00,0x69,0x00,0x63,0x00,
283
282
0x72,0x00,0x6f,0x00,0x73,0x00,0x6f,0x00,0x66,0x00,0x74,0x00,0x2e,0x00,
328
327
0x00,0x00,0x00,0x00,0x00,0x00
329
328
};
330
329
 
331
 
static uint8 server_app_get_resp_app_id[] =
 
330
static BYTE server_app_get_resp_app_id[] =
332
331
{
333
332
0x6d,0x00,0x69,0x00,0x63,0x00,0x72,0x00,0x6f,0x00,0x73,0x00,0x6f,0x00,
334
333
0x66,0x00,0x74,0x00,0x2e,0x00,0x77,0x00,0x69,0x00,0x6e,0x6f,0x00,0x77,
380
379
 
381
380
 
382
381
#define EMULATE_SERVER_SEND_CHANNEL_DATA(inst, byte_array) \
383
 
        emulate_server_send_channel_data(inst, byte_array, RAIL_ARRAY_SIZE(byte_array))
 
382
        emulate_server_send_channel_data(inst, byte_array, ARRAYSIZE(byte_array))
384
383
 
385
384
#define STREAM_EQUAL_TO_DUMP(stream, dump) \
386
 
        (stream_equal_dump((stream)->data, (stream)->size, dump, RAIL_ARRAY_SIZE(dump)))
 
385
        (stream_equal_dump((stream)->data, (stream)->size, dump, ARRAYSIZE(dump)))
387
386
 
388
387
#define UNICODE_STRING_EQUAL_TO_DUMP(ustring, dump) \
389
 
        (stream_equal_dump((ustring)->string, (ustring)->length, dump, RAIL_ARRAY_SIZE(dump)))
 
388
        (stream_equal_dump((ustring)->string, (ustring)->length, dump, ARRAYSIZE(dump)))
390
389
 
391
390
typedef struct
392
391
{
411
410
typedef struct
412
411
{
413
412
        RAIL_ORDERS order_info;
414
 
        uint32 event_type;
 
413
        UINT32 event_type;
415
414
}
416
415
RAIL_EVENT;
417
416
 
427
426
        RAIL_EVENT  in_events[20];
428
427
        size_t      in_events_number;
429
428
 
430
 
        STREAM      in_streams[20];
 
429
        wStream      in_streams[20];
431
430
        size_t      in_streams_number;
432
431
 
433
432
        RDP_PLUGIN_DATA plugin_data;
447
446
                printf("Stream and dump have different length (%d != %d)\n",
448
447
                        (int) sizeS, (int) size);
449
448
                printf("Stream hexdump:\n");
450
 
                freerdp_hexdump(dataS, sizeS);
 
449
                winpr_HexDump(dataS, sizeS);
451
450
 
452
451
                printf("Dump hexdump:\n");
453
 
                freerdp_hexdump(data, size);
 
452
                winpr_HexDump(data, size);
454
453
 
455
454
                printf("----------------- stream_equal_dump -----------------\n");
456
455
                return 0;
459
458
 
460
459
        for (i=0; i < size; i++)
461
460
        {
462
 
                if (((uint8*)dataS)[i] != ((uint8*)data)[i])
 
461
                if (((BYTE*)dataS)[i] != ((BYTE*)data)[i])
463
462
                {
464
463
                        printf("----------------- stream_equal_dump -----------------\n");
465
464
                        printf("Stream and dump have different content from %d offset.\n", (int) i);
466
465
                        printf("Stream hexdump:\n");
467
 
                        freerdp_hexdump(dataS, sizeS);
 
466
                        winpr_HexDump(dataS, sizeS);
468
467
 
469
468
                        printf("Dump hexdump:\n");
470
 
                        freerdp_hexdump(data, size);
 
469
                        winpr_HexDump(data, size);
471
470
                        printf("----------------- stream_equal_dump -----------------\n");
472
471
                        return 0;
473
472
                }
476
475
        return 1;
477
476
}
478
477
//-----------------------------------------------------------------------------
479
 
static void test_on_free_rail_client_event(RDP_EVENT* event)
 
478
static void test_on_free_rail_client_event(wMessage* event)
480
479
{
481
480
        if (event->event_class == RDP_EVENT_CLASS_RAIL)
482
481
        {
486
485
//-----------------------------------------------------------------------------
487
486
static void send_ui_event2plugin(
488
487
        rdpChannels* chan_man,
489
 
        uint16 event_type,
 
488
        UINT16 event_type,
490
489
        void * data
491
490
        )
492
491
{
493
 
        RDP_EVENT* out_event = NULL;
 
492
        wMessage* out_event = NULL;
494
493
        void * payload = NULL;
495
494
 
496
495
        payload = rail_clone_order(event_type, data);
512
511
        counter++;
513
512
 
514
513
        printf("Emulate server packet (%d packet):\n", counter);
515
 
        freerdp_hexdump(data, size);
 
514
        winpr_HexDump(data, size);
516
515
 
517
516
        freerdp_channels_data(instance, 0, (char*)data, size,
518
517
                        CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST, size);
521
520
static void save_dump(void* data, size_t size)
522
521
{
523
522
        thread_param * p = global_thread_params;
524
 
        if (p->in_streams_number < RAIL_ARRAY_SIZE(p->in_streams))
 
523
        if (p->in_streams_number < ARRAYSIZE(p->in_streams))
525
524
        {
526
 
                STREAM* s = &p->in_streams[p->in_streams_number];
527
 
                s->data = malloc(size);
528
 
                s->size = size;
 
525
                wStream* s = &p->in_streams[p->in_streams_number];
 
526
                s->buffer = malloc(size);
 
527
                s->capacity = size;
529
528
 
530
 
                memcpy(s->data, data, size);
 
529
                memcpy(s->buffer, data, size);
531
530
                p->in_streams_number++;
532
531
        }
533
532
}
534
533
//-----------------------------------------------------------------------------
535
534
static int emulate_client_send_channel_data(
536
 
        freerdp* freerdp, int channelId, uint8* data, int size
 
535
        freerdp* freerdp, int channelId, BYTE* data, int size
537
536
        )
538
537
{
539
538
        static int counter = 0;
540
539
        counter++;
541
540
 
542
541
        printf("Client send to server (%d packet):\n", counter);
543
 
        freerdp_hexdump(data, size);
 
542
        winpr_HexDump(data, size);
544
543
 
545
544
        // add to global dumps list
546
545
        save_dump(data, size);
548
547
        return 0;
549
548
}
550
549
//-----------------------------------------------------------------------------
551
 
void save_event(RDP_EVENT* event, RAIL_EVENT* rail_event)
 
550
void save_event(wMessage* event, RAIL_EVENT* rail_event)
552
551
{
553
552
        rail_event->event_type = event->event_type;
554
553
 
611
610
//-----------------------------------------------------------------------------
612
611
static void process_events_and_channel_data_from_plugin(thread_param* param)
613
612
{
614
 
        RDP_EVENT* event;
 
613
        wMessage* event;
615
614
 
616
615
        param->th_count++;
617
616
        while (param->th_to_finish == 0)
631
630
                                        counter);
632
631
 
633
632
                        // add to global event list
634
 
                        if (param->in_events_number < RAIL_ARRAY_SIZE(param->in_events))
 
633
                        if (param->in_events_number < ARRAYSIZE(param->in_events))
635
634
                        {
636
635
                                save_event(event, &param->in_events[param->in_events_number]);
637
636
                                param->in_events_number++;
664
663
        freerdp* inst = &s_inst;
665
664
        size_t sn = 0;
666
665
        size_t en = 0;
667
 
        STREAM* ss = NULL;
 
666
        wStream* ss = NULL;
668
667
        RAIL_EVENT* ee = NULL;
669
668
 
670
669
        printf("\n");
671
670
 
672
 
        settings.hostname = "testhost";
 
671
        settings.Hostname = "testhost";
673
672
        inst->settings = &settings;
674
673
        inst->SendChannelData = emulate_client_send_channel_data;
675
674
 
717
716
        param.out_rail_orders.sysparam.taskbarPos.bottom = 0x03c2;
718
717
 
719
718
        param.out_rail_orders.sysparam.params |= SPI_MASK_SET_MOUSE_BUTTON_SWAP;
720
 
        param.out_rail_orders.sysparam.mouseButtonSwap = false;
 
719
        param.out_rail_orders.sysparam.mouseButtonSwap = FALSE;
721
720
 
722
721
        param.out_rail_orders.sysparam.params |= SPI_MASK_SET_KEYBOARD_PREF;
723
 
        param.out_rail_orders.sysparam.keyboardPref = false;
 
722
        param.out_rail_orders.sysparam.keyboardPref = FALSE;
724
723
 
725
724
        param.out_rail_orders.sysparam.params |= SPI_MASK_SET_DRAG_FULL_WINDOWS;
726
 
        param.out_rail_orders.sysparam.dragFullWindows = true;
 
725
        param.out_rail_orders.sysparam.dragFullWindows = TRUE;
727
726
 
728
727
        param.out_rail_orders.sysparam.params |= SPI_MASK_SET_KEYBOARD_CUES;
729
 
        param.out_rail_orders.sysparam.keyboardCues = false;
 
728
        param.out_rail_orders.sysparam.keyboardCues = FALSE;
730
729
 
731
730
        param.out_rail_orders.sysparam.params |= SPI_MASK_SET_WORK_AREA;
732
731
        param.out_rail_orders.sysparam.workArea.left = 0;
744
743
        send_ui_event2plugin(chan_man, RDP_EVENT_TYPE_RAIL_CLIENT_EXEC_REMOTE_APP,
745
744
                &param.plugin_data);
746
745
 
747
 
        param.out_rail_orders.activate.enabled = true;
 
746
        param.out_rail_orders.activate.enabled = TRUE;
748
747
        param.out_rail_orders.activate.windowId = 0x0007008e;
749
748
        send_ui_event2plugin(chan_man, RDP_EVENT_TYPE_RAIL_CLIENT_ACTIVATE,
750
749
                &param.out_rail_orders.activate);
829
828
                );
830
829
        CU_ASSERT(en >  2 &&
831
830
                ee[ 2].event_type == RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_SYSPARAM &&
832
 
                ee[ 2].order_info.sysparam.setScreenSaveSecure == false
 
831
                ee[ 2].order_info.sysparam.setScreenSaveSecure == FALSE
833
832
                );
834
833
 
835
834
        CU_ASSERT(en >  3 &&
836
835
                ee[ 3].event_type == RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_SYSPARAM &&
837
 
                ee[ 3].order_info.sysparam.setScreenSaveActive == false
 
836
                ee[ 3].order_info.sysparam.setScreenSaveActive == FALSE
838
837
                );
839
838
 
840
839
        CU_ASSERT(en >  4 &&
841
840
                ee[ 4].event_type == RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_LOCALMOVESIZE &&
842
841
                ee[ 4].order_info.localmovesize.windowId == 0x0007008e &&
843
 
                ee[ 4].order_info.localmovesize.isMoveSizeStart == true &&
 
842
                ee[ 4].order_info.localmovesize.isMoveSizeStart == TRUE &&
844
843
                ee[ 4].order_info.localmovesize.moveSizeType == RAIL_WMSZ_MOVE &&
845
844
                ee[ 4].order_info.localmovesize.posX == 0x017e &&
846
845
                ee[ 4].order_info.localmovesize.posY == 0x000a
849
848
        CU_ASSERT(en >  5 &&
850
849
                ee[ 5].event_type == RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_LOCALMOVESIZE &&
851
850
                ee[ 5].order_info.localmovesize.windowId == 0x0007008e &&
852
 
                ee[ 5].order_info.localmovesize.isMoveSizeStart == false &&
 
851
                ee[ 5].order_info.localmovesize.isMoveSizeStart == FALSE &&
853
852
                ee[ 5].order_info.localmovesize.moveSizeType == RAIL_WMSZ_MOVE &&
854
853
                ee[ 5].order_info.localmovesize.posX == 0x00a6 &&
855
854
                ee[ 5].order_info.localmovesize.posY == 0x0044