cunit: started testing orders

This commit is contained in:
Marc-André Moreau 2011-08-03 19:15:37 -04:00
parent 38e2a2fc47
commit 33bc8553c2
5 changed files with 334 additions and 0 deletions

View File

@ -40,6 +40,8 @@ add_executable(test_freerdp
test_libgdi.h
test_list.c
test_list.h
test_orders.c
test_orders.h
test_license.c
test_license.h
test_stream.c

View File

@ -29,6 +29,7 @@
#include "test_list.h"
#include "test_stream.h"
#include "test_utils.h"
#include "test_orders.h"
#include "test_license.h"
#include "test_transport.h"
#include "test_chanman.h"
@ -122,6 +123,7 @@ int main(int argc, char* argv[])
add_bitmap_suite();
add_libgdi_suite();
add_list_suite();
add_orders_suite();
add_license_suite();
add_stream_suite();
}
@ -145,6 +147,10 @@ int main(int argc, char* argv[])
{
add_list_suite();
}
else if (strcmp("orders", argv[*pindex]) == 0)
{
add_orders_suite();
}
else if (strcmp("license", argv[*pindex]) == 0)
{
add_license_suite();

271
cunit/test_orders.c Normal file
View File

@ -0,0 +1,271 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* Drawing Orders Unit Tests
*
* Copyright 2011 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.
*/
#include <freerdp/freerdp.h>
#include <freerdp/utils/hexdump.h>
#include <freerdp/utils/stream.h>
#include "test_orders.h"
#include "libfreerdp-core/orders.h"
ORDER_INFO* orderInfo;
int init_orders_suite(void)
{
orderInfo = (ORDER_INFO*) malloc(sizeof(orderInfo));
return 0;
}
int clean_orders_suite(void)
{
free(orderInfo);
return 0;
}
int add_orders_suite(void)
{
add_test_suite(orders);
add_test_function(read_dstblt_order);
add_test_function(read_patblt_order);
add_test_function(read_scrblt_order);
add_test_function(read_opaque_rect_order);
add_test_function(read_draw_nine_grid_order);
add_test_function(read_line_to_order);
add_test_function(read_glyph_index_order);
return 0;
}
uint8 dstblt_order[] = "\x48\x00\x37\x01";
void test_read_dstblt_order(void)
{
STREAM* s;
DSTBLT_ORDER dstblt;
s = stream_new(0);
s->p = s->data = dstblt_order;
memset(orderInfo, 0, sizeof(ORDER_INFO));
orderInfo->fieldFlags = 0x0C;
memset(&dstblt, 0, sizeof(DSTBLT_ORDER));
update_read_dstblt_order(s, orderInfo, &dstblt);
CU_ASSERT(dstblt.nLeftRect == 0);
CU_ASSERT(dstblt.nTopRect == 0);
CU_ASSERT(dstblt.nWidth == 72);
CU_ASSERT(dstblt.nHeight == 311);
CU_ASSERT(dstblt.bRop == 0);
}
uint8 patblt_order[] = "\x1a\x00\xc3\x01\x0d\x00\x0d\x00\xf0\xff\xff\x00\x5b\xef\x00\x81";
void test_read_patblt_order(void)
{
STREAM* s;
PATBLT_ORDER patblt;
s = stream_new(0);
s->p = s->data = patblt_order;
memset(orderInfo, 0, sizeof(ORDER_INFO));
orderInfo->fieldFlags = 0x027F;
memset(&patblt, 0, sizeof(PATBLT_ORDER));
update_read_patblt_order(s, orderInfo, &patblt);
CU_ASSERT(patblt.nLeftRect == 26);
CU_ASSERT(patblt.nTopRect == 451);
CU_ASSERT(patblt.nWidth == 13);
CU_ASSERT(patblt.nHeight == 13);
CU_ASSERT(patblt.bRop == 240);
CU_ASSERT(patblt.backColor == 0x00FFFF);
CU_ASSERT(patblt.foreColor == 0x00EF5B);
CU_ASSERT(patblt.brushOrgX == 0);
CU_ASSERT(patblt.brushOrgY == 0);
CU_ASSERT(patblt.brushStyle == (BMF_1BPP | CACHED_BRUSH));
}
uint8 scrblt_order[] = "\x07\x00\xa1\x01\xf1\x00\xcc\x2f\x01\x8e";
void test_read_scrblt_order(void)
{
STREAM* s;
SCRBLT_ORDER scrblt;
s = stream_new(0);
s->p = s->data = scrblt_order;
memset(orderInfo, 0, sizeof(ORDER_INFO));
orderInfo->fieldFlags = 0x7D;
memset(&scrblt, 0, sizeof(SCRBLT_ORDER));
update_read_scrblt_order(s, orderInfo, &scrblt);
CU_ASSERT(scrblt.nLeftRect == 7);
CU_ASSERT(scrblt.nTopRect == 0);
CU_ASSERT(scrblt.nWidth == 417);
CU_ASSERT(scrblt.nHeight == 241);
CU_ASSERT(scrblt.bRop == 204);
CU_ASSERT(scrblt.nXSrc == 303);
CU_ASSERT(scrblt.nYSrc == 142);
}
uint8 opaque_rect_order[] = "\x00\x04\x00\x03\x73\x02\x06";
void test_read_opaque_rect_order(void)
{
STREAM* s;
OPAQUE_RECT_ORDER opaque_rect;
s = stream_new(0);
s->p = s->data = opaque_rect_order;
memset(orderInfo, 0, sizeof(ORDER_INFO));
orderInfo->fieldFlags = 0x3C;
memset(&opaque_rect, 0, sizeof(OPAQUE_RECT_ORDER));
update_read_opaque_rect_order(s, orderInfo, &opaque_rect);
CU_ASSERT(opaque_rect.nLeftRect == 0);
CU_ASSERT(opaque_rect.nTopRect == 0);
CU_ASSERT(opaque_rect.nWidth == 1024);
CU_ASSERT(opaque_rect.nHeight == 768);
}
uint8 draw_nine_grid_order[] = "\xfb\xf9\x0d";
void test_read_draw_nine_grid_order(void)
{
STREAM* s;
DRAW_NINE_GRID_ORDER draw_nine_grid;
s = stream_new(0);
s->p = s->data = draw_nine_grid_order;
memset(orderInfo, 0, sizeof(ORDER_INFO));
orderInfo->fieldFlags = 0x1C;
orderInfo->boundLeft = 925;
orderInfo->boundTop = 134;
orderInfo->boundRight = 846;
orderInfo->boundBottom = 155;
orderInfo->deltaCoordinates = True;
memset(&draw_nine_grid, 0, sizeof(DRAW_NINE_GRID_ORDER));
draw_nine_grid.srcRight = 38;
draw_nine_grid.srcBottom = 40;
update_read_draw_nine_grid_order(s, orderInfo, &draw_nine_grid);
CU_ASSERT(draw_nine_grid.srcLeft == 0);
CU_ASSERT(draw_nine_grid.srcTop == 0);
CU_ASSERT(draw_nine_grid.srcRight == 33);
CU_ASSERT(draw_nine_grid.srcBottom == 33);
CU_ASSERT(draw_nine_grid.bitmapId == 13);
}
uint8 line_to_order[] = "\x03\xb1\x0e\xa6\x5b\xef\x00";
void test_read_line_to_order(void)
{
STREAM* s;
LINE_TO_ORDER line_to;
s = stream_new(0);
s->p = s->data = line_to_order;
memset(orderInfo, 0, sizeof(ORDER_INFO));
orderInfo->fieldFlags = 0x021E;
orderInfo->boundLeft = 829;
orderInfo->boundTop = 257;
orderInfo->boundRight = 842;
orderInfo->boundBottom = 270;
orderInfo->deltaCoordinates = True;
memset(&line_to, 0, sizeof(LINE_TO_ORDER));
line_to.nXStart = 826;
line_to.nYStart = 350;
line_to.nXEnd = 829;
line_to.nYEnd = 347;
update_read_line_to_order(s, orderInfo, &line_to);
CU_ASSERT(line_to.nXStart == 829);
CU_ASSERT(line_to.nYStart == 271);
CU_ASSERT(line_to.nXEnd == 843);
CU_ASSERT(line_to.nYEnd == 257);
CU_ASSERT(line_to.backColor == 0);
CU_ASSERT(line_to.bRop2 == 0);
CU_ASSERT(line_to.penStyle == 0);
CU_ASSERT(line_to.penWidth == 0);
CU_ASSERT(line_to.penColor == 0x00EF5B);
}
uint8 glyph_index_order_1[] =
"\x6a\x02\x27\x38\x00\x39\x07\x3a\x06\x3b\x07\x3c\x06\x3d\x06\x18"
"\x04\x1f\x06\x17\x02\x14\x04\x1b\x06\x19\x06\x45\x05\x18\x06\x1f"
"\x06\x1f\x02\x14\x02\x46\x06\xff\x15\x24";
uint8 glyph_index_order_2[] =
"\x00\xff\xff\xff\x0c\x02\x6e\x01\x4d\x02\x7b\x01\x09\x02\x6e\x01"
"\xf6\x02\x7b\x01\x0c\x02\x79\x01\x03\xfe\x04\x00";
void test_read_glyph_index_order(void)
{
STREAM* s;
GLYPH_INDEX_ORDER glyph_index;
s = stream_new(0);
s->p = s->data = glyph_index_order_1;
memset(orderInfo, 0, sizeof(ORDER_INFO));
orderInfo->fieldFlags = 0x200100;
orderInfo->deltaCoordinates = True;
memset(&glyph_index, 0, sizeof(GLYPH_INDEX_ORDER));
update_read_glyph_index_order(s, orderInfo, &glyph_index);
CU_ASSERT(glyph_index.bkRight == 618);
s->p = s->data = glyph_index_order_2;
memset(orderInfo, 0, sizeof(ORDER_INFO));
orderInfo->fieldFlags = 0x383FE8;
orderInfo->deltaCoordinates = True;
memset(&glyph_index, 0, sizeof(GLYPH_INDEX_ORDER));
update_read_glyph_index_order(s, orderInfo, &glyph_index);
CU_ASSERT(glyph_index.fOpRedundant == 0);
CU_ASSERT(glyph_index.foreColor == 0x00FFFFFF);
CU_ASSERT(glyph_index.bkLeft == 524);
CU_ASSERT(glyph_index.bkTop == 366);
CU_ASSERT(glyph_index.bkRight == 589);
CU_ASSERT(glyph_index.bkBottom == 379);
CU_ASSERT(glyph_index.opLeft == 521);
CU_ASSERT(glyph_index.opTop == 366);
CU_ASSERT(glyph_index.opRight == 758);
CU_ASSERT(glyph_index.opBottom == 379);
CU_ASSERT(glyph_index.x == 524);
CU_ASSERT(glyph_index.y == 377);
}

32
cunit/test_orders.h Normal file
View File

@ -0,0 +1,32 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* Drawing Orders Unit Tests
*
* Copyright 2011 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.
*/
#include "test_freerdp.h"
int init_orders_suite(void);
int clean_orders_suite(void);
int add_orders_suite(void);
void test_read_dstblt_order(void);
void test_read_patblt_order(void);
void test_read_scrblt_order(void);
void test_read_opaque_rect_order(void);
void test_read_draw_nine_grid_order(void);
void test_read_line_to_order(void);
void test_read_glyph_index_order(void);

View File

@ -205,4 +205,27 @@
void update_recv_order(rdpUpdate* update, STREAM* s);
void update_read_dstblt_order(STREAM* s, ORDER_INFO* orderInfo, DSTBLT_ORDER* dstblt);
void update_read_patblt_order(STREAM* s, ORDER_INFO* orderInfo, PATBLT_ORDER* patblt);
void update_read_scrblt_order(STREAM* s, ORDER_INFO* orderInfo, SCRBLT_ORDER* scrblt);
void update_read_opaque_rect_order(STREAM* s, ORDER_INFO* orderInfo, OPAQUE_RECT_ORDER* opaque_rect);
void update_read_draw_nine_grid_order(STREAM* s, ORDER_INFO* orderInfo, DRAW_NINE_GRID_ORDER* draw_nine_grid);
void update_read_multi_dstblt_order(STREAM* s, ORDER_INFO* orderInfo, MULTI_DSTBLT_ORDER* multi_dstblt);
void update_read_multi_patblt_order(STREAM* s, ORDER_INFO* orderInfo, MULTI_PATBLT_ORDER* multi_patblt);
void update_read_multi_scrblt_order(STREAM* s, ORDER_INFO* orderInfo, MULTI_SCRBLT_ORDER* multi_scrblt);
void update_read_multi_opaque_rect_order(STREAM* s, ORDER_INFO* orderInfo, MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect);
void update_read_multi_draw_nine_grid_order(STREAM* s, ORDER_INFO* orderInfo, MULTI_DRAW_NINE_GRID_ORDER* multi_draw_nine_grid);
void update_read_line_to_order(STREAM* s, ORDER_INFO* orderInfo, LINE_TO_ORDER* line_to);
void update_read_polyline_order(STREAM* s, ORDER_INFO* orderInfo, POLYLINE_ORDER* polyline);
void update_read_memblt_order(STREAM* s, ORDER_INFO* orderInfo, MEMBLT_ORDER* memblt);
void update_read_mem3blt_order(STREAM* s, ORDER_INFO* orderInfo, MEM3BLT_ORDER* mem3blt);
void update_read_save_bitmap_order(STREAM* s, ORDER_INFO* orderInfo, SAVE_BITMAP_ORDER* save_bitmap);
void update_read_glyph_index_order(STREAM* s, ORDER_INFO* orderInfo, GLYPH_INDEX_ORDER* glyph_index);
void update_read_fast_index_order(STREAM* s, ORDER_INFO* orderInfo, FAST_INDEX_ORDER* fast_index);
void update_read_fast_glyph_order(STREAM* s, ORDER_INFO* orderInfo, FAST_GLYPH_ORDER* fast_glyph);
void update_read_polygon_sc_order(STREAM* s, ORDER_INFO* orderInfo, POLYGON_SC_ORDER* polygon_sc);
void update_read_polygon_cb_order(STREAM* s, ORDER_INFO* orderInfo, POLYGON_CB_ORDER* polygon_cb);
void update_read_ellipse_sc_order(STREAM* s, ORDER_INFO* orderInfo, ELLIPSE_SC_ORDER* ellipse_sc);
void update_read_ellipse_cb_order(STREAM* s, ORDER_INFO* orderInfo, ELLIPSE_CB_ORDER* ellipse_cb);
#endif /* __ORDERS_H */