Initial commit - from Precise source
[freerdp-ubuntu-pcb-backport.git] / cunit / test_freerdp.c
1 /**
2  * FreeRDP: A Remote Desktop Protocol Client
3  * FreeRDP Unit Tests
4  *
5  * Copyright 2010 Marc-Andre Moreau <marcandre.moreau@gmail.com>
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 <CUnit/Basic.h>
21
22 #include "test_per.h"
23 #include "test_ber.h"
24 #include "test_gcc.h"
25 #include "test_mcs.h"
26 #include "test_color.h"
27 #include "test_bitmap.h"
28 #include "test_libgdi.h"
29 #include "test_list.h"
30 #include "test_stream.h"
31 #include "test_utils.h"
32 #include "test_orders.h"
33 #include "test_license.h"
34 #include "test_channels.h"
35 #include "test_cliprdr.h"
36 #include "test_drdynvc.h"
37 #include "test_librfx.h"
38 #include "test_freerdp.h"
39 #include "test_rail.h"
40 #include "test_pcap.h"
41 #include "test_mppc.h"
42
43 void dump_data(unsigned char * p, int len, int width, char* name)
44 {
45         unsigned char *line = p;
46         int i, thisline, offset = 0;
47
48         printf("\n%s[%d][%d]:\n", name, len / width, width);
49         while (offset < len)
50         {
51                 printf("%04x ", offset);
52                 thisline = len - offset;
53                 if (thisline > width)
54                         thisline = width;
55
56                 for (i = 0; i < thisline; i++)
57                         printf("%02x ", line[i]);
58
59                 for (; i < width; i++)
60                         printf("   ");
61
62                 printf("\n");
63                 offset += thisline;
64                 line += thisline;
65         }
66         printf("\n");
67 }
68
69 void assert_stream(STREAM* s, uint8* data, int length, const char* func, int line)
70 {
71         int i;
72         int actual_length;
73         uint8* actual_data;
74
75         actual_data = s->data;
76         actual_length = stream_get_length(s);
77
78         if (actual_length != length)
79         {
80                 printf("\n %s (%d): length mismatch, actual:%d, expected:%d\n", func, line, actual_length, length);
81
82                 printf("\nActual:\n");
83                 freerdp_hexdump(actual_data, actual_length);
84
85                 printf("Expected:\n");
86                 freerdp_hexdump(data, length);
87
88                 CU_FAIL("assert_stream, length mismatch");
89                 return;
90         }
91
92         for (i = 0; i < length; i++)
93         {
94                 if (actual_data[i] != data[i])
95                 {
96                         printf("\n %s (%d): buffer mismatch:\n", func, line);
97
98                         printf("\nActual:\n");
99                         freerdp_hexdump(actual_data, length);
100
101                         printf("Expected:\n");
102                         freerdp_hexdump(data, length);
103
104                         CU_FAIL("assert_stream, buffer mismatch");
105                         return;
106                 }
107         }
108 }
109
110 int main(int argc, char* argv[])
111 {
112         int index = 1;
113         int *pindex = &index;
114         int ret = 0;
115
116         if (CU_initialize_registry() != CUE_SUCCESS)
117                 return CU_get_error();
118
119         if (argc < *pindex + 1)
120         {
121                 add_per_suite();
122                 add_ber_suite();
123                 add_gcc_suite();
124                 add_mcs_suite();
125                 add_color_suite();
126                 add_bitmap_suite();
127                 add_libgdi_suite();
128                 add_list_suite();
129                 add_orders_suite();
130                 add_license_suite();
131                 add_stream_suite();
132                 add_mppc_suite();
133         }
134         else
135         {
136                 while (*pindex < argc)
137                 {
138                         if (strcmp("rail", argv[*pindex]) == 0)
139                         {
140                                 add_rail_suite();
141                         }
142                         if (strcmp("color", argv[*pindex]) == 0)
143                         {
144                                 add_color_suite();
145                         }
146                         if (strcmp("bitmap", argv[*pindex]) == 0)
147                         {
148                                 add_bitmap_suite();
149                         }
150                         else if (strcmp("libgdi", argv[*pindex]) == 0)
151                         {
152                                 add_libgdi_suite();
153                         }
154                         else if (strcmp("list", argv[*pindex]) == 0)
155                         {
156                                 add_list_suite();
157                         }
158                         else if (strcmp("orders", argv[*pindex]) == 0)
159                         {
160                                 add_orders_suite();
161                         }
162                         else if (strcmp("license", argv[*pindex]) == 0)
163                         {
164                                 add_license_suite();
165                         }
166                         else if (strcmp("stream", argv[*pindex]) == 0)
167                         {
168                                 add_stream_suite();
169                         }
170                         else if (strcmp("utils", argv[*pindex]) == 0)
171                         {
172                                 add_utils_suite();
173                         }
174                         else if (strcmp("chanman", argv[*pindex]) == 0)
175                         {
176                                 add_chanman_suite();
177                         }
178                         else if (strcmp("cliprdr", argv[*pindex]) == 0)
179                         {
180                                 add_cliprdr_suite();
181                         }
182                         else if (strcmp("drdynvc", argv[*pindex]) == 0)
183                         {
184                                 add_drdynvc_suite();
185                         }
186                         else if (strcmp("librfx", argv[*pindex]) == 0)
187                         {
188                                 add_librfx_suite();
189                         }
190                         else if (strcmp("per", argv[*pindex]) == 0)
191                         {
192                                 add_per_suite();
193                         }
194                         else if (strcmp("pcap", argv[*pindex]) == 0)
195                         {
196                                 add_pcap_suite();
197                         }
198                         else if (strcmp("ber", argv[*pindex]) == 0)
199                         {
200                                 add_ber_suite();
201                         }
202                         else if (strcmp("gcc", argv[*pindex]) == 0)
203                         {
204                                 add_gcc_suite();
205                         }
206                         else if (strcmp("mcs", argv[*pindex]) == 0)
207                         {
208                                 add_mcs_suite();
209                         }
210                         else if (strcmp("mppc", argv[*pindex]) == 0)
211                         {
212                                 add_mppc_suite();
213                         }
214
215                         *pindex = *pindex + 1;
216                 }
217         }
218
219         CU_basic_set_mode(CU_BRM_VERBOSE);
220         CU_basic_run_tests();
221         ret = CU_get_number_of_failure_records();
222         CU_cleanup_registry();
223
224         return ret;
225 }
226