From c68dc38c362dcbb69728b92856fd0e48f1fe8500 Mon Sep 17 00:00:00 2001 From: Quentin Glidic Date: Tue, 30 May 2017 13:31:35 +0200 Subject: box.test: Test find_mouse_target Signed-off-by: Quentin Glidic --- test/box-test.c | 55 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/test/box-test.c b/test/box-test.c index 572e7077..e76459f9 100644 --- a/test/box-test.c +++ b/test/box-test.c @@ -53,6 +53,15 @@ unsigned int test =0; } \ } +#define TASSERTW( a, b ) { \ + if ( ( a ) == ( b ) ) { \ + printf ( "Test %i passed (%s == %s) (%p == %p)\n", ++test, # a, # b, (void *)a, (void *)b ); \ + }else { \ + printf ( "Test %i failed (%s == %s) (%p != %p)\n", ++test, # a, # b, (void *)a, (void *)b ); \ + abort ( ); \ + } \ +} + void config_parse_set_property ( G_GNUC_UNUSED const Property *p ) { } @@ -79,11 +88,6 @@ void rofi_view_get_current_monitor ( G_GNUC_UNUSED int *width, G_GNUC_UNUSED int } -static gboolean test_widget_clicked ( G_GNUC_UNUSED widget *wid, G_GNUC_UNUSED xcb_button_press_event_t* xce, G_GNUC_UNUSED void *data ) -{ - return TRUE; -} - int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv ) { { @@ -212,35 +216,38 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv ) } { box *b = box_create ( "box", BOX_VERTICAL ); - widget_resize ( WIDGET (b), 20, 100); + widget_resize ( WIDGET (b), 20, 90); //box_set_padding ( b, 5 ); widget *wid1 = g_malloc0(sizeof(widget)); + wid1->type = 1; widget_enable(wid1); - //FIXME: see below - //wid1->clicked = test_widget_clicked; box_add ( b , WIDGET( wid1 ), TRUE, 0 ); widget *wid2 = g_malloc0(sizeof(widget)); + wid2->type = 1; widget_enable(wid2); box_add ( b , WIDGET( wid2 ), TRUE, 1 ); - - /*FIXME: fix code for binding rework??? - * maybe test the find_mouse_target instead - xcb_button_press_event_t xce; - xce.event_x = 10; - xce.event_y = 60; - TASSERTE ( widget_clicked ( WIDGET(b), &xce ), 0); - - xce.event_y = 50; - TASSERTE ( widget_clicked ( WIDGET(b), &xce ), 0); - xce.event_y = 48; - TASSERTE ( widget_clicked ( WIDGET(b), &xce ), 1); + widget *wid3 = g_malloc0(sizeof(widget)); + wid3->type = 2; + widget_enable(wid3); + box_add ( b , WIDGET( wid3 ), TRUE, 2 ); + + 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 ); - xce.event_y = 60; - TASSERTE ( widget_clicked ( WIDGET(b), &xce ), 1); + y = 40; + TASSERTW ( widget_find_mouse_target ( WIDGET(b), 1, x, y ), WIDGET(wid1) ); widget_disable ( wid1 ); widget_enable ( wid2 ); - TASSERTE ( widget_clicked ( WIDGET(b), &xce ), 0); + 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 ) ); - */ } } -- cgit v1.2.3