cunit: fix compilation of unit tests

This commit is contained in:
Marc-André Moreau 2011-06-30 22:12:54 -04:00
parent 32cfd0f325
commit 7de0d21feb
9 changed files with 212 additions and 14 deletions

1
.gitignore vendored
View File

@ -13,3 +13,4 @@ Makefile
# Binaries
*.so
*.so.*
cunit/test_freerdp

View File

@ -21,6 +21,7 @@ endif()
set(FREERDP_KEYMAP_PATH "${CMAKE_INSTALL_PREFIX}/freerdp/keymaps")
# Libraries
add_subdirectory(cunit)
add_subdirectory(include)
add_subdirectory(libfreerdp-asn1)
add_subdirectory(libfreerdp-utils)

20
cunit/CMakeLists.txt Normal file
View File

@ -0,0 +1,20 @@
# cunit
include_directories(.)
include_directories(../include)
include_directories(../libfreerdp-gdi)
add_executable(test_freerdp
test_color.c
test_color.h
test_libgdi.c
test_libgdi.h
test_freerdp.c
test_freerdp.h)
target_link_libraries(test_freerdp cunit)
target_link_libraries(test_freerdp freerdp-gdi)
target_link_libraries(test_freerdp freerdp-asn1)
target_link_libraries(test_freerdp freerdp-utils)

152
cunit/test_color.c Normal file
View File

@ -0,0 +1,152 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* Color Conversion 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.
*/
#include <stdio.h>
#include <stdlib.h>
#include <freerdp/freerdp.h>
#include "gdi.h"
#include "color.h"
#include "test_color.h"
int init_color_suite(void)
{
return 0;
}
int clean_color_suite(void)
{
return 0;
}
int add_color_suite(void)
{
add_test_suite(color);
add_test_function(color_GetRGB32);
add_test_function(color_GetBGR32);
add_test_function(color_GetRGB_565);
add_test_function(color_GetRGB16);
add_test_function(color_GetBGR_565);
add_test_function(color_GetBGR16);
return 0;
}
/* GDI Color Space Conversions: http://msdn.microsoft.com/en-us/library/ff566496(VS.85).aspx */
void test_color_GetRGB32(void)
{
int r, g, b;
uint32 rgb32 = 0x00AABBCC;
GetRGB32(r, g, b, rgb32);
CU_ASSERT(r == 0xAA);
CU_ASSERT(g == 0xBB);
CU_ASSERT(b == 0xCC);
}
void test_color_GetBGR32(void)
{
int r, g, b;
uint32 bgr32 = 0x00CCBBAA;
GetBGR32(r, g, b, bgr32);
CU_ASSERT(r == 0xAA);
CU_ASSERT(g == 0xBB);
CU_ASSERT(b == 0xCC);
}
void test_color_GetRGB_565(void)
{
/*
R: 0x15, 10101
G: 0x33, 110011
B: 0x1D, 11101
0xAE7D, 10101110 01111101
*/
int r, g, b;
uint16 rgb16 = 0xAE7D;
GetRGB_565(r, g, b, rgb16);
CU_ASSERT(r == 0x15);
CU_ASSERT(g == 0x33);
CU_ASSERT(b == 0x1D);
}
void test_color_GetRGB16(void)
{
/*
R: 0x15 -> 0xAD, 10101 -> 10101101
G: 0x33 -> 0xCF, 110011 -> 11001111
B: 0x1D -> 0xEF, 11101 -> 11101101
0xAE7D -> 0xADCFEF
10101110 01111101 -> 10101101 11001111 11101101
*/
int r, g, b;
uint16 rgb16 = 0xAE7D;
GetRGB16(r, g, b, rgb16);
CU_ASSERT(r == 0xAD);
CU_ASSERT(g == 0xCF);
CU_ASSERT(b == 0xEF);
}
void test_color_GetBGR_565(void)
{
/*
B: 0x1D, 11101
G: 0x33, 110011
R: 0x15, 10101
0xEE75, 11101110 01110101
*/
int r, g, b;
uint16 bgr16 = 0xEE75;
GetBGR_565(r, g, b, bgr16);
CU_ASSERT(r == 0x15);
CU_ASSERT(g == 0x33);
CU_ASSERT(b == 0x1D);
}
void test_color_GetBGR16(void)
{
/*
B: 0x1D -> 0xEF, 11101 -> 11101101
G: 0x33 -> 0xCF, 110011 -> 11001111
R: 0x15 -> 0xAD, 10101 -> 10101101
0xEE75 -> 0xADCFEF
11101110 01110101 -> 10101101 11001111 11101101
*/
int r, g, b;
uint16 bgr16 = 0xEE75;
GetBGR16(r, g, b, bgr16);
CU_ASSERT(r == 0xAD);
CU_ASSERT(g == 0xCF);
CU_ASSERT(b == 0xEF);
}

31
cunit/test_color.h Normal file
View File

@ -0,0 +1,31 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* Color Conversion 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.
*/
#include "test_freerdp.h"
int init_color_suite(void);
int clean_color_suite(void);
int add_color_suite(void);
void test_color_GetRGB32(void);
void test_color_GetBGR32(void);
void test_color_GetRGB_565(void);
void test_color_GetRGB16(void);
void test_color_GetBGR_565(void);
void test_color_GetBGR16(void);

View File

@ -21,8 +21,6 @@
#include "test_color.h"
#include "test_libgdi.h"
#include "test_librfx.h"
#include "test_ntlmssp.h"
#include "test_freerdp.h"
void dump_data(unsigned char * p, int len, int width, char* name)
@ -63,8 +61,6 @@ int main(int argc, char* argv[])
{
add_color_suite();
add_libgdi_suite();
add_librfx_suite();
add_ntlmssp_suite();
}
else
{
@ -78,14 +74,6 @@ int main(int argc, char* argv[])
{
add_libgdi_suite();
}
else if (strcmp("librfx", argv[*pindex]) == 0)
{
add_librfx_suite();
}
else if (strcmp("ntlmssp", argv[*pindex]) == 0)
{
add_ntlmssp_suite();
}
*pindex = *pindex + 1;
}

View File

@ -1356,7 +1356,6 @@ void test_gdi_CreatePatternBrush(void)
CU_ASSERT(hBrush->style == GDI_BS_PATTERN);
CU_ASSERT(hBrush->pattern == hBitmap);
gdi_DeleteObject((HGDIOBJECT) hBrush);
gdi_DeleteObject((HGDIOBJECT) hBitmap);
}

View File

@ -146,7 +146,10 @@ int gdi_DeleteObject(HGDIOBJECT hgdiobject)
HGDI_BRUSH hBrush = (HGDI_BRUSH) hgdiobject;
if(hBrush->style == GDI_BS_PATTERN)
gdi_DeleteObject((HGDIOBJECT) hBrush->pattern);
{
if (hBrush->pattern != NULL)
gdi_DeleteObject((HGDIOBJECT) hBrush->pattern);
}
free(hBrush);
}

View File

@ -14,5 +14,8 @@ add_library(freerdp-utils SHARED ${FREERDP_UTILS_SRCS})
set_target_properties(freerdp-utils PROPERTIES VERSION ${FREERDP_VERSION_FULL} SOVERSION ${FREERDP_VERSION})
target_link_libraries(freerdp-utils pthread)
install(TARGETS freerdp-utils DESTINATION lib)