From 0e90fb065f488cde2584e1f0059e169141b04830 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Sat, 23 Jul 2022 00:28:55 +0200 Subject: [Build] Fix some compile warnings. --- include/mode-private.h | 2 +- include/mode.h | 2 +- include/theme.h | 2 +- meson.build | 1 + source/mode.c | 2 +- source/modes/combi.c | 2 +- source/modes/dmenu.c | 32 +- source/modes/drun.c | 2 +- source/modes/filebrowser.c | 2 +- source/modes/run.c | 2 +- source/modes/script.c | 9 +- source/modes/window.c | 5 +- source/rofi.c | 2 +- source/theme.c | 7 +- source/view.c | 4 +- source/widgets/widget.c | 6 +- source/xrmoptions.c | 4 +- test/box-test.c | 447 +++++++++++----------- test/helper-config-cmdline-parser.c | 195 +++++----- test/helper-expand.c | 167 ++++----- test/helper-pidfile.c | 18 +- test/helper-test.c | 366 +++++++++--------- test/helper-tokenize.c | 714 +++++++++++++++++------------------- test/mode-test.c | 18 +- test/scrollbar-test.c | 202 +++++----- test/textbox-test.c | 312 ++++++++-------- test/theme-parser-test.c | 15 +- test/widget-test.c | 352 +++++++++--------- 28 files changed, 1411 insertions(+), 1481 deletions(-) diff --git a/include/mode-private.h b/include/mode-private.h index 0f5bcaed..8becbdab 100644 --- a/include/mode-private.h +++ b/include/mode-private.h @@ -67,7 +67,7 @@ typedef char *(*_mode_get_display_value)(const Mode *sw, */ typedef cairo_surface_t *(*_mode_get_icon)(const Mode *sw, unsigned int selected_line, - int height); + unsigned int height); /** * @param sw The #Mode pointer diff --git a/include/mode.h b/include/mode.h index b0b8314a..3825ee43 100644 --- a/include/mode.h +++ b/include/mode.h @@ -139,7 +139,7 @@ char *mode_get_display_value(const Mode *mode, unsigned int selected_line, * @returns allocated new cairo_surface_t if applicable */ cairo_surface_t *mode_get_icon(Mode *mode, unsigned int selected_line, - int height); + unsigned int height); /** * @param mode The mode to query diff --git a/include/theme.h b/include/theme.h index 789aa5f3..45faa67c 100644 --- a/include/theme.h +++ b/include/theme.h @@ -144,7 +144,7 @@ void rofi_theme_property_free(Property *p); * * @returns a copy of p */ -Property *rofi_theme_property_copy(const Property *p); +Property *rofi_theme_property_copy(const Property *p, void *); /** * @param widget * diff --git a/meson.build b/meson.build index 987c021e..1a04ae87 100644 --- a/meson.build +++ b/meson.build @@ -22,6 +22,7 @@ flags = [ '-Wunreachable-code', '-Werror=missing-prototypes', '-Wno-inline', # A bit too noisy with Bison… + '-Wextra' ] foreach f : flags if c_compiler.has_argument(f) diff --git a/source/mode.c b/source/mode.c index 588f9718..02c4aaee 100644 --- a/source/mode.c +++ b/source/mode.c @@ -73,7 +73,7 @@ char *mode_get_display_value(const Mode *mode, unsigned int selected_line, } cairo_surface_t *mode_get_icon(Mode *mode, unsigned int selected_line, - int height) { + unsigned int height) { g_assert(mode != NULL); if (mode->_get_icon != NULL) { diff --git a/source/modes/combi.c b/source/modes/combi.c index cc60c33c..6293aa62 100644 --- a/source/modes/combi.c +++ b/source/modes/combi.c @@ -277,7 +277,7 @@ static char *combi_get_completion(const Mode *sw, unsigned int index) { } static cairo_surface_t *combi_get_icon(const Mode *sw, unsigned int index, - int height) { + unsigned int height) { CombiModePrivateData *pd = mode_get_private_data(sw); for (unsigned i = 0; i < pd->num_switchers; i++) { if (index >= pd->starts[i] && index < (pd->starts[i] + pd->lengths[i])) { diff --git a/source/modes/dmenu.c b/source/modes/dmenu.c index 62dc76d7..ad4a7ae5 100644 --- a/source/modes/dmenu.c +++ b/source/modes/dmenu.c @@ -56,8 +56,8 @@ static int dmenu_mode_init(Mode *sw); static int dmenu_token_match(const Mode *sw, rofi_int_matcher **tokens, unsigned int index); -static cairo_surface_t *dmenu_get_icon(const Mode *sw, - unsigned int selected_line, int height); +static cairo_surface_t * +dmenu_get_icon(const Mode *sw, unsigned int selected_line, unsigned int height); static char *dmenu_get_message(const Mode *sw); static inline unsigned int bitget(uint32_t const *const array, @@ -192,9 +192,13 @@ static gboolean dmenu_async_read_proc(gint fd, GIOCondition condition, gpointer user_data) { DmenuModePrivateData *pd = (DmenuModePrivateData *)user_data; char command; + // Only interrested in read events. + if ((condition & G_IO_IN) != G_IO_IN) { + return G_SOURCE_CONTINUE; + } // Read the entry from the pipe that was used to signal this action. if (read(fd, &command, 1) == 1) { - if ( command == 'r' ){ + if (command == 'r') { Block *block = NULL; gboolean changed = FALSE; // Empty out the AsyncQueue (that is thread safe) from all blocks pushed @@ -204,10 +208,10 @@ static gboolean dmenu_async_read_proc(gint fd, GIOCondition condition, if (pd->cmd_list_real_length < (pd->cmd_list_length + block->length)) { pd->cmd_list_real_length = MAX(pd->cmd_list_real_length * 2, 4096); pd->cmd_list = g_realloc(pd->cmd_list, sizeof(DmenuScriptEntry) * - pd->cmd_list_real_length); + pd->cmd_list_real_length); } memcpy(&(pd->cmd_list[pd->cmd_list_length]), &(block->values[0]), - sizeof(DmenuScriptEntry) * block->length); + sizeof(DmenuScriptEntry) * block->length); pd->cmd_list_length += block->length; g_free(block); changed = TRUE; @@ -215,8 +219,8 @@ static gboolean dmenu_async_read_proc(gint fd, GIOCondition condition, if (changed) { rofi_view_reload(); } - } else if ( command == 'q' ){ - if ( pd->loading ) { + } else if (command == 'q') { + if (pd->loading) { rofi_view_set_overlay(rofi_view_get_active(), NULL); } } @@ -239,7 +243,7 @@ static void read_input_sync(DmenuModePrivateData *pd, unsigned int pre_read) { static gpointer read_input_thread(gpointer userdata) { DmenuModePrivateData *pd = (DmenuModePrivateData *)userdata; ssize_t nread = 0; - size_t len = 0; + ssize_t len = 0; char *line = NULL; // Create the message passing queue to the UI thread. pd->async_queue = g_async_queue_new(); @@ -276,7 +280,7 @@ static gpointer read_input_thread(gpointer userdata) { if (readbytes > 0) { nread += readbytes; line[nread] = '\0'; - size_t i = 0; + ssize_t i = 0; while (i < nread) { if (line[i] == pd->separator) { line[i] = '\0'; @@ -632,7 +636,8 @@ static char *dmenu_get_message(const Mode *sw) { return NULL; } static cairo_surface_t *dmenu_get_icon(const Mode *sw, - unsigned int selected_line, int height) { + unsigned int selected_line, + unsigned int height) { DmenuModePrivateData *pd = (DmenuModePrivateData *)mode_get_private_data(sw); g_return_val_if_fail(pd->cmd_list != NULL, NULL); @@ -650,7 +655,8 @@ static cairo_surface_t *dmenu_get_icon(const Mode *sw, return rofi_icon_fetcher_get(uid); } -static void dmenu_finish(DmenuModePrivateData *pd, RofiViewState *state, int retv) { +static void dmenu_finish(DmenuModePrivateData *pd, RofiViewState *state, + int retv) { if (pd->reading_thread) { // Stop listinig to new messages from reading thread. @@ -779,7 +785,7 @@ static void dmenu_finalize(RofiViewState *state) { rofi_view_restart(state); rofi_view_set_selected_line(state, pd->selected_line); if (!restart) { - dmenu_finish(pd,state, retv); + dmenu_finish(pd, state, retv); } return; } @@ -835,7 +841,7 @@ static void dmenu_finalize(RofiViewState *state) { rofi_view_restart(state); rofi_view_set_selected_line(state, pd->selected_line); } else { - dmenu_finish(pd,state, retv); + dmenu_finish(pd, state, retv); } } diff --git a/source/modes/drun.c b/source/modes/drun.c index 711b57d8..f71e888b 100644 --- a/source/modes/drun.c +++ b/source/modes/drun.c @@ -1330,7 +1330,7 @@ static char *_get_display_value(const Mode *sw, unsigned int selected_line, } static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line, - int height) { + unsigned int height) { DRunModePrivateData *pd = (DRunModePrivateData *)mode_get_private_data(sw); if (pd->file_complete) { return pd->completer->_get_icon(pd->completer, selected_line, height); diff --git a/source/modes/filebrowser.c b/source/modes/filebrowser.c index 94a35623..2f889471 100644 --- a/source/modes/filebrowser.c +++ b/source/modes/filebrowser.c @@ -561,7 +561,7 @@ static int file_browser_token_match(const Mode *sw, rofi_int_matcher **tokens, } static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line, - int height) { + unsigned int height) { FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *)mode_get_private_data(sw); g_return_val_if_fail(pd->array != NULL, NULL); diff --git a/source/modes/run.c b/source/modes/run.c index e7a49f7f..1393471f 100644 --- a/source/modes/run.c +++ b/source/modes/run.c @@ -534,7 +534,7 @@ static char *run_get_message(const Mode *sw) { return NULL; } static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line, - int height) { + unsigned int height) { RunModePrivateData *pd = (RunModePrivateData *)mode_get_private_data(sw); if (pd->file_complete) { return pd->completer->_get_icon(pd->completer, selected_line, height); diff --git a/source/modes/script.c b/source/modes/script.c index c67ed263..25d8e852 100644 --- a/source/modes/script.c +++ b/source/modes/script.c @@ -429,8 +429,9 @@ static char *script_get_message(const Mode *sw) { ScriptModePrivateData *pd = sw->private_data; return g_strdup(pd->message); } -static cairo_surface_t * -script_get_icon(const Mode *sw, unsigned int selected_line, int height) { +static cairo_surface_t *script_get_icon(const Mode *sw, + unsigned int selected_line, + unsigned int height) { ScriptModePrivateData *pd = (ScriptModePrivateData *)mode_get_private_data(sw); g_return_val_if_fail(pd->cmd_list != NULL, NULL); @@ -454,7 +455,7 @@ typedef struct ScriptUser { } ScriptUser; ScriptUser *user_scripts = NULL; -int num_scripts = 0; +size_t num_scripts = 0; void script_mode_cleanup(void) { for (size_t i = 0; i < num_scripts; i++) { @@ -493,7 +494,7 @@ void script_mode_gather_user_scripts(void) { static int script_mode_has_user_script(char const *const user) { - for (int i = 0; i < num_scripts; i++) { + for (size_t i = 0; i < num_scripts; i++) { if (g_strcmp0(user_scripts[i].name, user) == 0) { return i; } diff --git a/source/modes/window.c b/source/modes/window.c index a121b8c7..768292c4 100644 --- a/source/modes/window.c +++ b/source/modes/window.c @@ -399,7 +399,8 @@ static gboolean window_client_reload(G_GNUC_UNUSED void *data) { } return G_SOURCE_REMOVE; } -void window_client_handle_signal(xcb_window_t win, gboolean create) { +void window_client_handle_signal(G_GNUC_UNUSED xcb_window_t win, + G_GNUC_UNUSED gboolean create) { // g_idle_add_full(G_PRIORITY_HIGH_IDLE, window_client_reload, NULL, NULL); if (window_reload_timeout > 0) { g_source_remove(window_reload_timeout); @@ -1023,7 +1024,7 @@ static cairo_surface_t *get_net_wm_icon(xcb_window_t xid, return surface; } static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line, - int size) { + unsigned int size) { WindowModePrivateData *rmpd = mode_get_private_data(sw); client *c = window_client(rmpd, rmpd->ids->array[selected_line]); if (c == NULL) { diff --git a/source/rofi.c b/source/rofi.c index 4d40b1cd..176ecb93 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -772,7 +772,7 @@ static gboolean record(G_GNUC_UNUSED void *data) { return G_SOURCE_CONTINUE; } static void rofi_custom_log_function(const char *log_domain, - GLogLevelFlags log_level, + G_GNUC_UNUSED GLogLevelFlags log_level, const gchar *message, gpointer user_data) { int fp = GPOINTER_TO_INT(user_data); dprintf(fp, "[%s]: %s\n", log_domain == NULL ? "default" : log_domain, diff --git a/source/theme.c b/source/theme.c index 83556c2f..7270d22d 100644 --- a/source/theme.c +++ b/source/theme.c @@ -120,7 +120,8 @@ RofiDistance rofi_theme_property_copy_distance(RofiDistance const distance) { return retv; } -Property *rofi_theme_property_copy(const Property *p) { +Property *rofi_theme_property_copy(const Property *p, + G_GNUC_UNUSED void *data) { Property *retv = rofi_theme_property_create(p->type); retv->name = g_strdup(p->name); @@ -137,7 +138,7 @@ Property *rofi_theme_property_copy(const Property *p) { retv->value.link.ref = NULL; if (p->value.link.def_value) { retv->value.link.def_value = - rofi_theme_property_copy(p->value.link.def_value); + rofi_theme_property_copy(p->value.link.def_value, NULL); } break; case P_PADDING: { @@ -635,7 +636,7 @@ void yyerror(YYLTYPE *yylloc, const char *what, const char *s) { static void rofi_theme_copy_property_int(G_GNUC_UNUSED gpointer key, gpointer value, gpointer user_data) { GHashTable *table = (GHashTable *)user_data; - Property *p = rofi_theme_property_copy((Property *)value); + Property *p = rofi_theme_property_copy((Property *)value, NULL); g_hash_table_replace(table, p->name, p); } void rofi_theme_widget_add_properties(ThemeWidget *widget, GHashTable *table) { diff --git a/source/view.c b/source/view.c index 18b8175d..29569f40 100644 --- a/source/view.c +++ b/source/view.c @@ -1007,8 +1007,8 @@ inline static void rofi_view_nav_last(RofiViewState *state) { // state->selected = state->filtered_lines - 1; listview_set_selected(state->list_view, -1); } -static void selection_changed_callback(listview *lv, unsigned int index, - void *udata) { +static void selection_changed_callback(G_GNUC_UNUSED listview *lv, + unsigned int index, void *udata) { RofiViewState *state = (RofiViewState *)udata; if (state->tb_current_entry) { if (index < state->filtered_lines) { diff --git a/source/widgets/widget.c b/source/widgets/widget.c index c556e98a..29812a61 100644 --- a/source/widgets/widget.c +++ b/source/widgets/widget.c @@ -526,8 +526,10 @@ widget *widget_find_mouse_target(widget *wid, WidgetType type, gint x, gint y) { return NULL; } -WidgetTriggerActionResult widget_check_action(widget *wid, guint action, gint x, - gint y) { +WidgetTriggerActionResult widget_check_action(widget *wid, + G_GNUC_UNUSED guint action, + G_GNUC_UNUSED gint x, + G_GNUC_UNUSED gint y) { if (wid == NULL) { return FALSE; } diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 14756096..1c53aeeb 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -744,13 +744,13 @@ gboolean config_parse_set_property(const Property *p, char **error) { iter = g_list_next(iter)) { if (g_strcmp0(((Property *)(iter->data))->name, p->name) == 0) { rofi_theme_property_free((Property *)(iter->data)); - iter->data = (void *)rofi_theme_property_copy(p); + iter->data = (void *)rofi_theme_property_copy(p, NULL); return FALSE; } } g_debug("Adding option: %s to backup list.", p->name); extra_parsed_options = - g_list_append(extra_parsed_options, rofi_theme_property_copy(p)); + g_list_append(extra_parsed_options, rofi_theme_property_copy(p, NULL)); return FALSE; } diff --git a/test/box-test.c b/test/box-test.c index af309f9c..e2a300e5 100644 --- a/test/box-test.c +++ b/test/box-test.c @@ -25,268 +25,255 @@ * */ -#include -#include -#include -#include +#include "helper.h" +#include "rofi-icon-fetcher.h" +#include "rofi.h" +#include "xrmoptions.h" #include #include +#include +#include +#include #include #include +#include #include -#include #include -#include "rofi.h" -#include "xrmoptions.h" -#include "helper.h" -#include "rofi-icon-fetcher.h" -unsigned int test =0; -#define TASSERT( a ) { \ - assert ( a ); \ - printf ( "Test %3u passed (%s)\n", ++test, # a ); \ -} +#include +unsigned int test = 0; +#define TASSERT(a) \ + { \ + assert(a); \ + printf("Test %3u passed (%s)\n", ++test, #a); \ + } -#define TASSERTE( a, b ) { \ - if ( ( a ) == ( b ) ) { \ - printf ( "Test %u passed (%s == %s) (%d == %d)\n", ++test, # a, # b, a, b ); \ - } else { \ - printf ( "Test %u failed (%s == %s) (%d != %d)\n", ++test, # a, # b, a, b ); \ - abort ( ); \ - } \ -} +#define TASSERTE(a, b) \ + { \ + if ((a) == (b)) { \ + printf("Test %u passed (%s == %s) (%d == %d)\n", ++test, #a, #b, a, b); \ + } else { \ + printf("Test %u failed (%s == %s) (%d != %d)\n", ++test, #a, #b, a, b); \ + abort(); \ + } \ + } -#define TASSERTW( a, b ) { \ - if ( ( a ) == ( b ) ) { \ - printf ( "Test %u passed (%s == %s) (%p == %p)\n", ++test, # a, # b, (void *)a, (void *)b ); \ - } else { \ - printf ( "Test %u failed (%s == %s) (%p != %p)\n", ++test, # a, # b, (void *)a, (void *)b ); \ - abort ( ); \ - } \ -} +#define TASSERTW(a, b) \ + { \ + if ((a) == (b)) { \ + printf("Test %u passed (%s == %s) (%p == %p)\n", ++test, #a, #b, \ + (void *)a, (void *)b); \ + } else { \ + printf("Test %u failed (%s == %s) (%p != %p)\n", ++test, #a, #b, \ + (void *)a, (void *)b); \ + abort(); \ + } \ + } ThemeWidget *rofi_configuration = NULL; -uint32_t rofi_icon_fetcher_query ( const char *name, const int size ) -{ +uint32_t rofi_icon_fetcher_query(G_GNUC_UNUSED const char *name, + G_GNUC_UNUSED const int size) { return 0; } -uint32_t rofi_icon_fetcher_query_advanced ( const char *name, const int wsize, const int hsize ) -{ +uint32_t rofi_icon_fetcher_query_advanced(G_GNUC_UNUSED const char *name, + G_GNUC_UNUSED const int wsize, + G_GNUC_UNUSED const int hsize) { return 0; } -cairo_surface_t * rofi_icon_fetcher_get ( const uint32_t uid ) -{ +cairo_surface_t *rofi_icon_fetcher_get(G_GNUC_UNUSED const uint32_t uid) { return NULL; } -int monitor_active ( G_GNUC_UNUSED workarea *mon ) -{ - return 0; -} - -gboolean config_parse_set_property ( G_GNUC_UNUSED const Property *p, G_GNUC_UNUSED char **error ) -{ - return FALSE; -} -char * rofi_expand_path ( G_GNUC_UNUSED const char *path ) -{ - return NULL; -} +int monitor_active(G_GNUC_UNUSED workarea *mon) { return 0; } -char * helper_get_theme_path ( const char *file, const char *ext) -{ - return g_strdup ( file ); -} -void rofi_add_error_message ( G_GNUC_UNUSED GString *msg ) -{ -} -int textbox_get_estimated_char_height ( void ); -int textbox_get_estimated_char_height ( void ) -{ - return 16; -} -double textbox_get_estimated_ch ( void ); -double textbox_get_estimated_ch ( void ) -{ - return 8; +gboolean config_parse_set_property(G_GNUC_UNUSED const Property *p, + G_GNUC_UNUSED char **error) { + return FALSE; } -void rofi_view_get_current_monitor ( G_GNUC_UNUSED int *width, G_GNUC_UNUSED int *height ) -{ +char *rofi_expand_path(G_GNUC_UNUSED const char *path) { return NULL; } +char *helper_get_theme_path(const char *file, G_GNUC_UNUSED const char *ext) { + return g_strdup(file); } +void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {} +int textbox_get_estimated_char_height(void); +int textbox_get_estimated_char_height(void) { return 16; } +double textbox_get_estimated_ch(void); +double textbox_get_estimated_ch(void) { return 8; } +void rofi_view_get_current_monitor(G_GNUC_UNUSED int *width, + G_GNUC_UNUSED int *height) {} -int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv ) -{ - { - box *b = box_create ( NULL, "box", ROFI_ORIENTATION_HORIZONTAL ); - //box_set_padding ( b, 5 ); - widget_resize ( WIDGET (b), 100, 20); +int main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv) { + { + box *b = box_create(NULL, "box", ROFI_ORIENTATION_HORIZONTAL); + // box_set_padding ( b, 5 ); + widget_resize(WIDGET(b), 100, 20); - widget *wid1 = g_malloc0(sizeof(widget)); - wid1->parent = WIDGET(b); - box_add ( b , WIDGET( wid1 ), TRUE ); - // Widget not enabled. no width allocated. - TASSERTE ( wid1->h, 0 ); - TASSERTE ( wid1->w, 0 ); - widget_enable ( WIDGET ( wid1 ) ); - widget_update ( WIDGET ( b ) ) ; - // Widget enabled. so width allocated. - TASSERTE ( wid1->h, 20 ); - TASSERTE ( wid1->w, 100 ); - widget *wid2 = g_malloc0(sizeof(widget)); - wid2->parent = WIDGET (b) ; - widget_enable ( WIDGET ( wid2 ) ); - box_add ( b , WIDGET( wid2 ), TRUE ); - TASSERTE ( wid1->h, 20); - TASSERTE ( wid1->w, 49); - TASSERTE ( wid2->h, 20); - TASSERTE ( wid2->w, 49); + widget *wid1 = g_malloc0(sizeof(widget)); + wid1->parent = WIDGET(b); + box_add(b, WIDGET(wid1), TRUE); + // Widget not enabled. no width allocated. + TASSERTE(wid1->h, 0); + TASSERTE(wid1->w, 0); + widget_enable(WIDGET(wid1)); + widget_update(WIDGET(b)); + // Widget enabled. so width allocated. + TASSERTE(wid1->h, 20); + TASSERTE(wid1->w, 100); + widget *wid2 = g_malloc0(sizeof(widget)); + wid2->parent = WIDGET(b); + widget_enable(WIDGET(wid2)); + box_add(b, WIDGET(wid2), TRUE); + TASSERTE(wid1->h, 20); + TASSERTE(wid1->w, 49); + TASSERTE(wid2->h, 20); + TASSERTE(wid2->w, 49); - widget *wid3 = g_malloc0(sizeof(widget)); - wid3->parent = WIDGET (b); - widget_enable ( WIDGET ( wid3 ) ); - box_add ( b , WIDGET( wid3 ), FALSE ); - TASSERTE ( wid1->h, 20); - TASSERTE ( wid1->w, 48); - TASSERTE ( wid2->h, 20); - TASSERTE ( wid2->w, 48); + widget *wid3 = g_malloc0(sizeof(widget)); + wid3->parent = WIDGET(b); + widget_enable(WIDGET(wid3)); + box_add(b, WIDGET(wid3), FALSE); + TASSERTE(wid1->h, 20); + TASSERTE(wid1->w, 48); + TASSERTE(wid2->h, 20); + TASSERTE(wid2->w, 48); - widget_resize ( WIDGET (wid3) , 20, 10 ); - // TODO should this happen automagically? - widget_update ( WIDGET ( b ) ) ; - TASSERTE ( wid1->h, 20); - TASSERTE ( wid1->w, 38); - TASSERTE ( wid2->h, 20); - TASSERTE ( wid2->w, 38); - TASSERTE ( wid3->h, 20); - TASSERTE ( wid3->w, 20); + widget_resize(WIDGET(wid3), 20, 10); + // TODO should this happen automagically? + widget_update(WIDGET(b)); + TASSERTE(wid1->h, 20); + TASSERTE(wid1->w, 38); + TASSERTE(wid2->h, 20); + TASSERTE(wid2->w, 38); + TASSERTE(wid3->h, 20); + TASSERTE(wid3->w, 20); - widget_resize ( WIDGET (b ), 200, 20 ); - TASSERTE ( wid1->h, 20); - TASSERTE ( wid1->w, 88); - TASSERTE ( wid2->h, 20); - TASSERTE ( wid2->w, 88); - TASSERTE ( wid3->h, 20); - TASSERTE ( wid3->w, 20); -// TASSERTE ( box_get_fixed_pixels ( b ) , 24 ); + widget_resize(WIDGET(b), 200, 20); + TASSERTE(wid1->h, 20); + TASSERTE(wid1->w, 88); + TASSERTE(wid2->h, 20); + TASSERTE(wid2->w, 88); + TASSERTE(wid3->h, 20); + TASSERTE(wid3->w, 20); + // TASSERTE ( box_get_fixed_pixels ( b ) , 24 ); - widget *wid4 = g_malloc0(sizeof(widget)); - wid4->parent = WIDGET ( b ); - widget_enable ( WIDGET ( wid4 ) ); - widget_resize ( WIDGET ( wid4 ), 20, 20 ); - box_add ( b , WIDGET( wid4 ), FALSE ); - TASSERTE ( wid4->x, 200-20); - widget *wid5 = g_malloc0(sizeof(widget)); - wid5->parent = WIDGET ( b ); - widget_enable ( WIDGET ( wid5 ) ); - widget_resize ( WIDGET ( wid5 ), 20, 20 ); - box_add ( b , WIDGET( wid5 ), TRUE ); - TASSERTE ( wid5->x, 149); - widget_free ( WIDGET ( b ) ); - } - { - box *b = box_create ( NULL, "box", ROFI_ORIENTATION_VERTICAL ); - widget_resize ( WIDGET (b), 20, 100); - //box_set_padding ( b, 5 ); + widget *wid4 = g_malloc0(sizeof(widget)); + wid4->parent = WIDGET(b); + widget_enable(WIDGET(wid4)); + widget_resize(WIDGET(wid4), 20, 20); + box_add(b, WIDGET(wid4), FALSE); + TASSERTE(wid4->x, 200 - 20); + widget *wid5 = g_malloc0(sizeof(widget)); + wid5->parent = WIDGET(b); + widget_enable(WIDGET(wid5)); + widget_resize(WIDGET(wid5), 20, 20); + box_add(b, WIDGET(wid5), TRUE); + TASSERTE(wid5->x, 149); + widget_free(WIDGET(b)); + } + { + box *b = box_create(NULL, "box", ROFI_ORIENTATION_VERTICAL); + widget_resize(WIDGET(b), 20, 100); + // box_set_padding ( b, 5 ); - widget *wid1 = g_malloc0(sizeof(widget)); - wid1->parent = WIDGET ( b ); - box_add ( b , WIDGET( wid1 ), TRUE ); - // Widget not enabled. no width allocated. - TASSERTE ( wid1->h, 0); - TASSERTE ( wid1->w, 0 ); - widget_enable ( WIDGET ( wid1 ) ); - widget_update ( WIDGET ( b ) ) ; - // Widget enabled. so width allocated. - TASSERTE ( wid1->h, 100); - TASSERTE ( wid1->w, 20 ); - widget *wid2 = g_malloc0(sizeof(widget)); - wid2->parent = WIDGET ( b ); - widget_enable ( WIDGET ( wid2 ) ); - box_add ( b , WIDGET( wid2 ), TRUE ); - TASSERTE ( wid1->w, 20); - TASSERTE ( wid1->h, 49); - TASSERTE ( wid2->w, 20); - TASSERTE ( wid2->h, 49); + widget *wid1 = g_malloc0(sizeof(widget)); + wid1->parent = WIDGET(b); + box_add(b, WIDGET(wid1), TRUE); + // Widget not enabled. no width allocated. + TASSERTE(wid1->h, 0); + TASSERTE(wid1->w, 0); + widget_enable(WIDGET(wid1)); + widget_update(WIDGET(b)); + // Widget enabled. so width allocated. + TASSERTE(wid1->h, 100); + TASSERTE(wid1->w, 20); + widget *wid2 = g_malloc0(sizeof(widget)); + wid2->parent = WIDGET(b); + widget_enable(WIDGET(wid2)); + box_add(b, WIDGET(wid2), TRUE); + TASSERTE(wid1->w, 20); + TASSERTE(wid1->h, 49); + TASSERTE(wid2->w, 20); + TASSERTE(wid2->h, 49); - widget *wid3 = g_malloc0(sizeof(widget)); - wid3->parent = WIDGET ( b ); - widget_enable ( WIDGET ( wid3 ) ); - box_add ( b , WIDGET( wid3 ), FALSE ); - TASSERTE ( wid1->w, 20); - TASSERTE ( wid1->h, 48); - TASSERTE ( wid2->w, 20); - TASSERTE ( wid2->h, 48); + widget *wid3 = g_malloc0(sizeof(widget)); + wid3->parent = WIDGET(b); + widget_enable(WIDGET(wid3)); + box_add(b, WIDGET(wid3), FALSE); + TASSERTE(wid1->w, 20); + TASSERTE(wid1->h, 48); + TASSERTE(wid2->w, 20); + TASSERTE(wid2->h, 48); - widget_resize ( WIDGET (wid3) , 10, 20 ); - // TODO should this happen automagically? - widget_update ( WIDGET ( b ) ) ; - TASSERTE ( wid1->w, 20); - TASSERTE ( wid1->h, 38); - TASSERTE ( wid2->w, 20); - TASSERTE ( wid2->h, 38); - TASSERTE ( wid3->w, 20); - TASSERTE ( wid3->h, 20); + widget_resize(WIDGET(wid3), 10, 20); + // TODO should this happen automagically? + widget_update(WIDGET(b)); + TASSERTE(wid1->w, 20); + TASSERTE(wid1->h, 38); + TASSERTE(wid2->w, 20); + TASSERTE(wid2->h, 38); + TASSERTE(wid3->w, 20); + TASSERTE(wid3->h, 20); - widget_resize ( WIDGET (b ), 20, 200 ); - TASSERTE ( wid1->w, 20); - TASSERTE ( wid1->h, 88); - TASSERTE ( wid2->w, 20); - TASSERTE ( wid2->h, 88); - TASSERTE ( wid3->w, 20); - TASSERTE ( wid3->h, 20); -// TASSERTE ( box_get_fixed_pixels ( b ) , 4 ); - widget *wid4 = g_malloc0(sizeof(widget)); - wid4->parent = WIDGET ( b ); - widget_enable ( WIDGET ( wid4 ) ); - widget_resize ( WIDGET ( wid4 ), 20, 20 ); - box_add ( b , WIDGET( wid4 ), FALSE ); - TASSERTE ( wid4->y, 180); - widget *wid5 = g_malloc0(sizeof(widget)); - wid5->parent = WIDGET ( b ); - widget_enable ( WIDGET ( wid5 ) ); - widget_resize ( WIDGET ( wid5 ), 20, 20 ); - box_add ( b , WIDGET( wid5 ), TRUE ); - TASSERTE ( wid5->y, 149); - widget_free ( WIDGET ( b ) ); - } - { - box *b = box_create ( NULL, "box", ROFI_ORIENTATION_VERTICAL ); - widget_resize ( WIDGET (b), 20, 90); - //box_set_padding ( b, 5 ); - widget *wid1 = g_malloc0(sizeof(widget)); - wid1->parent = WIDGET ( b ); - wid1->type = 1; - widget_enable(wid1); - box_add ( b , WIDGET( wid1 ), TRUE ); - widget *wid2 = g_malloc0(sizeof(widget)); - wid2->parent = WIDGET ( b ); - wid2->type = 1; - widget_enable(wid2); - box_add ( b , WIDGET( wid2 ), TRUE ); - widget *wid3 = g_malloc0(sizeof(widget)); - wid3->parent = WIDGET ( b ); - wid3->type = 2; - widget_enable(wid3); - box_add ( b , WIDGET( wid3 ), TRUE ); + widget_resize(WIDGET(b), 20, 200); + TASSERTE(wid1->w, 20); + TASSERTE(wid1->h, 88); + TASSERTE(wid2->w, 20); + TASSERTE(wid2->h, 88); + TASSERTE(wid3->w, 20); + TASSERTE(wid3->h, 20); + // TASSERTE ( box_get_fixed_pixels ( b ) , 4 ); + widget *wid4 = g_malloc0(sizeof(widget)); + wid4->parent = WIDGET(b); + widget_enable(WIDGET(wid4)); + widget_resize(WIDGET(wid4), 20, 20); + box_add(b, WIDGET(wid4), FALSE); + TASSERTE(wid4->y, 180); + widget *wid5 = g_malloc0(sizeof(widget)); + wid5->parent = WIDGET(b); + widget_enable(WIDGET(wid5)); + widget_resize(WIDGET(wid5), 20, 20); + box_add(b, WIDGET(wid5), TRUE); + TASSERTE(wid5->y, 149); + widget_free(WIDGET(b)); + } + { + box *b = box_create(NULL, "box", ROFI_ORIENTATION_VERTICAL); + widget_resize(WIDGET(b), 20, 90); + // box_set_padding ( b, 5 ); + widget *wid1 = g_malloc0(sizeof(widget)); + wid1->parent = WIDGET(b); + wid1->type = 1; + widget_enable(wid1); + box_add(b, WIDGET(wid1), TRUE); + widget *wid2 = g_malloc0(sizeof(widget)); + wid2->parent = WIDGET(b); + wid2->type = 1; + widget_enable(wid2); + box_add(b, WIDGET(wid2), TRUE); + widget *wid3 = g_malloc0(sizeof(widget)); + wid3->parent = WIDGET(b); + wid3->type = 2; + widget_enable(wid3); + box_add(b, WIDGET(wid3), TRUE); - gint x = 10; - gint y = 50; - TASSERTW ( widget_find_mouse_target ( WIDGET(b), 1, x, y ), WIDGET(wid2) ); + gint x = 10; + gint y = 50; + TASSERTW(widget_find_mouse_target(WIDGET(b), 1, x, y), WIDGET(wid2)); - y = 30; - TASSERTW ( widget_find_mouse_target ( WIDGET(b), 1, x, y ), WIDGET(wid2) ); - y = 27; - TASSERTW ( widget_find_mouse_target ( WIDGET(b), 1, x, y ), WIDGET(wid1) ); - widget_disable ( wid2 ); - y = 40; - TASSERTW ( widget_find_mouse_target ( WIDGET(b), 1, x, y ), WIDGET(wid1) ); - widget_disable ( wid1 ); - widget_enable ( wid2 ); - TASSERTW ( widget_find_mouse_target ( WIDGET(b), 1, x, y ), WIDGET(wid2) ); - TASSERTW ( widget_find_mouse_target ( WIDGET(b), 2, x, y ), NULL ); - y = 55; - TASSERTW ( widget_find_mouse_target ( WIDGET(b), 2, x, y ), WIDGET(wid3) ); - widget_free ( WIDGET ( b ) ); - } + y = 30; + TASSERTW(widget_find_mouse_target(WIDGET(b), 1, x, y), WIDGET(wid2)); + y = 27; + TASSERTW(widget_find_mouse_target(WIDGET(b), 1, x, y), WIDGET(wid1)); + widget_disable(wid2); + y = 40; + TASSERTW(widget_find_mouse_target(WIDGET(b), 1, x, y), WIDGET(wid1)); + widget_disable(wid1); + widget_enable(wid2); + TASSERTW(widget_find_mouse_target(WIDGET(b), 1, x, y), WIDGET(wid2)); + TASSERTW(widget_find_mouse_target(WIDGET(b), 2, x, y), NULL); + y = 55; + TASSERTW(widget_find_mouse_target(WIDGET(b), 2, x, y), WIDGET(wid3)); + widget_free(WIDGET(b)); + } } diff --git a/test/helper-config-cmdline-parser.c b/test/helper-config-cmdline-parser.c index f12e9079..24f0806e 100644 --- a/test/helper-config-cmdline-parser.c +++ b/test/helper-config-cmdline-parser.c @@ -25,139 +25,124 @@ * */ +#include "display.h" +#include "rofi-icon-fetcher.h" +#include "rofi.h" +#include "settings.h" +#include "widgets/textbox.h" +#include "xcb-internal.h" +#include "xcb.h" #include -#include #include -#include #include +#include +#include #include #include -#include "display.h" -#include "xcb.h" -#include "xcb-internal.h" -#include "rofi.h" -#include "settings.h" -#include "widgets/textbox.h" -#include "rofi-icon-fetcher.h" -static int test = 0; +static int test = 0; -#define TASSERT( a ) { \ - assert ( a ); \ - printf ( "Test %i 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 ( ); \ - } \ -} +#define TASSERT(a) \ + { \ + assert(a); \ + printf("Test %i 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(); \ + } \ + } #include "theme.h" ThemeWidget *rofi_theme = NULL; -uint32_t rofi_icon_fetcher_query ( const char *name, const int size ) -{ +uint32_t rofi_icon_fetcher_query(G_GNUC_UNUSED const char *name, + G_GNUC_UNUSED const int size) { return 0; } -uint32_t rofi_icon_fetcher_query_advanced ( const char *name, const int wsize, const int hsize ) -{ +uint32_t rofi_icon_fetcher_query_advanced(G_GNUC_UNUSED const char *name, + G_GNUC_UNUSED const int wsize, + G_GNUC_UNUSED const int hsize) { return 0; } -cairo_surface_t * rofi_icon_fetcher_get ( const uint32_t uid ) -{ +cairo_surface_t *rofi_icon_fetcher_get(G_GNUC_UNUSED const uint32_t uid) { return NULL; } -void rofi_clear_error_messages (void ) -{ -} +void rofi_clear_error_messages(void) {} -gboolean rofi_theme_parse_string ( const char *string ) -{ +gboolean rofi_theme_parse_string(G_GNUC_UNUSED const char *string) { return FALSE; } -double textbox_get_estimated_char_height ( void ) -{ - return 12.0; +double textbox_get_estimated_char_height(void) { return 12.0; } +void rofi_view_get_current_monitor(int *width, int *height) { + *width = 1920; + *height = 1080; } -void rofi_view_get_current_monitor ( int *width, int *height ) -{ -*width = 1920; -*height = 1080; -} -double textbox_get_estimated_ch ( void ) -{ - return 9.0; -} -void rofi_add_error_message ( G_GNUC_UNUSED GString *msg ) -{ -} -int rofi_view_error_dialog ( const char *msg, G_GNUC_UNUSED int markup ) -{ - fputs ( msg, stderr ); - return TRUE; +double textbox_get_estimated_ch(void) { return 9.0; } +void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {} +int rofi_view_error_dialog(const char *msg, G_GNUC_UNUSED int markup) { + fputs(msg, stderr); + return TRUE; } -int monitor_active ( G_GNUC_UNUSED workarea *mon ) -{ - return 0; -} - -void display_startup_notification ( G_GNUC_UNUSED RofiHelperExecuteContext *context, G_GNUC_UNUSED GSpawnChildSetupFunc *child_setup, G_GNUC_UNUSED gpointer *user_data ) -{ -} +int monitor_active(G_GNUC_UNUSED workarea *mon) { return 0; } -int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv ) -{ +void display_startup_notification( + G_GNUC_UNUSED RofiHelperExecuteContext *context, + G_GNUC_UNUSED GSpawnChildSetupFunc *child_setup, + G_GNUC_UNUSED gpointer *user_data) {} - if ( setlocale ( LC_ALL, "" ) == NULL ) { - fprintf ( stderr, "Failed to set locale.\n" ); - return EXIT_FAILURE; - } - char **list = NULL; - int llength = 0; - char * test_str = - "{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 ); +int main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv) { - 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 ); + if (setlocale(LC_ALL, "") == NULL) { + fprintf(stderr, "Failed to set locale.\n"); + return EXIT_FAILURE; + } + char **list = NULL; + int llength = 0; + char *test_str = "{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); - 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] ); + 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); - unsigned int u = 1234; - int d = -1234; - TASSERT ( find_arg_uint ( "-x", &u ) == FALSE ); - TASSERT ( u == 1234 ); - TASSERT ( find_arg_int ( "-x", &d ) == FALSE ); - TASSERT ( d == -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", &d ) == TRUE ); - TASSERT ( d == -3 ); + 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]); - g_strfreev ( list ); + unsigned int u = 1234; + int d = -1234; + TASSERT(find_arg_uint("-x", &u) == FALSE); + TASSERT(u == 1234); + TASSERT(find_arg_int("-x", &d) == FALSE); + TASSERT(d == -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", &d) == TRUE); + TASSERT(d == -3); + g_strfreev(list); } diff --git a/test/helper-expand.c b/test/helper-expand.c index b673e190..965512c8 100644 --- a/test/helper-expand.c +++ b/test/helper-expand.c @@ -25,119 +25,106 @@ * */ +#include "display.h" +#include "rofi-icon-fetcher.h" +#include "rofi.h" +#include "settings.h" +#include "theme.h" +#include "widgets/textbox.h" +#include "xcb-internal.h" +#include "xcb.h" #include -#include #include -#include #include +#include +#include #include #include -#include "theme.h" -#include "display.h" -#include "xcb.h" -#include "xcb-internal.h" -#include "rofi.h" -#include "settings.h" -#include "widgets/textbox.h" -#include "rofi-icon-fetcher.h" -static int test = 0; +static int test = 0; -#define TASSERT( a ) { \ - assert ( a ); \ - printf ( "Test %i 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 ( ); \ - } \ -} +#define TASSERT(a) \ + { \ + assert(a); \ + printf("Test %i 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(); \ + } \ + } ThemeWidget *rofi_theme = NULL; -void rofi_clear_error_messages ( void ) {} -uint32_t rofi_icon_fetcher_query ( const char *name, const int size ) -{ +void rofi_clear_error_messages(void) {} +uint32_t rofi_icon_fetcher_query(G_GNUC_UNUSED const char *name, + G_GNUC_UNUSED const int size) { return 0; } -uint32_t rofi_icon_fetcher_query_advanced ( const char *name, const int wsize, const int hsize ) -{ +uint32_t rofi_icon_fetcher_query_advanced(G_GNUC_UNUSED const char *name, + G_GNUC_UNUSED const int wsize, + G_GNUC_UNUSED const int hsize) { return 0; } -cairo_surface_t * rofi_icon_fetcher_get ( const uint32_t uid ) -{ +cairo_surface_t *rofi_icon_fetcher_get(G_GNUC_UNUSED const uint32_t uid) { return NULL; } -double textbox_get_estimated_char_height ( void ) -{ - return 12.0; -} -void rofi_view_get_current_monitor ( int *width, int *height ) -{ -*width = 1920; -*height = 1080; -} -double textbox_get_estimated_ch ( void ) -{ - return 9.0; -} -gboolean rofi_theme_parse_string ( const char *string ) -{ -return 0; +double textbox_get_estimated_char_height(void) { return 12.0; } +void rofi_view_get_current_monitor(int *width, int *height) { + *width = 1920; + *height = 1080; } +double textbox_get_estimated_ch(void) { return 9.0; } +gboolean rofi_theme_parse_string(G_GNUC_UNUSED const char *string) { return 0; } -void rofi_add_error_message ( G_GNUC_UNUSED GString *msg ) -{ -} +void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {} -int rofi_view_error_dialog ( const char *msg, G_GNUC_UNUSED int markup ) -{ - fputs ( msg, stderr ); - return TRUE; +int rofi_view_error_dialog(const char *msg, G_GNUC_UNUSED int markup) { + fputs(msg, stderr); + return TRUE; } -int monitor_active ( G_GNUC_UNUSED workarea *mon ) -{ - return 0; -} +int monitor_active(G_GNUC_UNUSED workarea *mon) { return 0; } -void display_startup_notification ( G_GNUC_UNUSED RofiHelperExecuteContext *context, G_GNUC_UNUSED GSpawnChildSetupFunc *child_setup, G_GNUC_UNUSED gpointer *user_data ) -{ -} +void display_startup_notification( + G_GNUC_UNUSED RofiHelperExecuteContext *context, + G_GNUC_UNUSED GSpawnChildSetupFunc *child_setup, + G_GNUC_UNUSED gpointer *user_data) {} -int main ( int argc, char **argv ) -{ - cmd_set_arguments ( argc, argv ); +int main(int argc, char **argv) { + cmd_set_arguments(argc, argv); - if ( setlocale ( LC_ALL, "" ) == NULL ) { - fprintf ( stderr, "Failed to set locale.\n" ); - return EXIT_FAILURE; - } + if (setlocale(LC_ALL, "") == NULL) { + fprintf(stderr, "Failed to set locale.\n"); + return EXIT_FAILURE; + } - /** - * Test some path functions. Not easy as not sure what is right output on travis. - */ - // Test if root is preserved. - char *str = rofi_expand_path ( "/" ); - TASSERT ( strcmp ( str, "/" ) == 0 ); - g_free ( str ); - // Test is relative path is preserved. - str = rofi_expand_path ( "../AUTHORS" ); - TASSERT ( strcmp ( str, "../AUTHORS" ) == 0 ); - g_free ( str ); - // Test another one. - str = rofi_expand_path ( "/bin/false" ); - TASSERT ( strcmp ( str, "/bin/false" ) == 0 ); - g_free ( str ); - // See if user paths get expanded in full path. - str = rofi_expand_path ( "~/" ); - const char *hd = g_get_home_dir (); - TASSERT ( strcmp ( str, hd ) == 0 ); - g_free ( str ); - str = rofi_expand_path ( "~root/" ); - TASSERT ( str[0] == '/' ); - g_free ( str ); + /** + * Test some path functions. Not easy as not sure what is right output on + * travis. + */ + // Test if root is preserved. + char *str = rofi_expand_path("/"); + TASSERT(strcmp(str, "/") == 0); + g_free(str); + // Test is relative path is preserved. + str = rofi_expand_path("../AUTHORS"); + TASSERT(strcmp(str, "../AUTHORS") == 0); + g_free(str); + // Test another one. + str = rofi_expand_path("/bin/false"); + TASSERT(strcmp(str, "/bin/false") == 0); + g_free(str); + // See if user paths get expanded in full path. + str = rofi_expand_path("~/"); + const char *hd = g_get_home_dir(); + TASSERT(strcmp(str, hd) == 0); + g_free(str); + str = rofi_expand_path("~root/"); + TASSERT(str[0] == '/'); + g_free(str); } diff --git a/test/helper-pidfile.c b/test/helper-pidfile.c index 090d7002..22b66d23 100644 --- a/test/helper-pidfile.c +++ b/test/helper-pidfile.c @@ -50,17 +50,25 @@ static int test = 0; #include "theme.h" ThemeWidget *rofi_theme = NULL; -uint32_t rofi_icon_fetcher_query(const char *name, const int size) { return 0; } -uint32_t rofi_icon_fetcher_query_advanced(const char *name, const int wsize, - const int hsize) { +uint32_t rofi_icon_fetcher_query(G_GNUC_UNUSED const char *name, + G_GNUC_UNUSED const int size) { + return 0; +} +uint32_t rofi_icon_fetcher_query_advanced(G_GNUC_UNUSED const char *name, + G_GNUC_UNUSED const int wsize, + G_GNUC_UNUSED const int hsize) { return 0; } -cairo_surface_t *rofi_icon_fetcher_get(const uint32_t uid) { return NULL; } +cairo_surface_t *rofi_icon_fetcher_get(G_GNUC_UNUSED const uint32_t uid) { + return NULL; +} void rofi_clear_error_messages(void) {} -gboolean rofi_theme_parse_string(const char *string) { return FALSE; } +gboolean rofi_theme_parse_string(G_GNUC_UNUSED const char *string) { + return FALSE; +} double textbox_get_estimated_char_height(void) { return 12.0; } void rofi_view_get_current_monitor(int *width, int *height) { *width = 1920; diff --git a/test/helper-test.c b/test/helper-test.c index 71109fd4..d8e53fef 100644 --- a/test/helper-test.c +++ b/test/helper-test.c @@ -25,205 +25,221 @@ * */ +#include "display.h" +#include "rofi-icon-fetcher.h" +#include "rofi.h" +#include "settings.h" +#include "theme.h" +#include "xcb-internal.h" +#include "xcb.h" #include -#include #include -#include #include +#include +#include #include #include -#include "theme.h" -#include "display.h" -#include "xcb.h" -#include "xcb-internal.h" -#include "rofi.h" -#include "settings.h" -#include "rofi-icon-fetcher.h" - -static int test = 0; -#define TASSERT( a ) { \ - assert ( a ); \ - printf ( "Test %i 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 ( ); \ - } \ -} -#define TASSERTL( a, b ) { \ - if ( ( a ) == ( b ) ) { \ - printf ( "Test %i passed (%s == %s) (%d == %d)\n", ++test, # a, # b, a, b ); \ - } else { \ - printf ( "Test %i failed (%s == %s) (%d != %d)\n", ++test, # a, # b, a, b ); \ - abort ( ); \ - } \ -} +static int test = 0; + +#define TASSERT(a) \ + { \ + assert(a); \ + printf("Test %i 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(); \ + } \ + } +#define TASSERTL(a, b) \ + { \ + if ((a) == (b)) { \ + printf("Test %i passed (%s == %s) (%d == %d)\n", ++test, #a, #b, a, b); \ + } else { \ + printf("Test %i failed (%s == %s) (%d != %d)\n", ++test, #a, #b, a, b); \ + abort(); \ + } \ + } #include "widgets/textbox.h" ThemeWidget *rofi_theme = NULL; -gboolean rofi_theme_parse_string ( const char *string ) -{ +gboolean rofi_theme_parse_string(G_GNUC_UNUSED const char *string) { return FALSE; } -uint32_t rofi_icon_fetcher_query ( const char *name, const int size ) -{ +uint32_t rofi_icon_fetcher_query(G_GNUC_UNUSED const char *name, + G_GNUC_UNUSED const int size) { return 0; } -void rofi_clear_error_messages ( void ) {} -uint32_t rofi_icon_fetcher_query_advanced ( const char *name, const int wsize, const int hsize ) -{ +void rofi_clear_error_messages(void) {} +uint32_t rofi_icon_fetcher_query_advanced(G_GNUC_UNUSED const char *name, + G_GNUC_UNUSED const int wsize, + G_GNUC_UNUSED const int hsize) { return 0; } -cairo_surface_t * rofi_icon_fetcher_get ( const uint32_t uid ) -{ +cairo_surface_t *rofi_icon_fetcher_get(G_GNUC_UNUSED const uint32_t uid) { return NULL; } -double textbox_get_estimated_char_height ( void ) -{ - return 12.0; -} -void rofi_view_get_current_monitor ( int *width, int *height ) -{ -*width = 1920; -*height = 1080; -} -double textbox_get_estimated_ch ( void ) -{ - return 9.0; -} -void rofi_add_error_message ( G_GNUC_UNUSED GString *msg ) -{ - -} - -int rofi_view_error_dialog ( const char *msg, G_GNUC_UNUSED int markup ) -{ - fputs ( msg, stderr ); - return TRUE; -} - -int monitor_active ( G_GNUC_UNUSED workarea *mon ) -{ - return 0; +double textbox_get_estimated_char_height(void) { return 12.0; } +void rofi_view_get_current_monitor(int *width, int *height) { + *width = 1920; + *height = 1080; } +double textbox_get_estimated_ch(void) { return 9.0; } +void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {} -void display_startup_notification ( G_GNUC_UNUSED RofiHelperExecuteContext *context, G_GNUC_UNUSED GSpawnChildSetupFunc *child_setup, G_GNUC_UNUSED gpointer *user_data ) -{ +int rofi_view_error_dialog(const char *msg, G_GNUC_UNUSED int markup) { + fputs(msg, stderr); + return TRUE; } -int main ( int argc, char **argv ) -{ - cmd_set_arguments ( argc, argv ); - - if ( setlocale ( LC_ALL, "" ) == NULL ) { - fprintf ( stderr, "Failed to set locale.\n" ); - return EXIT_FAILURE; - } - - /** - * Char function - */ - - TASSERT ( helper_parse_char ( "\\n" ) == '\n' ); - TASSERT ( helper_parse_char ( "\\a" ) == '\a' ); - TASSERT ( helper_parse_char ( "\\b" ) == '\b' ); - TASSERT ( helper_parse_char ( "\\t" ) == '\t' ); - TASSERT ( helper_parse_char ( "\\v" ) == '\v' ); - TASSERT ( helper_parse_char ( "\\f" ) == '\f' ); - TASSERT ( helper_parse_char ( "\\r" ) == '\r' ); - TASSERT ( helper_parse_char ( "\\\\" ) == '\\' ); - TASSERT ( helper_parse_char ( "\\0" ) == 0 ); - TASSERT ( helper_parse_char ( "\\x77" ) == 'w' ); - TASSERT ( helper_parse_char ( "\\x0A" ) == '\n' ); - - /** - * tokenize - */ - - TASSERT ( levenshtein ( "aap", g_utf8_strlen ( "aap", -1), "aap", g_utf8_strlen ( "aap", -1) ) == 0 ); - TASSERT ( levenshtein ( "aap", g_utf8_strlen ( "aap", -1), "aap ", g_utf8_strlen ( "aap ", -1) ) == 1 ); - TASSERT ( levenshtein ( "aap ", g_utf8_strlen ( "aap ", -1), "aap", g_utf8_strlen ( "aap", -1) ) == 1 ); - TASSERTE ( levenshtein ( "aap", g_utf8_strlen ( "aap", -1), "aap noot", g_utf8_strlen ( "aap noot", -1) ), 5u ); - TASSERTE ( levenshtein ( "aap", g_utf8_strlen ( "aap", -1), "noot aap", g_utf8_strlen ( "noot aap", -1) ), 5u ); - TASSERTE ( levenshtein ( "aap", g_utf8_strlen ( "aap", -1), "noot aap mies", g_utf8_strlen ( "noot aap mies", -1) ), 10u ); - TASSERTE ( levenshtein ( "noot aap mies", g_utf8_strlen ( "noot aap mies", -1), "aap", g_utf8_strlen ( "aap", -1) ), 10u ); - TASSERTE ( levenshtein ( "otp", g_utf8_strlen ( "otp", -1), "noot aap", g_utf8_strlen ( "noot aap", -1) ), 5u ); - /** - * Quick converision check. - */ - { - char *str = rofi_latin_to_utf8_strdup ( "\xA1\xB5", 2 ); - TASSERT ( g_utf8_collate ( str, "¡µ" ) == 0 ); - g_free ( str ); - } - - { - char *str = rofi_force_utf8 ( "Valid utf8", 10 ); - TASSERT ( g_utf8_collate ( str, "Valid utf8" ) == 0 ); - g_free ( str ); - char in[] = "Valid utf8 until \xc3\x28 we continue here"; - TASSERT ( g_utf8_validate ( in, -1, NULL ) == FALSE ); - str = rofi_force_utf8 ( in, strlen ( in ) ); - TASSERT ( g_utf8_validate ( str, -1, NULL ) == TRUE ); - TASSERT ( g_utf8_collate ( str, "Valid utf8 until �( we continue here" ) == 0 ); - g_free ( str ); - } - { - TASSERT ( utf8_strncmp ( "aapno", "aap€",3) == 0 ); - TASSERT ( utf8_strncmp ( "aapno", "aap€",4) != 0 ); - TASSERT ( utf8_strncmp ( "aapno", "a",4) != 0 ); - TASSERT ( utf8_strncmp ( "a", "aap€",4) != 0 ); -// char in[] = "Valid utf8 until \xc3\x28 we continue here"; -// TASSERT ( utf8_strncmp ( in, "Valid", 3 ) == 0); - } - { - TASSERTL ( rofi_scorer_fuzzy_evaluate ("aap noot mies", 12 , "aap noot mies", 12), -605); - TASSERTL ( rofi_scorer_fuzzy_evaluate ("anm", 3, "aap noot mies", 12), -155); - TASSERTL ( rofi_scorer_fuzzy_evaluate ("blu", 3, "aap noot mies", 12), 1073741824); - config.case_sensitive = TRUE; - TASSERTL ( rofi_scorer_fuzzy_evaluate ("Anm", 3, "aap noot mies", 12), 1073741754); - config.case_sensitive = FALSE; - TASSERTL ( rofi_scorer_fuzzy_evaluate ("Anm", 3, "aap noot mies", 12), -155); - TASSERTL ( rofi_scorer_fuzzy_evaluate ("aap noot mies", 12,"Anm", 3 ), 1073741824); - - } - - - char *a; - a = helper_string_replace_if_exists ( "{terminal} [-t {title} blub ]-e {cmd}", "{cmd}", "aap", "{title}", "some title", "{terminal}", "rofi-sensible-terminal", NULL); - printf("%s\n",a); - TASSERT ( g_utf8_collate ( a, "rofi-sensible-terminal -t some title blub -e aap") == 0); - g_free(a); - a = helper_string_replace_if_exists ( "{terminal} [-t {title} blub ]-e {cmd}", "{cmd}", "aap", "{terminal}", "rofi-sensible-terminal", NULL); - printf("%s\n",a); - TASSERT ( g_utf8_collate ( a, "rofi-sensible-terminal -e aap") == 0); - g_free(a); - a = helper_string_replace_if_exists ( "{name} [({category})]", "{name}", "Librecad", "{category}", "Desktop app", "{terminal}", "rofi-sensible-terminal", NULL ); - printf("%s\n",a); - TASSERT ( g_utf8_collate ( a, "Librecad (Desktop app)") == 0); - g_free(a); - a = helper_string_replace_if_exists ( "{name}[ ({category})]", "{name}", "Librecad", "{terminal}", "rofi-sensible-terminal", NULL ); - TASSERT ( g_utf8_collate ( a, "Librecad") == 0); - g_free(a); - a = helper_string_replace_if_exists ( "{terminal} [{title} blub ]-e {cmd}", "{cmd}", "aap", "{title}", "some title", "{terminal}", "rofi-sensible-terminal", NULL); - printf("%s\n",a); - TASSERT ( g_utf8_collate ( a, "rofi-sensible-terminal some title blub -e aap") == 0); - g_free(a); - a = helper_string_replace_if_exists ( "{terminal} [{title} blub ]-e {cmd}", - "{cmd}", "aap", - "{title}", NULL, - "{terminal}", "rofi-sensible-terminal", - NULL); - printf("%s\n",a); - TASSERT ( g_utf8_collate ( a, "rofi-sensible-terminal -e aap") == 0); - g_free(a); +int monitor_active(G_GNUC_UNUSED workarea *mon) { return 0; } + +void display_startup_notification( + G_GNUC_UNUSED RofiHelperExecuteContext *context, + G_GNUC_UNUSED GSpawnChildSetupFunc *child_setup, + G_GNUC_UNUSED gpointer *user_data) {} + +int main(int argc, char **argv) { + cmd_set_arguments(argc, argv); + + if (setlocale(LC_ALL, "") == NULL) { + fprintf(stderr, "Failed to set locale.\n"); + return EXIT_FAILURE; + } + + /** + * Char function + */ + + TASSERT(helper_parse_char("\\n") == '\n'); + TASSERT(helper_parse_char("\\a") == '\a'); + TASSER