[Build] Fix some compile warnings.

This commit is contained in:
Dave Davenport 2022-07-23 00:28:55 +02:00
parent 820b19e09a
commit 0e90fb065f
28 changed files with 1437 additions and 1507 deletions

View File

@ -67,7 +67,7 @@ typedef char *(*_mode_get_display_value)(const Mode *sw,
*/ */
typedef cairo_surface_t *(*_mode_get_icon)(const Mode *sw, typedef cairo_surface_t *(*_mode_get_icon)(const Mode *sw,
unsigned int selected_line, unsigned int selected_line,
int height); unsigned int height);
/** /**
* @param sw The #Mode pointer * @param sw The #Mode pointer

View File

@ -139,7 +139,7 @@ char *mode_get_display_value(const Mode *mode, unsigned int selected_line,
* @returns allocated new cairo_surface_t if applicable * @returns allocated new cairo_surface_t if applicable
*/ */
cairo_surface_t *mode_get_icon(Mode *mode, unsigned int selected_line, cairo_surface_t *mode_get_icon(Mode *mode, unsigned int selected_line,
int height); unsigned int height);
/** /**
* @param mode The mode to query * @param mode The mode to query

View File

@ -144,7 +144,7 @@ void rofi_theme_property_free(Property *p);
* *
* @returns a copy of 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 * @param widget
* *

View File

@ -22,6 +22,7 @@ flags = [
'-Wunreachable-code', '-Wunreachable-code',
'-Werror=missing-prototypes', '-Werror=missing-prototypes',
'-Wno-inline', # A bit too noisy with Bison… '-Wno-inline', # A bit too noisy with Bison…
'-Wextra'
] ]
foreach f : flags foreach f : flags
if c_compiler.has_argument(f) if c_compiler.has_argument(f)

View File

@ -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, cairo_surface_t *mode_get_icon(Mode *mode, unsigned int selected_line,
int height) { unsigned int height) {
g_assert(mode != NULL); g_assert(mode != NULL);
if (mode->_get_icon != NULL) { if (mode->_get_icon != NULL) {

View File

@ -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, 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); CombiModePrivateData *pd = mode_get_private_data(sw);
for (unsigned i = 0; i < pd->num_switchers; i++) { for (unsigned i = 0; i < pd->num_switchers; i++) {
if (index >= pd->starts[i] && index < (pd->starts[i] + pd->lengths[i])) { if (index >= pd->starts[i] && index < (pd->starts[i] + pd->lengths[i])) {

View File

@ -56,8 +56,8 @@
static int dmenu_mode_init(Mode *sw); static int dmenu_mode_init(Mode *sw);
static int dmenu_token_match(const Mode *sw, rofi_int_matcher **tokens, static int dmenu_token_match(const Mode *sw, rofi_int_matcher **tokens,
unsigned int index); unsigned int index);
static cairo_surface_t *dmenu_get_icon(const Mode *sw, static cairo_surface_t *
unsigned int selected_line, int height); dmenu_get_icon(const Mode *sw, unsigned int selected_line, unsigned int height);
static char *dmenu_get_message(const Mode *sw); static char *dmenu_get_message(const Mode *sw);
static inline unsigned int bitget(uint32_t const *const array, 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) { gpointer user_data) {
DmenuModePrivateData *pd = (DmenuModePrivateData *)user_data; DmenuModePrivateData *pd = (DmenuModePrivateData *)user_data;
char command; 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. // Read the entry from the pipe that was used to signal this action.
if (read(fd, &command, 1) == 1) { if (read(fd, &command, 1) == 1) {
if ( command == 'r' ){ if (command == 'r') {
Block *block = NULL; Block *block = NULL;
gboolean changed = FALSE; gboolean changed = FALSE;
// Empty out the AsyncQueue (that is thread safe) from all blocks pushed // 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)) { 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_real_length = MAX(pd->cmd_list_real_length * 2, 4096);
pd->cmd_list = g_realloc(pd->cmd_list, sizeof(DmenuScriptEntry) * 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]), 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; pd->cmd_list_length += block->length;
g_free(block); g_free(block);
changed = TRUE; changed = TRUE;
@ -215,8 +219,8 @@ static gboolean dmenu_async_read_proc(gint fd, GIOCondition condition,
if (changed) { if (changed) {
rofi_view_reload(); rofi_view_reload();
} }
} else if ( command == 'q' ){ } else if (command == 'q') {
if ( pd->loading ) { if (pd->loading) {
rofi_view_set_overlay(rofi_view_get_active(), NULL); 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) { static gpointer read_input_thread(gpointer userdata) {
DmenuModePrivateData *pd = (DmenuModePrivateData *)userdata; DmenuModePrivateData *pd = (DmenuModePrivateData *)userdata;
ssize_t nread = 0; ssize_t nread = 0;
size_t len = 0; ssize_t len = 0;
char *line = NULL; char *line = NULL;
// Create the message passing queue to the UI thread. // Create the message passing queue to the UI thread.
pd->async_queue = g_async_queue_new(); pd->async_queue = g_async_queue_new();
@ -276,7 +280,7 @@ static gpointer read_input_thread(gpointer userdata) {
if (readbytes > 0) { if (readbytes > 0) {
nread += readbytes; nread += readbytes;
line[nread] = '\0'; line[nread] = '\0';
size_t i = 0; ssize_t i = 0;
while (i < nread) { while (i < nread) {
if (line[i] == pd->separator) { if (line[i] == pd->separator) {
line[i] = '\0'; line[i] = '\0';
@ -632,7 +636,8 @@ static char *dmenu_get_message(const Mode *sw) {
return NULL; return NULL;
} }
static cairo_surface_t *dmenu_get_icon(const Mode *sw, 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); DmenuModePrivateData *pd = (DmenuModePrivateData *)mode_get_private_data(sw);
g_return_val_if_fail(pd->cmd_list != NULL, NULL); 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); 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) { if (pd->reading_thread) {
// Stop listinig to new messages from 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_restart(state);
rofi_view_set_selected_line(state, pd->selected_line); rofi_view_set_selected_line(state, pd->selected_line);
if (!restart) { if (!restart) {
dmenu_finish(pd,state, retv); dmenu_finish(pd, state, retv);
} }
return; return;
} }
@ -835,7 +841,7 @@ static void dmenu_finalize(RofiViewState *state) {
rofi_view_restart(state); rofi_view_restart(state);
rofi_view_set_selected_line(state, pd->selected_line); rofi_view_set_selected_line(state, pd->selected_line);
} else { } else {
dmenu_finish(pd,state, retv); dmenu_finish(pd, state, retv);
} }
} }

View File

@ -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, 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); DRunModePrivateData *pd = (DRunModePrivateData *)mode_get_private_data(sw);
if (pd->file_complete) { if (pd->file_complete) {
return pd->completer->_get_icon(pd->completer, selected_line, height); return pd->completer->_get_icon(pd->completer, selected_line, height);

View File

@ -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, static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line,
int height) { unsigned int height) {
FileBrowserModePrivateData *pd = FileBrowserModePrivateData *pd =
(FileBrowserModePrivateData *)mode_get_private_data(sw); (FileBrowserModePrivateData *)mode_get_private_data(sw);
g_return_val_if_fail(pd->array != NULL, NULL); g_return_val_if_fail(pd->array != NULL, NULL);

View File

@ -534,7 +534,7 @@ static char *run_get_message(const Mode *sw) {
return NULL; return NULL;
} }
static cairo_surface_t *_get_icon(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) {
RunModePrivateData *pd = (RunModePrivateData *)mode_get_private_data(sw); RunModePrivateData *pd = (RunModePrivateData *)mode_get_private_data(sw);
if (pd->file_complete) { if (pd->file_complete) {
return pd->completer->_get_icon(pd->completer, selected_line, height); return pd->completer->_get_icon(pd->completer, selected_line, height);

View File

@ -429,8 +429,9 @@ static char *script_get_message(const Mode *sw) {
ScriptModePrivateData *pd = sw->private_data; ScriptModePrivateData *pd = sw->private_data;
return g_strdup(pd->message); return g_strdup(pd->message);
} }
static cairo_surface_t * static cairo_surface_t *script_get_icon(const Mode *sw,
script_get_icon(const Mode *sw, unsigned int selected_line, int height) { unsigned int selected_line,
unsigned int height) {
ScriptModePrivateData *pd = ScriptModePrivateData *pd =
(ScriptModePrivateData *)mode_get_private_data(sw); (ScriptModePrivateData *)mode_get_private_data(sw);
g_return_val_if_fail(pd->cmd_list != NULL, NULL); g_return_val_if_fail(pd->cmd_list != NULL, NULL);
@ -454,7 +455,7 @@ typedef struct ScriptUser {
} ScriptUser; } ScriptUser;
ScriptUser *user_scripts = NULL; ScriptUser *user_scripts = NULL;
int num_scripts = 0; size_t num_scripts = 0;
void script_mode_cleanup(void) { void script_mode_cleanup(void) {
for (size_t i = 0; i < num_scripts; i++) { 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) { 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) { if (g_strcmp0(user_scripts[i].name, user) == 0) {
return i; return i;
} }

View File

@ -399,7 +399,8 @@ static gboolean window_client_reload(G_GNUC_UNUSED void *data) {
} }
return G_SOURCE_REMOVE; 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); // g_idle_add_full(G_PRIORITY_HIGH_IDLE, window_client_reload, NULL, NULL);
if (window_reload_timeout > 0) { if (window_reload_timeout > 0) {
g_source_remove(window_reload_timeout); g_source_remove(window_reload_timeout);
@ -1023,7 +1024,7 @@ static cairo_surface_t *get_net_wm_icon(xcb_window_t xid,
return surface; return surface;
} }
static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line, 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); WindowModePrivateData *rmpd = mode_get_private_data(sw);
client *c = window_client(rmpd, rmpd->ids->array[selected_line]); client *c = window_client(rmpd, rmpd->ids->array[selected_line]);
if (c == NULL) { if (c == NULL) {

View File

@ -772,7 +772,7 @@ static gboolean record(G_GNUC_UNUSED void *data) {
return G_SOURCE_CONTINUE; return G_SOURCE_CONTINUE;
} }
static void rofi_custom_log_function(const char *log_domain, 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) { const gchar *message, gpointer user_data) {
int fp = GPOINTER_TO_INT(user_data); int fp = GPOINTER_TO_INT(user_data);
dprintf(fp, "[%s]: %s\n", log_domain == NULL ? "default" : log_domain, dprintf(fp, "[%s]: %s\n", log_domain == NULL ? "default" : log_domain,

View File

@ -120,7 +120,8 @@ RofiDistance rofi_theme_property_copy_distance(RofiDistance const distance) {
return retv; 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); Property *retv = rofi_theme_property_create(p->type);
retv->name = g_strdup(p->name); retv->name = g_strdup(p->name);
@ -137,7 +138,7 @@ Property *rofi_theme_property_copy(const Property *p) {
retv->value.link.ref = NULL; retv->value.link.ref = NULL;
if (p->value.link.def_value) { if (p->value.link.def_value) {
retv->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; break;
case P_PADDING: { 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, static void rofi_theme_copy_property_int(G_GNUC_UNUSED gpointer key,
gpointer value, gpointer user_data) { gpointer value, gpointer user_data) {
GHashTable *table = (GHashTable *)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); g_hash_table_replace(table, p->name, p);
} }
void rofi_theme_widget_add_properties(ThemeWidget *widget, GHashTable *table) { void rofi_theme_widget_add_properties(ThemeWidget *widget, GHashTable *table) {

View File

@ -1007,8 +1007,8 @@ inline static void rofi_view_nav_last(RofiViewState *state) {
// state->selected = state->filtered_lines - 1; // state->selected = state->filtered_lines - 1;
listview_set_selected(state->list_view, -1); listview_set_selected(state->list_view, -1);
} }
static void selection_changed_callback(listview *lv, unsigned int index, static void selection_changed_callback(G_GNUC_UNUSED listview *lv,
void *udata) { unsigned int index, void *udata) {
RofiViewState *state = (RofiViewState *)udata; RofiViewState *state = (RofiViewState *)udata;
if (state->tb_current_entry) { if (state->tb_current_entry) {
if (index < state->filtered_lines) { if (index < state->filtered_lines) {

View File

@ -526,8 +526,10 @@ widget *widget_find_mouse_target(widget *wid, WidgetType type, gint x, gint y) {
return NULL; return NULL;
} }
WidgetTriggerActionResult widget_check_action(widget *wid, guint action, gint x, WidgetTriggerActionResult widget_check_action(widget *wid,
gint y) { G_GNUC_UNUSED guint action,
G_GNUC_UNUSED gint x,
G_GNUC_UNUSED gint y) {
if (wid == NULL) { if (wid == NULL) {
return FALSE; return FALSE;
} }

View File

@ -744,13 +744,13 @@ gboolean config_parse_set_property(const Property *p, char **error) {
iter = g_list_next(iter)) { iter = g_list_next(iter)) {
if (g_strcmp0(((Property *)(iter->data))->name, p->name) == 0) { if (g_strcmp0(((Property *)(iter->data))->name, p->name) == 0) {
rofi_theme_property_free((Property *)(iter->data)); 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; return FALSE;
} }
} }
g_debug("Adding option: %s to backup list.", p->name); g_debug("Adding option: %s to backup list.", p->name);
extra_parsed_options = 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; return FALSE;
} }

View File

@ -25,268 +25,255 @@
* *
*/ */
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <assert.h>
#include <glib.h>
#include <string.h>
#include <theme.h>
#include <widgets/box.h>
#include <widgets/widget.h>
#include <widgets/widget-internal.h>
#include "rofi.h"
#include "xrmoptions.h"
#include "helper.h" #include "helper.h"
#include "rofi-icon-fetcher.h" #include "rofi-icon-fetcher.h"
unsigned int test =0; #include "rofi.h"
#define TASSERT( a ) { \ #include "xrmoptions.h"
assert ( a ); \ #include <assert.h>
printf ( "Test %3u passed (%s)\n", ++test, # a ); \ #include <glib.h>
} #include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <theme.h>
#include <unistd.h>
#include <widgets/box.h>
#include <widgets/widget-internal.h>
#include <widgets/widget.h>
unsigned int test = 0;
#define TASSERT(a) \
{ \
assert(a); \
printf("Test %3u passed (%s)\n", ++test, #a); \
}
#define TASSERTE( a, b ) { \ #define TASSERTE(a, b) \
if ( ( a ) == ( b ) ) { \ { \
printf ( "Test %u passed (%s == %s) (%d == %d)\n", ++test, # a, # b, a, b ); \ if ((a) == (b)) { \
} else { \ printf("Test %u passed (%s == %s) (%d == %d)\n", ++test, #a, #b, a, b); \
printf ( "Test %u failed (%s == %s) (%d != %d)\n", ++test, # a, # b, a, b ); \ } else { \
abort ( ); \ printf("Test %u failed (%s == %s) (%d != %d)\n", ++test, #a, #b, a, b); \
} \ abort(); \
} } \
}
#define TASSERTW( a, b ) { \ #define TASSERTW(a, b) \
if ( ( a ) == ( b ) ) { \ { \
printf ( "Test %u passed (%s == %s) (%p == %p)\n", ++test, # a, # b, (void *)a, (void *)b ); \ if ((a) == (b)) { \
} else { \ printf("Test %u passed (%s == %s) (%p == %p)\n", ++test, #a, #b, \
printf ( "Test %u failed (%s == %s) (%p != %p)\n", ++test, # a, # b, (void *)a, (void *)b ); \ (void *)a, (void *)b); \
abort ( ); \ } else { \
} \ printf("Test %u failed (%s == %s) (%p != %p)\n", ++test, #a, #b, \
} (void *)a, (void *)b); \
abort(); \
} \
}
ThemeWidget *rofi_configuration = NULL; 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; 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; 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; return NULL;
} }
int monitor_active ( G_GNUC_UNUSED workarea *mon ) int monitor_active(G_GNUC_UNUSED workarea *mon) { return 0; }
{
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; }
gboolean config_parse_set_property ( G_GNUC_UNUSED const Property *p, G_GNUC_UNUSED char **error ) char *helper_get_theme_path(const char *file, G_GNUC_UNUSED const char *ext) {
{ return g_strdup(file);
return FALSE;
} }
char * rofi_expand_path ( G_GNUC_UNUSED const char *path ) void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {}
{ int textbox_get_estimated_char_height(void);
return NULL; int textbox_get_estimated_char_height(void) { return 16; }
} double textbox_get_estimated_ch(void);
double textbox_get_estimated_ch(void) { return 8; }
char * helper_get_theme_path ( const char *file, const char *ext) void rofi_view_get_current_monitor(G_GNUC_UNUSED int *width,
{ G_GNUC_UNUSED int *height) {}
return g_strdup ( file );
} int main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv) {
void rofi_add_error_message ( G_GNUC_UNUSED GString *msg ) {
{ box *b = box_create(NULL, "box", ROFI_ORIENTATION_HORIZONTAL);
} // box_set_padding ( b, 5 );
int textbox_get_estimated_char_height ( void ); widget_resize(WIDGET(b), 100, 20);
int textbox_get_estimated_char_height ( void )
{ widget *wid1 = g_malloc0(sizeof(widget));
return 16; wid1->parent = WIDGET(b);
} box_add(b, WIDGET(wid1), TRUE);
double textbox_get_estimated_ch ( void ); // Widget not enabled. no width allocated.
double textbox_get_estimated_ch ( void ) TASSERTE(wid1->h, 0);
{ TASSERTE(wid1->w, 0);
return 8; widget_enable(WIDGET(wid1));
} widget_update(WIDGET(b));
void rofi_view_get_current_monitor ( G_GNUC_UNUSED int *width, G_GNUC_UNUSED int *height ) // Widget enabled. so width allocated.
{ TASSERTE(wid1->h, 20);
TASSERTE(wid1->w, 100);
} widget *wid2 = g_malloc0(sizeof(widget));
wid2->parent = WIDGET(b);
int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv ) widget_enable(WIDGET(wid2));
{ box_add(b, WIDGET(wid2), TRUE);
{ TASSERTE(wid1->h, 20);
box *b = box_create ( NULL, "box", ROFI_ORIENTATION_HORIZONTAL ); TASSERTE(wid1->w, 49);
//box_set_padding ( b, 5 ); TASSERTE(wid2->h, 20);
widget_resize ( WIDGET (b), 100, 20); TASSERTE(wid2->w, 49);
widget *wid1 = g_malloc0(sizeof(widget)); widget *wid3 = g_malloc0(sizeof(widget));
wid1->parent = WIDGET(b); wid3->parent = WIDGET(b);
box_add ( b , WIDGET( wid1 ), TRUE ); widget_enable(WIDGET(wid3));
// Widget not enabled. no width allocated. box_add(b, WIDGET(wid3), FALSE);
TASSERTE ( wid1->h, 0 ); TASSERTE(wid1->h, 20);
TASSERTE ( wid1->w, 0 ); TASSERTE(wid1->w, 48);
widget_enable ( WIDGET ( wid1 ) ); TASSERTE(wid2->h, 20);
widget_update ( WIDGET ( b ) ) ; TASSERTE(wid2->w, 48);
// Widget enabled. so width allocated.
TASSERTE ( wid1->h, 20 ); widget_resize(WIDGET(wid3), 20, 10);
TASSERTE ( wid1->w, 100 ); // TODO should this happen automagically?
widget *wid2 = g_malloc0(sizeof(widget)); widget_update(WIDGET(b));
wid2->parent = WIDGET (b) ; TASSERTE(wid1->h, 20);
widget_enable ( WIDGET ( wid2 ) ); TASSERTE(wid1->w, 38);
box_add ( b , WIDGET( wid2 ), TRUE ); TASSERTE(wid2->h, 20);
TASSERTE ( wid1->h, 20); TASSERTE(wid2->w, 38);
TASSERTE ( wid1->w, 49); TASSERTE(wid3->h, 20);
TASSERTE ( wid2->h, 20); TASSERTE(wid3->w, 20);
TASSERTE ( wid2->w, 49);
widget_resize(WIDGET(b), 200, 20);
widget *wid3 = g_malloc0(sizeof(widget)); TASSERTE(wid1->h, 20);
wid3->parent = WIDGET (b); TASSERTE(wid1->w, 88);
widget_enable ( WIDGET ( wid3 ) ); TASSERTE(wid2->h, 20);
box_add ( b , WIDGET( wid3 ), FALSE ); TASSERTE(wid2->w, 88);
TASSERTE ( wid1->h, 20); TASSERTE(wid3->h, 20);
TASSERTE ( wid1->w, 48); TASSERTE(wid3->w, 20);
TASSERTE ( wid2->h, 20); // TASSERTE ( box_get_fixed_pixels ( b ) , 24 );
TASSERTE ( wid2->w, 48);
widget *wid4 = g_malloc0(sizeof(widget));
widget_resize ( WIDGET (wid3) , 20, 10 ); wid4->parent = WIDGET(b);
// TODO should this happen automagically? widget_enable(WIDGET(wid4));
widget_update ( WIDGET ( b ) ) ; widget_resize(WIDGET(wid4), 20, 20);
TASSERTE ( wid1->h, 20); box_add(b, WIDGET(wid4), FALSE);
TASSERTE ( wid1->w, 38); TASSERTE(wid4->x, 200 - 20);
TASSERTE ( wid2->h, 20); widget *wid5 = g_malloc0(sizeof(widget));
TASSERTE ( wid2->w, 38); wid5->parent = WIDGET(b);
TASSERTE ( wid3->h, 20); widget_enable(WIDGET(wid5));
TASSERTE ( wid3->w, 20); widget_resize(WIDGET(wid5), 20, 20);
box_add(b, WIDGET(wid5), TRUE);
widget_resize ( WIDGET (b ), 200, 20 ); TASSERTE(wid5->x, 149);
TASSERTE ( wid1->h, 20); widget_free(WIDGET(b));
TASSERTE ( wid1->w, 88); }
TASSERTE ( wid2->h, 20); {
TASSERTE ( wid2->w, 88); box *b = box_create(NULL, "box", ROFI_ORIENTATION_VERTICAL);
TASSERTE ( wid3->h, 20); widget_resize(WIDGET(b), 20, 100);
TASSERTE ( wid3->w, 20); // box_set_padding ( b, 5 );
// TASSERTE ( box_get_fixed_pixels ( b ) , 24 );
widget *wid1 = g_malloc0(sizeof(widget));
widget *wid4 = g_malloc0(sizeof(widget)); wid1->parent = WIDGET(b);
wid4->parent = WIDGET ( b ); box_add(b, WIDGET(wid1), TRUE);
widget_enable ( WIDGET ( wid4 ) ); // Widget not enabled. no width allocated.
widget_resize ( WIDGET ( wid4 ), 20, 20 ); TASSERTE(wid1->h, 0);
box_add ( b , WIDGET( wid4 ), FALSE ); TASSERTE(wid1->w, 0);
TASSERTE ( wid4->x, 200-20); widget_enable(WIDGET(wid1));
widget *wid5 = g_malloc0(sizeof(widget)); widget_update(WIDGET(b));
wid5->parent = WIDGET ( b ); // Widget enabled. so width allocated.
widget_enable ( WIDGET ( wid5 ) ); TASSERTE(wid1->h, 100);
widget_resize ( WIDGET ( wid5 ), 20, 20 ); TASSERTE(wid1->w, 20);
box_add ( b , WIDGET( wid5 ), TRUE ); widget *wid2 = g_malloc0(sizeof(widget));
TASSERTE ( wid5->x, 149); wid2->parent = WIDGET(b);
widget_free ( WIDGET ( b ) ); widget_enable(WIDGET(wid2));
} box_add(b, WIDGET(wid2), TRUE);
{ TASSERTE(wid1->w, 20);
box *b = box_create ( NULL, "box", ROFI_ORIENTATION_VERTICAL ); TASSERTE(wid1->h, 49);
widget_resize ( WIDGET (b), 20, 100); TASSERTE(wid2->w, 20);
//box_set_padding ( b, 5 ); TASSERTE(wid2->h, 49);
widget *wid1 = g_malloc0(sizeof(widget)); widget *wid3 = g_malloc0(sizeof(widget));
wid1->parent = WIDGET ( b ); wid3->parent = WIDGET(b);
box_add ( b , WIDGET( wid1 ), TRUE ); widget_enable(WIDGET(wid3));
// Widget not enabled. no width allocated. box_add(b, WIDGET(wid3), FALSE);
TASSERTE ( wid1->h, 0); TASSERTE(wid1->w, 20);
TASSERTE ( wid1->w, 0 ); TASSERTE(wid1->h, 48);
widget_enable ( WIDGET ( wid1 ) ); TASSERTE(wid2->w, 20);
widget_update ( WIDGET ( b ) ) ; TASSERTE(wid2->h, 48);
// Widget enabled. so width allocated.
TASSERTE ( wid1->h, 100); widget_resize(WIDGET(wid3), 10, 20);
TASSERTE ( wid1->w, 20 ); // TODO should this happen automagically?
widget *wid2 = g_malloc0(sizeof(widget)); widget_update(WIDGET(b));
wid2->parent = WIDGET ( b ); TASSERTE(wid1->w, 20);
widget_enable ( WIDGET ( wid2 ) ); TASSERTE(wid1->h, 38);
box_add ( b , WIDGET( wid2 ), TRUE ); TASSERTE(wid2->w, 20);
TASSERTE ( wid1->w, 20); TASSERTE(wid2->h, 38);
TASSERTE ( wid1->h, 49); TASSERTE(wid3->w, 20);
TASSERTE ( wid2->w, 20); TASSERTE(wid3->h, 20);
TASSERTE ( wid2->h, 49);
widget_resize(WIDGET(b), 20, 200);
widget *wid3 = g_malloc0(sizeof(widget)); TASSERTE(wid1->w, 20);
wid3->parent = WIDGET ( b ); TASSERTE(wid1->h, 88);
widget_enable ( WIDGET ( wid3 ) ); TASSERTE(wid2->w, 20);
box_add ( b , WIDGET( wid3 ), FALSE ); TASSERTE(wid2->h, 88);
TASSERTE ( wid1->w, 20); TASSERTE(wid3->w, 20);
TASSERTE ( wid1->h, 48); TASSERTE(wid3->h, 20);
TASSERTE ( wid2->w, 20); // TASSERTE ( box_get_fixed_pixels ( b ) , 4 );
TASSERTE ( wid2->h, 48); widget *wid4 = g_malloc0(sizeof(widget));
wid4->parent = WIDGET(b);
widget_resize ( WIDGET (wid3) , 10, 20 ); widget_enable(WIDGET(wid4));
// TODO should this happen automagically? widget_resize(WIDGET(wid4), 20, 20);
widget_update ( WIDGET ( b ) ) ; box_add(b, WIDGET(wid4), FALSE);
TASSERTE ( wid1->w, 20); TASSERTE(wid4->y, 180);
TASSERTE ( wid1->h, 38); widget *wid5 = g_malloc0(sizeof(widget));
TASSERTE ( wid2->w, 20); wid5->parent = WIDGET(b);
TASSERTE ( wid2->h, 38); widget_enable(WIDGET(wid5));
TASSERTE ( wid3->w, 20); widget_resize(WIDGET(wid5), 20, 20);
TASSERTE ( wid3->h, 20); box_add(b, WIDGET(wid5), TRUE);
TASSERTE(wid5->y, 149);
widget_resize ( WIDGET (b ), 20, 200 ); widget_free(WIDGET(b));
TASSERTE ( wid1->w, 20); }
TASSERTE ( wid1->h, 88); {
TASSERTE ( wid2->w, 20); box *b = box_create(NULL, "box", ROFI_ORIENTATION_VERTICAL);
TASSERTE ( wid2->h, 88); widget_resize(WIDGET(b), 20, 90);
TASSERTE ( wid3->w, 20); // box_set_padding ( b, 5 );
TASSERTE ( wid3->h, 20); widget *wid1 = g_malloc0(sizeof(widget));
// TASSERTE ( box_get_fixed_pixels ( b ) , 4 ); wid1->parent = WIDGET(b);
widget *wid4 = g_malloc0(sizeof(widget)); wid1->type = 1;
wid4->parent = WIDGET ( b ); widget_enable(wid1);
widget_enable ( WIDGET ( wid4 ) ); box_add(b, WIDGET(wid1), TRUE);
widget_resize ( WIDGET ( wid4 ), 20, 20 ); widget *wid2 = g_malloc0(sizeof(widget));
box_add ( b , WIDGET( wid4 ), FALSE ); wid2->parent = WIDGET(b);
TASSERTE ( wid4->y, 180); wid2->type = 1;
widget *wid5 = g_malloc0(sizeof(widget)); widget_enable(wid2);
wid5->parent = WIDGET ( b ); box_add(b, WIDGET(wid2), TRUE);
widget_enable ( WIDGET ( wid5 ) ); widget *wid3 = g_malloc0(sizeof(widget));
widget_resize ( WIDGET ( wid5 ), 20, 20 ); wid3->parent = WIDGET(b);
box_add ( b , WIDGET( wid5 ), TRUE ); wid3->type = 2;
TASSERTE ( wid5->y, 149); widget_enable(wid3);
widget_free ( WIDGET ( b ) ); box_add(b, WIDGET(wid3), TRUE);
}
{ gint x = 10;
box *b = box_create ( NULL, "box", ROFI_ORIENTATION_VERTICAL ); gint y = 50;
widget_resize ( WIDGET (b), 20, 90); TASSERTW(widget_find_mouse_target(WIDGET(b), 1, x, y), WIDGET(wid2));
//box_set_padding ( b, 5 );
widget *wid1 = g_malloc0(sizeof(widget)); y = 30;
wid1->parent = WIDGET ( b ); TASSERTW(widget_find_mouse_target(WIDGET(b), 1, x, y), WIDGET(wid2));
wid1->type = 1; y = 27;
widget_enable(wid1); TASSERTW(widget_find_mouse_target(WIDGET(b), 1, x, y), WIDGET(wid1));
box_add ( b , WIDGET( wid1 ), TRUE ); widget_disable(wid2);
widget *wid2 = g_malloc0(sizeof(widget)); y = 40;
wid2->parent = WIDGET ( b ); TASSERTW(widget_find_mouse_target(WIDGET(b), 1, x, y), WIDGET(wid1));
wid2->type = 1; widget_disable(wid1);
widget_enable(wid2); widget_enable(wid2);
box_add ( b , WIDGET( wid2 ), TRUE ); TASSERTW(widget_find_mouse_target(WIDGET(b), 1, x, y), WIDGET(wid2));
widget *wid3 = g_malloc0(sizeof(widget)); TASSERTW(widget_find_mouse_target(WIDGET(b), 2, x, y), NULL);
wid3->parent = WIDGET ( b ); y = 55;
wid3->type = 2; TASSERTW(widget_find_mouse_target(WIDGET(b), 2, x, y), WIDGET(wid3));
widget_enable(wid3); widget_free(WIDGET(b));
box_add ( b , WIDGET( wid3 ), TRUE ); }
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 ) );
}
} }

