1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-25 13:55:34 -05:00

Add more tests and re-add textbox_test to normal check set.

This commit is contained in:
Dave Davenport 2016-10-20 19:34:03 +02:00
parent 881056ea9b
commit c8d2069098
5 changed files with 398 additions and 6 deletions

View file

@ -143,7 +143,16 @@ update-manpage: $(top_srcdir)/doc/rofi-manpage.markdown
##
# Rofi test program
##
check_PROGRAMS=history_test textbox_test helper_test helper_expand helper_config_cmdline_parser widget_test
check_PROGRAMS=\
history_test\
textbox_test\
helper_test\
helper_expand\
helper_pidfile\
helper_tokenize\
helper_config_cmdline_parser\
widget_test
history_test_CFLAGS=\
$(AM_CFLAGS)\
@ -185,6 +194,36 @@ textbox_test_LDADD=\
$(cairo_LIBS)\
$(libsn_LIBS)
helper_pidfile_CFLAGS=$(textbox_test_CFLAGS)
helper_pidfile_LDADD=$(textbox_test_LDADD)
helper_pidfile_SOURCES=\
config/config.c\
include/rofi.h\
include/mode.h\
include/mode-private.h\
source/helper.c\
include/helper.h\
include/xrmoptions.h\
source/xrmoptions.c\
source/x11-helper.c\
inlucde/x11-helper.h\
test/helper-pidfile.c
helper_tokenize_CFLAGS=$(textbox_test_CFLAGS)
helper_tokenize_LDADD=$(textbox_test_LDADD)
helper_tokenize_SOURCES=\
config/config.c\
include/rofi.h\
include/mode.h\
include/mode-private.h\
source/helper.c\
include/helper.h\
include/xrmoptions.h\
source/xrmoptions.c\
source/x11-helper.c\
inlucde/x11-helper.h\
test/helper-tokenize.c
widget_test_LDADD=$(textbox_test_LDADD)
widget_test_CFLAGS=$(textbox_test_CFLAGS)
widget_test_SOURCES=\
@ -271,13 +310,14 @@ TESTS=\
history_test\
helper_test\
helper_expand\
helper_pidfile\
helper_tokenize\
helper_config_cmdline_parser\
textbox_test\
widget_test
.PHONY: test-x
test-x: $(bin_PROGRAMS) textbox_test
echo "Test 1"
$(top_srcdir)/test/run_test.sh 123 $(top_builddir)/textbox_test $(top_builddir)
test-x: $(bin_PROGRAMS)
echo "Test 2"
$(top_srcdir)/test/run_test.sh 200 $(top_srcdir)/test/run_errormsg_test.sh $(top_builddir)
echo "Test 3"

View file

@ -47,17 +47,45 @@ int main ( int argc, char ** argv )
char **list = NULL;
int llength = 0;
char * test_str =
"{host} {terminal} -e bash -c \"{ssh-client} {host}; echo '{terminal} {host}'\"";
"{host} {terminal} -e bash -c \"{ssh-client} {host}; echo '{terminal} {host}'\" -i -3 -u 4";
helper_parse_setup ( test_str, &list, &llength, "{host}", "chuck",
"{terminal}", "x-terminal-emulator", NULL );
TASSERT ( llength == 6 );
TASSERT ( llength == 10);
TASSERT ( strcmp ( list[0], "chuck" ) == 0 );
TASSERT ( strcmp ( list[1], "x-terminal-emulator" ) == 0 );
TASSERT ( strcmp ( list[2], "-e" ) == 0 );
TASSERT ( strcmp ( list[3], "bash" ) == 0 );
TASSERT ( strcmp ( list[4], "-c" ) == 0 );
TASSERT ( strcmp ( list[5], "ssh chuck; echo 'x-terminal-emulator chuck'" ) == 0 );
TASSERT ( strcmp ( list[6], "-i" ) == 0 );
TASSERT ( strcmp ( list[7], "-3" ) == 0 );
TASSERT ( strcmp ( list[8], "-u" ) == 0 );
TASSERT ( strcmp ( list[9], "4" ) == 0 );
cmd_set_arguments ( llength, list);
TASSERT( find_arg ( "-e") == 2 );
TASSERT( find_arg ( "-x") == -1 );
char *str;
TASSERT( find_arg_str ( "-e", &str) == TRUE );
TASSERT ( str == list[3] );
TASSERT( find_arg_str ( "-x", &str) == FALSE );
// Should be unmodified.
TASSERT ( str == list[3] );
unsigned int u = 1234;
unsigned int i = -1234;
TASSERT ( find_arg_uint ( "-x", &u ) == FALSE );
TASSERT ( u == 1234 );
TASSERT ( find_arg_int ( "-x", &i ) == FALSE );
TASSERT ( i == -1234 );
TASSERT ( find_arg_uint ( "-u", &u ) == TRUE );
TASSERT ( u == 4 );
TASSERT ( find_arg_uint ( "-i", &u ) == TRUE );
TASSERT ( u == 4294967293 );
TASSERT ( find_arg_int ( "-i", &i ) == TRUE );
TASSERT ( i == -3 );
g_strfreev ( list );
}

