Add test for Conference Join Request packet creation

Signed-off-by: Henrik Andersson <hean01@cendio.com>
Signed-off-by: Thomas Nilefalk <thoni56@cendio.se>
This commit is contained in:
Cendio 2018-01-17 13:08:18 +01:00
parent 585f319aea
commit bdb92839f3
4 changed files with 136 additions and 1 deletions

View File

@ -2,7 +2,7 @@ CC=gcc
CFLAGS=-fPIC -Wall -Wextra -ggdb -gdwarf-2 -g3
CGREEN_RUNNER=cgreen-runner
TESTS=resize rdp xwin utils parse_geometry
TESTS=resize rdp xwin utils parse_geometry mcs
RDP_MOCKS=ui_mock.o bitmap_mock.o secure_mock.o ssl_mock.o mppc_mock.o \
@ -23,6 +23,8 @@ PARSE_MOCKS=ui_mock.o rdpdr_mock.o rdpedisp_mock.o ssl_mock.o ctrl_mock.o secure
tcp_mock.o dvc_mock.o rdp_mock.o cache_mock.o cliprdr_mock.o disk_mock.o lspci_mock.o \
parallel_mock.o printer_mock.o serial_mock.o xkeymap_mock.o utils_mock.o xwin_mock.o
MCS_MOCKS=utils_mock.o secure_mock.o iso_mock.o
all: test
.PHONY: test
@ -49,6 +51,12 @@ resize: resize_test.o $(RESIZE_MOCKS)
parse_geometry: parse_geometry_test.o $(PARSE_MOCKS) ../rdesktop.c
$(CC) $(CFLAGS) -shared -lcgreen -o $@ parse_geometry_test.o $(PARSE_MOCKS)
mcs: mcs_test.o $(MCS_MOCKS) stream.o
$(CC) $(CFLAGS) -shared -lcgreen -o $@ $^
stream.o: ../stream.c
$(CC) $(CFLAGS) -c -o $@ $^
.PHONY: clean
clean:
rm -f $(TESTS) *_mock.o *_test.o

37
tests/iso_mock.c Normal file
View File

@ -0,0 +1,37 @@
#include <cgreen/mocks.h>
#include "../rdesktop.h"
RD_BOOL
iso_connect(char *server, char *username, char *domain, char *password,
RD_BOOL reconnect, uint32 * selected_protocol)
{
return (RD_BOOL) mock(server, username, domain, password, reconnect, selected_protocol);
}
void
iso_disconnect(void)
{
mock();
}
void iso_send(STREAM stream)
{
mock(stream->data);
}
STREAM iso_recv(uint8 *rdpver)
{
return (STREAM)mock(rdpver);
}
void
iso_reset_state(void)
{
mock();
}
STREAM iso_init(int length)
{
return (STREAM)mock(length);
}

83
tests/mcs_test.c Normal file
View File

@ -0,0 +1,83 @@
#include <cgreen/cgreen.h>
#include <cgreen/mocks.h>
#include "../rdesktop.h"
/* Boilerplate */
Describe(MCS);
BeforeEach(MCS) {};
AfterEach(MCS) {};
char g_codepage[16];
VCHANNEL g_channels[1];
unsigned int g_num_channels;
#include "../asn.c"
#include "../mcs.c"
#include "../stream.h"
/* malloc; exit if out of memory */
void *
xmalloc(int size)
{
void *mem = malloc(size);
if (mem == NULL)
{
logger(Core, Error, "xmalloc, failed to allocate %d bytes", size);
exit(EX_UNAVAILABLE);
}
return mem;
}
/* realloc; exit if out of memory */
void *
xrealloc(void *oldmem, size_t size)
{
void *mem;
if (size == 0)
size = 1;
mem = realloc(oldmem, size);
if (mem == NULL)
{
logger(Core, Error, "xrealloc, failed to reallocate %ld bytes", size);
exit(EX_UNAVAILABLE);
}
return mem;
}
/* free */
void
xfree(void *mem)
{
free(mem);
}
static struct stream *stream_new(size_t size) {
struct stream *s;
s = malloc(sizeof(struct stream));
memset(s, 0, sizeof(struct stream));
s_realloc(s, size);
s_reset(s);
return(s);
}
/* Test function */
Ensure(MCS, should_produce_valid_packet_for_McsSendCJrq)
{
uint16 chan_id;
uint8_t content[] = {0x38, 0x00, 0x2A, 0x00, 0x0D};
struct stream *s;
s = stream_new(5);
chan_id = 13;
g_mcs_userid = 42;
expect(logger);
expect(iso_init, will_return(s));
expect(iso_send, when(stream->data, is_equal_to_contents_of(content, sizeof(content))));
mcs_send_cjrq(chan_id);
s_free(s);
}

View File

@ -42,3 +42,10 @@ sec_hash_to_string(char *out, int out_size, uint8 * in, int in_size)
{
mock(out, out_size, in, in_size);
}
void
sec_process_mcs_data(STREAM s)
{
mock(s);
}