View File

@ -25,139 +25,124 @@
* *
*/ */
#include <assert.h>
#include <locale.h>
#include <glib.h>
#include <stdio.h>
#include <helper.h>
#include <string.h>
#include <xcb/xcb_ewmh.h>
#include "display.h" #include "display.h"
#include "xcb.h" #include "rofi-icon-fetcher.h"
#include "xcb-internal.h"
#include "rofi.h" #include "rofi.h"
#include "settings.h" #include "settings.h"
#include "widgets/textbox.h" #include "widgets/textbox.h"
#include "rofi-icon-fetcher.h" #include "xcb-internal.h"
#include "xcb.h"
#include <assert.h>
#include <glib.h>
#include <helper.h>
#include <locale.h>
#include <stdio.h>
#include <string.h>
#include <xcb/xcb_ewmh.h>
static int test = 0; static int test = 0;
#define TASSERT( a ) { \ #define TASSERT(a) \
assert ( a ); \ { \
printf ( "Test %i passed (%s)\n", ++test, # a ); \ assert(a); \
} printf("Test %i passed (%s)\n", ++test, #a); \
#define TASSERTE( a, b ) { \ }
if ( ( a ) == ( b ) ) { \ #define TASSERTE(a, b) \
printf ( "Test %i passed (%s == %s) (%u == %u)\n", ++test, # a, # b, a, b ); \ { \
} else { \ if ((a) == (b)) { \
printf ( "Test %i failed (%s == %s) (%u != %u)\n", ++test, # a, # b, a, b ); \ printf("Test %i passed (%s == %s) (%u == %u)\n", ++test, #a, #b, a, b); \
abort ( ); \ } else { \
} \ printf("Test %i failed (%s == %s) (%u != %u)\n", ++test, #a, #b, a, b); \
} abort(); \
} \
}
#include "theme.h" #include "theme.h"
ThemeWidget *rofi_theme = NULL; 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; 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; 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; 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; return FALSE;
} }
double textbox_get_estimated_char_height ( void ) double textbox_get_estimated_char_height(void) { return 12.0; }
{ void rofi_view_get_current_monitor(int *width, int *height) {
return 12.0; *width = 1920;
*height = 1080;
} }
void rofi_view_get_current_monitor ( int *width, int *height ) double textbox_get_estimated_ch(void) { return 9.0; }
{ void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {}
*width = 1920; int rofi_view_error_dialog(const char *msg, G_GNUC_UNUSED int markup) {
*height = 1080; 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 ) int monitor_active(G_GNUC_UNUSED workarea *mon) { return 0; }
{
return 0; void display_startup_notification(
} G_GNUC_UNUSED RofiHelperExecuteContext *context,
G_GNUC_UNUSED GSpawnChildSetupFunc *child_setup,
void display_startup_notification ( G_GNUC_UNUSED RofiHelperExecuteContext *context, G_GNUC_UNUSED GSpawnChildSetupFunc *child_setup, G_GNUC_UNUSED gpointer *user_data ) G_GNUC_UNUSED gpointer *user_data) {}
{
} int main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv) {
int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **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" ); char **list = NULL;
return EXIT_FAILURE; int llength = 0;
} char *test_str = "{host} {terminal} -e bash -c \"{ssh-client} {host}; echo "
char **list = NULL; "'{terminal} {host}'\" -i -3 -u 4";
int llength = 0; helper_parse_setup(test_str, &list, &llength, "{host}", "chuck", "{terminal}",
char * test_str = "x-terminal-emulator", NULL);
"{host} {terminal} -e bash -c \"{ssh-client} {host}; echo '{terminal} {host}'\" -i -3 -u 4";
helper_parse_setup ( test_str, &list, &llength, "{host}", "chuck", TASSERT(llength == 10);
"{terminal}", "x-terminal-emulator", NULL ); TASSERT(strcmp(list[0], "chuck") == 0);
TASSERT(strcmp(list[1], "x-terminal-emulator") == 0);
TASSERT ( llength == 10); TASSERT(strcmp(list[2], "-e") == 0);
TASSERT ( strcmp ( list[0], "chuck" ) == 0 ); TASSERT(strcmp(list[3], "bash") == 0);
TASSERT ( strcmp ( list[1], "x-terminal-emulator" ) == 0 ); TASSERT(strcmp(list[4], "-c") == 0);
TASSERT ( strcmp ( list[2], "-e" ) == 0 ); TASSERT(strcmp(list[5], "ssh chuck; echo 'x-terminal-emulator chuck'") == 0);
TASSERT ( strcmp ( list[3], "bash" ) == 0 ); TASSERT(strcmp(list[6], "-i") == 0);
TASSERT ( strcmp ( list[4], "-c" ) == 0 ); TASSERT(strcmp(list[7], "-3") == 0);
TASSERT ( strcmp ( list[5], "ssh chuck; echo 'x-terminal-emulator chuck'" ) == 0 ); TASSERT(strcmp(list[8], "-u") == 0);
TASSERT ( strcmp ( list[6], "-i" ) == 0 ); TASSERT(strcmp(list[9], "4") == 0);
TASSERT ( strcmp ( list[7], "-3" ) == 0 );
TASSERT ( strcmp ( list[8], "-u" ) == 0 ); cmd_set_arguments(llength, list);
TASSERT ( strcmp ( list[9], "4" ) == 0 ); TASSERT(find_arg("-e") == 2);
TASSERT(find_arg("-x") == -1);
cmd_set_arguments ( llength, list); char *str;
TASSERT ( find_arg ( "-e") == 2 ); TASSERT(find_arg_str("-e", &str) == TRUE);
TASSERT ( find_arg ( "-x") == -1 ); TASSERT(str == list[3]);
char *str; TASSERT(find_arg_str("-x", &str) == FALSE);
TASSERT ( find_arg_str ( "-e", &str) == TRUE ); // Should be unmodified.
TASSERT ( str == list[3] ); TASSERT(str == list[3]);
TASSERT ( find_arg_str ( "-x", &str) == FALSE );
// Should be unmodified. unsigned int u = 1234;
TASSERT ( str == list[3] ); int d = -1234;
TASSERT(find_arg_uint("-x", &u) == FALSE);
unsigned int u = 1234; TASSERT(u == 1234);
int d = -1234; TASSERT(find_arg_int("-x", &d) == FALSE);
TASSERT ( find_arg_uint ( "-x", &u ) == FALSE ); TASSERT(d == -1234);
TASSERT ( u == 1234 ); TASSERT(find_arg_uint("-u", &u) == TRUE);
TASSERT ( find_arg_int ( "-x", &d ) == FALSE ); TASSERT(u == 4);
TASSERT ( d == -1234 ); TASSERT(find_arg_uint("-i", &u) == TRUE);
TASSERT ( find_arg_uint ( "-u", &u ) == TRUE ); TASSERT(u == 4294967293);
TASSERT ( u == 4 ); TASSERT(find_arg_int("-i", &d) == TRUE);
TASSERT ( find_arg_uint ( "-i", &u ) == TRUE ); TASSERT(d == -3);
TASSERT ( u == 4294967293 );
TASSERT ( find_arg_int ( "-i", &d ) == TRUE ); g_strfreev(list);
TASSERT ( d == -3 );
g_strfreev ( list );
} }

