Details
[Home]
Issue of the Implementation # S0788
Brief
atk_object_add_relationship does not add relationship that already exists but returns TRUE
Detailed Description
The description of the function states the following:
gboolean atk_object_add_relationship(AtkObject *object, AtkRelationType relationship, AtkObject *target):
Adds a relationship of the specified type with the specified target.
...
Returns : TRUE if the relationship is added.
It is not clear from documentation when a relationship may be not added to the object's relation set. Nevertheless, when a relationship is not added for any reason, the function should return FALSE.
The implementation of the function behaves differently though. When a relationship to be added already exists in the object's relation set, the relation is not going to be added. But the function returns TRUE in this case as if it did add the relationship, which is wrong. The example below demonstrates this situation.
Problem location(s) in the standard
ATK 1.9.0 Reference Manual, AtkObject
Example
#include <atk/atk.h> #include <stdio.h> //Return total number of object's relationships. gint get_n_relationships(AtkObject* obj) { gint n_relationships = 0; AtkRelationSet* relation_set = atk_object_ref_relation_set(obj); gint nrelations = atk_relation_set_get_n_relations(relation_set); for(gint i = 0; i < nrelations; i++) { AtkRelation* relation = atk_relation_set_get_relation(relation_set, i); GPtrArray* relationships = atk_relation_get_target(relation); n_relationships += relationships->len; } g_object_unref(relation_set); return n_relationships; } int main() { g_type_init(); AtkObject *obj = g_object_new(ATK_TYPE_OBJECT,NULL); AtkObject *obj1 = g_object_new(ATK_TYPE_OBJECT,NULL); AtkRelationType type = ATK_RELATION_CONTROLLED_BY; atk_object_add_relationship(obj, type, obj1); printf("Number of relationships after first call: %d. ", get_n_relationships(obj)); gboolean result = atk_object_add_relationship(obj, type, obj1); printf("Second call of atk_object_add_relationship returns %s. ", result ? "TRUE" : "FALSE"); printf("Number of relationships after second call: %d. ", get_n_relationships(obj)); g_object_unref(obj); g_object_unref(obj1); return 0; }
Component
gtk-atk 1.25 or later
Accepted
Gnome Bugzilla 578602
Status
Fixed in gtk-atk 2.5.4
[Home]