2020-07-08 15:51:57 +00:00
|
|
|
/* gtktestatcontext.c: Test AT context
|
|
|
|
*
|
|
|
|
* Copyright 2020 GNOME Foundation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtktestatcontextprivate.h"
|
|
|
|
|
|
|
|
#include "gtkatcontextprivate.h"
|
2020-10-12 17:05:43 +00:00
|
|
|
#include "gtkaccessibleprivate.h"
|
2020-07-17 14:36:43 +00:00
|
|
|
#include "gtkdebug.h"
|
2020-07-08 15:51:57 +00:00
|
|
|
#include "gtkenums.h"
|
2020-07-17 14:36:43 +00:00
|
|
|
#include "gtkprivate.h"
|
2020-07-17 13:39:56 +00:00
|
|
|
#include "gtktypebuiltins.h"
|
2020-07-08 15:51:57 +00:00
|
|
|
|
|
|
|
struct _GtkTestATContext
|
|
|
|
{
|
|
|
|
GtkATContext parent_instance;
|
|
|
|
};
|
|
|
|
|
2020-07-17 13:39:56 +00:00
|
|
|
struct _GtkTestATContextClass
|
|
|
|
{
|
|
|
|
GtkATContextClass parent_class;
|
|
|
|
};
|
|
|
|
|
2020-07-08 15:51:57 +00:00
|
|
|
G_DEFINE_TYPE (GtkTestATContext, gtk_test_at_context, GTK_TYPE_AT_CONTEXT)
|
|
|
|
|
|
|
|
static void
|
2020-07-13 14:51:39 +00:00
|
|
|
gtk_test_at_context_state_change (GtkATContext *self,
|
|
|
|
GtkAccessibleStateChange changed_states,
|
|
|
|
GtkAccessiblePropertyChange changed_properties,
|
2020-07-17 11:00:31 +00:00
|
|
|
GtkAccessibleRelationChange changed_relations,
|
2020-07-17 11:49:59 +00:00
|
|
|
GtkAccessibleAttributeSet *states,
|
|
|
|
GtkAccessibleAttributeSet *properties,
|
|
|
|
GtkAccessibleAttributeSet *relations)
|
2020-07-08 15:51:57 +00:00
|
|
|
{
|
2020-08-04 15:02:00 +00:00
|
|
|
if (GTK_DEBUG_CHECK (A11Y))
|
2020-07-17 16:42:24 +00:00
|
|
|
{
|
2020-08-04 15:02:00 +00:00
|
|
|
char *states_str = gtk_accessible_attribute_set_to_string (states);
|
|
|
|
char *properties_str = gtk_accessible_attribute_set_to_string (properties);
|
|
|
|
char *relations_str = gtk_accessible_attribute_set_to_string (relations);
|
2020-07-22 12:48:00 +00:00
|
|
|
GtkAccessibleRole role = gtk_at_context_get_accessible_role (self);
|
|
|
|
GtkAccessible *accessible = gtk_at_context_get_accessible (self);
|
|
|
|
GEnumClass *class = g_type_class_ref (GTK_TYPE_ACCESSIBLE_ROLE);
|
|
|
|
GEnumValue *value = g_enum_get_value (class, role);
|
2020-08-04 15:02:00 +00:00
|
|
|
|
2020-07-22 12:48:00 +00:00
|
|
|
g_print ("*** Accessible state changed for accessible “%s”, with role “%s” (%d):\n"
|
|
|
|
"*** states = %s\n"
|
|
|
|
"*** properties = %s\n"
|
|
|
|
"*** relations = %s\n",
|
|
|
|
G_OBJECT_TYPE_NAME (accessible),
|
|
|
|
value->value_nick,
|
|
|
|
role,
|
|
|
|
states_str,
|
|
|
|
properties_str,
|
|
|
|
relations_str);
|
|
|
|
g_type_class_unref (class);
|
2020-07-08 15:51:57 +00:00
|
|
|
|
2020-08-04 15:02:00 +00:00
|
|
|
g_free (states_str);
|
|
|
|
g_free (properties_str);
|
|
|
|
g_free (relations_str);
|
|
|
|
}
|
2020-07-08 15:51:57 +00:00
|
|
|
}
|
|
|
|
|
2021-04-17 02:18:52 +00:00
|
|
|
static void
|
|
|
|
gtk_test_at_context_platform_change (GtkATContext *self,
|
|
|
|
GtkAccessiblePlatformChange changed_platform)
|
|
|
|
{
|
|
|
|
if (GTK_DEBUG_CHECK (A11Y))
|
|
|
|
{
|
|
|
|
GtkAccessible *accessible;
|
|
|
|
|
|
|
|
accessible = gtk_at_context_get_accessible (self);
|
|
|
|
|
|
|
|
g_print ("*** Accessible platform state changed for accessible “%s”:\n",
|
|
|
|
G_OBJECT_TYPE_NAME (accessible));
|
|
|
|
if (changed_platform & GTK_ACCESSIBLE_PLATFORM_CHANGE_FOCUSABLE)
|
|
|
|
g_print ("*** focusable = %d\n",
|
|
|
|
gtk_accessible_get_platform_state (accessible, GTK_ACCESSIBLE_PLATFORM_STATE_FOCUSABLE));
|
|
|
|
if (changed_platform & GTK_ACCESSIBLE_PLATFORM_CHANGE_FOCUSED)
|
|
|
|
g_print ("*** focused = %d\n",
|
|
|
|
gtk_accessible_get_platform_state (accessible, GTK_ACCESSIBLE_PLATFORM_STATE_FOCUSED));
|
2021-04-17 19:23:04 +00:00
|
|
|
if (changed_platform & GTK_ACCESSIBLE_PLATFORM_CHANGE_ACTIVE)
|
|
|
|
g_print ("*** active = %d\n",
|
|
|
|
gtk_accessible_get_platform_state (accessible, GTK_ACCESSIBLE_PLATFORM_STATE_ACTIVE));
|
2021-04-17 02:18:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-08 15:51:57 +00:00
|
|
|
static void
|
|
|
|
gtk_test_at_context_class_init (GtkTestATContextClass *klass)
|
|
|
|
{
|
|
|
|
GtkATContextClass *context_class = GTK_AT_CONTEXT_CLASS (klass);
|
|
|
|
|
|
|
|
context_class->state_change = gtk_test_at_context_state_change;
|
2021-04-17 02:18:52 +00:00
|
|
|
context_class->platform_change = gtk_test_at_context_platform_change;
|
2020-07-08 15:51:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_test_at_context_init (GtkTestATContext *self)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-07-17 13:39:56 +00:00
|
|
|
/*< private >
|
|
|
|
* gtk_test_at_context_new:
|
2021-05-20 13:17:04 +00:00
|
|
|
* @accessible_role: the `GtkAccessibleRole` for the AT context
|
|
|
|
* @accessible: the `GtkAccessible` instance which owns the AT context
|
|
|
|
* @display: a `GdkDisplay`
|
2020-07-17 13:39:56 +00:00
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
* Creates a new `GtkTestATContext` instance for @accessible, using the
|
2020-07-17 13:39:56 +00:00
|
|
|
* given @accessible_role.
|
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
* Returns: (transfer full): the newly created `GtkTestATContext` instance
|
2020-07-17 13:39:56 +00:00
|
|
|
*/
|
2020-07-08 15:51:57 +00:00
|
|
|
GtkATContext *
|
|
|
|
gtk_test_at_context_new (GtkAccessibleRole accessible_role,
|
2020-11-07 12:50:11 +00:00
|
|
|
GtkAccessible *accessible,
|
|
|
|
GdkDisplay *display)
|
2020-07-08 15:51:57 +00:00
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_TEST_AT_CONTEXT,
|
|
|
|
"accessible-role", accessible_role,
|
|
|
|
"accessible", accessible,
|
2020-11-07 12:50:11 +00:00
|
|
|
"display", display,
|
2020-07-08 15:51:57 +00:00
|
|
|
NULL);
|
|
|
|
}
|
2020-07-17 13:39:56 +00:00
|
|
|
|
2020-12-16 15:47:29 +00:00
|
|
|
/**
|
|
|
|
* gtk_test_accessible_has_role:
|
2021-05-20 13:17:04 +00:00
|
|
|
* @accessible: a `GtkAccessible`
|
|
|
|
* @role: a `GtkAccessibleRole`
|
2020-12-16 15:47:29 +00:00
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
* Checks whether the `GtkAccessible:accessible-role` of the accessible
|
2020-12-16 15:47:29 +00:00
|
|
|
* is @role.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the role matches
|
|
|
|
*/
|
2020-07-17 13:39:56 +00:00
|
|
|
gboolean
|
|
|
|
gtk_test_accessible_has_role (GtkAccessible *accessible,
|
|
|
|
GtkAccessibleRole role)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_ACCESSIBLE (accessible), FALSE);
|
|
|
|
|
2020-11-11 19:37:26 +00:00
|
|
|
return gtk_accessible_get_accessible_role (accessible) == role;
|
2020-07-17 13:39:56 +00:00
|
|
|
}
|
|
|
|
|
2020-12-16 15:47:29 +00:00
|
|
|
/**
|
|
|
|
* gtk_test_accessible_has_property:
|
2021-05-20 13:17:04 +00:00
|
|
|
* @accessible: a `GtkAccessible`
|
|
|
|
* @property: a `GtkAccessibleProperty`
|
2020-12-16 15:47:29 +00:00
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
* Checks whether the `GtkAccessible` has @property set.
|
2020-12-16 15:47:29 +00:00
|
|
|
*
|
|
|
|
* Returns: %TRUE if the @property is set in the @accessible
|
|
|
|
*/
|
2020-07-17 13:39:56 +00:00
|
|
|
gboolean
|
|
|
|
gtk_test_accessible_has_property (GtkAccessible *accessible,
|
|
|
|
GtkAccessibleProperty property)
|
|
|
|
{
|
|
|
|
GtkATContext *context;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_ACCESSIBLE (accessible), FALSE);
|
|
|
|
|
|
|
|
context = gtk_accessible_get_at_context (accessible);
|
|
|
|
if (context == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return gtk_at_context_has_accessible_property (context, property);
|
|
|
|
}
|
|
|
|
|
2020-07-26 19:29:00 +00:00
|
|
|
/**
|
|
|
|
* gtk_test_accessible_check_property:
|
2021-05-20 13:17:04 +00:00
|
|
|
* @accessible: a `GtkAccessible`
|
|
|
|
* @property: a `GtkAccessibleProperty`
|
2020-07-26 19:29:00 +00:00
|
|
|
* @...: the expected value of @property
|
|
|
|
*
|
|
|
|
* Checks whether the accessible @property of @accessible is set to
|
|
|
|
* a specific value.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the value of the accessible property
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
gtk_test_accessible_check_property (GtkAccessible *accessible,
|
|
|
|
GtkAccessibleProperty property,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
char *res = NULL;
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start (args, property);
|
|
|
|
|
a11y: Add proper error reporting to value collection
We're currently overloading NULL to mean both "this value is undefined,
and should be reset to its default" and "the value collection failed".
Let's do error reporting right, by using GError to mean "the collection
failed, for this specific reason"; then, we can use a NULL return value
to signal that the accessible attribute should be reset to its default
value.
This is only relevant for pointer-sized attribute values: strings,
references, and reference lists; numeric, boolean, tristate, and token
values either cannot be undefined, or have a specific "undefined" value.
2020-07-28 15:41:44 +00:00
|
|
|
GError *error = NULL;
|
2020-07-26 19:29:00 +00:00
|
|
|
GtkAccessibleValue *check_value =
|
a11y: Add proper error reporting to value collection
We're currently overloading NULL to mean both "this value is undefined,
and should be reset to its default" and "the value collection failed".
Let's do error reporting right, by using GError to mean "the collection
failed, for this specific reason"; then, we can use a NULL return value
to signal that the accessible attribute should be reset to its default
value.
This is only relevant for pointer-sized attribute values: strings,
references, and reference lists; numeric, boolean, tristate, and token
values either cannot be undefined, or have a specific "undefined" value.
2020-07-28 15:41:44 +00:00
|
|
|
gtk_accessible_value_collect_for_property (property, &error, &args);
|
2020-07-26 19:29:00 +00:00
|
|
|
|
|
|
|
va_end (args);
|
|
|
|
|
2020-11-10 14:14:47 +00:00
|
|
|
if (error != NULL)
|
|
|
|
{
|
|
|
|
res = g_strdup (error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
return res;
|
|
|
|
}
|
a11y: Add proper error reporting to value collection
We're currently overloading NULL to mean both "this value is undefined,
and should be reset to its default" and "the value collection failed".
Let's do error reporting right, by using GError to mean "the collection
failed, for this specific reason"; then, we can use a NULL return value
to signal that the accessible attribute should be reset to its default
value.
This is only relevant for pointer-sized attribute values: strings,
references, and reference lists; numeric, boolean, tristate, and token
values either cannot be undefined, or have a specific "undefined" value.
2020-07-28 15:41:44 +00:00
|
|
|
|
2020-07-26 19:29:00 +00:00
|
|
|
if (check_value == NULL)
|
a11y: Add proper error reporting to value collection
We're currently overloading NULL to mean both "this value is undefined,
and should be reset to its default" and "the value collection failed".
Let's do error reporting right, by using GError to mean "the collection
failed, for this specific reason"; then, we can use a NULL return value
to signal that the accessible attribute should be reset to its default
value.
This is only relevant for pointer-sized attribute values: strings,
references, and reference lists; numeric, boolean, tristate, and token
values either cannot be undefined, or have a specific "undefined" value.
2020-07-28 15:41:44 +00:00
|
|
|
check_value = gtk_accessible_value_get_default_for_property (property);
|
2020-07-26 19:29:00 +00:00
|
|
|
|
|
|
|
GtkATContext *context = gtk_accessible_get_at_context (accessible);
|
|
|
|
GtkAccessibleValue *real_value =
|
|
|
|
gtk_at_context_get_accessible_property (context, property);
|
|
|
|
|
|
|
|
if (gtk_accessible_value_equal (check_value, real_value))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
res = gtk_accessible_value_to_string (real_value);
|
|
|
|
|
|
|
|
out:
|
|
|
|
gtk_accessible_value_unref (check_value);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2020-12-16 15:47:29 +00:00
|
|
|
/**
|
|
|
|
* gtk_test_accessible_has_state:
|
2021-05-20 13:17:04 +00:00
|
|
|
* @accessible: a `GtkAccessible`
|
|
|
|
* @state: a `GtkAccessibleState`
|
2020-12-16 15:47:29 +00:00
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
* Checks whether the `GtkAccessible` has @state set.
|
2020-12-16 15:47:29 +00:00
|
|
|
*
|
|
|
|
* Returns: %TRUE if the @state is set in the @accessible
|
|
|
|
*/
|
2020-07-22 15:32:09 +00:00
|
|
|
gboolean
|
|
|
|
gtk_test_accessible_has_state (GtkAccessible *accessible,
|
|
|
|
GtkAccessibleState state)
|
|
|
|
{
|
|
|
|
GtkATContext *context;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_ACCESSIBLE (accessible), FALSE);
|
|
|
|
|
|
|
|
context = gtk_accessible_get_at_context (accessible);
|
|
|
|
if (context == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return gtk_at_context_has_accessible_state (context, state);
|
|
|
|
}
|
|
|
|
|
2020-07-26 19:29:00 +00:00
|
|
|
/**
|
|
|
|
* gtk_test_accessible_check_state:
|
2021-05-20 13:17:04 +00:00
|
|
|
* @accessible: a `GtkAccessible`
|
|
|
|
* @state: a `GtkAccessibleState`
|
2020-07-26 19:29:00 +00:00
|
|
|
* @...: the expected value of @state
|
|
|
|
*
|
|
|
|
* Checks whether the accessible @state of @accessible is set to
|
|
|
|
* a specific value.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the value of the accessible state
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
gtk_test_accessible_check_state (GtkAccessible *accessible,
|
|
|
|
GtkAccessibleState state,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
char *res = NULL;
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start (args, state);
|
|
|
|
|
a11y: Add proper error reporting to value collection
We're currently overloading NULL to mean both "this value is undefined,
and should be reset to its default" and "the value collection failed".
Let's do error reporting right, by using GError to mean "the collection
failed, for this specific reason"; then, we can use a NULL return value
to signal that the accessible attribute should be reset to its default
value.
This is only relevant for pointer-sized attribute values: strings,
references, and reference lists; numeric, boolean, tristate, and token
values either cannot be undefined, or have a specific "undefined" value.
2020-07-28 15:41:44 +00:00
|
|
|
GError *error = NULL;
|
2020-07-26 19:29:00 +00:00
|
|
|
GtkAccessibleValue *check_value =
|
a11y: Add proper error reporting to value collection
We're currently overloading NULL to mean both "this value is undefined,
and should be reset to its default" and "the value collection failed".
Let's do error reporting right, by using GError to mean "the collection
failed, for this specific reason"; then, we can use a NULL return value
to signal that the accessible attribute should be reset to its default
value.
This is only relevant for pointer-sized attribute values: strings,
references, and reference lists; numeric, boolean, tristate, and token
values either cannot be undefined, or have a specific "undefined" value.
2020-07-28 15:41:44 +00:00
|
|
|
gtk_accessible_value_collect_for_state (state, &error, &args);
|
2020-07-26 19:29:00 +00:00
|
|
|
|
|
|
|
va_end (args);
|
|
|
|
|
2020-11-10 14:14:47 +00:00
|
|
|
if (error != NULL)
|
|
|
|
{
|
|
|
|
res = g_strdup (error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
return res;
|
|
|
|
}
|
a11y: Add proper error reporting to value collection
We're currently overloading NULL to mean both "this value is undefined,
and should be reset to its default" and "the value collection failed".
Let's do error reporting right, by using GError to mean "the collection
failed, for this specific reason"; then, we can use a NULL return value
to signal that the accessible attribute should be reset to its default
value.
This is only relevant for pointer-sized attribute values: strings,
references, and reference lists; numeric, boolean, tristate, and token
values either cannot be undefined, or have a specific "undefined" value.
2020-07-28 15:41:44 +00:00
|
|
|
|
2020-07-26 19:29:00 +00:00
|
|
|
if (check_value == NULL)
|
a11y: Add proper error reporting to value collection
We're currently overloading NULL to mean both "this value is undefined,
and should be reset to its default" and "the value collection failed".
Let's do error reporting right, by using GError to mean "the collection
failed, for this specific reason"; then, we can use a NULL return value
to signal that the accessible attribute should be reset to its default
value.
This is only relevant for pointer-sized attribute values: strings,
references, and reference lists; numeric, boolean, tristate, and token
values either cannot be undefined, or have a specific "undefined" value.
2020-07-28 15:41:44 +00:00
|
|
|
check_value = gtk_accessible_value_get_default_for_state (state);
|
2020-07-26 19:29:00 +00:00
|
|
|
|
|
|
|
GtkATContext *context = gtk_accessible_get_at_context (accessible);
|
|
|
|
GtkAccessibleValue *real_value =
|
|
|
|
gtk_at_context_get_accessible_state (context, state);
|
|
|
|
|
|
|
|
if (gtk_accessible_value_equal (check_value, real_value))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
res = gtk_accessible_value_to_string (real_value);
|
|
|
|
|
|
|
|
out:
|
|
|
|
gtk_accessible_value_unref (check_value);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2020-12-16 15:47:29 +00:00
|
|
|
/**
|
|
|
|
* gtk_test_accessible_has_relation:
|
2021-05-20 13:17:04 +00:00
|
|
|
* @accessible: a `GtkAccessible`
|
|
|
|
* @relation: a `GtkAccessibleRelation`
|
2020-12-16 15:47:29 +00:00
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
* Checks whether the `GtkAccessible` has @relation set.
|
2020-12-16 15:47:29 +00:00
|
|
|
*
|
|
|
|
* Returns: %TRUE if the @relation is set in the @accessible
|
|
|
|
*/
|
2020-07-22 15:32:09 +00:00
|
|
|
gboolean
|
|
|
|
gtk_test_accessible_has_relation (GtkAccessible *accessible,
|
|
|
|
GtkAccessibleRelation relation)
|
|
|
|
{
|
|
|
|
GtkATContext *context;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_ACCESSIBLE (accessible), FALSE);
|
|
|
|
|
|
|
|
context = gtk_accessible_get_at_context (accessible);
|
|
|
|
if (context == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return gtk_at_context_has_accessible_relation (context, relation);
|
|
|
|
}
|
|
|
|
|
2020-07-26 19:29:00 +00:00
|
|
|
/**
|
|
|
|
* gtk_test_accessible_check_relation:
|
2021-05-20 13:17:04 +00:00
|
|
|
* @accessible: a `GtkAccessible`
|
|
|
|
* @relation: a `GtkAccessibleRelation`
|
2020-07-26 19:29:00 +00:00
|
|
|
* @...: the expected value of @relation
|
|
|
|
*
|
|
|
|
* Checks whether the accessible @relation of @accessible is set to
|
|
|
|
* a specific value.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the value of the accessible relation
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
gtk_test_accessible_check_relation (GtkAccessible *accessible,
|
|
|
|
GtkAccessibleRelation relation,
|
|
|
|
...)
|
2020-07-17 13:39:56 +00:00
|
|
|
{
|
2020-07-26 19:29:00 +00:00
|
|
|
char *res = NULL;
|
|
|
|
va_list args;
|
2020-07-17 13:39:56 +00:00
|
|
|
|
2020-07-26 19:29:00 +00:00
|
|
|
va_start (args, relation);
|
2020-07-17 13:39:56 +00:00
|
|
|
|
a11y: Add proper error reporting to value collection
We're currently overloading NULL to mean both "this value is undefined,
and should be reset to its default" and "the value collection failed".
Let's do error reporting right, by using GError to mean "the collection
failed, for this specific reason"; then, we can use a NULL return value
to signal that the accessible attribute should be reset to its default
value.
This is only relevant for pointer-sized attribute values: strings,
references, and reference lists; numeric, boolean, tristate, and token
values either cannot be undefined, or have a specific "undefined" value.
2020-07-28 15:41:44 +00:00
|
|
|
GError *error = NULL;
|
2020-07-26 19:29:00 +00:00
|
|
|
GtkAccessibleValue *check_value =
|
a11y: Add proper error reporting to value collection
We're currently overloading NULL to mean both "this value is undefined,
and should be reset to its default" and "the value collection failed".
Let's do error reporting right, by using GError to mean "the collection
failed, for this specific reason"; then, we can use a NULL return value
to signal that the accessible attribute should be reset to its default
value.
This is only relevant for pointer-sized attribute values: strings,
references, and reference lists; numeric, boolean, tristate, and token
values either cannot be undefined, or have a specific "undefined" value.
2020-07-28 15:41:44 +00:00
|
|
|
gtk_accessible_value_collect_for_relation (relation, &error, &args);
|
2020-07-17 13:39:56 +00:00
|
|
|
|
2020-07-26 19:29:00 +00:00
|
|
|
va_end (args);
|
2020-07-17 13:39:56 +00:00
|
|
|
|
2020-11-10 14:14:47 +00:00
|
|
|
if (error != NULL)
|
|
|
|
{
|
|
|
|
res = g_strdup (error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
return res;
|
|
|
|
}
|
a11y: Add proper error reporting to value collection
We're currently overloading NULL to mean both "this value is undefined,
and should be reset to its default" and "the value collection failed".
Let's do error reporting right, by using GError to mean "the collection
failed, for this specific reason"; then, we can use a NULL return value
to signal that the accessible attribute should be reset to its default
value.
This is only relevant for pointer-sized attribute values: strings,
references, and reference lists; numeric, boolean, tristate, and token
values either cannot be undefined, or have a specific "undefined" value.
2020-07-28 15:41:44 +00:00
|
|
|
|
2020-07-26 19:29:00 +00:00
|
|
|
if (check_value == NULL)
|
a11y: Add proper error reporting to value collection
We're currently overloading NULL to mean both "this value is undefined,
and should be reset to its default" and "the value collection failed".
Let's do error reporting right, by using GError to mean "the collection
failed, for this specific reason"; then, we can use a NULL return value
to signal that the accessible attribute should be reset to its default
value.
This is only relevant for pointer-sized attribute values: strings,
references, and reference lists; numeric, boolean, tristate, and token
values either cannot be undefined, or have a specific "undefined" value.
2020-07-28 15:41:44 +00:00
|
|
|
check_value = gtk_accessible_value_get_default_for_relation (relation);
|
2020-07-17 13:39:56 +00:00
|
|
|
|
2020-07-26 19:29:00 +00:00
|
|
|
GtkATContext *context = gtk_accessible_get_at_context (accessible);
|
|
|
|
GtkAccessibleValue *real_value =
|
|
|
|
gtk_at_context_get_accessible_relation (context, relation);
|
2020-07-22 15:32:09 +00:00
|
|
|
|
2020-07-26 19:29:00 +00:00
|
|
|
if (gtk_accessible_value_equal (check_value, real_value))
|
|
|
|
goto out;
|
2020-07-22 15:32:09 +00:00
|
|
|
|
2020-07-26 19:29:00 +00:00
|
|
|
res = gtk_accessible_value_to_string (real_value);
|
2020-07-22 15:32:09 +00:00
|
|
|
|
2020-07-26 19:29:00 +00:00
|
|
|
out:
|
|
|
|
gtk_accessible_value_unref (check_value);
|
|
|
|
|
|
|
|
return res;
|
2020-07-22 15:32:09 +00:00
|
|
|
}
|
|
|
|
|
2020-12-16 15:47:29 +00:00
|
|
|
/*< private >
|
|
|
|
* gtk_test_accessible_assertion_message_role:
|
|
|
|
* @domain: a domain
|
|
|
|
* @file: a file name
|
|
|
|
* @line: the line in @file
|
|
|
|
* @func: a function name in @file
|
|
|
|
* @expr: the expression being tested
|
2021-05-20 13:17:04 +00:00
|
|
|
* @accessible: a `GtkAccessible`
|
|
|
|
* @expected_role: the expected `GtkAccessibleRole`
|
|
|
|
* @actual_role: the actual `GtkAccessibleRole`
|
2020-12-16 15:47:29 +00:00
|
|
|
*
|
|
|
|
* Prints an assertion message for gtk_test_accessible_assert_role().
|
|
|
|
*/
|
2020-07-22 15:32:09 +00:00
|
|
|
void
|
2020-07-26 19:29:00 +00:00
|
|
|
gtk_test_accessible_assertion_message_role (const char *domain,
|
|
|
|
const char *file,
|
|
|
|
int line,
|
|
|
|
const char *func,
|
|
|
|
const char *expr,
|
|
|
|
GtkAccessible *accessible,
|
|
|
|
GtkAccessibleRole expected_role,
|
|
|
|
GtkAccessibleRole actual_role)
|
2020-07-22 15:32:09 +00:00
|
|
|
{
|
2020-07-26 19:29:00 +00:00
|
|
|
char *role_name = g_enum_to_string (GTK_TYPE_ACCESSIBLE_ROLE, actual_role);
|
|
|
|
char *s = g_strdup_printf ("assertion failed: (%s): %s.accessible-role = %s (%d)",
|
|
|
|
expr,
|
2020-07-22 15:32:09 +00:00
|
|
|
G_OBJECT_TYPE_NAME (accessible),
|
2020-07-26 19:29:00 +00:00
|
|
|
role_name,
|
|
|
|
actual_role);
|
2020-07-22 15:32:09 +00:00
|
|
|
|
2020-07-26 19:29:00 +00:00
|
|
|
g_assertion_message (domain, file, line, func, s);
|
2020-07-22 15:32:09 +00:00
|
|
|
|
2020-07-26 19:29:00 +00:00
|
|
|
g_free (role_name);
|
2020-07-22 15:32:09 +00:00
|
|
|
g_free (s);
|
|
|
|
}
|