Skip to content

Commit

Permalink
Ensure (partial) resize functionality with automated tests
Browse files Browse the repository at this point in the history
This test suite was built with cgreen, and has various tests that
tries to ensure that we didn't break something while developing the
dynamic resize feature.

Signed-off-by: Henrik Andersson <hean01@cendio.com>
Signed-off-by: Karl Mikaelsson <derfian@cendio.se>
Signed-off-by: Thomas Nilefalk <thoni56@cendio.se>
  • Loading branch information
Cendio committed Dec 7, 2017
1 parent 85c10b5 commit d10df45
Show file tree
Hide file tree
Showing 31 changed files with 1,912 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
rdesktop
autom4te.cache
Makefile
/Makefile
config.log
config.status
configure
Expand Down
49 changes: 49 additions & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
CC=gcc
CFLAGS=-fPIC -Wall -Wextra -ggdb -gdwarf-2 -g3
CGREEN_RUNNER=cgreen-runner

TESTS=resize rdp xwin utils


RDP_MOCKS=ui_mock.o bitmap_mock.o secure_mock.o ssl_mock.o mppc_mock.o \
cache_mock.o pstcache_mock.o orders_mock.o rdesktop_mock.o \
rdp5_mock.o xkeymap_mock.o tcp_mock.o

XWIN_MOCKS=x11_mock.o cache_mock.o xclip_mock.o xkeymap_mock.o seamless_mock.o \
ctrl_mock.o rdpdr_mock.o ewmh_mock.o rdpedisp_mock.o rdp_mock.o

UTILS_MOCKS=

RESIZE_MOCKS=x11_mock.o cache_mock.o xclip_mock.o xkeymap_mock.o seamless_mock.o \
ctrl_mock.o rdpdr_mock.o ewmh_mock.o rdpedisp_mock.o bitmap_mock.o \
ssl_mock.o mppc_mock.o pstcache_mock.o orders_mock.o rdesktop_mock.o rdp5_mock.o \
tcp_mock.o licence_mock.o mcs_mock.o channels_mock.o


all: test

.PHONY: test
test: $(foreach test, $(TESTS), runtest.$(test))


.PHONY: runtest.%
runtest.%: %
$(CGREEN_RUNNER) $^


rdp: rdp_test.o $(RDP_MOCKS)
$(CC) $(CFLAGS) -shared -lcgreen -o $@ $^

xwin: xwin_test.o $(XWIN_MOCKS)
$(CC) $(CFLAGS) -shared -lcgreen -o $@ $^ -lX11 -lXcursor

utils: utils_test.o $(UTILS_MOCKS)
$(CC) $(CFLAGS) -shared -lcgreen -o $@ $^

resize: resize_test.o $(RESIZE_MOCKS)
$(CC) $(CFLAGS) -shared -lcgreen -o $@ $^ -lX11 -lXcursor


.PHONY: clean
clean:
rm -f $(TESTS) *_mock.o *_test.o
26 changes: 26 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Automated test suite

An basic test suite was added while implementing the dynamic resize
feature. Improvements to this test suite are very welcome.


## Requirements

In addition to the build requirements of rdesktop itself, you also need:

* [cgreen](https://github.com/cgreen-devs/cgreen)


## Building and running the tests

cd tests
make

This will build and run each test in turn. Re-running `make` will
recompile the tests as necessary, and run them again.


## Cgreen documentation

You can find the Cgreen documentation over
at [their github site](https://cgreen-devs.github.io).
7 changes: 7 additions & 0 deletions tests/bitmap_mock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <cgreen/mocks.h>
#include "../rdesktop.h"

RD_BOOL bitmap_decompress(uint8 * output, int width, int height, uint8 * input, int size, int Bpp)
{
return mock(output, width, height, input, size, Bpp);
};
46 changes: 46 additions & 0 deletions tests/cache_mock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <cgreen/mocks.h>
#include "../rdesktop.h"

RD_HCURSOR
cache_get_cursor(uint16 cache_idx)
{
return (RD_HCURSOR)mock(cache_idx);
}

void
cache_put_cursor(uint16 cache_idx, RD_HCURSOR cursor)
{
mock(cache_idx, cursor);
}


FONTGLYPH *
cache_get_font(uint8 font, uint16 character)
{
return (FONTGLYPH *) mock(font, character);
}

DATABLOB *
cache_get_text(uint8 cache_id)
{
return (DATABLOB *)mock(cache_id);
}

void
cache_put_text(uint8 cache_id, void *data, int length)
{
mock(cache_id, data, length);
}

uint8 *
cache_get_desktop(uint32 offset, int cx, int cy, int bytes_per_pixel)
{
return (uint8 *) mock(offset, cx, cy, bytes_per_pixel);
}

void
cache_put_desktop(uint32 offset, int cx, int cy, int scanline,
int bytes_per_pixel, uint8 * data)
{
mock(offset, cx, cy, scanline, bytes_per_pixel, data);
}
7 changes: 7 additions & 0 deletions tests/channels_mock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <cgreen/mocks.h>
#include "../rdesktop.h"

void channel_process(STREAM s, uint16 mcs_channel)
{
mock(s, mcs_channel);
}
14 changes: 14 additions & 0 deletions tests/ctrl_mock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <cgreen/mocks.h>
#include "../rdesktop.h"

void
ctrl_add_fds(int *n, fd_set * rfds)
{
mock(n, rfds);
}

void
ctrl_check_fds(fd_set * rfds, fd_set * wfds)
{
mock(rfds, wfds);
}
26 changes: 26 additions & 0 deletions tests/dvc_mock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <cgreen/mocks.h>
#include "../rdesktop.h"

RD_BOOL
dvc_init(void)
{
return mock();
}

RD_BOOL
dvc_channels_register(const char *name, dvc_channel_process_fn handler)
{
return mock(name, handler);
}

RD_BOOL
dvc_channels_is_available(const char *name)
{
return mock(name);
}

void
dvc_send(const char *name, STREAM s)
{
mock(name, s);
}
87 changes: 87 additions & 0 deletions tests/ewmh_mock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include <cgreen/mocks.h>
#include "../rdesktop.h"
#include <X11/Xlib.h>

int
ewmh_get_window_state(Window w)
{
return mock(w);
}

int
ewmh_change_state(Window wnd, int state)
{
return mock(wnd, state);
}

int
ewmh_move_to_desktop(Window wnd, unsigned int desktop)
{
return mock(wnd, desktop);
}

int
ewmh_get_window_desktop(Window wnd)
{
return mock(wnd);
}

void
ewmh_set_wm_name(Window wnd, const char *title)
{
mock(wnd, title);
}

void
ewmh_set_wm_pid(Window wnd, pid_t pid)
{
mock(wnd, pid);
}

int
ewmh_set_window_popup(Window wnd)
{
return mock(wnd);
}

int
ewmh_set_window_modal(Window wnd)
{
return mock(wnd);
}

void
ewmh_set_icon(Window wnd, int width, int height, const char *rgba_data)
{
mock(wnd, width, height, rgba_data);
}

void
ewmh_del_icon(Window wnd, int width, int height)
{
mock(wnd, width, height);
}

int
ewmh_set_window_above(Window wnd)
{
return mock(wnd);
}

RD_BOOL
ewmh_is_window_above(Window w)
{
return mock(w);
}

int
get_current_workarea(uint32 *x, uint32 *y, uint32 *width, uint32 *height)
{
return mock(x, y, width, height);
}

void
ewmh_init()
{
mock();
}
9 changes: 9 additions & 0 deletions tests/licence_mock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <cgreen/mocks.h>
#include "../rdesktop.h"


void
licence_process(STREAM s)
{
mock(s);
}
51 changes: 51 additions & 0 deletions tests/mcs_mock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <cgreen/mocks.h>
#include "../rdesktop.h"

STREAM
mcs_init(int length)
{
return (STREAM)mock(length);
}

void
mcs_send_to_channel(STREAM s, uint16 channel)
{
mock(s, channel);
}

void
mcs_send(STREAM s)
{
mock(s);
}

STREAM
mcs_recv(uint16 * channel, uint8 * rdpver)
{
return (STREAM)mock(channel, rdpver);
}

RD_BOOL
mcs_connect_start(char *server, char *username, char *domain, char *password,
RD_BOOL reconnect, uint32 * selected_protocol)
{
return mock(server,username,domain,password,reconnect,selected_protocol);
}

RD_BOOL
mcs_connect_finalize(STREAM s)
{
return mock(s);
}

void
mcs_disconnect(void)
{
mock();
}

void
mcs_reset_state(void)
{
mock();
}
8 changes: 8 additions & 0 deletions tests/mppc_mock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <cgreen/mocks.h>
#include "../rdesktop.h"

int
mppc_expand(uint8 * data, uint32 clen, uint8 ctype, uint32 * roff, uint32 * rlen)
{
return mock(data, clen, ctype, roff, rlen);
}
12 changes: 12 additions & 0 deletions tests/orders_mock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <cgreen/mocks.h>
#include "../rdesktop.h"

void process_orders(STREAM s, uint16 num_orders)
{
mock(s, num_orders);
}

void reset_order_state()
{
mock();
}
12 changes: 12 additions & 0 deletions tests/pstcache_mock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <cgreen/mocks.h>
#include "../rdesktop.h"

int pstcache_enumerate(uint8 id, HASH_KEY * keylist)
{
return mock(id, keylist);
}

RD_BOOL pstcache_init(uint8 cache_id)
{
return mock(cache_id);
}
13 changes: 13 additions & 0 deletions tests/rdesktop_mock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <cgreen/mocks.h>
#include "../rdesktop.h"

void rd_create_ui(void)
{
mock();
}


void generate_random(uint8 * random)
{
mock(random);
}
7 changes: 7 additions & 0 deletions tests/rdp5_mock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <cgreen/mocks.h>
#include "../rdesktop.h"

void process_ts_fp_updates(STREAM s)
{
mock(s);
}
Loading

0 comments on commit d10df45

Please sign in to comment.