View File

@ -25,119 +25,106 @@
* *
*/ */
#include <assert.h>
#include <locale.h>
#include <glib.h>
#include <stdio.h>
#include <helper.h>
#include <string.h>
#include <xcb/xcb_ewmh.h>
#include "theme.h"
#include "display.h" #include "display.h"
#include "xcb.h" #include "rofi-icon-fetcher.h"
#include "xcb-internal.h"
#include "rofi.h" #include "rofi.h"
#include "settings.h" #include "settings.h"
#include "theme.h"
#include "widgets/textbox.h" #include "widgets/textbox.h"
#include "rofi-icon-fetcher.h" #include "xcb-internal.h"
#include "xcb.h"
#include <assert.h>
#include <glib.h>
#include <helper.h>
#include <locale.h>
#include <stdio.h>
#include <string.h>
#include <xcb/xcb_ewmh.h>
static int test = 0; static int test = 0;
#define TASSERT( a ) { \ #define TASSERT(a) \
assert ( a ); \ { \
printf ( "Test %i passed (%s)\n", ++test, # a ); \ assert(a); \
} printf("Test %i passed (%s)\n", ++test, #a); \
#define TASSERTE( a, b ) { \ }
if ( ( a ) == ( b ) ) { \ #define TASSERTE(a, b) \
printf ( "Test %i passed (%s == %s) (%u == %u)\n", ++test, # a, # b, a, b ); \ { \
} else { \ if ((a) == (b)) { \
printf ( "Test %i failed (%s == %s) (%u != %u)\n", ++test, # a, # b, a, b ); \ printf("Test %i passed (%s == %s) (%u == %u)\n", ++test, #a, #b, a, b); \
abort ( ); \ } else { \
} \ printf("Test %i failed (%s == %s) (%u != %u)\n", ++test, #a, #b, a, b); \
} abort(); \
} \
}
ThemeWidget *rofi_theme = NULL; ThemeWidget *rofi_theme = NULL;
void rofi_clear_error_messages ( void ) {} void rofi_clear_error_messages(void) {}
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; 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; 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; return NULL;
} }
double textbox_get_estimated_char_height ( void ) double textbox_get_estimated_char_height(void) { return 12.0; }
{ void rofi_view_get_current_monitor(int *width, int *height) {
return 12.0; *width = 1920;
*height = 1080;
} }
void rofi_view_get_current_monitor ( int *width, int *height ) double textbox_get_estimated_ch(void) { return 9.0; }
{ gboolean rofi_theme_parse_string(G_GNUC_UNUSED const char *string) { return 0; }
*width = 1920;
*height = 1080; void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {}
}
double textbox_get_estimated_ch ( void ) int rofi_view_error_dialog(const char *msg, G_GNUC_UNUSED int markup) {
{ fputs(msg, stderr);
return 9.0; return TRUE;
}
gboolean rofi_theme_parse_string ( const char *string )
{
return 0;
} }
void rofi_add_error_message ( G_GNUC_UNUSED GString *msg ) int monitor_active(G_GNUC_UNUSED workarea *mon) { return 0; }
{
} void display_startup_notification(
G_GNUC_UNUSED RofiHelperExecuteContext *context,
int rofi_view_error_dialog ( const char *msg, G_GNUC_UNUSED int markup ) G_GNUC_UNUSED GSpawnChildSetupFunc *child_setup,
{ G_GNUC_UNUSED gpointer *user_data) {}
fputs ( msg, stderr );
return TRUE; int main(int argc, char **argv) {
} cmd_set_arguments(argc, argv);
int monitor_active ( G_GNUC_UNUSED workarea *mon ) if (setlocale(LC_ALL, "") == NULL) {
{ fprintf(stderr, "Failed to set locale.\n");
return 0; return EXIT_FAILURE;
} }
void display_startup_notification ( G_GNUC_UNUSED RofiHelperExecuteContext *context, G_GNUC_UNUSED GSpawnChildSetupFunc *child_setup, G_GNUC_UNUSED gpointer *user_data ) /**
{ * Test some path functions. Not easy as not sure what is right output on
} * travis.
*/
int main ( int argc, char **argv ) // Test if root is preserved.
{ char *str = rofi_expand_path("/");
cmd_set_arguments ( argc, argv ); TASSERT(strcmp(str, "/") == 0);
g_free(str);
if ( setlocale ( LC_ALL, "" ) == NULL ) { // Test is relative path is preserved.
fprintf ( stderr, "Failed to set locale.\n" ); str = rofi_expand_path("../AUTHORS");
return EXIT_FAILURE; TASSERT(strcmp(str, "../AUTHORS") == 0);
} g_free(str);
// Test another one.
/** str = rofi_expand_path("/bin/false");
* Test some path functions. Not easy as not sure what is right output on travis. TASSERT(strcmp(str, "/bin/false") == 0);
*/ g_free(str);
// Test if root is preserved. // See if user paths get expanded in full path.
char *str = rofi_expand_path ( "/" ); str = rofi_expand_path("~/");
TASSERT ( strcmp ( str, "/" ) == 0 ); const char *hd = g_get_home_dir();
g_free ( str ); TASSERT(strcmp(str, hd) == 0);
// Test is relative path is preserved. g_free(str);
str = rofi_expand_path ( "../AUTHORS" ); str = rofi_expand_path("~root/");
TASSERT ( strcmp ( str, "../AUTHORS" ) == 0 ); TASSERT(str[0] == '/');
g_free ( str ); 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 );
} }

View File

