2011-07-01 02:17:37 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-07-01 02:17:37 +04:00
|
|
|
* FreeRDP Unit Tests
|
|
|
|
*
|
|
|
|
* Copyright 2010 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2011-07-05 01:05:58 +04:00
|
|
|
#include <CUnit/Basic.h>
|
2011-07-01 02:17:37 +04:00
|
|
|
|
2011-07-05 03:13:01 +04:00
|
|
|
#include "test_gcc.h"
|
2011-07-07 23:51:23 +04:00
|
|
|
#include "test_mcs.h"
|
2011-07-01 02:17:37 +04:00
|
|
|
#include "test_color.h"
|
2011-07-10 08:24:09 +04:00
|
|
|
#include "test_bitmap.h"
|
2012-02-14 06:02:09 +04:00
|
|
|
#include "test_gdi.h"
|
2011-08-04 03:15:37 +04:00
|
|
|
#include "test_orders.h"
|
2012-03-03 22:02:13 +04:00
|
|
|
#include "test_ntlm.h"
|
2011-07-13 19:40:19 +04:00
|
|
|
#include "test_license.h"
|
2011-07-12 13:06:14 +04:00
|
|
|
#include "test_cliprdr.h"
|
2011-07-19 10:07:15 +04:00
|
|
|
#include "test_drdynvc.h"
|
2012-02-14 06:02:09 +04:00
|
|
|
#include "test_rfx.h"
|
2012-03-06 14:55:54 +04:00
|
|
|
#include "test_nsc.h"
|
2011-07-01 02:17:37 +04:00
|
|
|
#include "test_freerdp.h"
|
2011-08-21 05:15:30 +04:00
|
|
|
#include "test_rail.h"
|
2011-08-27 02:36:35 +04:00
|
|
|
#include "test_pcap.h"
|
2011-09-02 08:20:08 +04:00
|
|
|
#include "test_mppc.h"
|
2012-03-19 10:02:13 +04:00
|
|
|
#include "test_mppc_enc.h"
|
2011-07-01 02:17:37 +04:00
|
|
|
|
|
|
|
void dump_data(unsigned char * p, int len, int width, char* name)
|
|
|
|
{
|
|
|
|
unsigned char *line = p;
|
|
|
|
int i, thisline, offset = 0;
|
|
|
|
|
|
|
|
printf("\n%s[%d][%d]:\n", name, len / width, width);
|
|
|
|
while (offset < len)
|
|
|
|
{
|
|
|
|
printf("%04x ", offset);
|
|
|
|
thisline = len - offset;
|
|
|
|
if (thisline > width)
|
|
|
|
thisline = width;
|
|
|
|
|
|
|
|
for (i = 0; i < thisline; i++)
|
|
|
|
printf("%02x ", line[i]);
|
|
|
|
|
|
|
|
for (; i < width; i++)
|
|
|
|
printf(" ");
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
offset += thisline;
|
|
|
|
line += thisline;
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void assert_stream(STREAM* s, BYTE* data, int length, const char* func, int line)
|
2011-07-05 01:05:58 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int actual_length;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* actual_data;
|
2011-07-05 01:05:58 +04:00
|
|
|
|
2011-07-06 07:18:00 +04:00
|
|
|
actual_data = s->data;
|
2011-07-05 01:05:58 +04:00
|
|
|
actual_length = stream_get_length(s);
|
|
|
|
|
|
|
|
if (actual_length != length)
|
|
|
|
{
|
2011-07-05 03:13:01 +04:00
|
|
|
printf("\n %s (%d): length mismatch, actual:%d, expected:%d\n", func, line, actual_length, length);
|
|
|
|
|
|
|
|
printf("\nActual:\n");
|
|
|
|
freerdp_hexdump(actual_data, actual_length);
|
|
|
|
|
|
|
|
printf("Expected:\n");
|
|
|
|
freerdp_hexdump(data, length);
|
|
|
|
|
2011-07-05 01:05:58 +04:00
|
|
|
CU_FAIL("assert_stream, length mismatch");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
{
|
|
|
|
if (actual_data[i] != data[i])
|
|
|
|
{
|
|
|
|
printf("\n %s (%d): buffer mismatch:\n", func, line);
|
|
|
|
|
|
|
|
printf("\nActual:\n");
|
|
|
|
freerdp_hexdump(actual_data, length);
|
|
|
|
|
|
|
|
printf("Expected:\n");
|
|
|
|
freerdp_hexdump(data, length);
|
|
|
|
|
|
|
|
CU_FAIL("assert_stream, buffer mismatch");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
typedef BOOL (*pInitTestSuite)(void);
|
2012-02-14 06:02:09 +04:00
|
|
|
|
|
|
|
struct _test_suite
|
|
|
|
{
|
|
|
|
char name[32];
|
|
|
|
pInitTestSuite Init;
|
|
|
|
};
|
|
|
|
typedef struct _test_suite test_suite;
|
|
|
|
|
2012-04-21 19:19:59 +04:00
|
|
|
const static test_suite suites[] =
|
2012-02-14 06:02:09 +04:00
|
|
|
{
|
|
|
|
{ "bitmap", add_bitmap_suite },
|
2012-10-01 00:33:42 +04:00
|
|
|
//{ "cliprdr", add_cliprdr_suite },
|
2012-02-14 06:02:09 +04:00
|
|
|
{ "color", add_color_suite },
|
2012-10-01 00:33:42 +04:00
|
|
|
//{ "drdynvc", add_drdynvc_suite },
|
2012-10-01 04:15:42 +04:00
|
|
|
//{ "gcc", add_gcc_suite },
|
2012-02-14 06:02:09 +04:00
|
|
|
{ "gdi", add_gdi_suite },
|
|
|
|
{ "license", add_license_suite },
|
2012-10-01 04:15:42 +04:00
|
|
|
//{ "mcs", add_mcs_suite },
|
2012-02-14 06:02:09 +04:00
|
|
|
{ "mppc", add_mppc_suite },
|
2012-03-19 10:02:13 +04:00
|
|
|
{ "mppc_enc", add_mppc_enc_suite },
|
2012-03-03 22:02:13 +04:00
|
|
|
{ "ntlm", add_ntlm_suite },
|
2012-10-01 04:15:42 +04:00
|
|
|
//{ "orders", add_orders_suite },
|
2012-02-14 06:02:09 +04:00
|
|
|
{ "pcap", add_pcap_suite },
|
2012-10-01 00:33:42 +04:00
|
|
|
//{ "rail", add_rail_suite },
|
2012-02-14 06:02:09 +04:00
|
|
|
{ "rfx", add_rfx_suite },
|
2012-10-01 04:15:42 +04:00
|
|
|
{ "nsc", add_nsc_suite }
|
2012-02-14 06:02:09 +04:00
|
|
|
};
|
2012-04-21 19:19:59 +04:00
|
|
|
#define N_SUITES (sizeof suites / sizeof suites[0])
|
2012-02-14 06:02:09 +04:00
|
|
|
|
2011-07-01 02:17:37 +04:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2012-04-21 19:19:59 +04:00
|
|
|
int i, k;
|
2012-02-14 06:02:09 +04:00
|
|
|
int status = 0;
|
2011-07-01 02:17:37 +04:00
|
|
|
|
|
|
|
if (CU_initialize_registry() != CUE_SUCCESS)
|
|
|
|
return CU_get_error();
|
|
|
|
|
2012-04-21 19:19:59 +04:00
|
|
|
if (argc < 2)
|
2011-07-01 02:17:37 +04:00
|
|
|
{
|
2012-04-21 19:19:59 +04:00
|
|
|
for (k = 0; k < N_SUITES; k++)
|
|
|
|
suites[k].Init();
|
2011-07-01 02:17:37 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-21 19:19:59 +04:00
|
|
|
if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
|
2011-07-01 02:17:37 +04:00
|
|
|
{
|
2012-04-21 19:19:59 +04:00
|
|
|
puts("Test suites:");
|
|
|
|
for (k = 0; k < N_SUITES; k++)
|
|
|
|
printf("\t%s\n", suites[k].name);
|
|
|
|
printf("\nUsage: %s [suite-1] [suite-2] ...\n", argv[0]);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-02-14 06:02:09 +04:00
|
|
|
|
2012-04-21 19:19:59 +04:00
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
{
|
|
|
|
for (k = 0; k < N_SUITES; k++)
|
2011-09-02 08:20:08 +04:00
|
|
|
{
|
2012-04-21 19:19:59 +04:00
|
|
|
if (!strcmp(suites[k].name, argv[i]))
|
2012-02-14 06:02:09 +04:00
|
|
|
{
|
|
|
|
suites[k].Init();
|
|
|
|
break;
|
|
|
|
}
|
2011-09-02 08:20:08 +04:00
|
|
|
}
|
2011-07-01 02:17:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CU_basic_set_mode(CU_BRM_VERBOSE);
|
|
|
|
CU_basic_run_tests();
|
2012-02-14 06:02:09 +04:00
|
|
|
|
|
|
|
status = CU_get_number_of_failure_records();
|
2011-07-01 02:17:37 +04:00
|
|
|
CU_cleanup_registry();
|
|
|
|
|
2012-02-14 06:02:09 +04:00
|
|
|
return status;
|
2011-07-01 02:17:37 +04:00
|
|
|
}
|
|
|
|
|