mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-13 14:00:09 +00:00
a11y: Add tests for GtkStack and GtkStackSwitcher
Test that the roles, states and relations are as expected.
This commit is contained in:
parent
b10d5ec8ff
commit
7c47b6907b
@ -25,6 +25,7 @@ tests = [
|
||||
{ 'name': 'searchentry' },
|
||||
{ 'name': 'separator' },
|
||||
{ 'name': 'spinbutton' },
|
||||
{ 'name': 'stack' },
|
||||
{ 'name': 'switch' },
|
||||
{ 'name': 'textview' },
|
||||
{ 'name': 'window' },
|
||||
|
111
testsuite/a11y/stack.c
Normal file
111
testsuite/a11y/stack.c
Normal file
@ -0,0 +1,111 @@
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
static void
|
||||
stack_role (void)
|
||||
{
|
||||
GtkWidget *stack = gtk_stack_new ();
|
||||
GtkWidget *child1 = gtk_label_new ("a");
|
||||
GtkWidget *child2 = gtk_label_new ("b");
|
||||
GtkWidget *switcher = gtk_stack_switcher_new ();
|
||||
GtkWidget *child;
|
||||
GtkStackPage *page;
|
||||
|
||||
g_object_ref_sink (stack);
|
||||
g_object_ref_sink (switcher);
|
||||
|
||||
gtk_stack_add_named (GTK_STACK (stack), child1, "a");
|
||||
gtk_stack_add_named (GTK_STACK (stack), child2, "b");
|
||||
|
||||
gtk_stack_switcher_set_stack (GTK_STACK_SWITCHER (switcher), GTK_STACK (stack));
|
||||
|
||||
gtk_test_accessible_assert_role (GTK_ACCESSIBLE (stack), GTK_ACCESSIBLE_ROLE_WIDGET);
|
||||
gtk_test_accessible_assert_role (GTK_ACCESSIBLE (switcher), GTK_ACCESSIBLE_ROLE_TAB_LIST);
|
||||
|
||||
child = gtk_widget_get_first_child (switcher);
|
||||
page = gtk_stack_get_page (GTK_STACK (stack), child1);
|
||||
gtk_test_accessible_assert_role (GTK_ACCESSIBLE (child), GTK_ACCESSIBLE_ROLE_TAB);
|
||||
gtk_test_accessible_assert_role (GTK_ACCESSIBLE (page), GTK_ACCESSIBLE_ROLE_TAB_PANEL);
|
||||
|
||||
child = gtk_widget_get_last_child (switcher);
|
||||
page = gtk_stack_get_page (GTK_STACK (stack), child2);
|
||||
gtk_test_accessible_assert_role (GTK_ACCESSIBLE (child), GTK_ACCESSIBLE_ROLE_TAB);
|
||||
gtk_test_accessible_assert_role (GTK_ACCESSIBLE (page), GTK_ACCESSIBLE_ROLE_TAB_PANEL);
|
||||
|
||||
g_object_unref (stack);
|
||||
g_object_unref (switcher);
|
||||
}
|
||||
|
||||
static void
|
||||
stack_state (void)
|
||||
{
|
||||
GtkWidget *stack = gtk_stack_new ();
|
||||
GtkWidget *child1 = gtk_label_new ("a");
|
||||
GtkWidget *child2 = gtk_label_new ("b");
|
||||
GtkWidget *switcher = gtk_stack_switcher_new ();
|
||||
GtkWidget *child;
|
||||
|
||||
g_object_ref_sink (stack);
|
||||
g_object_ref_sink (switcher);
|
||||
|
||||
gtk_stack_add_named (GTK_STACK (stack), child1, "a");
|
||||
gtk_stack_add_named (GTK_STACK (stack), child2, "b");
|
||||
|
||||
gtk_stack_switcher_set_stack (GTK_STACK_SWITCHER (switcher), GTK_STACK (stack));
|
||||
|
||||
child = gtk_widget_get_first_child (switcher);
|
||||
gtk_test_accessible_assert_state (GTK_ACCESSIBLE (child), GTK_ACCESSIBLE_STATE_SELECTED, TRUE);
|
||||
|
||||
child = gtk_widget_get_last_child (switcher);
|
||||
gtk_test_accessible_assert_state (GTK_ACCESSIBLE (child), GTK_ACCESSIBLE_STATE_SELECTED, FALSE);
|
||||
|
||||
g_object_unref (stack);
|
||||
g_object_unref (switcher);
|
||||
}
|
||||
|
||||
static void
|
||||
stack_relations (void)
|
||||
{
|
||||
GtkWidget *stack = gtk_stack_new ();
|
||||
GtkWidget *child1 = gtk_label_new ("a");
|
||||
GtkWidget *child2 = gtk_label_new ("b");
|
||||
GtkWidget *switcher = gtk_stack_switcher_new ();
|
||||
GtkWidget *child;
|
||||
GtkStackPage *page;
|
||||
GList *list;
|
||||
|
||||
g_object_ref_sink (stack);
|
||||
g_object_ref_sink (switcher);
|
||||
|
||||
gtk_stack_add_named (GTK_STACK (stack), child1, "a");
|
||||
gtk_stack_add_named (GTK_STACK (stack), child2, "b");
|
||||
|
||||
gtk_stack_switcher_set_stack (GTK_STACK_SWITCHER (switcher), GTK_STACK (stack));
|
||||
|
||||
child = gtk_widget_get_first_child (switcher);
|
||||
page = gtk_stack_get_page (GTK_STACK (stack), child1);
|
||||
list = g_list_append (NULL, page);
|
||||
gtk_test_accessible_assert_relation (GTK_ACCESSIBLE (child), GTK_ACCESSIBLE_RELATION_CONTROLS, list);
|
||||
g_list_free (list);
|
||||
|
||||
child = gtk_widget_get_last_child (switcher);
|
||||
page = gtk_stack_get_page (GTK_STACK (stack), child2);
|
||||
list = g_list_append (NULL, page);
|
||||
gtk_test_accessible_assert_relation (GTK_ACCESSIBLE (child), GTK_ACCESSIBLE_RELATION_CONTROLS, list);
|
||||
g_list_free (list);
|
||||
|
||||
g_object_unref (stack);
|
||||
g_object_unref (switcher);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
gtk_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/a11y/stack/role", stack_role);
|
||||
g_test_add_func ("/a11y/stack/state", stack_state);
|
||||
g_test_add_func ("/a11y/stack/relations", stack_relations);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user