@ -50,17 +50,25 @@ static int test = 0;
#include "theme.h" #include "theme.h"
ThemeWidget *rofi_theme = NULL; ThemeWidget *rofi_theme = NULL;
uint32_t rofi_icon_fetcher_query(const char *name, const int size) { return 0; } uint32_t rofi_icon_fetcher_query(G_GNUC_UNUSED const char *name,
uint32_t rofi_icon_fetcher_query_advanced(const char *name, const int wsize, G_GNUC_UNUSED const int size) {
const int hsize) { 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; 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) {} 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; } double textbox_get_estimated_char_height(void) { return 12.0; }
void rofi_view_get_current_monitor(int *width, int *height) { void rofi_view_get_current_monitor(int *width, int *height) {
*width = 1920; *width = 1920;

View File

@ -25,205 +25,221 @@
* *
*/ */
#include <assert.h>
#include <locale.h>
#include <glib.h>
#include <stdio.h>
#include <helper.h>
#include <string.h>
#include <xcb/xcb_ewmh.h>
#include "theme.h"
#include "display.h" #include "display.h"
#include "xcb.h" #include "rofi-icon-fetcher.h"
#include "xcb-internal.h"
#include "rofi.h" #include "rofi.h"
#include "settings.h" #include "settings.h"
#include "rofi-icon-fetcher.h" #include "theme.h"
#include "xcb-internal.h"
#include "xcb.h"
#include <assert.h>
#include <glib.h>
#include <helper.h>
#include <locale.h>
#include <stdio.h>
#include <string.h>
#include <xcb/xcb_ewmh.h>
static int test = 0; static int test = 0;
#define TASSERT( a ) { \ #define TASSERT(a) \
assert ( a ); \ { \
printf ( "Test %i passed (%s)\n", ++test, # a ); \ assert(a); \
} printf("Test %i passed (%s)\n", ++test, #a); \
#define TASSERTE( a, b ) { \ }
if ( ( a ) == ( b ) ) { \ #define TASSERTE(a, b) \
printf ( "Test %i passed (%s == %s) (%u == %u)\n", ++test, # a, # b, a, b ); \ { \
} else { \ if ((a) == (b)) { \
printf ( "Test %i failed (%s == %s) (%u != %u)\n", ++test, # a, # b, a, b ); \ printf("Test %i passed (%s == %s) (%u == %u)\n", ++test, #a, #b, a, b); \
abort ( ); \ } 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 ); \ #define TASSERTL(a, b) \
} else { \ { \
printf ( "Test %i failed (%s == %s) (%d != %d)\n", ++test, # a, # b, a, b ); \ if ((a) == (b)) { \
abort ( ); \ 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" #include "widgets/textbox.h"
ThemeWidget *rofi_theme = NULL; 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; 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; return 0;
} }
void rofi_clear_error_messages ( void ) {} void rofi_clear_error_messages(void) {}
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; 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; return NULL;
} }
double textbox_get_estimated_char_height ( void ) double textbox_get_estimated_char_height(void) { return 12.0; }
{ void rofi_view_get_current_monitor(int *width, int *height) {
return 12.0; *width = 1920;
*height = 1080;
} }
void rofi_view_get_current_monitor ( int *width, int *height ) double textbox_get_estimated_ch(void) { return 9.0; }
{ void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {}
*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 rofi_view_error_dialog ( const char *msg, G_GNUC_UNUSED int markup ) int monitor_active(G_GNUC_UNUSED workarea *mon) { return 0; }
{
fputs ( msg, stderr ); void display_startup_notification(
return TRUE; 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 )
{ int main(int argc, char **argv) {
return 0; cmd_set_arguments(argc, argv);
}
if (setlocale(LC_ALL, "") == NULL) {
void display_startup_notification ( G_GNUC_UNUSED RofiHelperExecuteContext *context, G_GNUC_UNUSED GSpawnChildSetupFunc *child_setup, G_GNUC_UNUSED gpointer *user_data ) fprintf(stderr, "Failed to set locale.\n");
{ return EXIT_FAILURE;
} }
int main ( int argc, char **argv ) /**
{ * Char function
cmd_set_arguments ( argc, argv ); */
if ( setlocale ( LC_ALL, "" ) == NULL ) { TASSERT(helper_parse_char("\\n") == '\n');
fprintf ( stderr, "Failed to set locale.\n" ); TASSERT(helper_parse_char("\\a") == '\a');
return EXIT_FAILURE; TASSERT(helper_parse_char("\\b") == '\b');
} TASSERT(helper_parse_char("\\t") == '\t');
TASSERT(helper_parse_char("\\v") == '\v');
/** TASSERT(helper_parse_char("\\f") == '\f');
* Char function TASSERT(helper_parse_char("\\r") == '\r');
*/ TASSERT(helper_parse_char("\\\\") == '\\');
TASSERT(helper_parse_char("\\0") == 0);
TASSERT ( helper_parse_char ( "\\n" ) == '\n' ); TASSERT(helper_parse_char("\\x77") == 'w');
TASSERT ( helper_parse_char ( "\\a" ) == '\a' ); TASSERT(helper_parse_char("\\x0A") == '\n');
TASSERT ( helper_parse_char ( "\\b" ) == '\b' );
TASSERT ( helper_parse_char ( "\\t" ) == '\t' ); /**
TASSERT ( helper_parse_char ( "\\v" ) == '\v' ); * tokenize
TASSERT ( helper_parse_char ( "\\f" ) == '\f' ); */
TASSERT ( helper_parse_char ( "\\r" ) == '\r' );
TASSERT ( helper_parse_char ( "\\\\" ) == '\\' ); TASSERT(levenshtein("aap", g_utf8_strlen("aap", -1), "aap",
TASSERT ( helper_parse_char ( "\\0" ) == 0 ); g_utf8_strlen("aap", -1)) == 0);
TASSERT ( helper_parse_char ( "\\x77" ) == 'w' ); TASSERT(levenshtein("aap", g_utf8_strlen("aap", -1), "aap ",
TASSERT ( helper_parse_char ( "\\x0A" ) == '\n' ); g_utf8_strlen("aap ", -1)) == 1);
TASSERT(levenshtein("aap ", g_utf8_strlen("aap ", -1), "aap",
/** g_utf8_strlen("aap", -1)) == 1);
* tokenize TASSERTE(levenshtein("aap", g_utf8_strlen("aap", -1), "aap noot",
*/ g_utf8_strlen("aap noot", -1)),
5u);
TASSERT ( levenshtein ( "aap", g_utf8_strlen ( "aap", -1), "aap", g_utf8_strlen ( "aap", -1) ) == 0 ); TASSERTE(levenshtein("aap", g_utf8_strlen("aap", -1), "noot aap",
TASSERT ( levenshtein ( "aap", g_utf8_strlen ( "aap", -1), "aap ", g_utf8_strlen ( "aap ", -1) ) == 1 ); g_utf8_strlen("noot aap", -1)),
TASSERT ( levenshtein ( "aap ", g_utf8_strlen ( "aap ", -1), "aap", g_utf8_strlen ( "aap", -1) ) == 1 ); 5u);
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 mies",
TASSERTE ( levenshtein ( "aap", g_utf8_strlen ( "aap", -1), "noot aap", g_utf8_strlen ( "noot aap", -1) ), 5u ); g_utf8_strlen("noot aap mies", -1)),
TASSERTE ( levenshtein ( "aap", g_utf8_strlen ( "aap", -1), "noot aap mies", g_utf8_strlen ( "noot aap mies", -1) ), 10u ); 10u);
TASSERTE ( levenshtein ( "noot aap mies", g_utf8_strlen ( "noot aap mies", -1), "aap", g_utf8_strlen ( "aap", -1) ), 10u ); TASSERTE(levenshtein("noot aap mies", g_utf8_strlen("noot aap mies", -1),
TASSERTE ( levenshtein ( "otp", g_utf8_strlen ( "otp", -1), "noot aap", g_utf8_strlen ( "noot aap", -1) ), 5u ); "aap", g_utf8_strlen("aap", -1)),
/** 10u);
* Quick converision check. TASSERTE(levenshtein("otp", g_utf8_strlen("otp", -1), "noot aap",
*/ g_utf8_strlen("noot aap", -1)),
{ 5u);
char *str = rofi_latin_to_utf8_strdup ( "\xA1\xB5", 2 ); /**
TASSERT ( g_utf8_collate ( str, "¡µ" ) == 0 ); * Quick converision check.
g_free ( str ); */
} {
char *str = rofi_latin_to_utf8_strdup("\xA1\xB5", 2);
{ TASSERT(g_utf8_collate(str, "¡µ") == 0);
char *str = rofi_force_utf8 ( "Valid utf8", 10 ); g_free(str);
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 ); char *str = rofi_force_utf8("Valid utf8", 10);
str = rofi_force_utf8 ( in, strlen ( in ) ); TASSERT(g_utf8_collate(str, "Valid utf8") == 0);
TASSERT ( g_utf8_validate ( str, -1, NULL ) == TRUE ); g_free(str);
TASSERT ( g_utf8_collate ( str, "Valid utf8 until <20>( we continue here" ) == 0 ); char in[] = "Valid utf8 until \xc3\x28 we continue here";
g_free ( str ); TASSERT(g_utf8_validate(in, -1, NULL) == FALSE);
} str = rofi_force_utf8(in, strlen(in));
{ TASSERT(g_utf8_validate(str, -1, NULL) == TRUE);
TASSERT ( utf8_strncmp ( "aapno", "aap€",3) == 0 ); TASSERT(g_utf8_collate(str, "Valid utf8 until <20>( we continue here") == 0);
TASSERT ( utf8_strncmp ( "aapno", "aap€",4) != 0 ); g_free(str);
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("aapno", "aap€", 3) == 0);
// TASSERT ( utf8_strncmp ( in, "Valid", 3 ) == 0); TASSERT(utf8_strncmp("aapno", "aap€", 4) != 0);
} TASSERT(utf8_strncmp("aapno", "a", 4) != 0);
{ TASSERT(utf8_strncmp("a", "aap€", 4) != 0);
TASSERTL ( rofi_scorer_fuzzy_evaluate ("aap noot mies", 12 , "aap noot mies", 12), -605); // char in[] = "Valid utf8 until \xc3\x28 we continue here";
TASSERTL ( rofi_scorer_fuzzy_evaluate ("anm", 3, "aap noot mies", 12), -155); // TASSERT ( utf8_strncmp ( in, "Valid", 3 ) == 0);
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); TASSERTL(
config.case_sensitive = FALSE; rofi_scorer_fuzzy_evaluate("aap noot mies", 12, "aap noot mies", 12),
TASSERTL ( rofi_scorer_fuzzy_evaluate ("Anm", 3, "aap noot mies", 12), -155); -605);
TASSERTL ( rofi_scorer_fuzzy_evaluate ("aap noot mies", 12,"Anm", 3 ), 1073741824); 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),
char *a; 1073741754);
a = helper_string_replace_if_exists ( "{terminal} [-t {title} blub ]-e {cmd}", "{cmd}", "aap", "{title}", "some title", "{terminal}", "rofi-sensible-terminal", NULL); config.case_sensitive = FALSE;
printf("%s\n",a); TASSERTL(rofi_scorer_fuzzy_evaluate("Anm", 3, "aap noot mies", 12), -155);
TASSERT ( g_utf8_collate ( a, "rofi-sensible-terminal -t some title blub -e aap") == 0); TASSERTL(rofi_scorer_fuzzy_evaluate("aap noot mies", 12, "Anm", 3),
g_free(a); 1073741824);
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); char *a;
g_free(a); a = helper_string_replace_if_exists(
a = helper_string_replace_if_exists ( "{name} [<span weight='light' size='small'><i>({category})</i></span>]", "{name}", "Librecad", "{category}", "Desktop app", "{terminal}", "rofi-sensible-terminal", NULL ); "{terminal} [-t {title} blub ]-e {cmd}", "{cmd}", "aap", "{title}",
printf("%s\n",a); "some title", "{terminal}", "rofi-sensible-terminal", NULL);
TASSERT ( g_utf8_collate ( a, "Librecad <span weight='light' size='small'><i>(Desktop app)</i></span>") == 0); printf("%s\n", a);
g_free(a); TASSERT(g_utf8_collate(
a = helper_string_replace_if_exists ( "{name}[ <span weight='light' size='small'><i>({category})</i></span>]", "{name}", "Librecad", "{terminal}", "rofi-sensible-terminal", NULL ); a, "rofi-sensible-terminal -t some title blub -e aap") == 0);
TASSERT ( g_utf8_collate ( a, "Librecad") == 0); g_free(a);
g_free(a); a = helper_string_replace_if_exists("{terminal} [-t {title} blub ]-e {cmd}",
a = helper_string_replace_if_exists ( "{terminal} [{title} blub ]-e {cmd}", "{cmd}", "aap", "{title}", "some title", "{terminal}", "rofi-sensible-terminal", NULL); "{cmd}", "aap", "{terminal}",
printf("%s\n",a); "rofi-sensible-terminal", NULL);
TASSERT ( g_utf8_collate ( a, "rofi-sensible-terminal some title blub -e aap") == 0); printf("%s\n", a);
g_free(a); TASSERT(g_utf8_collate(a, "rofi-sensible-terminal -e aap") == 0);
a = helper_string_replace_if_exists ( "{terminal} [{title} blub ]-e {cmd}", g_free(a);
"{cmd}", "aap", a = helper_string_replace_if_exists(
"{title}", NULL, "{name} [<span weight='light' size='small'><i>({category})</i></span>]",
"{terminal}", "rofi-sensible-terminal", "{name}", "Librecad", "{category}", "Desktop app", "{terminal}",
NULL); "rofi-sensible-terminal", NULL);
printf("%s\n",a); printf("%s\n", a);
TASSERT ( g_utf8_collate ( a, "rofi-sensible-terminal -e aap") == 0); TASSERT(g_utf8_collate(a, "Librecad <span weight='light' "
g_free(a); "size='small'><i>(Desktop app)</i></span>") == 0);
g_free(a);
a = helper_string_replace_if_exists(
"{name}[ <span weight='light' size='small'><i>({category})</i></span>]",
"{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);
} }

View File