57
test/helper-pidfile.c Normal file
View file

@ -0,0 +1,57 @@
#include <assert.h>
#include <locale.h>
#include <glib.h>
#include <stdio.h>
#include <helper.h>
#include <string.h>
#include <xcb/xcb_ewmh.h>
#include "xcb-internal.h"
#include "rofi.h"
#include "settings.h"
static int test = 0;
#define TASSERT( a ) { \
assert ( a ); \
printf ( "Test %i passed (%s)\n", ++test, # a ); \
}
int rofi_view_error_dialog ( const char *msg, G_GNUC_UNUSED int markup )
{
fputs ( msg, stderr );
return TRUE;
}
int show_error_message ( const char *msg, int markup )
{
fputs ( msg, stderr );
return 0;
}
xcb_screen_t *xcb_screen;
xcb_ewmh_connection_t xcb_ewmh;
int xcb_screen_nbr;
#include <x11-helper.h>
int main ( int argc, char ** argv )
{
if ( setlocale ( LC_ALL, "" ) == NULL ) {
fprintf ( stderr, "Failed to set locale.\n" );
return EXIT_FAILURE;
}
// Pid test.
// Tests basic functionality of writing it, locking, seeing if I can write same again
// And close/reopen it again.
{
const char *path = "/tmp/rofi-test.pid";
TASSERT( create_pid_file ( NULL ) == -1 );
int fd = create_pid_file ( path );
TASSERT( fd >= 0 );
int fd2 = create_pid_file ( path );
TASSERT ( fd2 < 0 );
remove_pid_file ( fd );
fd = create_pid_file ( path );
TASSERT( fd >= 0 );
remove_pid_file ( fd );
}
}

View file

@ -98,4 +98,20 @@ int main ( int argc, char ** argv )
TASSERT ( g_utf8_collate ( str, "Valid utf8 until <20>( we continue here") == 0 );
g_free(str);
}
// Pid test.
// Tests basic functionality of writing it, locking, seeing if I can write same again
// And close/reopen it again.
{
const char *path = "/tmp/rofi-test.pid";
TASSERT( create_pid_file ( NULL ) == -1 );
int fd = create_pid_file ( path );
TASSERT( fd >= 0 );
int fd2 = create_pid_file ( path );
TASSERT ( fd2 < 0 );
remove_pid_file ( fd );
fd = create_pid_file ( path );
TASSERT( fd >= 0 );
remove_pid_file ( fd );
}
}

251
test/helper-tokenize.c Normal file
View file

