diff options
author | Cendio <cendio@pairstation.lkpg.cendio.se> | 2018-01-17 13:08:18 +0100 |
---|---|---|
committer | Cendio <cendio@pairstation.lkpg.cendio.se> | 2018-01-31 11:03:32 +0100 |
commit | bdb92839f3c5cebc2043aef70afa5c0dcfeb62c7 (patch) | |
tree | 7ea3197995238e2a99b578f247b3f2cfc3d85509 | |
parent | 585f319aea24f0cc76fdd77880425f1da660ead1 (diff) | |
download | rdesktop-bdb92839f3c5cebc2043aef70afa5c0dcfeb62c7.zip |
Add test for Conference Join Request packet creation
Signed-off-by: Henrik Andersson <hean01@cendio.com>
Signed-off-by: Thomas Nilefalk <thoni56@cendio.se>
-rw-r--r-- | tests/Makefile | 10 | ||||
-rw-r--r-- | tests/iso_mock.c | 37 | ||||
-rw-r--r-- | tests/mcs_test.c | 83 | ||||
-rw-r--r-- | tests/secure_mock.c | 7 |
4 files changed, 136 insertions, 1 deletions
diff --git a/tests/Makefile b/tests/Makefile index f7b39c8..71f6c0f 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -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 diff --git a/tests/iso_mock.c b/tests/iso_mock.c new file mode 100644 index 0000000..5280443 --- /dev/null +++ b/tests/iso_mock.c @@ -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); +} diff --git a/tests/mcs_test.c b/tests/mcs_test.c new file mode 100644 index 0000000..5799602 --- /dev/null +++ b/tests/mcs_test.c @@ -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); +} diff --git a/tests/secure_mock.c b/tests/secure_mock.c index 8d19c7d..69390e5 100644 --- a/tests/secure_mock.c +++ b/tests/secure_mock.c @@ -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); +} |