@ -25,483 +25,439 @@
* *
*/ */
#include <assert.h>
#include <locale.h>
#include <glib.h>
#include <stdio.h>
#include <helper.h>
#include <string.h>
#include <xcb/xcb_ewmh.h>
#include "display.h" #include "display.h"
#include "theme.h" #include "rofi-icon-fetcher.h"
#include "xcb.h" #include "rofi-types.h"
#include "xcb-internal.h"
#include "rofi.h" #include "rofi.h"
#include "settings.h" #include "settings.h"
#include "rofi-types.h" #include "theme.h"
#include "widgets/textbox.h" #include "widgets/textbox.h"
#include "rofi-icon-fetcher.h" #include "xcb-internal.h"
#include "xcb.h"
#include <assert.h>
#include <glib.h>
#include <helper.h>
#include <locale.h>
#include <stdio.h>
#include <string.h>
#include <xcb/xcb_ewmh.h>
#include <check.h> #include <check.h>
ThemeWidget *rofi_theme = NULL; 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; 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; return 0;
} }
void rofi_clear_error_messages ( void ) {} void rofi_clear_error_messages(void) {}
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; return NULL;
} }
gboolean rofi_theme_parse_string ( G_GNUC_UNUSED const char *string ) gboolean rofi_theme_parse_string(G_GNUC_UNUSED const char *string) {
{
return FALSE; return FALSE;
} }
double textbox_get_estimated_char_height ( void ) double textbox_get_estimated_char_height(void) { return 12.0; }
{ void rofi_view_get_current_monitor(int *width, int *height) {
return 12.0; *width = 1920;
*height = 1080;
} }
void rofi_view_get_current_monitor ( int *width, int *height ) double textbox_get_estimated_ch(void) { return 9.0; }
{ void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {}
*width = 1920; int rofi_view_error_dialog(const char *msg, G_GNUC_UNUSED int markup) {
*height = 1080; 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;
} }
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,
START_TEST(test_tokenizer_free ) G_GNUC_UNUSED gpointer *user_data) {}
{ START_TEST(test_tokenizer_free) { helper_tokenize_free(NULL); }
helper_tokenize_free ( NULL );
}
END_TEST END_TEST
START_TEST ( test_tokenizer_match_normal_single_ci ) START_TEST(test_tokenizer_match_normal_single_ci) {
{ config.matching_method = MM_NORMAL;
config.matching_method = MM_NORMAL; rofi_int_matcher **tokens = helper_tokenize("noot", FALSE);
rofi_int_matcher **tokens = helper_tokenize ( "noot", FALSE );
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "aap noot mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nooaap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "nootap mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap Noot mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "aap Noot mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "Nooaap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "Nooaap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "noOTap mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "noOTap mies"), TRUE);
helper_tokenize_free ( tokens ); helper_tokenize_free(tokens);
} }
END_TEST END_TEST
START_TEST ( test_tokenizer_match_normal_single_cs ) START_TEST(test_tokenizer_match_normal_single_cs) {
{ config.matching_method = MM_NORMAL;
config.matching_method = MM_NORMAL; rofi_int_matcher **tokens = helper_tokenize("noot", TRUE);
rofi_int_matcher **tokens = helper_tokenize ( "noot", TRUE );
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "aap noot mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nooaap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "nootap mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap Noot mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap Noot mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "Nooaap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "Nooaap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "noOTap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "noOTap mies"), FALSE);
helper_tokenize_free ( tokens ); helper_tokenize_free(tokens);
} }
END_TEST END_TEST
START_TEST ( test_tokenizer_match_normal_multiple_ci ) START_TEST(test_tokenizer_match_normal_multiple_ci) {
{ config.matching_method = MM_NORMAL;
config.matching_method = MM_NORMAL; rofi_int_matcher **tokens = helper_tokenize("no ot", FALSE);
rofi_int_matcher **tokens = helper_tokenize ( "no ot", FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap noot mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "aap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nooaap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nootap mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "noap miesot"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "noap miesot") , TRUE ); helper_tokenize_free(tokens);
helper_tokenize_free ( tokens );
} }
END_TEST END_TEST
START_TEST ( test_tokenizer_match_normal_single_ci_negate ) START_TEST(test_tokenizer_match_normal_single_ci_negate) {
{ config.matching_method = MM_NORMAL;
config.matching_method = MM_NORMAL; rofi_int_matcher **tokens = helper_tokenize("-noot", FALSE);
rofi_int_matcher **tokens = helper_tokenize ( "-noot", FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap noot mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "nooaap mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "nootap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "noap miesot"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "noap miesot") , TRUE ); helper_tokenize_free(tokens);
helper_tokenize_free ( tokens );
} }
END_TEST END_TEST
START_TEST ( test_tokenizer_match_normal_multiple_ci_negate ) START_TEST(test_tokenizer_match_normal_multiple_ci_negate) {
{ config.matching_method = MM_NORMAL;
config.matching_method = MM_NORMAL; rofi_int_matcher **tokens = helper_tokenize("-noot aap", FALSE);
rofi_int_matcher **tokens = helper_tokenize ( "-noot aap", FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap noot mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "nooaap mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "nootap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "noap miesot"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "noap miesot") , FALSE ); helper_tokenize_free(tokens);
helper_tokenize_free ( tokens );
} }
END_TEST END_TEST
START_TEST ( test_tokenizer_match_glob_single_ci ) START_TEST(test_tokenizer_match_glob_single_ci) {
{ config.matching_method = MM_GLOB;
config.matching_method = MM_GLOB; rofi_int_matcher **tokens = helper_tokenize("noot", FALSE);
rofi_int_matcher **tokens = helper_tokenize ( "noot", FALSE );
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "aap noot mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nooaap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "nootap mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap Noot mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "aap Noot mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "Nooaap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "Nooaap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "noOTap mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "noOTap mies"), TRUE);
helper_tokenize_free ( tokens ); helper_tokenize_free(tokens);
} }
END_TEST END_TEST
START_TEST ( test_tokenizer_match_glob_single_cs ) START_TEST(test_tokenizer_match_glob_single_cs) {
{ config.matching_method = MM_GLOB;
config.matching_method = MM_GLOB; rofi_int_matcher **tokens = helper_tokenize("noot", TRUE);
rofi_int_matcher **tokens = helper_tokenize ( "noot", TRUE );
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE );
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE );
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE );
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE );
ck_assert_int_eq ( helper_token_match ( tokens, "aap Noot mies") , FALSE );
ck_assert_int_eq ( helper_token_match ( tokens, "Nooaap mies") , FALSE );
ck_assert_int_eq ( helper_token_match ( tokens, "noOTap mies") , FALSE );
helper_tokenize_free ( tokens );
ck_assert_int_eq(helper_token_match(tokens, "aap noot mies"), TRUE);
ck_assert_int_eq(helper_token_match(tokens, "aap mies"), FALSE);
ck_assert_int_eq(helper_token_match(tokens, "nooaap mies"), FALSE);
ck_assert_int_eq(helper_token_match(tokens, "nootap mies"), TRUE);
ck_assert_int_eq(helper_token_match(tokens, "aap Noot mies"), FALSE);
ck_assert_int_eq(helper_token_match(tokens, "Nooaap mies"), FALSE);
ck_assert_int_eq(helper_token_match(tokens, "noOTap mies"), FALSE);
helper_tokenize_free(tokens);
} }
END_TEST END_TEST
START_TEST ( test_tokenizer_match_glob_multiple_ci ) START_TEST(test_tokenizer_match_glob_multiple_ci) {
{ config.matching_method = MM_GLOB;
config.matching_method = MM_GLOB; rofi_int_matcher **tokens = helper_tokenize("no ot", FALSE);
rofi_int_matcher **tokens = helper_tokenize ( "no ot", FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap noot mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "aap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nooaap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nootap mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "noap miesot"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "noap miesot") , TRUE ); helper_tokenize_free(tokens);
helper_tokenize_free ( tokens );
} }
END_TEST END_TEST
START_TEST ( test_tokenizer_match_glob_single_ci_question ) START_TEST(test_tokenizer_match_glob_single_ci_question) {
{ config.matching_method = MM_GLOB;
config.matching_method = MM_GLOB; rofi_int_matcher **tokens = helper_tokenize("n?ot", FALSE);
rofi_int_matcher **tokens = helper_tokenize ( "n?ot", FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap noot mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "aap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nooaap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nootap mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "noap miesot"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "noap miesot") , FALSE); helper_tokenize_free(tokens);
helper_tokenize_free ( tokens );
} }
END_TEST END_TEST
START_TEST ( test_tokenizer_match_glob_single_ci_star ) START_TEST(test_tokenizer_match_glob_single_ci_star) {
{ config.matching_method = MM_GLOB;
config.matching_method = MM_GLOB; rofi_int_matcher **tokens = helper_tokenize("n*ot", FALSE);
rofi_int_matcher **tokens = helper_tokenize ( "n*ot", FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap noot mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "aap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nooaap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nootap mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "noap miesot"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "noap miesot") , TRUE); helper_tokenize_free(tokens);
helper_tokenize_free ( tokens );
} }
END_TEST END_TEST
START_TEST ( test_tokenizer_match_glob_multiple_ci_star ) START_TEST(test_tokenizer_match_glob_multiple_ci_star) {
{ config.matching_method = MM_GLOB;
config.matching_method = MM_GLOB; rofi_int_matcher **tokens = helper_tokenize("n* ot", FALSE);
rofi_int_matcher **tokens = helper_tokenize ( "n* ot", FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap noot mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "aap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nooaap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nootap mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "noap miesot"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "noap miesot") , TRUE); ck_assert_int_eq(helper_token_match(tokens, "ot nap mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "ot nap mies") , TRUE); helper_tokenize_free(tokens);
helper_tokenize_free ( tokens );
} }
END_TEST END_TEST
START_TEST ( test_tokenizer_match_fuzzy_single_ci ) START_TEST(test_tokenizer_match_fuzzy_single_ci) {
{ config.matching_method = MM_FUZZY;
config.matching_method = MM_FUZZY; rofi_int_matcher **tokens = helper_tokenize("noot", FALSE);
rofi_int_matcher **tokens = helper_tokenize ( "noot", FALSE );
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "aap noot mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nooaap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "nootap mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap Noot mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "aap Noot mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "Nooaap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "Nooaap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "noOTap mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "noOTap mies"), TRUE);
helper_tokenize_free ( tokens ); helper_tokenize_free(tokens);
} }
END_TEST END_TEST
START_TEST ( test_tokenizer_match_fuzzy_single_cs ) START_TEST(test_tokenizer_match_fuzzy_single_cs) {
{ config.matching_method = MM_FUZZY;
config.matching_method = MM_FUZZY; rofi_int_matcher **tokens = helper_tokenize("noot", TRUE);
rofi_int_matcher **tokens = helper_tokenize ( "noot", TRUE );
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "aap noot mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nooaap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "nootap mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap Noot mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap Noot mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "Nooaap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "Nooaap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "noOTap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "noOTap mies"), FALSE);
helper_tokenize_free ( tokens ); helper_tokenize_free(tokens);
} }
END_TEST END_TEST
START_TEST ( test_tokenizer_match_fuzzy_multiple_ci ) START_TEST(test_tokenizer_match_fuzzy_multiple_ci) {
{ config.matching_method = MM_FUZZY;
config.matching_method = MM_FUZZY; rofi_int_matcher **tokens = helper_tokenize("no ot", FALSE);
rofi_int_matcher **tokens = helper_tokenize ( "no ot", FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap noot mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "aap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nooaap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nootap mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "noap miesot"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "noap miesot") , TRUE ); helper_tokenize_free(tokens);
helper_tokenize_free ( tokens );
tokens = helper_tokenize ( "n ot", FALSE ); tokens = helper_tokenize("n ot", FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "aap noot mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nooaap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "nootap mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "noap miesot") , TRUE); ck_assert_int_eq(helper_token_match(tokens, "noap miesot"), TRUE);
helper_tokenize_free ( tokens ); helper_tokenize_free(tokens);
} }
END_TEST END_TEST
START_TEST ( test_tokenizer_match_fuzzy_single_ci_split ) START_TEST(test_tokenizer_match_fuzzy_single_ci_split) {
{ config.matching_method = MM_FUZZY;
config.matching_method = MM_FUZZY; rofi_int_matcher **tokens = helper_tokenize("ont", FALSE);
rofi_int_matcher **tokens = helper_tokenize ( "ont", FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap noot mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , FALSE); ck_assert_int_eq(helper_token_match(tokens, "aap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nooaap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nootap nmiest"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "nootap nmiest") , TRUE ); helper_tokenize_free(tokens);
helper_tokenize_free ( tokens );
} }
END_TEST END_TEST
START_TEST ( test_tokenizer_match_fuzzy_multiple_ci_split ) START_TEST(test_tokenizer_match_fuzzy_multiple_ci_split) {
{ config.matching_method = MM_FUZZY;
config.matching_method = MM_FUZZY; rofi_int_matcher **tokens = helper_tokenize("o n t", FALSE);
rofi_int_matcher **tokens = helper_tokenize ( "o n t", FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap noot mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "aap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nooaap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nootap mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "noap miesot"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "noap miesot") , TRUE); ck_assert_int_eq(helper_token_match(tokens, "ot nap mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "ot nap mies") , TRUE); helper_tokenize_free(tokens);
helper_tokenize_free ( tokens );
} }
END_TEST END_TEST
START_TEST ( test_tokenizer_match_regex_single_ci ) START_TEST(test_tokenizer_match_regex_single_ci) {
{ config.matching_method = MM_REGEX;
config.matching_method = MM_REGEX; rofi_int_matcher **tokens = helper_tokenize("noot", FALSE);
rofi_int_matcher **tokens = helper_tokenize ( "noot", FALSE );
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "aap noot mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nooaap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "nootap mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap Noot mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "aap Noot mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "Nooaap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "Nooaap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "noOTap mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "noOTap mies"), TRUE);
helper_tokenize_free ( tokens ); helper_tokenize_free(tokens);
} }
END_TEST END_TEST
START_TEST ( test_tokenizer_match_regex_single_cs ) START_TEST(test_tokenizer_match_regex_single_cs) {
{ config.matching_method = MM_REGEX;
config.matching_method = MM_REGEX; rofi_int_matcher **tokens = helper_tokenize("noot", TRUE);
rofi_int_matcher **tokens = helper_tokenize ( "noot", TRUE );
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "aap noot mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nooaap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "nootap mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap Noot mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap Noot mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "Nooaap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "Nooaap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "noOTap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "noOTap mies"), FALSE);
helper_tokenize_free ( tokens ); helper_tokenize_free(tokens);
} }
END_TEST END_TEST
START_TEST ( test_tokenizer_match_regex_multiple_ci ) START_TEST(test_tokenizer_match_regex_multiple_ci) {
{ config.matching_method = MM_REGEX;
config.matching_method = MM_REGEX; rofi_int_matcher **tokens = helper_tokenize("no ot", FALSE);
rofi_int_matcher **tokens = helper_tokenize ( "no ot", FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap noot mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "aap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nooaap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nootap mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "noap miesot"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "noap miesot") , TRUE ); helper_tokenize_free(tokens);
helper_tokenize_free ( tokens );
} }
END_TEST END_TEST
START_TEST ( test_tokenizer_match_regex_single_ci_dq ) START_TEST(test_tokenizer_match_regex_single_ci_dq) {
{ config.matching_method = MM_REGEX;
config.matching_method = MM_REGEX; rofi_int_matcher **tokens = helper_tokenize("n.?ot", FALSE);
rofi_int_matcher **tokens = helper_tokenize ( "n.?ot", FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap noot mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "aap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nooaap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nootap mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "noap miesot"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "noap miesot") , FALSE); helper_tokenize_free(tokens);
helper_tokenize_free ( tokens );
} }
END_TEST END_TEST
START_TEST ( test_tokenizer_match_regex_single_two_char ) START_TEST(test_tokenizer_match_regex_single_two_char) {
{ config.matching_method = MM_REGEX;
config.matching_method = MM_REGEX; rofi_int_matcher **tokens = helper_tokenize("n[oa]{2}t", FALSE);
rofi_int_matcher **tokens = helper_tokenize ( "n[oa]{2}t", FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap noot mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "aap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nooaap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nootap mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE ); ck_assert_int_eq(helper_token_match(tokens, "noat miesot"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "noat miesot") , TRUE); ck_assert_int_eq(helper_token_match(tokens, "noaat miesot"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "noaat miesot") , FALSE); helper_tokenize_free(tokens);
helper_tokenize_free ( tokens );
} }
END_TEST END_TEST
START_TEST ( test_tokenizer_match_regex_single_two_word_till_end ) START_TEST(test_tokenizer_match_regex_single_two_word_till_end) {
{ config.matching_method = MM_REGEX;
config.matching_method = MM_REGEX; rofi_int_matcher **tokens = helper_tokenize("^(aap|noap)\\sMie.*", FALSE);
rofi_int_matcher **tokens = helper_tokenize ( "^(aap|noap)\\sMie.*", FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap noot mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "aap mies"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , TRUE); ck_assert_int_eq(helper_token_match(tokens, "nooaap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "nootap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , FALSE ); ck_assert_int_eq(helper_token_match(tokens, "noap miesot"), TRUE);
ck_assert_int_eq ( helper_token_match ( tokens, "noap miesot") , TRUE); ck_assert_int_eq(helper_token_match(tokens, "ot nap mies"), FALSE);
ck_assert_int_eq ( helper_token_match ( tokens, "ot nap mies") , FALSE ); helper_tokenize_free(tokens);
helper_tokenize_free ( tokens );
} }
END_TEST END_TEST
static Suite * helper_tokenizer_suite (void) static Suite *helper_tokenizer_suite(void) {
{ Suite *s;
Suite *s;
s = suite_create("Tokenizer"); s = suite_create("Tokenizer");
/* Core test case */ /* Core test case */
{ {
TCase *tc_core; TCase *tc_core;
tc_core = tcase_create("Core"); tc_core = tcase_create("Core");
tcase_add_test(tc_core, test_tokenizer_free); tcase_add_test(tc_core, test_tokenizer_free);
suite_add_tcase(s, tc_core); suite_add_tcase(s, tc_core);
} }
{ {
TCase *tc_normal = tcase_create ("Normal"); TCase *tc_normal = tcase_create("Normal");
tcase_add_test(tc_normal, test_tokenizer_match_normal_single_ci ); tcase_add_test(tc_normal, test_tokenizer_match_normal_single_ci);
tcase_add_test(tc_normal, test_tokenizer_match_normal_single_cs ); tcase_add_test(tc_normal, test_tokenizer_match_normal_single_cs);
tcase_add_test(tc_normal, test_tokenizer_match_normal_multiple_ci ); tcase_add_test(tc_normal, test_tokenizer_match_normal_multiple_ci);
tcase_add_test(tc_normal, test_tokenizer_match_normal_single_ci_negate ); tcase_add_test(tc_normal, test_tokenizer_match_normal_single_ci_negate);
tcase_add_test(tc_normal, test_tokenizer_match_normal_multiple_ci_negate); tcase_add_test(tc_normal, test_tokenizer_match_normal_multiple_ci_negate);
suite_add_tcase(s, tc_normal); suite_add_tcase(s, tc_normal);
} }
{ {
TCase *tc_glob = tcase_create ("Glob"); TCase *tc_glob = tcase_create("Glob");
tcase_add_test(tc_glob, test_tokenizer_match_glob_single_ci); tcase_add_test(tc_glob, test_tokenizer_match_glob_single_ci);
tcase_add_test(tc_glob, test_tokenizer_match_glob_single_cs); tcase_add_test(tc_glob, test_tokenizer_match_glob_single_cs);
tcase_add_test(tc_glob, test_tokenizer_match_glob_multiple_ci); tcase_add_test(tc_glob, test_tokenizer_match_glob_multiple_ci);
tcase_add_test(tc_glob, test_tokenizer_match_glob_single_ci_question); tcase_add_test(tc_glob, test_tokenizer_match_glob_single_ci_question);
tcase_add_test(tc_glob, test_tokenizer_match_glob_single_ci_star); tcase_add_test(tc_glob, test_tokenizer_match_glob_single_ci_star);
tcase_add_test(tc_glob, test_tokenizer_match_glob_multiple_ci_star); tcase_add_test(tc_glob, test_tokenizer_match_glob_multiple_ci_star);
suite_add_tcase(s, tc_glob); suite_add_tcase(s, tc_glob);
} }
{ {
TCase *tc_fuzzy = tcase_create ("Fuzzy"); TCase *tc_fuzzy = tcase_create("Fuzzy");
tcase_add_test(tc_fuzzy, test_tokenizer_match_fuzzy_single_ci); tcase_add_test(tc_fuzzy, test_tokenizer_match_fuzzy_single_ci);
tcase_add_test(tc_fuzzy, test_tokenizer_match_fuzzy_single_cs); tcase_add_test(tc_fuzzy, test_tokenizer_match_fuzzy_single_cs);
tcase_add_test(tc_fuzzy, test_tokenizer_match_fuzzy_single_ci_split); tcase_add_test(tc_fuzzy, test_tokenizer_match_fuzzy_single_ci_split);
tcase_add_test(tc_fuzzy, test_tokenizer_match_fuzzy_multiple_ci); tcase_add_test(tc_fuzzy, test_tokenizer_match_fuzzy_multiple_ci);
tcase_add_test(tc_fuzzy, test_tokenizer_match_fuzzy_multiple_ci_split); tcase_add_test(tc_fuzzy, test_tokenizer_match_fuzzy_multiple_ci_split);
suite_add_tcase(s, tc_fuzzy); suite_add_tcase(s, tc_fuzzy);
} }
{ {
TCase *tc_regex = tcase_create ("Regex"); TCase *tc_regex = tcase_create("Regex");
tcase_add_test(tc_regex, test_tokenizer_match_regex_single_ci); tcase_add_test(tc_regex, test_tokenizer_match_regex_single_ci);
tcase_add_test(tc_regex, test_tokenizer_match_regex_single_cs); tcase_add_test(tc_regex, test_tokenizer_match_regex_single_cs);
tcase_add_test(tc_regex, test_tokenizer_match_regex_single_ci_dq); tcase_add_test(tc_regex, test_tokenizer_match_regex_single_ci_dq);
tcase_add_test(tc_regex, test_tokenizer_match_regex_single_two_char); tcase_add_test(tc_regex, test_tokenizer_match_regex_single_two_char);
tcase_add_test(tc_regex, test_tokenizer_match_regex_single_two_word_till_end); tcase_add_test(tc_regex,
tcase_add_test(tc_regex, test_tokenizer_match_regex_multiple_ci); test_tokenizer_match_regex_single_two_word_till_end);
suite_add_tcase(s, tc_regex); tcase_add_test(tc_regex, test_tokenizer_match_regex_multiple_ci);
} suite_add_tcase(s, tc_regex);
}
return s;
return s;
} }
int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv ) int main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv) {
{ if (setlocale(LC_ALL, "") == NULL) {
if ( setlocale ( LC_ALL, "" ) == NULL ) { fprintf(stderr, "Failed to set locale.\n");
fprintf ( stderr, "Failed to set locale.\n" ); return EXIT_FAILURE;
return EXIT_FAILURE; }
}
int number_failed = 0; int number_failed = 0;
Suite *s; Suite *s;
SRunner *sr; SRunner *sr;
s = helper_tokenizer_suite(); s = helper_tokenizer_suite();
sr = srunner_create(s); sr = srunner_create(s);
srunner_run_all(sr, CK_NORMAL);
number_failed = srunner_ntests_failed(sr);
srunner_free(sr);
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
srunner_run_all(sr, CK_NORMAL);
number_failed = srunner_ntests_failed(sr);
srunner_free(sr);
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
} }

View File

@ -50,15 +50,23 @@
ThemeWidget *rofi_theme = NULL; ThemeWidget *rofi_theme = NULL;
uint32_t rofi_icon_fetcher_query(const char *name, const int size) { return 0; } uint32_t rofi_icon_fetcher_query(G_GNUC_UNUSED const char *name,
uint32_t rofi_icon_fetcher_query_advanced(const char *name, const int wsize, G_GNUC_UNUSED const int size) {
const int hsize) { 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; return 0;
} }
void rofi_clear_error_messages(void) {} void rofi_clear_error_messages(void) {}
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;
}
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 16.0; } double textbox_get_estimated_char_height(void) { return 16.0; }
double textbox_get_estimated_ch(void) { return 9.0; } double textbox_get_estimated_ch(void) { return 9.0; }

