diff --git a/Makefile.am b/Makefile.am index 148282c3..50cbcdd1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -226,7 +226,8 @@ check_PROGRAMS=\ widget_test\ box_test\ theme_parser_test\ - scrollbar_test + scrollbar_test\ + mode_test history_test_CFLAGS=\ @@ -450,6 +451,20 @@ helper_config_cmdline_parser_SOURCES=\ source/x11-helper.c\ test/helper-config-cmdline-parser.c + +mode_test_CFLAGS=$(textbox_test_CFLAGS) +mode_test_LDADD=$(textbox_test_LDADD) +mode_test_SOURCES=\ + config/config.c\ + test/mode-test.c\ + source/dialogs/help-keys.c\ + source/helper.c\ + source/mode.c\ + source/xrmoptions.c\ + source/keyb.c\ + include/mode.h\ + include/mode-private.h + TESTS=\ history_test\ helper_test\ @@ -461,7 +476,8 @@ TESTS=\ widget_test\ box_test\ theme_parser_test\ - scrollbar_test + scrollbar_test\ + mode_test .PHONY: test-x test-x: $(bin_PROGRAMS) diff --git a/test/mode-test.c b/test/mode-test.c new file mode 100644 index 00000000..05e9410c --- /dev/null +++ b/test/mode-test.c @@ -0,0 +1,108 @@ +/* + * rofi + * + * MIT/X11 License + * Copyright © 2013-2017 Qball Cow + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +unsigned int test =0; +#define TASSERT( a ) { \ + assert ( a ); \ + printf ( "Test %3i passed (%s)\n", ++test, # a ); \ +} + +#define TASSERTE( a, b ) { \ + if ( ( a ) == ( b ) ) { \ + printf ( "Test %i passed (%s == %s) (%u == %u)\n", ++test, # a, # b, a, b ); \ + }else { \ + printf ( "Test %i failed (%s == %s) (%u != %u)\n", ++test, # a, # b, a, b ); \ + abort ( ); \ + } \ +} +void rofi_add_error_message ( GString *msg ) +{ +} +int monitor_active ( void *d ) +{ + return 0; +} +int rofi_view_error_dialog ( const char *msg, G_GNUC_UNUSED int markup ) +{ + fputs ( msg, stderr ); + return TRUE; +} +int textbox_get_estimated_char_height ( void ); +int textbox_get_estimated_char_height ( void ) +{ + return 16; +} +void rofi_view_get_current_monitor ( int *width, int *height ) +{ + +} +void * rofi_view_get_active ( void ) +{ + return NULL; +} +gboolean rofi_view_trigger_action ( void *state, KeyBindingAction action ) +{ +} +gboolean x11_parse_key ( const char *combo, unsigned int *mod, xkb_keysym_t *key, gboolean *release, GString *msg ) +{ + return TRUE; +} + + +int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv ) +{ + setup_abe (); + TASSERTE ( mode_init ( &help_keys_mode ), TRUE ); + + unsigned int rows = mode_get_num_entries ( &help_keys_mode); + TASSERTE ( rows , 64); + + for ( int i =0; i < rows; i++ ){ + int state = 0; + GList *list = NULL; + char *v = mode_get_display_value ( &help_keys_mode, i, &state, &list, TRUE ); + TASSERT ( v != NULL ); + g_free ( v ); + v = mode_get_display_value ( &help_keys_mode, i, &state, &list, FALSE ); + TASSERT ( v == NULL ); + } + + mode_destroy ( &help_keys_mode ); +}