#include <atk/atk.h>
#include <stdio.h>
//Returns 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.\n",
        get_n_relationships(obj));
    gboolean result = atk_object_add_relationship(obj, type, obj1);
    printf("Second call of atk_object_add_relationship returns %s.\n",
        result ? "TRUE" : "FALSE");
    printf("Number of relationships after second call: %d.\n",
        get_n_relationships(obj));
    
    g_object_unref(obj);
    g_object_unref(obj1);
    
    return 0;
}