@ -0,0 +1,251 @@
#include <assert.h>
#include <locale.h>
#include <glib.h>
#include <stdio.h>
#include <helper.h>
#include <string.h>
#include <xcb/xcb_ewmh.h>
#include "xcb-internal.h"
#include "rofi.h"
#include "settings.h"
static int test = 0;
#define TASSERT( a ) { \
assert ( a ); \
printf ( "Test %i passed (%s)\n", ++test, # a ); \
}
int rofi_view_error_dialog ( const char *msg, G_GNUC_UNUSED int markup )
{
fputs ( msg, stderr );
return TRUE;
}
int show_error_message ( const char *msg, int markup )
{
fputs ( msg, stderr );
return 0;
}
xcb_screen_t *xcb_screen;
xcb_ewmh_connection_t xcb_ewmh;
int xcb_screen_nbr;
#include <x11-helper.h>
int main ( int argc, char ** argv )
{
if ( setlocale ( LC_ALL, "" ) == NULL ) {
fprintf ( stderr, "Failed to set locale.\n" );
return EXIT_FAILURE;
}
// Pid test.
// Tests basic functionality of writing it, locking, seeing if I can write same again
// And close/reopen it again.
{
tokenize_free ( NULL );
}
{
config.matching_method = MM_NORMAL;
GRegex **tokens = tokenize ( "noot", FALSE );
TASSERT ( token_match ( tokens, "aap noot mies") == TRUE );
TASSERT ( token_match ( tokens, "aap mies") == FALSE );
TASSERT ( token_match ( tokens, "nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "nootap mies") == TRUE );
TASSERT ( token_match ( tokens, "aap Noot mies") == TRUE );
TASSERT ( token_match ( tokens, "Nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "noOTap mies") == TRUE );
tokenize_free ( tokens );
tokens = tokenize ( "noot", TRUE );
TASSERT ( token_match ( tokens, "aap noot mies") == TRUE );
TASSERT ( token_match ( tokens, "aap mies") == FALSE );
TASSERT ( token_match ( tokens, "nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "nootap mies") == TRUE );
TASSERT ( token_match ( tokens, "aap Noot mies") == FALSE );
TASSERT ( token_match ( tokens, "Nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "noOTap mies") == FALSE );
tokenize_free ( tokens );
tokens = tokenize ( "no ot", FALSE );
TASSERT ( token_match ( tokens, "aap noot mies") == TRUE );
TASSERT ( token_match ( tokens, "aap mies") == FALSE );
TASSERT ( token_match ( tokens, "nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "nootap mies") == TRUE );
TASSERT ( token_match ( tokens, "noap miesot") == TRUE );
tokenize_free ( tokens );
}
{
config.matching_method = MM_GLOB;
GRegex **tokens = tokenize ( "noot", FALSE );
TASSERT ( token_match ( tokens, "aap noot mies") == TRUE );
TASSERT ( token_match ( tokens, "aap mies") == FALSE );
TASSERT ( token_match ( tokens, "nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "nootap mies") == TRUE );
TASSERT ( token_match ( tokens, "aap Noot mies") == TRUE );
TASSERT ( token_match ( tokens, "Nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "noOTap mies") == TRUE );
tokenize_free ( tokens );
tokens = tokenize ( "noot", TRUE );
TASSERT ( token_match ( tokens, "aap noot mies") == TRUE );
TASSERT ( token_match ( tokens, "aap mies") == FALSE );
TASSERT ( token_match ( tokens, "nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "nootap mies") == TRUE );
TASSERT ( token_match ( tokens, "aap Noot mies") == FALSE );
TASSERT ( token_match ( tokens, "Nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "noOTap mies") == FALSE );
tokenize_free ( tokens );
tokens = tokenize ( "no ot", FALSE );
TASSERT ( token_match ( tokens, "aap noot mies") == TRUE );
TASSERT ( token_match ( tokens, "aap mies") == FALSE );
TASSERT ( token_match ( tokens, "nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "nootap mies") == TRUE );
TASSERT ( token_match ( tokens, "noap miesot") == TRUE );
tokenize_free ( tokens );
tokens = tokenize ( "n?ot", FALSE );
TASSERT ( token_match ( tokens, "aap noot mies") == TRUE );
TASSERT ( token_match ( tokens, "aap mies") == FALSE );
TASSERT ( token_match ( tokens, "nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "nootap mies") == TRUE );
TASSERT ( token_match ( tokens, "noap miesot") == FALSE);
tokenize_free ( tokens );
tokens = tokenize ( "n*ot", FALSE );
TASSERT ( token_match ( tokens, "aap noot mies") == TRUE );
TASSERT ( token_match ( tokens, "aap mies") == FALSE );
TASSERT ( token_match ( tokens, "nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "nootap mies") == TRUE );
TASSERT ( token_match ( tokens, "noap miesot") == TRUE);
tokenize_free ( tokens );
tokens = tokenize ( "n* ot", FALSE );
TASSERT ( token_match ( tokens, "aap noot mies") == TRUE );
TASSERT ( token_match ( tokens, "aap mies") == FALSE );
TASSERT ( token_match ( tokens, "nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "nootap mies") == TRUE );
TASSERT ( token_match ( tokens, "noap miesot") == TRUE);
TASSERT ( token_match ( tokens, "ot nap mies") == TRUE);
tokenize_free ( tokens );
}
{
config.matching_method = MM_FUZZY;
GRegex **tokens = tokenize ( "noot", FALSE );
TASSERT ( token_match ( tokens, "aap noot mies") == TRUE );
TASSERT ( token_match ( tokens, "aap mies") == FALSE );
TASSERT ( token_match ( tokens, "nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "nootap mies") == TRUE );
TASSERT ( token_match ( tokens, "aap Noot mies") == TRUE );
TASSERT ( token_match ( tokens, "Nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "noOTap mies") == TRUE );
tokenize_free ( tokens );
tokens = tokenize ( "noot", TRUE );
TASSERT ( token_match ( tokens, "aap noot mies") == TRUE );
TASSERT ( token_match ( tokens, "aap mies") == FALSE );
TASSERT ( token_match ( tokens, "nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "nootap mies") == TRUE );
TASSERT ( token_match ( tokens, "aap Noot mies") == FALSE );
TASSERT ( token_match ( tokens, "Nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "noOTap mies") == FALSE );
tokenize_free ( tokens );
tokens = tokenize ( "no ot", FALSE );
TASSERT ( token_match ( tokens, "aap noot mies") == TRUE );
TASSERT ( token_match ( tokens, "aap mies") == FALSE );
TASSERT ( token_match ( tokens, "nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "nootap mies") == TRUE );
TASSERT ( token_match ( tokens, "noap miesot") == TRUE );
tokenize_free ( tokens );
tokens = tokenize ( "n ot", FALSE );
TASSERT ( token_match ( tokens, "aap noot mies") == TRUE );
TASSERT ( token_match ( tokens, "aap mies") == FALSE );
TASSERT ( token_match ( tokens, "nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "nootap mies") == TRUE );
TASSERT ( token_match ( tokens, "noap miesot") == TRUE);
tokenize_free ( tokens );
tokens = tokenize ( "ont", FALSE );
TASSERT ( token_match ( tokens, "aap noot mies") == FALSE);
TASSERT ( token_match ( tokens, "aap mies") == FALSE );
TASSERT ( token_match ( tokens, "nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "nootap nmiest") == TRUE );
tokenize_free ( tokens );
tokens = tokenize ( "o n t", FALSE );
TASSERT ( token_match ( tokens, "aap noot mies") == TRUE );
TASSERT ( token_match ( tokens, "aap mies") == FALSE );
TASSERT ( token_match ( tokens, "nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "nootap mies") == TRUE );
TASSERT ( token_match ( tokens, "noap miesot") == TRUE);
TASSERT ( token_match ( tokens, "ot nap mies") == TRUE);
tokenize_free ( tokens );
}
{
config.matching_method = MM_REGEX;
GRegex **tokens = tokenize ( "noot", FALSE );
TASSERT ( token_match ( tokens, "aap noot mies") == TRUE );
TASSERT ( token_match ( tokens, "aap mies") == FALSE );
TASSERT ( token_match ( tokens, "nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "nootap mies") == TRUE );
TASSERT ( token_match ( tokens, "aap Noot mies") == TRUE );
TASSERT ( token_match ( tokens, "Nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "noOTap mies") == TRUE );
tokenize_free ( tokens );
tokens = tokenize ( "noot", TRUE );
TASSERT ( token_match ( tokens, "aap noot mies") == TRUE );
TASSERT ( token_match ( tokens, "aap mies") == FALSE );
TASSERT ( token_match ( tokens, "nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "nootap mies") == TRUE );
TASSERT ( token_match ( tokens, "aap Noot mies") == FALSE );
TASSERT ( token_match ( tokens, "Nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "noOTap mies") == FALSE );
tokenize_free ( tokens );
tokens = tokenize ( "no ot", FALSE );
TASSERT ( token_match ( tokens, "aap noot mies") == TRUE );
TASSERT ( token_match ( tokens, "aap mies") == FALSE );
TASSERT ( token_match ( tokens, "nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "nootap mies") == TRUE );
TASSERT ( token_match ( tokens, "noap miesot") == TRUE );
tokenize_free ( tokens );
tokens = tokenize ( "n.?ot", FALSE );
TASSERT ( token_match ( tokens, "aap noot mies") == TRUE );
TASSERT ( token_match ( tokens, "aap mies") == FALSE );
TASSERT ( token_match ( tokens, "nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "nootap mies") == TRUE );
TASSERT ( token_match ( tokens, "noap miesot") == FALSE);
tokenize_free ( tokens );
tokens = tokenize ( "n[oa]{2}t", FALSE );
TASSERT ( token_match ( tokens, "aap noot mies") == TRUE );
TASSERT ( token_match ( tokens, "aap mies") == FALSE );
TASSERT ( token_match ( tokens, "nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "nootap mies") == TRUE );
TASSERT ( token_match ( tokens, "noat miesot") == TRUE);
TASSERT ( token_match ( tokens, "noaat miesot") == FALSE);
tokenize_free ( tokens );
tokens = tokenize ( "^(aap|noap)\\sMie.*", FALSE );
TASSERT ( token_match ( tokens, "aap noot mies") == FALSE );
TASSERT ( token_match ( tokens, "aap mies") == TRUE);
TASSERT ( token_match ( tokens, "nooaap mies") == FALSE );
TASSERT ( token_match ( tokens, "nootap mies") == FALSE );
TASSERT ( token_match ( tokens, "noap miesot") == TRUE);
TASSERT ( token_match ( tokens, "ot nap mies") == FALSE );
tokenize_free ( tokens );
}
}