diff options
author | Dave Davenport <qball@gmpclient.org> | 2016-10-20 19:34:03 +0200 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2016-10-20 19:34:03 +0200 |
commit | c8d206909874d986ea6640e917e49c67322915e4 (patch) | |
tree | 32e04116d12781d61b467c518f7a58521aa4421d /test | |
parent | 881056ea9b1a606d1d979be631795a3a07d5621e (diff) |
Add more tests and re-add textbox_test to normal check set.
Diffstat (limited to 'test')
-rw-r--r-- | test/helper-config-cmdline-parser.c | 32 | ||||
-rw-r--r-- | test/helper-pidfile.c | 57 | ||||
-rw-r--r-- | test/helper-test.c | 16 | ||||
-rw-r--r-- | test/helper-tokenize.c | 251 |
4 files changed, 354 insertions, 2 deletions
diff --git a/test/helper-config-cmdline-parser.c b/test/helper-config-cmdline-parser.c index 861b43bf..c1521aa5 100644 --- a/test/helper-config-cmdline-parser.c +++ b/test/helper-config-cmdline-parser.c @@ -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 ); } diff --git a/test/helper-pidfile.c b/test/helper-pidfile.c new file mode 100644 index 00000000..dae85829 --- /dev/null +++ b/test/helper-pidfile.c @@ -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 ); + } +} diff --git a/test/helper-test.c b/test/helper-test.c index 4ae5694a..4ed00128 100644 --- a/test/helper-test.c +++ b/test/helper-test.c @@ -98,4 +98,20 @@ int main ( int argc, char ** argv ) TASSERT ( g_utf8_collate ( str, "Valid utf8 until �( 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 ); + } } diff --git a/test/helper-tokenize.c b/test/helper-tokenize.c new file mode 100644 index 00000000..ea82da03 --- /dev/null +++ b/test/helper-tokenize.c @@ -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 ); + } +} |