diff options
author | Dave Davenport <qball@gmpclient.org> | 2014-08-30 20:45:08 +0200 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2014-08-30 20:45:08 +0200 |
commit | 229bb6931b278d455a35359db8361c1b9aa6c013 (patch) | |
tree | 3d89133b25c706b69026861fca2acba7cf0eca3f /test | |
parent | 91ccb54199a533ce574fc9f0d158d64c38d406ec (diff) |
Play with adding some more test, bug fixes
* delete an invalid memmove in textbox
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile.am | 19 | ||||
-rwxr-xr-x | test/run_dmenu_custom_test.sh | 26 | ||||
-rwxr-xr-x | test/run_dmenu_test.sh | 15 | ||||
-rwxr-xr-x | test/run_errormsg_test.sh | 10 | ||||
-rwxr-xr-x | test/run_run_test.sh | 21 | ||||
-rwxr-xr-x | test/run_switchdialog_test.sh | 15 | ||||
-rwxr-xr-x | test/run_test.sh | 35 | ||||
-rw-r--r-- | test/textbox-test.c | 136 |
8 files changed, 212 insertions, 65 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index 0b4be914..3627af70 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,7 +1,7 @@ ## # Rofi the program ## -bin_PROGRAMS=rofi_test +bin_PROGRAMS=rofi_test textbox_test LIBS=\ @xft_LIBS@\ @@ -26,6 +26,19 @@ rofi_test_SOURCES=\ ../include/history.h\ history-test.c +textbox_test_SOURCES=\ + ../source/textbox.c\ + ../config/config.c\ + ../include/rofi.h\ + ../include/textbox.h\ + textbox-test.c + .PHONY: test -test: rofi_test - ./$^ +test: ${bin_PROGRAMS} + ./rofi_test + $(top_srcdir)/test/run_test.sh 123 $(top_builddir)/test/textbox_test $(top_builddir) + $(top_srcdir)/test/run_test.sh 200 $(top_srcdir)/test/run_errormsg_test.sh $(top_builddir) + $(top_srcdir)/test/run_test.sh 201 $(top_srcdir)/test/run_switchdialog_test.sh $(top_builddir) + $(top_srcdir)/test/run_test.sh 202 $(top_srcdir)/test/run_dmenu_test.sh $(top_builddir) + $(top_srcdir)/test/run_test.sh 203 $(top_srcdir)/test/run_dmenu_custom_test.sh $(top_builddir) + $(top_srcdir)/test/run_test.sh 204 $(top_srcdir)/test/run_run_test.sh $(top_builddir) diff --git a/test/run_dmenu_custom_test.sh b/test/run_dmenu_custom_test.sh index 95f7710d..039d5ab8 100755 --- a/test/run_dmenu_custom_test.sh +++ b/test/run_dmenu_custom_test.sh @@ -1,37 +1,27 @@ #!/usr/bin/env bash -# Create fake X -Xvfb :202 & -XPID=$! - -# wait till it is up, run rofi with error message -sleep 1; -xrdb -display :202 -load doc/example.xresources -echo -e -n "aap\nnoot\nmies" | ./rofi -width -30 -dmenu -display :202 > output.txt & +echo -e -n "aap\nnoot\nmies" | rofi -width -30 -dmenu > output.txt & RPID=$! # send enter. sleep 5; -DISPLAY=:202 xdotool key 'c' +xdotool key 'c' sleep 0.2 -DISPLAY=:202 xdotool key 'o' +xdotool key 'o' sleep 0.2 -DISPLAY=:202 xdotool key 'f' +xdotool key 'f' sleep 0.2 -DISPLAY=:202 xdotool key 'f' +xdotool key 'f' sleep 0.2 -DISPLAY=:202 xdotool key 'e' +xdotool key 'e' sleep 0.2 -DISPLAY=:202 xdotool key 'e' +xdotool key 'e' sleep 0.2 -DISPLAY=:202 xdotool key Return +xdotool key Return # Get result, kill xvfb wait ${RPID} RETV=$? -kill ${XPID} - -sleep 1 if [ `cat output.txt` != 'coffee' ] then diff --git a/test/run_dmenu_test.sh b/test/run_dmenu_test.sh index 06232768..3cedd65e 100755 --- a/test/run_dmenu_test.sh +++ b/test/run_dmenu_test.sh @@ -1,28 +1,21 @@ #!/usr/bin/env bash -# Create fake X -Xvfb :202 & -XPID=$! - # wait till it is up, run rofi with error message sleep 1; -echo -e -n "aap\nnoot\nmies" | ./rofi -dmenu -display :202 > output.txt & +echo -e -n "aap\nnoot\nmies" | rofi -dmenu > output.txt & RPID=$! # send enter. sleep 5; -DISPLAY=:202 xdotool key 'Down' +xdotool key 'Down' sleep 0.4 -DISPLAY=:202 xdotool key 'Down' +xdotool key 'Down' sleep 0.4 -DISPLAY=:202 xdotool key Return +xdotool key Return # Get result, kill xvfb wait ${RPID} RETV=$? -kill ${XPID} - -sleep 1 if [ `cat output.txt` != 'mies' ] then diff --git a/test/run_errormsg_test.sh b/test/run_errormsg_test.sh index 606dadf9..b2bfc6a2 100755 --- a/test/run_errormsg_test.sh +++ b/test/run_errormsg_test.sh @@ -1,19 +1,13 @@ #!/usr/bin/env bash -# Create fake X -Xvfb :200 & -XPID=$! - # wait till it is up, run rofi with error message -sleep 1 && ./rofi -e "Printing error message" -display :200 & +sleep 1 && rofi -e "Printing error message" & RPID=$! # send enter. -sleep 5 && DISPLAY=:200 xdotool key Return +sleep 5 && xdotool key Return # Get result, kill xvfb wait ${RPID} RETV=$? -kill ${XPID} -sleep 1 exit ${RETV} diff --git a/test/run_run_test.sh b/test/run_run_test.sh index 92f2e2ac..8b220a76 100755 --- a/test/run_run_test.sh +++ b/test/run_run_test.sh @@ -1,31 +1,22 @@ #!/usr/bin/env bash -# Create fake X -Xvfb :203 & -XPID=$! - -# wait till it is up, run rofi with error message -sleep 1; -./rofi -rnow -display :203 & +rofi -rnow & RPID=$! # send enter. sleep 5; -DISPLAY=:203 xdotool key 't' +xdotool key 't' sleep 0.4 -DISPLAY=:203 xdotool key 'r' +xdotool key 'r' sleep 0.4 -DISPLAY=:203 xdotool key 'u' +xdotool key 'u' sleep 0.4 -DISPLAY=:203 xdotool key 'e' +xdotool key 'e' sleep 0.4 -DISPLAY=:203 xdotool key Return +xdotool key Return # Get result, kill xvfb wait ${RPID} RETV=$? -kill ${XPID} - -sleep 1 exit ${RETV} diff --git a/test/run_switchdialog_test.sh b/test/run_switchdialog_test.sh index 820937e0..e6394d81 100755 --- a/test/run_switchdialog_test.sh +++ b/test/run_switchdialog_test.sh @@ -1,27 +1,22 @@ #!/usr/bin/env bash -# Create fake X -Xvfb :201 & -XPID=$! - # wait till it is up, run rofi with error message -sleep 1 && ./rofi -rnow -display :201 & +sleep 1 && rofi -rnow -display :201 & RPID=$! # send enter. sleep 5; -DISPLAY=:201 xdotool key 'shift+slash' +xdotool key 'shift+slash' sleep 0.4 -DISPLAY=:201 xdotool key 'shift+slash' +xdotool key 'shift+slash' sleep 0.4 -DISPLAY=:201 xdotool key 'shift+slash' +xdotool key 'shift+slash' sleep 0.4 -DISPLAY=:201 xdotool key Escape +xdotool key Escape # Get result, kill xvfb wait ${RPID} RETV=$? -kill ${XPID} sleep 1 diff --git a/test/run_test.sh b/test/run_test.sh new file mode 100755 index 00000000..eab3c838 --- /dev/null +++ b/test/run_test.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +XPID= +DISPLAY=":0" +function create_fake_x ( ) +{ + DISPLAY=":$1" + echo "Starting fake X: ${DISPLAY}" + Xvfb ${DISPLAY} & + XPID=$! + sleep 1 +} + +function destroy_fake_x ( ) +{ + if [ -n "${XPID}" ] + then + echo "Stopping fake X: ${XPID}" + kill ${XPID} + wait ${XPID} + fi +} + +if [ -n "$3" ] +then + PATH=$3:$PATH +fi + +create_fake_x "$1" +$2 +RES=$? + +destroy_fake_x + +exit ${RES} diff --git a/test/textbox-test.c b/test/textbox-test.c new file mode 100644 index 00000000..09ba9973 --- /dev/null +++ b/test/textbox-test.c @@ -0,0 +1,136 @@ +#include <unistd.h> +#include <stdlib.h> + +#include <stdio.h> +#include <assert.h> +#include <glib.h> +#include <history.h> +#include <string.h> +#include <X11/X.h> +#include <X11/Xlib.h> + +#include <textbox.h> +#include <rofi.h> + + +static int test = 0; + +#define TASSERT(a) {\ + assert ( a );\ + printf("Test %3i passed (%s)\n", ++test, #a);\ +} + +Display *display = NULL; + +static unsigned int color_get ( Display *display, const char *const name ) +{ + int screen_id = DefaultScreen ( display ); + XColor color; + Colormap map = DefaultColormap ( display, screen_id ); + return XAllocNamedColor ( display, map, name, &color, &color ) ? color.pixel : None; +} + +int main ( int argc, char **argv ) +{ + + // Get DISPLAY + const char *display_str = getenv ( "DISPLAY" ); + if ( !( display = XOpenDisplay ( display_str ) ) ) { + fprintf ( stderr, "cannot open display!\n" ); + return EXIT_FAILURE; + } + + TASSERT( display != NULL ); + Screen *screen = DefaultScreenOfDisplay ( display ); + Window root = RootWindow ( display, XScreenNumberOfScreen ( screen ) ); + Window mw = XCreateSimpleWindow ( display, root, 0, 0, 200, 100, + config.menu_bw, + color_get ( display, config.menu_bc ), + color_get ( display, config.menu_bg ) ); + TASSERT( mw != None ); + + textbox_setup ( config.menu_bg, config.menu_fg, + config.menu_hlbg, config.menu_hlfg ); + textbox *box = textbox_create(mw , TB_EDITABLE|TB_AUTOWIDTH|TB_AUTOHEIGHT, 0,0, -1, -1, NORMAL, "test"); + TASSERT( box != NULL ); + + textbox_cursor_end ( box ); + TASSERT ( box->cursor == 4); + textbox_cursor ( box, -1 ); + TASSERT ( box->cursor == 0 ); + textbox_cursor ( box, 8 ); + TASSERT ( box->cursor == 4 ); + textbox_cursor ( box, 2 ); + TASSERT ( box->cursor == 2 ); + textbox_insert ( box, 3, "bo"); + TASSERT ( strcmp(box->text, "tesbot") == 0 ); + textbox_cursor_end ( box ); + TASSERT ( box->cursor == 6); + + TASSERT( textbox_get_width( box) > 0 ); + TASSERT( textbox_get_height( box) > 0 ); + + TASSERT( textbox_get_width( box) >= textbox_get_font_width( box) ); + TASSERT( textbox_get_height( box) >= textbox_get_font_height( box) ); + + TASSERT( textbox_get_estimated_char_width ( box) > 0 ); + + textbox_cursor_bkspc ( box ); + TASSERT ( strcmp(box->text, "tesbo") == 0 ); + TASSERT ( box->cursor == 5); + + textbox_cursor_dec ( box ); + TASSERT ( box->cursor == 4); + textbox_cursor_del ( box ); + TASSERT ( strcmp(box->text, "tesb") == 0 ); + textbox_cursor_dec ( box ); + TASSERT ( box->cursor == 3); + textbox_cursor_inc ( box ); + TASSERT ( box->cursor == 4); + textbox_cursor_inc ( box ); + TASSERT ( box->cursor == 4); + // Cursor after delete section. + textbox_delete ( box, 0, 1 ); + TASSERT ( strcmp(box->text, "esb") == 0 ); + TASSERT ( box->cursor == 3); + // Cursor before delete. + textbox_text( box, "aap noot mies"); + TASSERT ( strcmp(box->text, "aap noot mies") == 0 ); + textbox_cursor( box, 3 ); + TASSERT ( box->cursor == 3); + textbox_delete ( box, 3, 6 ); + TASSERT ( strcmp(box->text, "aapmies") == 0 ); + TASSERT ( box->cursor == 3); + + // Cursor within delete + textbox_text( box, "aap noot mies"); + TASSERT ( strcmp(box->text, "aap noot mies") == 0 ); + textbox_cursor( box, 5 ); + TASSERT ( box->cursor == 5); + textbox_delete ( box, 3, 6 ); + TASSERT ( strcmp(box->text, "aapmies") == 0 ); + TASSERT ( box->cursor == 3); + // Cursor after delete. + textbox_text( box, "aap noot mies"); + TASSERT ( strcmp(box->text, "aap noot mies") == 0 ); + textbox_cursor( box, 11 ); + TASSERT ( box->cursor == 11); + textbox_delete ( box, 3, 6 ); + TASSERT ( strcmp(box->text, "aapmies") == 0 ); + TASSERT ( box->cursor == 5); + + + textbox_font ( box, HIGHLIGHT ); + textbox_draw( box ); + + textbox_show( box ); + textbox_move ( box, 12, 13); + TASSERT ( box->x == 12 ); + TASSERT ( box->y == 13 ); + textbox_hide( box ); + + textbox_free(box); + textbox_cleanup(); + XDestroyWindow ( display, mw); + XCloseDisplay ( display ); +} |