inscription: Add tests for gtk_accessible_text_get_offset
Test that we get the expected values on an inscription.
This commit is contained in:
@@ -52,12 +52,65 @@ inscription_text_interface (void)
|
||||
g_object_unref (inscription);
|
||||
}
|
||||
|
||||
/* Some of the text interface functions require an allocated widget */
|
||||
static void
|
||||
more_inscription_text_interface (void)
|
||||
{
|
||||
GtkWidget *window, *inscription;
|
||||
int width, height;
|
||||
gboolean res;
|
||||
unsigned int offset;
|
||||
|
||||
window = gtk_window_new ();
|
||||
inscription = gtk_inscription_new ("AAA");
|
||||
gtk_widget_set_halign (inscription, GTK_ALIGN_CENTER);
|
||||
gtk_widget_set_valign (inscription, GTK_ALIGN_CENTER);
|
||||
gtk_window_set_child (GTK_WINDOW (window), inscription);
|
||||
|
||||
gtk_window_present (GTK_WINDOW (window));
|
||||
|
||||
while (gtk_widget_get_width (inscription) == 0)
|
||||
g_main_context_iteration (NULL, TRUE);
|
||||
|
||||
width = gtk_widget_get_width (inscription);
|
||||
height = gtk_widget_get_height (inscription);
|
||||
g_assert_true (width > 0);
|
||||
g_assert_true (height > 0);
|
||||
|
||||
res = gtk_accessible_text_get_offset (GTK_ACCESSIBLE_TEXT (inscription),
|
||||
&GRAPHENE_POINT_INIT (width / 12, height / 2),
|
||||
&offset);
|
||||
g_assert_true (res);
|
||||
g_assert_cmpuint (offset, ==, 0);
|
||||
|
||||
res = gtk_accessible_text_get_offset (GTK_ACCESSIBLE_TEXT (inscription),
|
||||
&GRAPHENE_POINT_INIT (width / 2, height / 2),
|
||||
&offset);
|
||||
g_assert_true (res);
|
||||
g_assert_cmpuint (offset, ==, 1);
|
||||
|
||||
res = gtk_accessible_text_get_offset (GTK_ACCESSIBLE_TEXT (inscription),
|
||||
&GRAPHENE_POINT_INIT (width - width / 4, height / 2),
|
||||
&offset);
|
||||
g_assert_true (res);
|
||||
g_assert_cmpuint (offset, ==, 2);
|
||||
|
||||
res = gtk_accessible_text_get_offset (GTK_ACCESSIBLE_TEXT (inscription),
|
||||
&GRAPHENE_POINT_INIT (width, height / 2),
|
||||
&offset);
|
||||
g_assert_true (res);
|
||||
g_assert_cmpuint (offset, ==, 3);
|
||||
|
||||
gtk_window_destroy (GTK_WINDOW (window));
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
gtk_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/a11y/inscription/text-interface", inscription_text_interface);
|
||||
g_test_add_func ("/a11y/inscription/more-text-interface", more_inscription_text_interface);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user