View File

@ -25,134 +25,116 @@
* *
*/ */
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <assert.h>
#include <glib.h>
#include <string.h>
#include <widgets/scrollbar.h>
#include <widgets/textbox.h>
#include <widgets/icon.h>
#include <widgets/listview.h>
#include <widgets/widget.h>
#include <widgets/widget-internal.h>
#include "rofi.h"
#include "xrmoptions.h"
#include "helper.h" #include "helper.h"
#include "rofi-icon-fetcher.h" #include "rofi-icon-fetcher.h"
unsigned int test =0; #include "rofi.h"
#define TASSERT( a ) { \ #include "xrmoptions.h"
assert ( a ); \ #include <assert.h>
printf ( "Test %3u passed (%s)\n", ++test, # a ); \ #include <glib.h>
} #include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <widgets/icon.h>
#include <widgets/listview.h>
#include <widgets/scrollbar.h>
#include <widgets/textbox.h>
#include <widgets/widget-internal.h>
#include <widgets/widget.h>
unsigned int test = 0;
#define TASSERT(a) \
{ \
assert(a); \
printf("Test %3u passed (%s)\n", ++test, #a); \
}
#define TASSERTE( a, b ) { \ #define TASSERTE(a, b) \
if ( ( a ) == ( b ) ) { \ { \
printf ( "Test %u passed (%s == %s) (%u == %u)\n", ++test, # a, # b, a, b ); \ if ((a) == (b)) { \
} else { \ printf("Test %u passed (%s == %s) (%u == %u)\n", ++test, #a, #b, a, b); \
printf ( "Test %u failed (%s == %s) (%u != %u)\n", ++test, # a, # b, a, b ); \ } else { \
abort ( ); \ printf("Test %u failed (%s == %s) (%u != %u)\n", ++test, #a, #b, a, b); \
} \ abort(); \
} } \
}
ThemeWidget *rofi_configuration = NULL; 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; 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; 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; return NULL;
} }
int monitor_active ( G_GNUC_UNUSED workarea *mon ) int monitor_active(G_GNUC_UNUSED workarea *mon) { return 0; }
{
return 0; char *helper_get_theme_path(const char *file, G_GNUC_UNUSED const char *ext) {
return g_strdup(file);
} }
gboolean config_parse_set_property(G_GNUC_UNUSED const Property *p,
char * helper_get_theme_path ( const char *file, const char *ext ) G_GNUC_UNUSED char **error) {
{ return FALSE;
return g_strdup ( file );
} }
gboolean config_parse_set_property ( G_GNUC_UNUSED const Property *p, G_GNUC_UNUSED char **error ) void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {}
{
return FALSE; char *rofi_expand_path(G_GNUC_UNUSED const char *path) { return NULL; }
} double textbox_get_estimated_char_height(void) { return 16; }
void rofi_add_error_message ( G_GNUC_UNUSED GString *msg ) double textbox_get_estimated_ch(void) { return 8.0; }
{}
void listview_set_selected(G_GNUC_UNUSED listview *lv,
char * rofi_expand_path ( G_GNUC_UNUSED const char *path ) G_GNUC_UNUSED unsigned int selected) {}
{ void rofi_view_get_current_monitor(G_GNUC_UNUSED int *width,
return NULL; G_GNUC_UNUSED int *height) {}
}
double textbox_get_estimated_char_height ( void ) int main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv) {
{ scrollbar *sb = scrollbar_create(NULL, "scrollbar");
return 16; widget_resize(WIDGET(sb), 10, 100);
}
double textbox_get_estimated_ch ( void ) scrollbar_set_handle(NULL, 10213);
{ scrollbar_set_max_value(NULL, 10);
return 8.0; scrollbar_set_handle_length(NULL, 1000);
}
scrollbar_set_max_value(sb, 10000);
void listview_set_selected ( G_GNUC_UNUSED listview *lv, G_GNUC_UNUSED unsigned int selected ) TASSERTE(sb->length, 10000u);
{ scrollbar_set_handle_length(sb, 10);
TASSERTE(sb->pos_length, 10u);
} scrollbar_set_handle(sb, 5000);
void rofi_view_get_current_monitor ( G_GNUC_UNUSED int *width, G_GNUC_UNUSED int *height ) TASSERTE(sb->pos, 5000u);
{ scrollbar_set_handle(sb, 15000);
TASSERTE(sb->pos, 10000u);
} scrollbar_set_handle(sb, UINT32_MAX);
TASSERTE(sb->pos, 10000u);
int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv ) scrollbar_set_handle_length(sb, 15000);
{ TASSERTE(sb->pos_length, 10000u);
scrollbar * sb = scrollbar_create ( NULL, "scrollbar" ); scrollbar_set_handle_length(sb, 0);
widget_resize ( WIDGET (sb), 10, 100); TASSERTE(sb->pos_length, 1u);
scrollbar_set_handle ( NULL, 10213); guint cl = scrollbar_scroll_get_line(sb, 10);
scrollbar_set_max_value ( NULL, 10 ); TASSERTE(cl, 1010u);
scrollbar_set_handle_length ( NULL , 1000); cl = scrollbar_scroll_get_line(sb, 20);
TASSERTE(cl, 2020u);
scrollbar_set_max_value ( sb, 10000); cl = scrollbar_scroll_get_line(sb, 0);
TASSERTE ( sb->length, 10000u ); TASSERTE(cl, 0u);
scrollbar_set_handle_length ( sb, 10); cl = scrollbar_scroll_get_line(sb, 99);
TASSERTE ( sb->pos_length, 10u ); TASSERTE(cl, 9999u);
scrollbar_set_handle ( sb , 5000 ); scrollbar_set_handle_length(sb, 1000);
TASSERTE ( sb->pos, 5000u ); cl = scrollbar_scroll_get_line(sb, 10);
scrollbar_set_handle ( sb , 15000 ); TASSERTE(cl, 555u);
TASSERTE ( sb->pos, 10000u ); cl = scrollbar_scroll_get_line(sb, 20);
scrollbar_set_handle ( sb , UINT32_MAX ); TASSERTE(cl, 1666u);
TASSERTE ( sb->pos, 10000u ); cl = scrollbar_scroll_get_line(sb, 0);
scrollbar_set_handle_length ( sb, 15000); TASSERTE(cl, 0u);
TASSERTE ( sb->pos_length, 10000u ); cl = scrollbar_scroll_get_line(sb, 99);
scrollbar_set_handle_length ( sb, 0); TASSERTE(cl, 9999u);
TASSERTE ( sb->pos_length, 1u );
widget_free(WIDGET(sb));
guint cl = scrollbar_scroll_get_line ( sb, 10 );
TASSERTE ( cl, 1010u);
cl = scrollbar_scroll_get_line ( sb, 20 );
TASSERTE ( cl, 2020u);
cl = scrollbar_scroll_get_line ( sb, 0 );
TASSERTE ( cl, 0u);
cl = scrollbar_scroll_get_line ( sb, 99 );
TASSERTE ( cl, 9999u);
scrollbar_set_handle_length ( sb, 1000);
cl = scrollbar_scroll_get_line ( sb, 10 );
TASSERTE ( cl, 555u);
cl = scrollbar_scroll_get_line ( sb, 20 );
TASSERTE ( cl, 1666u);
cl = scrollbar_scroll_get_line ( sb, 0 );
TASSERTE ( cl, 0u);
cl = scrollbar_scroll_get_line ( sb, 99 );
TASSERTE ( cl, 9999u);
widget_free( WIDGET (sb ) );
} }

View File

