1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

Play with adding some more test, bug fixes

* delete an invalid memmove in textbox
This commit is contained in:
Dave Davenport 2014-08-30 20:45:08 +02:00
parent 91ccb54199
commit 229bb6931b
11 changed files with 228 additions and 71 deletions

View file

@ -88,8 +88,3 @@ update-manpage: ${top_srcdir}/doc/rofi-manpage.markdown
.PHONY: test
test: rofi
make -C test/ test
./test/run_errormsg_test.sh
./test/run_switchdialog_test.sh
./test/run_dmenu_test.sh
./test/run_dmenu_custom_test.sh
./test/run_run_test.sh

View file

@ -92,4 +92,13 @@ int textbox_get_font_height ( textbox *tb );
int textbox_get_font_width ( textbox *tb );
double textbox_get_estimated_char_width ( );
void textbox_cursor_bkspc ( textbox *tb );
void textbox_cursor_del ( textbox *tb );
void textbox_cursor_dec ( textbox *tb );
void textbox_cursor_inc ( textbox *tb );
void textbox_delete ( textbox *tb, int pos, int dlen );
#endif //__TEXTBOX_H__

View file

@ -320,7 +320,13 @@ void textbox_delete ( textbox *tb, int pos, int dlen )
pos = MAX ( 0, MIN ( len, pos ) );
// move everything after pos+dlen down
char *at = tb->text + pos;
memmove ( at, at + dlen, len - pos );
// Move remainder + closing \0
memmove ( at, at + dlen, len - pos-dlen+1 );
if ( tb->cursor >= pos && tb->cursor < (pos+dlen) ) {
tb->cursor = pos;
} else if ( tb->cursor >= (pos+dlen) ) {
tb->cursor -= dlen;
}
}
// delete on character

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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}

View file

@ -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}

View file

@ -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

35
test/run_test.sh Executable file
View file

@ -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}

136
test/textbox-test.c Normal file
View file

@ -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 );
}