cunit: add network stream unit tests.

This commit is contained in:
Vic Lee 2011-07-02 23:39:35 +08:00
parent 8c161b8a20
commit dd27013552
4 changed files with 109 additions and 0 deletions

View File

@ -9,6 +9,8 @@ add_executable(test_freerdp
test_color.h
test_libgdi.c
test_libgdi.h
test_network.c
test_network.h
test_freerdp.c
test_freerdp.h)

View File

@ -21,6 +21,7 @@
#include "test_color.h"
#include "test_libgdi.h"
#include "test_network.h"
#include "test_freerdp.h"
void dump_data(unsigned char * p, int len, int width, char* name)
@ -61,6 +62,7 @@ int main(int argc, char* argv[])
{
add_color_suite();
add_libgdi_suite();
add_network_suite();
}
else
{
@ -74,6 +76,10 @@ int main(int argc, char* argv[])
{
add_libgdi_suite();
}
else if (strcmp("network", argv[*pindex]) == 0)
{
add_network_suite();
}
*pindex = *pindex + 1;
}

74
cunit/test_network.c Normal file
View File

@ -0,0 +1,74 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* Network Tests
*
* Copyright 2011 Vic Lee
*
* 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 <string.h>
#include <stdlib.h>
#include <freerdp/freerdp.h>
#include <freerdp/utils/hexdump.h>
#include <freerdp/utils/stream.h>
#include "test_network.h"
int init_network_suite(void)
{
return 0;
}
int clean_network_suite(void)
{
return 0;
}
int add_network_suite(void)
{
add_test_suite(network);
add_test_function(network_stream);
}
void test_network_stream(void)
{
STREAM * stream;
int pos;
uint32 n;
uint64 n64;
stream = stream_new(1);
pos = stream_get_pos(stream);
stream_write_uint8(stream, 0xFE);
stream_check_capacity(stream, 14);
stream_write_uint16(stream, 0x0102);
stream_write_uint32(stream, 0x03040506);
stream_write_uint64(stream, 0x0708091011121314LL);
/*freerdp_hexdump(stream->buffer, 15);*/
stream_set_pos(stream, pos);
stream_seek(stream, 3);
stream_read_uint32(stream, n);
stream_read_uint64(stream, n64);
CU_ASSERT(n == 0x03040506);
CU_ASSERT(n64 == 0x0708091011121314LL);
stream_free(stream);
}

27
cunit/test_network.h Normal file
View File

@ -0,0 +1,27 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* Network Tests
*
* Copyright 2011 Vic Lee
*
* 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_network_suite(void);
int clean_network_suite(void);
int add_network_suite(void);
void test_network_stream(void);