@ -25,192 +25,184 @@
* *
*/ */
#include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <stdio.h> #include "display.h"
#include "settings.h"
#include "xcb.h"
#include "xrmoptions.h"
#include <assert.h> #include <assert.h>
#include <cairo-xlib.h>
#include <glib.h> #include <glib.h>
#include <history.h> #include <history.h>
#include <string.h>
#include <xcb/xcb.h>
#include <widgets/textbox.h>
#include <rofi.h> #include <rofi.h>
#include <cairo-xlib.h> #include <stdio.h>
#include "display.h" #include <string.h>
#include "xcb.h" #include <widgets/textbox.h>
#include "settings.h" #include <xcb/xcb.h>
#include "xrmoptions.h"
#include "rofi-icon-fetcher.h" #include "rofi-icon-fetcher.h"
static int test = 0; static int test = 0;
unsigned int normal_window_mode = 0; unsigned int normal_window_mode = 0;
#define TASSERT( a ) { \ #define TASSERT(a) \
assert ( a ); \ { \
printf ( "Test %3i passed (%s)\n", ++test, # a ); \ assert(a); \
} printf("Test %3i passed (%s)\n", ++test, #a); \
}
#include "view.h" #include "view.h"
ThemeWidget *rofi_configuration = NULL; 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; 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; 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; return NULL;
} }
gboolean config_parse_set_property ( G_GNUC_UNUSED const Property *p, G_GNUC_UNUSED char **error ) gboolean config_parse_set_property(G_GNUC_UNUSED const Property *p,
{ G_GNUC_UNUSED char **error) {
return FALSE; return FALSE;
} }
void rofi_add_error_message ( G_GNUC_UNUSED GString *msg ) void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {}
{ void rofi_view_queue_redraw() {}
} void rofi_view_get_current_monitor(G_GNUC_UNUSED int *width,
void rofi_view_queue_redraw () G_GNUC_UNUSED int *height) {}
{ int rofi_view_error_dialog(const char *msg, G_GNUC_UNUSED int markup) {
} fputs(msg, stderr);
void rofi_view_get_current_monitor ( G_GNUC_UNUSED int *width, G_GNUC_UNUSED int *height ) return FALSE;
{
}
int rofi_view_error_dialog ( const char *msg, G_GNUC_UNUSED int markup )
{
fputs ( msg, stderr );
return FALSE;
} }
int monitor_active ( G_GNUC_UNUSED workarea *mon ) int monitor_active(G_GNUC_UNUSED workarea *mon) { return 0; }
{
return 0; void display_startup_notification(
} G_GNUC_UNUSED RofiHelperExecuteContext *context,
G_GNUC_UNUSED GSpawnChildSetupFunc *child_setup,
void display_startup_notification ( G_GNUC_UNUSED RofiHelperExecuteContext *context, G_GNUC_UNUSED GSpawnChildSetupFunc *child_setup, G_GNUC_UNUSED gpointer *user_data ) G_GNUC_UNUSED gpointer *user_data) {}
{
} int main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv) {
cairo_surface_t *surf =
int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv ) cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 100, 100);
{ cairo_t *draw = cairo_create(surf);
cairo_surface_t *surf = cairo_image_surface_create ( CAIRO_FORMAT_ARGB32, 100, 100 ); PangoContext *p = pango_cairo_create_context(draw);
cairo_t *draw = cairo_create ( surf );
PangoContext *p = pango_cairo_create_context ( draw ); textbox_setup();
textbox_set_pango_context("default", p);
textbox_setup(); textbox *box = textbox_create(NULL, WIDGET_TYPE_TEXTBOX_TEXT, "textbox",
textbox_set_pango_context ( "default", p ); TB_EDITABLE | TB_AUTOWIDTH | TB_AUTOHEIGHT,
NORMAL, "test", 0, 0);
TASSERT(box != NULL);
textbox *box = textbox_create ( NULL, WIDGET_TYPE_TEXTBOX_TEXT, "textbox", TB_EDITABLE | TB_AUTOWIDTH | TB_AUTOHEIGHT, NORMAL, "test",0,0 );
TASSERT ( box != NULL ); textbox_keybinding(box, MOVE_END);
TASSERT(box->cursor == 4);
textbox_keybinding ( box, MOVE_END ); textbox_cursor(box, -1);
TASSERT ( box->cursor == 4 ); TASSERT(box->cursor == 0);
textbox_cursor ( box, -1 ); textbox_cursor(box, 8);
TASSERT ( box->cursor == 0 ); TASSERT(box->cursor == 4);
textbox_cursor ( box, 8 ); textbox_cursor(box, 2);
TASSERT ( box->cursor == 4 ); TASSERT(box->cursor == 2);
textbox_cursor ( box, 2 ); textbox_insert(box, 3, "bo", 2);
TASSERT ( box->cursor == 2 ); TASSERT(strcmp(box->text, "tesbot") == 0);
textbox_insert ( box, 3, "bo", 2 ); textbox_keybinding(box, MOVE_END);
TASSERT ( strcmp ( box->text, "tesbot" ) == 0 ); TASSERT(box->cursor == 6);
textbox_keybinding ( box, MOVE_END );
TASSERT ( box->cursor == 6 ); TASSERT(widget_get_width(WIDGET(box)) > 0);
TASSERT(textbox_get_height(box) > 0);
TASSERT ( widget_get_width ( WIDGET ( box ) ) > 0 );
TASSERT ( textbox_get_height ( box ) > 0 ); TASSERT(widget_get_width(WIDGET(box)) >= textbox_get_font_width(box));
TASSERT(textbox_get_height(box) >= textbox_get_font_height(box));
TASSERT ( widget_get_width ( WIDGET ( box ) ) >= textbox_get_font_width ( box ) );
TASSERT ( textbox_get_height ( box ) >= textbox_get_font_height ( box ) ); TASSERT(textbox_get_estimated_char_width() > 0);
TASSERT ( textbox_get_estimated_char_width ( ) > 0 ); textbox_keybinding(box, REMOVE_CHAR_BACK);
TASSERT(strcmp(box->text, "tesbo") == 0);
textbox_keybinding ( box, REMOVE_CHAR_BACK ); TASSERT(box->cursor == 5);
TASSERT ( strcmp ( box->text, "tesbo" ) == 0 );
TASSERT ( box->cursor == 5 ); textbox_keybinding(box, MOVE_CHAR_BACK);
TASSERT(box->cursor == 4);
textbox_keybinding ( box, MOVE_CHAR_BACK ); textbox_keybinding(box, REMOVE_CHAR_FORWARD);
TASSERT ( box->cursor == 4 ); TASSERT(strcmp(box->text, "tesb") == 0);
textbox_keybinding ( box, REMOVE_CHAR_FORWARD ); textbox_keybinding(box, MOVE_CHAR_BACK);
TASSERT ( strcmp ( box->text, "tesb" ) == 0 ); TASSERT(box->cursor == 3);
textbox_keybinding ( box, MOVE_CHAR_BACK ); textbox_keybinding(box, MOVE_CHAR_FORWARD);
TASSERT ( box->cursor == 3 ); TASSERT(box->cursor == 4);
textbox_keybinding ( box, MOVE_CHAR_FORWARD ); textbox_keybinding(box, MOVE_CHAR_FORWARD);
TASSERT ( box->cursor == 4 ); TASSERT(box->cursor == 4);
textbox_keybinding ( box, MOVE_CHAR_FORWARD ); // Cursor after delete section.
TASSERT ( box->cursor == 4 ); textbox_delete(box, 0, 1);
// Cursor after delete section. TASSERT(strcmp(box->text, "esb") == 0);
textbox_delete ( box, 0, 1 ); TASSERT(box->cursor == 3);
TASSERT ( strcmp ( box->text, "esb" ) == 0 ); // Cursor before delete.
TASSERT ( box->cursor == 3 ); textbox_text(box, "aap noot mies");
// Cursor before delete. TASSERT(strcmp(box->text, "aap noot mies") == 0);
textbox_text ( box, "aap noot mies" ); textbox_cursor(box, 3);
TASSERT ( strcmp ( box->text, "aap noot mies" ) == 0 ); TASSERT(box->cursor == 3);
textbox_cursor ( box, 3 ); textbox_delete(box, 3, 6);
TASSERT ( box->cursor == 3 ); TASSERT(strcmp(box->text, "aapmies") == 0);
textbox_delete ( box, 3, 6 ); TASSERT(box->cursor == 3);
TASSERT ( strcmp ( box->text, "aapmies" ) == 0 );
TASSERT ( box->cursor == 3 ); // Cursor within delete
textbox_text(box, "aap noot mies");
// Cursor within delete TASSERT(strcmp(box->text, "aap noot mies") == 0);
textbox_text ( box, "aap noot mies" ); textbox_cursor(box, 5);
TASSERT ( strcmp ( box->text, "aap noot mies" ) == 0 ); TASSERT(box->cursor == 5);
textbox_cursor ( box, 5 ); textbox_delete(box, 3, 6);
TASSERT ( box->cursor == 5 ); TASSERT(strcmp(box->text, "aapmies") == 0);
textbox_delete ( box, 3, 6 ); TASSERT(box->cursor == 3);
TASSERT ( strcmp ( box->text, "aapmies" ) == 0 ); // Cursor after delete.
TASSERT ( box->cursor == 3 ); textbox_text(box, "aap noot mies");
// Cursor after delete. TASSERT(strcmp(box->text, "aap noot mies") == 0);
textbox_text ( box, "aap noot mies" ); textbox_cursor(box, 11);
TASSERT ( strcmp ( box->text, "aap noot mies" ) == 0 ); TASSERT(box->cursor == 11);
textbox_cursor ( box, 11 ); textbox_delete(box, 3, 6);
TASSERT ( box->cursor == 11 ); TASSERT(strcmp(box->text, "aapmies") == 0);
textbox_delete ( box, 3, 6 ); TASSERT(box->cursor == 5);
TASSERT ( strcmp ( box->text, "aapmies" ) == 0 );
TASSERT ( box->cursor == 5 ); textbox_text(box, "aap noot mies");
textbox_cursor(box, 8);
textbox_text ( box, "aap noot mies" ); textbox_keybinding(box, REMOVE_WORD_BACK);
textbox_cursor ( box, 8 ); TASSERT(box->cursor == 4);
textbox_keybinding ( box, REMOVE_WORD_BACK ); TASSERT(strcmp(box->text, "aap mies") == 0);
TASSERT ( box->cursor == 4 ); textbox_keybinding(box, REMOVE_TO_EOL);
TASSERT ( strcmp ( box->text, "aap mies" ) == 0 ); TASSERT(box->cursor == 4);
textbox_keybinding ( box, REMOVE_TO_EOL ); TASSERT(strcmp(box->text, "aap ") == 0);
TASSERT ( box->cursor == 4 ); textbox_text(box, "aap noot mies");
TASSERT ( strcmp ( box->text, "aap " ) == 0 ); textbox_cursor(box, 8);
textbox_text ( box, "aap noot mies" ); textbox_keybinding(box, REMOVE_WORD_FORWARD);
textbox_cursor ( box, 8 ); TASSERT(strcmp(box->text, "aap noot") == 0);
textbox_keybinding ( box, REMOVE_WORD_FORWARD ); textbox_keybinding(box, MOVE_FRONT);
TASSERT ( strcmp ( box->text, "aap noot" ) == 0 ); TASSERT(box->cursor == 0);
textbox_keybinding ( box, MOVE_FRONT ); textbox_keybinding(box, CLEAR_LINE);
TASSERT ( box->cursor == 0 ); TASSERT(strcmp(box->text, "") == 0);
textbox_keybinding ( box, CLEAR_LINE ); textbox_text(box, "aap noot mies");
TASSERT ( strcmp ( box->text, "" ) == 0 ); textbox_keybinding(box, MOVE_END);
textbox_text ( box, "aap noot mies" ); textbox_keybinding(box, MOVE_WORD_BACK);
textbox_keybinding ( box, MOVE_END ); TASSERT(box->cursor == 9);
textbox_keybinding ( box, MOVE_WORD_BACK ); textbox_keybinding(box, MOVE_WORD_BACK);
TASSERT ( box->cursor == 9 ); TASSERT(box->cursor == 4);
textbox_keybinding ( box, MOVE_WORD_BACK ); textbox_keybinding(box, REMOVE_TO_SOL);
TASSERT ( box->cursor == 4 ); TASSERT(strcmp(box->text, "noot mies") == 0);
textbox_keybinding ( box, REMOVE_TO_SOL ); TASSERT(box->cursor == 0);
TASSERT ( strcmp ( box->text, "noot mies" ) == 0 );
TASSERT ( box->cursor == 0 ); textbox_font(box, HIGHLIGHT);
// textbox_draw ( box, draw );
textbox_font ( box, HIGHLIGHT );
//textbox_draw ( box, draw ); widget_move(WIDGET(box), 12, 13);
TASSERT(box->widget.x == 12);
widget_move ( WIDGET ( box ), 12, 13 ); TASSERT(box->widget.y == 13);
TASSERT ( box->widget.x == 12 );
TASSERT ( box->widget.y == 13 ); widget_free(WIDGET(box));
textbox_cleanup();
widget_free ( WIDGET ( box ) );
textbox_cleanup ( );
} }

View File

