Add screenshot test

This commit is contained in:
Dave Davenport 2015-12-31 21:55:15 +01:00
parent de96149bed
commit 745f9f3c62
5 changed files with 34 additions and 5 deletions

View file

@ -186,6 +186,8 @@ test-x: ${bin_PROGRAMS}
$(top_srcdir)/test/run_test.sh 208 $(top_srcdir)/test/run_dmenu_empty.sh $(top_builddir)
echo "Test multiple select"
$(top_srcdir)/test/run_test.sh 209 $(top_srcdir)/test/run_dmenu_issue_292.sh $(top_builddir)
echo "Test screenshot"
$(top_srcdir)/test/run_test.sh 210 $(top_srcdir)/test/run_screenshot_test.sh $(top_builddir)
echo "End tests"

View file

@ -613,14 +613,15 @@ static int locate_switcher ( KeySym key, unsigned int modstate )
*/
static void menu_capture_screenshot ( void )
{
const char *outp = g_getenv ( "ROFI_PNG_OUTPUT" );
if ( surface == NULL ) {
// Nothing to store.
fprintf ( stderr, "There is no rofi surface to store\n" );
return;
}
const char *xdg_pict_dir = g_get_user_special_dir ( G_USER_DIRECTORY_PICTURES );
if ( xdg_pict_dir == NULL ) {
fprintf ( stderr, "XDG user picture directory is not set. Cannot store screenshot.\n" );
if ( outp == NULL && xdg_pict_dir == NULL ) {
fprintf ( stderr, "XDG user picture directory or ROFI_PNG_OUTPUT is not set. Cannot store screenshot.\n" );
return;
}
// Get current time.
@ -630,7 +631,6 @@ static void menu_capture_screenshot ( void )
char *filename = g_strdup_printf ( "%s.png", timestmp );
// Build full path
char *fpath = NULL;
const char *outp = g_getenv ( "ROFI_PNG_OUTPUT" );
if ( outp == NULL ) {
int index = 0;
fpath = g_build_filename ( xdg_pict_dir, filename, NULL );

View file

@ -1,6 +1,5 @@
#!/usr/bin/env bash
xrdb -load ../doc/example.xresources
echo -e -n "aap\nnoot\nmies" | rofi -width -30 -dmenu > output.txt &
RPID=$!

28
test/run_screenshot_test.sh Executable file
View file

@ -0,0 +1,28 @@
#!/usr/bin/env bash
export ROFI_PNG_OUTPUT=out.png
rofi -show run &
RPID=$!
# send enter.
sleep 5;
xdotool key 't'
sleep 0.4
xdotool key 'r'
sleep 0.4
xdotool key 'u'
sleep 0.4
xdotool key Alt+Shift+s
sleep 0.4
xdotool key Return
# Get result, kill xvfb
wait ${RPID}
RETV=$?
if [ ! -f out.png ]
then
echo "Failed to create screenshot"
exit 1
fi
exit ${RETV}

View file

@ -28,7 +28,7 @@ fi
create_fake_x "$1"
if [ -n "$4" ]
then
xrdb -load "$4"
xrdb -load -retain "$4"
fi
echo "$DISPLAY"
$2