@ -47,14 +47,21 @@
#define REAL_COMPARE_DELTA 0.001 #define REAL_COMPARE_DELTA 0.001
uint32_t rofi_icon_fetcher_query(const char *name, const int size) { return 0; } 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) {} void rofi_clear_error_messages(void) {}
uint32_t rofi_icon_fetcher_query_advanced(const char *name, const int wsize, uint32_t
const int hsize) { rofi_icon_fetcher_query_advanced(G_GNUC_UNUSED const char *name,
G_GNUC_UNUSED G_GNUC_UNUSED const int wsize,
G_GNUC_UNUSED const int hsize) {
return 0; 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;
}
int rofi_view_error_dialog(const char *msg, G_GNUC_UNUSED int markup) { int rofi_view_error_dialog(const char *msg, G_GNUC_UNUSED int markup) {
fputs(msg, stderr); fputs(msg, stderr);

View File

@ -25,200 +25,190 @@
* *
*/ */
#include <unistd.h> #include "display.h"
#include <stdlib.h> #include "rofi-icon-fetcher.h"
#include <stdint.h> #include "rofi.h"
#include <stdio.h> #include "xcb.h"
#include "xrmoptions.h"
#include <assert.h> #include <assert.h>
#include <glib.h> #include <glib.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <widgets/widget.h> #include <unistd.h>
#include <widgets/widget-internal.h> #include <widgets/widget-internal.h>
#include "rofi.h" #include <widgets/widget.h>
#include "display.h" unsigned int test = 0;
#include "xrmoptions.h" #define TASSERT(a) \
#include "xcb.h" { \
#include "rofi-icon-fetcher.h" assert(a); \
unsigned int test =0; printf("Test %3u passed (%s)\n", ++test, #a); \
#define TASSERT( a ) { \ }
assert ( a ); \
printf ( "Test %3u passed (%s)\n", ++test, # a ); \
}
ThemeWidget *rofi_configuration = NULL; 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; 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,
return 0; 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;
return NULL;
} }
gboolean config_parse_set_property ( G_GNUC_UNUSED const Property *p, G_GNUC_UNUSED char **error ) gboolean config_parse_set_property(G_GNUC_UNUSED const Property *p,
{ G_GNUC_UNUSED char **error) {
return FALSE; return FALSE;
} }
void rofi_add_error_message ( G_GNUC_UNUSED GString *msg ) void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {}
{ void rofi_view_queue_redraw(void) {}
} int monitor_active(G_GNUC_UNUSED workarea *mon) { return 0; }
void rofi_view_queue_redraw ( void ) void rofi_view_get_current_monitor(G_GNUC_UNUSED int *width,
{ G_GNUC_UNUSED int *height) {}
int rofi_view_error_dialog(const char *msg, G_GNUC_UNUSED int markup) {
} fputs(msg, stderr);
int monitor_active ( G_GNUC_UNUSED workarea *mon ) return FALSE;
{
return 0;
}
void rofi_view_get_current_monitor ( G_GNUC_UNUSED int *width, G_GNUC_UNUSED int *height )
{
}
int rofi_view_error_dialog ( const char *msg, G_GNUC_UNUSED int markup )
{
fputs ( msg, stderr );
return FALSE;
} }
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 ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
{ int main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv) {
// box 20 by 40 // box 20 by 40
widget *wid= (widget*)g_malloc0(sizeof(widget)); widget *wid = (widget *)g_malloc0(sizeof(widget));
widget_resize ( wid, 20, 40); widget_resize(wid, 20, 40);
widget_move ( wid, 10, 10); widget_move(wid, 10, 10);
// Getter, setter x pos // Getter, setter x pos
// //
TASSERT ( widget_get_x_pos ( wid ) == 10 ); TASSERT(widget_get_x_pos(wid) == 10);
TASSERT ( widget_get_y_pos ( wid ) == 10 ); TASSERT(widget_get_y_pos(wid) == 10);
// Left of box // Left of box
TASSERT ( widget_intersect ( wid, 0, 0) == 0 ); TASSERT(widget_intersect(wid, 0, 0) == 0);
TASSERT ( widget_intersect ( wid, 0, 10) == 0 ); TASSERT(widget_intersect(wid, 0, 10) == 0);
TASSERT ( widget_intersect ( wid, 0, 25) == 0 ); TASSERT(widget_intersect(wid, 0, 25) == 0);
TASSERT ( widget_intersect ( wid, 0, 40) == 0 ); TASSERT(widget_intersect(wid, 0, 40) == 0);
TASSERT ( widget_intersect ( wid, 0, 50) == 0 ); TASSERT(widget_intersect(wid, 0, 50) == 0);
TASSERT ( widget_intersect ( wid, 9, 0) == 0 ); TASSERT(widget_intersect(wid, 9, 0) == 0);
TASSERT ( widget_intersect ( wid, 9, 10) == 0 ); TASSERT(widget_intersect(wid, 9, 10) == 0);
TASSERT ( widget_intersect ( wid, 9, 25) == 0 ); TASSERT(widget_intersect(wid, 9, 25) == 0);
TASSERT ( widget_intersect ( wid, 9, 40) == 0 ); TASSERT(widget_intersect(wid, 9, 40) == 0);
TASSERT ( widget_intersect ( wid, 9, 50) == 0 ); TASSERT(widget_intersect(wid, 9, 50) == 0);
TASSERT ( widget_intersect ( wid, 10, 0) == 0 ); TASSERT(widget_intersect(wid, 10, 0) == 0);
TASSERT ( widget_intersect ( wid, 10, 10) == 1 ); TASSERT(widget_intersect(wid, 10, 10) == 1);
TASSERT ( widget_intersect ( wid, 10, 25) == 1 ); TASSERT(widget_intersect(wid, 10, 25) == 1);
TASSERT ( widget_intersect ( wid, 10, 40) == 1 ); TASSERT(widget_intersect(wid, 10, 40) == 1);
TASSERT ( widget_intersect ( wid, 10, 50) == 0 ); TASSERT(widget_intersect(wid, 10, 50) == 0);
// Middle // Middle
TASSERT ( widget_intersect ( wid, 25, 0) == 0 ); TASSERT(widget_intersect(wid, 25, 0) == 0);
TASSERT ( widget_intersect ( wid, 25, 10) == 1 ); TASSERT(widget_intersect(wid, 25, 10) == 1);
TASSERT ( widget_intersect ( wid, 25, 25) == 1 ); TASSERT(widget_intersect(wid, 25, 25) == 1);
TASSERT ( widget_intersect ( wid, 25, 40) == 1 ); TASSERT(widget_intersect(wid, 25, 40) == 1);
TASSERT ( widget_intersect ( wid, 25, 50) == 0 ); TASSERT(widget_intersect(wid, 25, 50) == 0);
// Right // Right
TASSERT ( widget_intersect ( wid, 29, 0) == 0 ); TASSERT(widget_intersect(wid, 29, 0) == 0);
TASSERT ( widget_intersect ( wid, 29, 10) == 1 ); TASSERT(widget_intersect(wid, 29, 10) == 1);
TASSERT ( widget_intersect ( wid, 29, 25) == 1 ); TASSERT(widget_intersect(wid, 29, 25) == 1);
TASSERT ( widget_intersect ( wid, 29, 40) == 1 ); TASSERT(widget_intersect(wid, 29, 40) == 1);
TASSERT ( widget_intersect ( wid, 29, 50) == 0 ); TASSERT(widget_intersect(wid, 29, 50) == 0);
TASSERT ( widget_intersect ( wid, 30, 0) == 0 ); TASSERT(widget_intersect(wid, 30, 0) == 0);
TASSERT ( widget_intersect ( wid, 30, 10) == 0 ); TASSERT(widget_intersect(wid, 30, 10) == 0);
TASSERT ( widget_intersect ( wid, 30, 25) == 0 ); TASSERT(widget_intersect(wid, 30, 25) == 0);
TASSERT ( widget_intersect ( wid, 30, 40) == 0 ); TASSERT(widget_intersect(wid, 30, 40) == 0);
TASSERT ( widget_intersect ( wid, 30, 50) == 0 ); TASSERT(widget_intersect(wid, 30, 50) == 0);
widget_move ( wid, 30, 30); widget_move(wid, 30, 30);
// Left of box // Left of box
TASSERT ( widget_intersect ( wid, 10, 20) == 0 ); TASSERT(widget_intersect(wid, 10, 20) == 0);
TASSERT ( widget_intersect ( wid, 10, 30) == 0 ); TASSERT(widget_intersect(wid, 10, 30) == 0);
TASSERT ( widget_intersect ( wid, 10, 45) == 0 ); TASSERT(widget_intersect(wid, 10, 45) == 0);
TASSERT ( widget_intersect ( wid, 10, 60) == 0 ); TASSERT(widget_intersect(wid, 10, 60) == 0);
TASSERT ( widget_intersect ( wid, 10, 70) == 0 ); TASSERT(widget_intersect(wid, 10, 70) == 0);
TASSERT ( widget_intersect ( wid, 19, 20) == 0 ); TASSERT(widget_intersect(wid, 19, 20) == 0);
TASSERT ( widget_intersect ( wid, 19, 30) == 0 ); TASSERT(widget_intersect(wid, 19, 30) == 0);
TASSERT ( widget_intersect ( wid, 19, 45) == 0 ); TASSERT(widget_intersect(wid, 19, 45) == 0);
TASSERT ( widget_intersect ( wid, 19, 60) == 0 ); TASSERT(widget_intersect(wid, 19, 60) == 0);
TASSERT ( widget_intersect ( wid, 19, 70) == 0 ); TASSERT(widget_intersect(wid, 19, 70) == 0);
TASSERT ( widget_intersect ( wid, 30, 20) == 0 ); TASSERT(widget_intersect(wid, 30, 20) == 0);
TASSERT ( widget_intersect ( wid, 30, 30) == 1 ); TASSERT(widget_intersect(wid, 30, 30) == 1);
TASSERT ( widget_intersect ( wid, 30, 45) == 1 ); TASSERT(widget_intersect(wid, 30, 45) == 1);
TASSERT ( widget_intersect ( wid, 30, 60) == 1 ); TASSERT(widget_intersect(wid, 30, 60) == 1);
TASSERT ( widget_intersect ( wid, 30, 70) == 0 ); TASSERT(widget_intersect(wid, 30, 70) == 0);
// Middle // Middle
TASSERT ( widget_intersect ( wid, 20+25,20+ 0) == 0 ); TASSERT(widget_intersect(wid, 20 + 25, 20 + 0) == 0);
TASSERT ( widget_intersect ( wid, 20+25,20+ 10) == 1 ); TASSERT(widget_intersect(wid, 20 + 25, 20 + 10) == 1);
TASSERT ( widget_intersect ( wid, 20+25,20+ 25) == 1 ); TASSERT(widget_intersect(wid, 20 + 25, 20 + 25) == 1);
TASSERT ( widget_intersect ( wid, 20+25,20+ 40) == 1 ); TASSERT(widget_intersect(wid, 20 + 25, 20 + 40) == 1);
TASSERT ( widget_intersect ( wid, 20+25,20+ 50) == 0 ); TASSERT(widget_intersect(wid, 20 + 25, 20 + 50) == 0);
TASSERT ( widget_intersect ( wid, 20+29, 20+0) == 0 ); TASSERT(widget_intersect(wid, 20 + 29, 20 + 0) == 0);
TASSERT ( widget_intersect ( wid, 20+29, 20+10) == 1 ); TASSERT(widget_intersect(wid, 20 + 29, 20 + 10) == 1);
TASSERT ( widget_intersect ( wid, 20+29, 20+25) == 1 ); TASSERT(widget_intersect(wid, 20 + 29, 20 + 25) == 1);
TASSERT ( widget_intersect ( wid, 20+29, 20+40) == 1 ); TASSERT(widget_intersect(wid, 20 + 29, 20 + 40) == 1);
TASSERT ( widget_intersect ( wid, 20+29, 20+50) == 0 ); TASSERT(widget_intersect(wid, 20 + 29, 20 + 50) == 0);
TASSERT ( widget_intersect ( wid, 20+30, 20+0) == 0 ); TASSERT(widget_intersect(wid, 20 + 30, 20 + 0) == 0);
TASSERT ( widget_intersect ( wid, 20+30, 20+10) == 0 ); TASSERT(widget_intersect(wid, 20 + 30, 20 + 10) == 0);
TASSERT ( widget_intersect ( wid, 20+30, 20+25) == 0 ); TASSERT(widget_intersect(wid, 20 + 30, 20 + 25) == 0);
TASSERT ( widget_intersect ( wid, 20+30, 20+40) == 0 ); TASSERT(widget_intersect(wid, 20 + 30, 20 + 40) == 0);
TASSERT ( widget_intersect ( wid, 20+30, 20+50) == 0 ); TASSERT(widget_intersect(wid, 20 + 30, 20 + 50) == 0);
// Right // Right
TASSERT ( widget_intersect ( wid, 20+29, 20+0) == 0 ); TASSERT(widget_intersect(wid, 20 + 29, 20 + 0) == 0);
TASSERT ( widget_intersect ( wid, 20+29, 20+10) == 1 ); TASSERT(widget_intersect(wid, 20 + 29, 20 + 10) == 1);
TASSERT ( widget_intersect ( wid, 20+29, 20+25) == 1 ); TASSERT(widget_intersect(wid, 20 + 29, 20 + 25) == 1);
TASSERT ( widget_intersect ( wid, 20+29, 20+40) == 1 ); TASSERT(widget_intersect(wid, 20 + 29, 20 + 40) == 1);
TASSERT ( widget_intersect ( wid, 20+29, 20+50) == 0 ); TASSERT(widget_intersect(wid, 20 + 29, 20 + 50) == 0);
TASSERT ( widget_intersect ( wid, 20+30, 20+0) == 0 ); TASSERT(widget_intersect(wid, 20 + 30, 20 + 0) == 0);
TASSERT ( widget_intersect ( wid, 20+30, 20+10) == 0 ); TASSERT(widget_intersect(wid, 20 + 30, 20 + 10) == 0);
TASSERT ( widget_intersect ( wid, 20+30, 20+25) == 0 ); TASSERT(widget_intersect(wid, 20 + 30, 20 + 25) == 0);
TASSERT ( widget_intersect ( wid, 20+30, 20+40) == 0 ); TASSERT(widget_intersect(wid, 20 + 30, 20 + 40) == 0);
TASSERT ( widget_intersect ( wid, 20+30, 20+50) == 0 ); TASSERT(widget_intersect(wid, 20 + 30, 20 + 50) == 0);
TASSERT ( widget_intersect ( wid, -100, -100) == 0); TASSERT(widget_intersect(wid, -100, -100) == 0);
TASSERT ( widget_intersect ( wid, INT_MIN, INT_MIN) == 0); TASSERT(widget_intersect(wid, INT_MIN, INT_MIN) == 0);
TASSERT ( widget_intersect ( wid, INT_MAX, INT_MAX) == 0); TASSERT(widget_intersect(wid, INT_MAX, INT_MAX) == 0);
// Other wrappers. // Other wrappers.
TASSERT ( widget_get_height ( wid ) == wid->h); TASSERT(widget_get_height(wid) == wid->h);
TASSERT ( widget_get_width ( wid ) == wid->w); TASSERT(widget_get_width(wid) == wid->w);
TASSERT ( widget_enabled ( wid ) == FALSE ); TASSERT(widget_enabled(wid) == FALSE);
widget_enable ( wid ); widget_enable(wid);
TASSERT ( widget_enabled ( wid ) == TRUE ); TASSERT(widget_enabled(wid) == TRUE);
widget_disable ( wid ); widget_disable(wid);
TASSERT ( widget_enabled ( wid ) == FALSE ); TASSERT(widget_enabled(wid) == FALSE);
// Null pointer tests. // Null pointer tests.
TASSERT ( widget_intersect ( NULL, 0, 0) == 0 ); TASSERT(widget_intersect(NULL, 0, 0) == 0);
widget_move ( NULL, 0, 0 ); widget_move(NULL, 0, 0);
TASSERT ( widget_get_height ( NULL ) == 0); TASSERT(widget_get_height(NULL) == 0);
TASSERT ( widget_get_width ( NULL ) == 0); TASSERT(widget_get_width(NULL) == 0);
TASSERT ( widget_enabled ( NULL ) == 0); TASSERT(widget_enabled(NULL) == 0);
widget_disable ( NULL ); widget_disable(NULL);
widget_enable ( NULL ); widget_enable(NULL);
widget_draw ( NULL, NULL ); widget_draw(NULL, NULL);
widget_free ( NULL ); widget_free(NULL);
widget_resize ( NULL, 0, 0); widget_resize(NULL, 0, 0);
widget_update ( NULL ); widget_update(NULL);
widget_queue_redraw ( NULL ); widget_queue_redraw(NULL);
TASSERT (widget_need_redraw ( NULL ) == FALSE); TASSERT(widget_need_redraw(NULL) == FALSE);
widget_trigger_action ( NULL, 0, 0, 0 ); widget_trigger_action(NULL, 0, 0, 0);
widget_set_trigger_action_handler ( NULL, NULL, NULL ); widget_set_trigger_action_handler(NULL, NULL, NULL);
g_free(wid); g_free(wid);
} }