/* link-personas.c generated by valac 0.13.1.106-1068, the Vala compiler
 * generated from link-personas.vala, do not modify */

/*
 * Copyright (C) 2011 Collabora Ltd.
 *
 * 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/>.
 *
 * Authors: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk>
 *
 */

#include <glib.h>
#include <glib-object.h>
#include <folks-test.h>
#include <tracker-test.h>
#include <folks/folks.h>
#include <stdlib.h>
#include <string.h>
#include <gee.h>
#include <gconf/gconf-client.h>
#include <gconf/gconf.h>
#include <gio/gio.h>


#define TYPE_LINK_PERSONAS_TESTS (link_personas_tests_get_type ())
#define LINK_PERSONAS_TESTS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_LINK_PERSONAS_TESTS, LinkPersonasTests))
#define LINK_PERSONAS_TESTS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_LINK_PERSONAS_TESTS, LinkPersonasTestsClass))
#define IS_LINK_PERSONAS_TESTS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_LINK_PERSONAS_TESTS))
#define IS_LINK_PERSONAS_TESTS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_LINK_PERSONAS_TESTS))
#define LINK_PERSONAS_TESTS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_LINK_PERSONAS_TESTS, LinkPersonasTestsClass))

typedef struct _LinkPersonasTests LinkPersonasTests;
typedef struct _LinkPersonasTestsClass LinkPersonasTestsClass;
typedef struct _LinkPersonasTestsPrivate LinkPersonasTestsPrivate;
#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL)))
#define _tracker_test_backend_unref0(var) ((var == NULL) ? NULL : (var = (tracker_test_backend_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _gconf_value_free0(var) ((var == NULL) ? NULL : (var = (gconf_value_free (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _LinkPersonasTestsTestLinkingPersonasAsyncData LinkPersonasTestsTestLinkingPersonasAsyncData;
#define __vala_GValue_free0(var) ((var == NULL) ? NULL : (var = (_vala_GValue_free (var), NULL)))
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
typedef struct _LinkPersonasTestsAddPersonasData LinkPersonasTestsAddPersonasData;

struct _LinkPersonasTests {
	FolksTestCase parent_instance;
	LinkPersonasTestsPrivate * priv;
};

struct _LinkPersonasTestsClass {
	FolksTestCaseClass parent_class;
};

struct _LinkPersonasTestsPrivate {
	GMainLoop* _main_loop;
	TrackerTestBackend* _tracker_backend;
	FolksIndividualAggregator* _aggregator;
	gchar* _persona_fullname_1;
	gchar* _persona_fullname_2;
	gchar* _proto;
	gchar* _im_address_1;
	gchar* _im_address_2;
	gboolean _linking_fired;
	gboolean _persona_found_1;
	gboolean _persona_found_2;
	gchar* _persona_iid_1;
	gchar* _persona_iid_2;
	GeeHashSet* _personas;
	gint _removed_individuals;
	gchar* _folks_config_key;
	GConfClient* _gconf_client;
	GeeHashMap* _linking_props;
};

struct _LinkPersonasTestsTestLinkingPersonasAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	LinkPersonasTests* self;
	FolksBackendStore* _tmp0_;
	FolksBackendStore* store;
	FolksBackendStore* _tmp1_;
	FolksIndividualAggregator* _tmp2_;
	FolksIndividualAggregator* _tmp3_;
	FolksIndividualAggregator* _tmp4_;
	FolksPersonaStore* pstore;
	FolksBackendStore* _tmp5_;
	GeeMap* _tmp6_;
	GeeMap* _tmp7_;
	GeeCollection* _tmp8_;
	GeeCollection* _tmp9_;
	GeeCollection* _tmp10_;
	GeeIterator* _tmp11_;
	GeeIterator* _tmp12_;
	GeeIterator* _backend_it;
	GeeIterator* _tmp13_;
	gboolean _tmp14_;
	GeeIterator* _tmp15_;
	gpointer _tmp16_;
	FolksBackend* backend;
	FolksBackend* _tmp17_;
	GeeMap* _tmp18_;
	GeeMap* _tmp19_;
	gpointer _tmp20_;
	FolksPersonaStore* _tmp21_;
	FolksPersonaStore* _tmp22_;
	FolksPersonaStore* _tmp23_;
	GError* e;
	GError* _tmp24_;
	const gchar* _tmp25_;
	GError * _inner_error_;
};

struct _LinkPersonasTestsAddPersonasData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	LinkPersonasTests* self;
	FolksPersonaStore* pstore;
	GHashFunc _tmp0_;
	GEqualFunc _tmp1_;
	GHashTable* _tmp2_;
	GHashTable* details1;
	GValue _tmp3_;
	GValue _tmp4_;
	GValue _tmp5_;
	GValue* _tmp6_;
	GValue* _tmp7_;
	GValue* v1;
	GeeHashMultiMap* _tmp8_;
	GeeHashMultiMap* im_addrs1;
	GeeHashMultiMap* _tmp9_;
	const gchar* _tmp10_;
	const gchar* _tmp11_;
	FolksImFieldDetails* _tmp12_;
	FolksImFieldDetails* _tmp13_;
	GValue* _tmp14_;
	GeeHashMultiMap* _tmp15_;
	GHashTable* _tmp16_;
	gchar* _tmp17_;
	GValue* _tmp18_;
	GValue _tmp19_;
	GValue _tmp20_;
	GValue _tmp21_;
	GValue* _tmp22_;
	GValue* _tmp23_;
	GValue* v2;
	GValue* _tmp24_;
	const gchar* _tmp25_;
	GHashTable* _tmp26_;
	gchar* _tmp27_;
	GValue* _tmp28_;
	GHashFunc _tmp29_;
	GEqualFunc _tmp30_;
	GHashTable* _tmp31_;
	GHashTable* details2;
	GValue _tmp32_;
	GValue _tmp33_;
	GValue _tmp34_;
	GValue* _tmp35_;
	GValue* _tmp36_;
	GValue* v3;
	GeeHashMultiMap* _tmp37_;
	GeeHashMultiMap* im_addrs2;
	GeeHashMultiMap* _tmp38_;
	const gchar* _tmp39_;
	const gchar* _tmp40_;
	FolksImFieldDetails* _tmp41_;
	FolksImFieldDetails* _tmp42_;
	GValue* _tmp43_;
	GeeHashMultiMap* _tmp44_;
	GHashTable* _tmp45_;
	gchar* _tmp46_;
	GValue* _tmp47_;
	GValue _tmp48_;
	GValue _tmp49_;
	GValue _tmp50_;
	GValue* _tmp51_;
	GValue* _tmp52_;
	GValue* v4;
	GValue* _tmp53_;
	const gchar* _tmp54_;
	GHashTable* _tmp55_;
	gchar* _tmp56_;
	GValue* _tmp57_;
	FolksIndividualAggregator* _tmp58_;
	FolksPersonaStore* _tmp59_;
	GHashTable* _tmp60_;
	FolksPersona* _tmp61_;
	FolksPersona* _tmp62_;
	FolksIndividualAggregator* _tmp63_;
	FolksPersonaStore* _tmp64_;
	GHashTable* _tmp65_;
	FolksPersona* _tmp66_;
	FolksPersona* _tmp67_;
	GError* e;
	GError* _tmp68_;
	const gchar* _tmp69_;
	GError * _inner_error_;
};


static gpointer link_personas_tests_parent_class = NULL;

GType link_personas_tests_get_type (void) G_GNUC_CONST;
#define LINK_PERSONAS_TESTS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_LINK_PERSONAS_TESTS, LinkPersonasTestsPrivate))
enum  {
	LINK_PERSONAS_TESTS_DUMMY_PROPERTY
};
LinkPersonasTests* link_personas_tests_new (void);
LinkPersonasTests* link_personas_tests_construct (GType object_type);
void link_personas_tests_test_linking_personas (LinkPersonasTests* self);
static void _link_personas_tests_test_linking_personas_folks_test_case_test_method (gpointer self);
static void link_personas_tests_real_set_up (FolksTestCase* base);
static void link_personas_tests_real_tear_down (FolksTestCase* base);
static void _link_personas_tests_test_linking_personas_async (LinkPersonasTests* self, GAsyncReadyCallback _callback_, gpointer _user_data_);
static void _link_personas_tests_test_linking_personas_finish (LinkPersonasTests* self, GAsyncResult* _res_);
static gboolean _lambda1_ (LinkPersonasTests* self);
static gboolean __lambda1__gsource_func (gpointer self);
static void _link_personas_tests_test_linking_personas_async_data_free (gpointer _data);
static gboolean _link_personas_tests_test_linking_personas_async_co (LinkPersonasTestsTestLinkingPersonasAsyncData* _data_);
static void _link_personas_tests_test_linking_personas_async_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
static void _link_personas_tests_individuals_changed_cb (LinkPersonasTests* self, GeeSet* added, GeeSet* removed, const gchar* message, FolksPersona* actor, FolksGroupDetailsChangeReason reason);
static void __link_personas_tests_individuals_changed_cb_folks_individual_aggregator_individuals_changed (FolksIndividualAggregator* _sender, GeeSet* added, GeeSet* removed, const gchar* message, FolksPersona* actor, FolksGroupDetailsChangeReason reason, gpointer self);
static void _link_personas_tests_add_personas (LinkPersonasTests* self, FolksPersonaStore* pstore, GAsyncReadyCallback _callback_, gpointer _user_data_);
static void _link_personas_tests_add_personas_finish (LinkPersonasTests* self, GAsyncResult* _res_);
static void _link_personas_tests_add_personas_data_free (gpointer _data);
static gboolean _link_personas_tests_add_personas_co (LinkPersonasTestsAddPersonasData* _data_);
static void _g_free0_ (gpointer var);
static void _vala_GValue_free (GValue* self);
static void __vala_GValue_free0_ (gpointer var);
static GValue* _g_value_dup (GValue* self);
static void _link_personas_tests_add_personas_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
static void _link_personas_tests_check_personas (LinkPersonasTests* self, FolksIndividual* i);
static void _link_personas_tests_notify_cb (LinkPersonasTests* self, GObject* individual_obj, GParamSpec* ps);
static void __link_personas_tests_notify_cb_g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self);
static gboolean _lambda0_ (LinkPersonasTests* self);
static gboolean __lambda0__gsource_func (gpointer self);
static void link_personas_tests_finalize (GObject* obj);
gint _vala_main (gchar** args, int args_length1);


static void _link_personas_tests_test_linking_personas_folks_test_case_test_method (gpointer self) {
	link_personas_tests_test_linking_personas (self);
}


LinkPersonasTests* link_personas_tests_construct (GType object_type) {
	LinkPersonasTests * self = NULL;
	TrackerTestBackend* _tmp0_;
	self = (LinkPersonasTests*) folks_test_case_construct (object_type, "LinkPersonasTests");
	_tmp0_ = tracker_test_backend_new ();
	_tracker_test_backend_unref0 (self->priv->_tracker_backend);
	self->priv->_tracker_backend = _tmp0_;
	folks_test_case_add_test ((FolksTestCase*) self, "test linking personas", _link_personas_tests_test_linking_personas_folks_test_case_test_method, self);
	return self;
}


LinkPersonasTests* link_personas_tests_new (void) {
	return link_personas_tests_construct (TYPE_LINK_PERSONAS_TESTS);
}


static void link_personas_tests_real_set_up (FolksTestCase* base) {
	LinkPersonasTests * self;
	GConfClient* _tmp0_ = NULL;
	TrackerTestBackend* _tmp8_;
	GError * _inner_error_ = NULL;
	self = (LinkPersonasTests*) base;
	_tmp0_ = gconf_client_get_default ();
	self->priv->_gconf_client = _tmp0_;
	{
		GConfValue* _tmp1_;
		GConfValue* val;
		GConfValue* _tmp2_;
		GConfClient* _tmp3_;
		const gchar* _tmp4_;
		GConfValue* _tmp5_;
		_tmp1_ = gconf_value_new (GCONF_VALUE_STRING);
		val = _tmp1_;
		_tmp2_ = val;
		gconf_value_set_string (_tmp2_, "tracker");
		_tmp3_ = self->priv->_gconf_client;
		_tmp4_ = self->priv->_folks_config_key;
		_tmp5_ = val;
		gconf_client_set (_tmp3_, _tmp4_, _tmp5_, &_inner_error_);
		if (_inner_error_ != NULL) {
			_gconf_value_free0 (val);
			goto __catch0_g_error;
		}
		_gconf_value_free0 (val);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp6_;
		const gchar* _tmp7_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp6_ = e;
		_tmp7_ = _tmp6_->message;
		g_warning ("link-personas.vala:70: Couldn't set primary store: %s\n", _tmp7_);
		_g_error_free0 (e);
	}
	__finally0:
	if (_inner_error_ != NULL) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return;
	}
	_tmp8_ = self->priv->_tracker_backend;
	tracker_test_backend_set_up (_tmp8_);
}


static void link_personas_tests_real_tear_down (FolksTestCase* base) {
	LinkPersonasTests * self;
	TrackerTestBackend* _tmp0_;
	GError * _inner_error_ = NULL;
	self = (LinkPersonasTests*) base;
	_tmp0_ = self->priv->_tracker_backend;
	tracker_test_backend_tear_down (_tmp0_);
	{
		GConfClient* _tmp1_;
		const gchar* _tmp2_;
		_tmp1_ = self->priv->_gconf_client;
		_tmp2_ = self->priv->_folks_config_key;
		gconf_client_unset (_tmp1_, _tmp2_, &_inner_error_);
		if (_inner_error_ != NULL) {
			goto __catch1_g_error;
		}
	}
	goto __finally1;
	__catch1_g_error:
	{
		GError* e = NULL;
		GError* _tmp3_;
		const gchar* _tmp4_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp3_ = e;
		_tmp4_ = _tmp3_->message;
		g_warning ("link-personas.vala:92: Couldn't unset primary store: %s\n", _tmp4_);
		_g_error_free0 (e);
	}
	__finally1:
	if (_inner_error_ != NULL) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return;
	}
}


static gboolean _lambda1_ (LinkPersonasTests* self) {
	gboolean result = FALSE;
	GMainLoop* _tmp0_;
	_tmp0_ = self->priv->_main_loop;
	g_main_loop_quit (_tmp0_);
	g_assert_not_reached ();
	return result;
}


static gboolean __lambda1__gsource_func (gpointer self) {
	gboolean result;
	result = _lambda1_ (self);
	return result;
}


void link_personas_tests_test_linking_personas (LinkPersonasTests* self) {
	GMainLoop* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	GeeHashSet* _tmp3_;
	GeeHashMap* _tmp4_;
	GeeHashMap* _tmp5_;
	const gchar* _tmp6_;
	GeeHashMap* _tmp7_;
	const gchar* _tmp8_;
	GMainLoop* _tmp9_;
	GeeHashMap* _tmp10_;
	gint _tmp11_;
	gint _tmp12_;
	gint _tmp13_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_main_loop_new (NULL, FALSE);
	_g_main_loop_unref0 (self->priv->_main_loop);
	self->priv->_main_loop = _tmp0_;
	_tmp1_ = g_strdup ("persona #1");
	_g_free0 (self->priv->_persona_fullname_1);
	self->priv->_persona_fullname_1 = _tmp1_;
	_tmp2_ = g_strdup ("persona #2");
	_g_free0 (self->priv->_persona_fullname_2);
	self->priv->_persona_fullname_2 = _tmp2_;
	_tmp3_ = gee_hash_set_new (FOLKS_TYPE_PERSONA, (GBoxedCopyFunc) g_object_ref, g_object_unref, NULL, NULL);
	_g_object_unref0 (self->priv->_personas);
	self->priv->_personas = _tmp3_;
	self->priv->_persona_found_1 = FALSE;
	self->priv->_persona_found_2 = FALSE;
	self->priv->_linking_fired = FALSE;
	_tmp4_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, NULL, NULL, NULL);
	_g_object_unref0 (self->priv->_linking_props);
	self->priv->_linking_props = _tmp4_;
	_tmp5_ = self->priv->_linking_props;
	_tmp6_ = self->priv->_im_address_1;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp5_, "prop1", _tmp6_);
	_tmp7_ = self->priv->_linking_props;
	_tmp8_ = self->priv->_im_address_2;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp7_, "prop2", _tmp8_);
	_link_personas_tests_test_linking_personas_async (self, NULL, NULL);
	g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, (guint) 5, __lambda1__gsource_func, g_object_ref (self), g_object_unref);
	_tmp9_ = self->priv->_main_loop;
	g_main_loop_run (_tmp9_);
	_tmp10_ = self->priv->_linking_props;
	_tmp11_ = gee_map_get_size ((GeeMap*) _tmp10_);
	_tmp12_ = _tmp11_;
	g_assert (_tmp12_ == 0);
	_tmp13_ = self->priv->_removed_individuals;
	g_assert (_tmp13_ == 2);
}


static void _link_personas_tests_test_linking_personas_async_data_free (gpointer _data) {
	LinkPersonasTestsTestLinkingPersonasAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (LinkPersonasTestsTestLinkingPersonasAsyncData, _data_);
}


static gpointer _g_object_ref0 (gpointer self) {
	return self ? g_object_ref (self) : NULL;
}


static void _link_personas_tests_test_linking_personas_async (LinkPersonasTests* self, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	LinkPersonasTestsTestLinkingPersonasAsyncData* _data_;
	LinkPersonasTests* _tmp0_;
	_data_ = g_slice_new0 (LinkPersonasTestsTestLinkingPersonasAsyncData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, _link_personas_tests_test_linking_personas_async);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, _link_personas_tests_test_linking_personas_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_link_personas_tests_test_linking_personas_async_co (_data_);
}


static void _link_personas_tests_test_linking_personas_finish (LinkPersonasTests* self, GAsyncResult* _res_) {
	LinkPersonasTestsTestLinkingPersonasAsyncData* _data_;
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
}


static void _link_personas_tests_test_linking_personas_async_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	LinkPersonasTestsTestLinkingPersonasAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	_link_personas_tests_test_linking_personas_async_co (_data_);
}


static void __link_personas_tests_individuals_changed_cb_folks_individual_aggregator_individuals_changed (FolksIndividualAggregator* _sender, GeeSet* added, GeeSet* removed, const gchar* message, FolksPersona* actor, FolksGroupDetailsChangeReason reason, gpointer self) {
	_link_personas_tests_individuals_changed_cb (self, added, removed, message, actor, reason);
}


static gboolean _link_personas_tests_test_linking_personas_async_co (LinkPersonasTestsTestLinkingPersonasAsyncData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = NULL;
	_data_->_tmp0_ = folks_backend_store_dup ();
	_data_->store = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->store;
	_data_->_state_ = 1;
	folks_backend_store_prepare (_data_->_tmp1_, _link_personas_tests_test_linking_personas_async_ready, _data_);
	return FALSE;
	_state_1:
	folks_backend_store_prepare_finish (_data_->_tmp1_, _data_->_res_);
	_data_->_tmp2_ = folks_individual_aggregator_new ();
	_g_object_unref0 (_data_->self->priv->_aggregator);
	_data_->self->priv->_aggregator = _data_->_tmp2_;
	_data_->_tmp3_ = _data_->self->priv->_aggregator;
	g_signal_connect_object (_data_->_tmp3_, "individuals-changed", (GCallback) __link_personas_tests_individuals_changed_cb_folks_individual_aggregator_individuals_changed, _data_->self, 0);
	{
		_data_->_tmp4_ = _data_->self->priv->_aggregator;
		_data_->_state_ = 2;
		folks_individual_aggregator_prepare (_data_->_tmp4_, _link_personas_tests_test_linking_personas_async_ready, _data_);
		return FALSE;
		_state_2:
		folks_individual_aggregator_prepare_finish (_data_->_tmp4_, _data_->_res_, &_data_->_inner_error_);
		if (_data_->_inner_error_ != NULL) {
			goto __catch2_g_error;
		}
		_data_->pstore = NULL;
		{
			_data_->_tmp5_ = _data_->store;
			_data_->_tmp6_ = folks_backend_store_get_enabled_backends (_data_->_tmp5_);
			_data_->_tmp7_ = _data_->_tmp6_;
			_data_->_tmp8_ = gee_map_get_values (_data_->_tmp7_);
			_data_->_tmp9_ = _data_->_tmp8_;
			_data_->_tmp10_ = _data_->_tmp9_;
			_data_->_tmp11_ = NULL;
			_data_->_tmp11_ = gee_iterable_iterator ((GeeIterable*) _data_->_tmp10_);
			_data_->_tmp12_ = _data_->_tmp11_;
			_g_object_unref0 (_data_->_tmp10_);
			_data_->_backend_it = _data_->_tmp12_;
			while (TRUE) {
				_data_->_tmp13_ = _data_->_backend_it;
				_data_->_tmp14_ = FALSE;
				_data_->_tmp14_ = gee_iterator_next (_data_->_tmp13_);
				if (!_data_->_tmp14_) {
					break;
				}
				_data_->_tmp15_ = _data_->_backend_it;
				_data_->_tmp16_ = NULL;
				_data_->_tmp16_ = gee_iterator_get (_data_->_tmp15_);
				_data_->backend = (FolksBackend*) _data_->_tmp16_;
				_data_->_tmp17_ = _data_->backend;
				_data_->_tmp18_ = folks_backend_get_persona_stores (_data_->_tmp17_);
				_data_->_tmp19_ = _data_->_tmp18_;
				_data_->_tmp20_ = NULL;
				_data_->_tmp20_ = gee_map_get (_data_->_tmp19_, "tracker");
				_g_object_unref0 (_data_->pstore);
				_data_->pstore = (FolksPersonaStore*) _data_->_tmp20_;
				_data_->_tmp21_ = _data_->pstore;
				if (_data_->_tmp21_ != NULL) {
					_g_object_unref0 (_data_->backend);
					break;
				}
				_g_object_unref0 (_data_->backend);
			}
			_g_object_unref0 (_data_->_backend_it);
		}
		_data_->_tmp22_ = _data_->pstore;
		g_assert (_data_->_tmp22_ != NULL);
		_data_->_tmp23_ = _data_->pstore;
		_data_->_state_ = 3;
		_link_personas_tests_add_personas (_data_->self, _data_->_tmp23_, _link_personas_tests_test_linking_personas_async_ready, _data_);
		return FALSE;
		_state_3:
		_link_personas_tests_add_personas_finish (_data_->self, _data_->_res_);
		_g_object_unref0 (_data_->pstore);
	}
	goto __finally2;
	__catch2_g_error:
	{
		_data_->e = _data_->_inner_error_;
		_data_->_inner_error_ = NULL;
		_data_->_tmp24_ = _data_->e;
		_data_->_tmp25_ = _data_->_tmp24_->message;
		g_warning ("link-personas.vala:154: Error when calling prepare: %s\n", _data_->_tmp25_);
		_g_error_free0 (_data_->e);
	}
	__finally2:
	if (_data_->_inner_error_ != NULL) {
		_g_object_unref0 (_data_->store);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
		g_clear_error (&_data_->_inner_error_);
		return FALSE;
	}
	_g_object_unref0 (_data_->store);
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


static void _link_personas_tests_add_personas_data_free (gpointer _data) {
	LinkPersonasTestsAddPersonasData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->pstore);
	_g_object_unref0 (_data_->self);
	g_slice_free (LinkPersonasTestsAddPersonasData, _data_);
}


static void _link_personas_tests_add_personas (LinkPersonasTests* self, FolksPersonaStore* pstore, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	LinkPersonasTestsAddPersonasData* _data_;
	LinkPersonasTests* _tmp0_;
	FolksPersonaStore* _tmp1_;
	FolksPersonaStore* _tmp2_;
	_data_ = g_slice_new0 (LinkPersonasTestsAddPersonasData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, _link_personas_tests_add_personas);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, _link_personas_tests_add_personas_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = pstore;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	_data_->pstore = _tmp2_;
	_link_personas_tests_add_personas_co (_data_);
}


static void _link_personas_tests_add_personas_finish (LinkPersonasTests* self, GAsyncResult* _res_) {
	LinkPersonasTestsAddPersonasData* _data_;
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
}


static void _g_free0_ (gpointer var) {
	var = (g_free (var), NULL);
}


static void _vala_GValue_free (GValue* self) {
	g_value_unset (self);
	g_free (self);
}


static void __vala_GValue_free0_ (gpointer var) {
	(var == NULL) ? NULL : (var = (_vala_GValue_free (var), NULL));
}


static GValue* _g_value_dup (GValue* self) {
	return g_boxed_copy (G_TYPE_VALUE, self);
}


static gpointer __g_value_dup0 (gpointer self) {
	return self ? _g_value_dup (self) : NULL;
}


static void _link_personas_tests_add_personas_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	LinkPersonasTestsAddPersonasData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	_link_personas_tests_add_personas_co (_data_);
}


static gboolean _link_personas_tests_add_personas_co (LinkPersonasTestsAddPersonasData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = g_str_hash;
	_data_->_tmp1_ = g_str_equal;
	_data_->_tmp2_ = g_hash_table_new_full (_data_->_tmp0_, _data_->_tmp1_, _g_free0_, __vala_GValue_free0_);
	_data_->details1 = _data_->_tmp2_;
	memset (&_data_->_tmp3_, 0, sizeof (GValue));
	g_value_init (&_data_->_tmp3_, GEE_TYPE_MULTI_MAP);
	_data_->_tmp4_ = _data_->_tmp3_;
	_data_->_tmp5_ = _data_->_tmp4_;
	_data_->_tmp6_ = __g_value_dup0 (&_data_->_tmp5_);
	_data_->_tmp7_ = _data_->_tmp6_;
	G_IS_VALUE (&_data_->_tmp5_) ? (g_value_unset (&_data_->_tmp5_), NULL) : NULL;
	_data_->v1 = _data_->_tmp7_;
	_data_->_tmp8_ = gee_hash_multi_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, FOLKS_TYPE_IM_FIELD_DETAILS, (GBoxedCopyFunc) g_object_ref, g_object_unref, NULL, NULL, (GHashFunc) folks_abstract_field_details_hash, (GEqualFunc) folks_abstract_field_details_equal);
	_data_->im_addrs1 = _data_->_tmp8_;
	_data_->_tmp9_ = _data_->im_addrs1;
	_data_->_tmp10_ = _data_->self->priv->_proto;
	_data_->_tmp11_ = _data_->self->priv->_im_address_1;
	_data_->_tmp12_ = folks_im_field_details_new (_data_->_tmp11_, NULL);
	_data_->_tmp13_ = _data_->_tmp12_;
	gee_multi_map_set ((GeeMultiMap*) _data_->_tmp9_, _data_->_tmp10_, _data_->_tmp13_);
	_g_object_unref0 (_data_->_tmp13_);
	_data_->_tmp14_ = _data_->v1;
	_data_->_tmp15_ = _data_->im_addrs1;
	g_value_set_object (_data_->_tmp14_, (GObject*) _data_->_tmp15_);
	_data_->_tmp16_ = _data_->details1;
	_data_->_tmp17_ = g_strdup ("im-addresses");
	_data_->_tmp18_ = _data_->v1;
	_data_->v1 = NULL;
	g_hash_table_insert (_data_->_tmp16_, _data_->_tmp17_, _data_->_tmp18_);
	memset (&_data_->_tmp19_, 0, sizeof (GValue));
	g_value_init (&_data_->_tmp19_, G_TYPE_STRING);
	_data_->_tmp20_ = _data_->_tmp19_;
	_data_->_tmp21_ = _data_->_tmp20_;
	_data_->_tmp22_ = __g_value_dup0 (&_data_->_tmp21_);
	_data_->_tmp23_ = _data_->_tmp22_;
	G_IS_VALUE (&_data_->_tmp21_) ? (g_value_unset (&_data_->_tmp21_), NULL) : NULL;
	_data_->v2 = _data_->_tmp23_;
	_data_->_tmp24_ = _data_->v2;
	_data_->_tmp25_ = _data_->self->priv->_persona_fullname_1;
	g_value_set_string (_data_->_tmp24_, _data_->_tmp25_);
	_data_->_tmp26_ = _data_->details1;
	_data_->_tmp27_ = g_strdup ("full-name");
	_data_->_tmp28_ = _data_->v2;
	_data_->v2 = NULL;
	g_hash_table_insert (_data_->_tmp26_, _data_->_tmp27_, _data_->_tmp28_);
	_data_->_tmp29_ = g_str_hash;
	_data_->_tmp30_ = g_str_equal;
	_data_->_tmp31_ = g_hash_table_new_full (_data_->_tmp29_, _data_->_tmp30_, _g_free0_, __vala_GValue_free0_);
	_data_->details2 = _data_->_tmp31_;
	memset (&_data_->_tmp32_, 0, sizeof (GValue));
	g_value_init (&_data_->_tmp32_, GEE_TYPE_MULTI_MAP);
	_data_->_tmp33_ = _data_->_tmp32_;
	_data_->_tmp34_ = _data_->_tmp33_;
	_data_->_tmp35_ = __g_value_dup0 (&_data_->_tmp34_);
	_data_->_tmp36_ = _data_->_tmp35_;
	G_IS_VALUE (&_data_->_tmp34_) ? (g_value_unset (&_data_->_tmp34_), NULL) : NULL;
	_data_->v3 = _data_->_tmp36_;
	_data_->_tmp37_ = gee_hash_multi_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, FOLKS_TYPE_IM_FIELD_DETAILS, (GBoxedCopyFunc) g_object_ref, g_object_unref, NULL, NULL, (GHashFunc) folks_abstract_field_details_hash, (GEqualFunc) folks_abstract_field_details_equal);
	_data_->im_addrs2 = _data_->_tmp37_;
	_data_->_tmp38_ = _data_->im_addrs2;
	_data_->_tmp39_ = _data_->self->priv->_proto;
	_data_->_tmp40_ = _data_->self->priv->_im_address_2;
	_data_->_tmp41_ = folks_im_field_details_new (_data_->_tmp40_, NULL);
	_data_->_tmp42_ = _data_->_tmp41_;
	gee_multi_map_set ((GeeMultiMap*) _data_->_tmp38_, _data_->_tmp39_, _data_->_tmp42_);
	_g_object_unref0 (_data_->_tmp42_);
	_data_->_tmp43_ = _data_->v3;
	_data_->_tmp44_ = _data_->im_addrs2;
	g_value_set_object (_data_->_tmp43_, (GObject*) _data_->_tmp44_);
	_data_->_tmp45_ = _data_->details2;
	_data_->_tmp46_ = g_strdup ("im-addresses");
	_data_->_tmp47_ = _data_->v3;
	_data_->v3 = NULL;
	g_hash_table_insert (_data_->_tmp45_, _data_->_tmp46_, _data_->_tmp47_);
	memset (&_data_->_tmp48_, 0, sizeof (GValue));
	g_value_init (&_data_->_tmp48_, G_TYPE_STRING);
	_data_->_tmp49_ = _data_->_tmp48_;
	_data_->_tmp50_ = _data_->_tmp49_;
	_data_->_tmp51_ = __g_value_dup0 (&_data_->_tmp50_);
	_data_->_tmp52_ = _data_->_tmp51_;
	G_IS_VALUE (&_data_->_tmp50_) ? (g_value_unset (&_data_->_tmp50_), NULL) : NULL;
	_data_->v4 = _data_->_tmp52_;
	_data_->_tmp53_ = _data_->v4;
	_data_->_tmp54_ = _data_->self->priv->_persona_fullname_2;
	g_value_set_string (_data_->_tmp53_, _data_->_tmp54_);
	_data_->_tmp55_ = _data_->details2;
	_data_->_tmp56_ = g_strdup ("full-name");
	_data_->_tmp57_ = _data_->v4;
	_data_->v4 = NULL;
	g_hash_table_insert (_data_->_tmp55_, _data_->_tmp56_, _data_->_tmp57_);
	{
		_data_->_tmp58_ = _data_->self->priv->_aggregator;
		_data_->_tmp59_ = _data_->pstore;
		_data_->_tmp60_ = _data_->details1;
		_data_->_state_ = 1;
		folks_individual_aggregator_add_persona_from_details (_data_->_tmp58_, NULL, _data_->_tmp59_, _data_->_tmp60_, _link_personas_tests_add_personas_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp61_ = NULL;
		_data_->_tmp61_ = folks_individual_aggregator_add_persona_from_details_finish (_data_->_tmp58_, _data_->_res_, &_data_->_inner_error_);
		_data_->_tmp62_ = _data_->_tmp61_;
		_g_object_unref0 (_data_->_tmp62_);
		if (_data_->_inner_error_ != NULL) {
			if (_data_->_inner_error_->domain == FOLKS_INDIVIDUAL_AGGREGATOR_ERROR) {
				goto __catch3_folks_individual_aggregator_error;
			}
			__vala_GValue_free0 (_data_->v4);
			_g_object_unref0 (_data_->im_addrs2);
			__vala_GValue_free0 (_data_->v3);
			_g_hash_table_unref0 (_data_->details2);
			__vala_GValue_free0 (_data_->v2);
			_g_object_unref0 (_data_->im_addrs1);
			__vala_GValue_free0 (_data_->v1);
			_g_hash_table_unref0 (_data_->details1);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
			g_clear_error (&_data_->_inner_error_);
			return FALSE;
		}
		_data_->_tmp63_ = _data_->self->priv->_aggregator;
		_data_->_tmp64_ = _data_->pstore;
		_data_->_tmp65_ = _data_->details2;
		_data_->_state_ = 2;
		folks_individual_aggregator_add_persona_from_details (_data_->_tmp63_, NULL, _data_->_tmp64_, _data_->_tmp65_, _link_personas_tests_add_personas_ready, _data_);
		return FALSE;
		_state_2:
		_data_->_tmp66_ = NULL;
		_data_->_tmp66_ = folks_individual_aggregator_add_persona_from_details_finish (_data_->_tmp63_, _data_->_res_, &_data_->_inner_error_);
		_data_->_tmp67_ = _data_->_tmp66_;
		_g_object_unref0 (_data_->_tmp67_);
		if (_data_->_inner_error_ != NULL) {
			if (_data_->_inner_error_->domain == FOLKS_INDIVIDUAL_AGGREGATOR_ERROR) {
				goto __catch3_folks_individual_aggregator_error;
			}
			__vala_GValue_free0 (_data_->v4);
			_g_object_unref0 (_data_->im_addrs2);
			__vala_GValue_free0 (_data_->v3);
			_g_hash_table_unref0 (_data_->details2);
			__vala_GValue_free0 (_data_->v2);
			_g_object_unref0 (_data_->im_addrs1);
			__vala_GValue_free0 (_data_->v1);
			_g_hash_table_unref0 (_data_->details1);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
			g_clear_error (&_data_->_inner_error_);
			return FALSE;
		}
	}
	goto __finally3;
	__catch3_folks_individual_aggregator_error:
	{
		_data_->e = _data_->_inner_error_;
		_data_->_inner_error_ = NULL;
		_data_->_tmp68_ = _data_->e;
		_data_->_tmp69_ = _data_->_tmp68_->message;
		g_warning ("link-personas.vala:206: [AddPersonaError] add_persona_from_details: %s" \
"\n", _data_->_tmp69_);
		_g_error_free0 (_data_->e);
	}
	__finally3:
	if (_data_->_inner_error_ != NULL) {
		__vala_GValue_free0 (_data_->v4);
		_g_object_unref0 (_data_->im_addrs2);
		__vala_GValue_free0 (_data_->v3);
		_g_hash_table_unref0 (_data_->details2);
		__vala_GValue_free0 (_data_->v2);
		_g_object_unref0 (_data_->im_addrs1);
		__vala_GValue_free0 (_data_->v1);
		_g_hash_table_unref0 (_data_->details1);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
		g_clear_error (&_data_->_inner_error_);
		return FALSE;
	}
	__vala_GValue_free0 (_data_->v4);
	_g_object_unref0 (_data_->im_addrs2);
	__vala_GValue_free0 (_data_->v3);
	_g_hash_table_unref0 (_data_->details2);
	__vala_GValue_free0 (_data_->v2);
	_g_object_unref0 (_data_->im_addrs1);
	__vala_GValue_free0 (_data_->v1);
	_g_hash_table_unref0 (_data_->details1);
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


static void __link_personas_tests_notify_cb_g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self) {
	_link_personas_tests_notify_cb (self, _sender, pspec);
}


static void _link_personas_tests_individuals_changed_cb (LinkPersonasTests* self, GeeSet* added, GeeSet* removed, const gchar* message, FolksPersona* actor, FolksGroupDetailsChangeReason reason) {
	GeeSet* _tmp12_;
	gint _tmp13_;
	gint _tmp14_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (added != NULL);
	g_return_if_fail (removed != NULL);
	{
		GeeSet* _tmp0_;
		GeeIterator* _tmp1_ = NULL;
		GeeIterator* _i_it;
		_tmp0_ = added;
		_tmp1_ = gee_iterable_iterator ((GeeIterable*) _tmp0_);
		_i_it = _tmp1_;
		while (TRUE) {
			GeeIterator* _tmp2_;
			gboolean _tmp3_ = FALSE;
			GeeIterator* _tmp4_;
			gpointer _tmp5_ = NULL;
			FolksIndividual* i;
			FolksIndividual* _tmp6_;
			gboolean _tmp7_;
			gboolean _tmp8_;
			_tmp2_ = _i_it;
			_tmp3_ = gee_iterator_next (_tmp2_);
			if (!_tmp3_) {
				break;
			}
			_tmp4_ = _i_it;
			_tmp5_ = gee_iterator_get (_tmp4_);
			i = (FolksIndividual*) _tmp5_;
			_tmp6_ = i;
			_tmp7_ = folks_individual_get_is_user (_tmp6_);
			_tmp8_ = _tmp7_;
			if (!_tmp8_) {
				FolksIndividual* _tmp9_;
				FolksIndividual* _tmp10_;
				FolksIndividual* _tmp11_;
				_tmp9_ = i;
				_link_personas_tests_check_personas (self, _tmp9_);
				_tmp10_ = i;
				g_signal_connect_object ((GObject*) _tmp10_, "notify::full-name", (GCallback) __link_personas_tests_notify_cb_g_object_notify, self, 0);
				_tmp11_ = i;
				g_signal_connect_object ((GObject*) _tmp11_, "notify::im-addresses", (GCallback) __link_personas_tests_notify_cb_g_object_notify, self, 0);
			}
			_g_object_unref0 (i);
		}
		_g_object_unref0 (_i_it);
	}
	_tmp12_ = removed;
	_tmp13_ = gee_collection_get_size ((GeeCollection*) _tmp12_);
	_tmp14_ = _tmp13_;
	if (_tmp14_ > 0) {
		gint _tmp15_;
		GeeSet* _tmp16_;
		gint _tmp17_;
		gint _tmp18_;
		_tmp15_ = self->priv->_removed_individuals;
		_tmp16_ = removed;
		_tmp17_ = gee_collection_get_size ((GeeCollection*) _tmp16_);
		_tmp18_ = _tmp17_;
		self->priv->_removed_individuals = _tmp15_ + ((gint) _tmp18_);
	}
}


static void _link_personas_tests_notify_cb (LinkPersonasTests* self, GObject* individual_obj, GParamSpec* ps) {
	GObject* _tmp0_;
	FolksIndividual* _tmp1_;
	FolksIndividual* i;
	FolksIndividual* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (individual_obj != NULL);
	g_return_if_fail (ps != NULL);
	_tmp0_ = individual_obj;
	_tmp1_ = _g_object_ref0 (FOLKS_INDIVIDUAL (_tmp0_));
	i = _tmp1_;
	_tmp2_ = i;
	_link_personas_tests_check_personas (self, _tmp2_);
	_g_object_unref0 (i);
}


static gboolean _lambda0_ (LinkPersonasTests* self) {
	gboolean result = FALSE;
	FolksIndividualAggregator* _tmp0_;
	GeeHashSet* _tmp1_;
	_tmp0_ = self->priv->_aggregator;
	_tmp1_ = self->priv->_personas;
	folks_individual_aggregator_link_personas (_tmp0_, (GeeSet*) _tmp1_, NULL, NULL);
	result = FALSE;
	return result;
}


static gboolean __lambda0__gsource_func (gpointer self) {
	gboolean result;
	result = _lambda0_ (self);
	return result;
}


static void _link_personas_tests_check_personas (LinkPersonasTests* self, FolksIndividual* i) {
	FolksPersona* first_persona;
	gboolean _tmp10_ = FALSE;
	FolksIndividual* _tmp11_;
	const gchar* _tmp12_;
	const gchar* _tmp13_;
	const gchar* _tmp14_;
	gboolean _tmp16_;
	gboolean _tmp83_ = FALSE;
	GeeHashSet* _tmp84_;
	gint _tmp85_;
	gint _tmp86_;
	gboolean _tmp88_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (i != NULL);
	first_persona = NULL;
	{
		FolksIndividual* _tmp0_;
		GeeSet* _tmp1_;
		GeeSet* _tmp2_;
		GeeIterator* _tmp3_ = NULL;
		GeeIterator* _p_it;
		_tmp0_ = i;
		_tmp1_ = folks_individual_get_personas (_tmp0_);
		_tmp2_ = _tmp1_;
		_tmp3_ = gee_iterable_iterator ((GeeIterable*) _tmp2_);
		_p_it = _tmp3_;
		while (TRUE) {
			GeeIterator* _tmp4_;
			gboolean _tmp5_ = FALSE;
			GeeIterator* _tmp6_;
			gpointer _tmp7_ = NULL;
			FolksPersona* p;
			FolksPersona* _tmp8_;
			FolksPersona* _tmp9_;
			_tmp4_ = _p_it;
			_tmp5_ = gee_iterator_next (_tmp4_);
			if (!_tmp5_) {
				break;
			}
			_tmp6_ = _p_it;
			_tmp7_ = gee_iterator_get (_tmp6_);
			p = (FolksPersona*) _tmp7_;
			_tmp8_ = p;
			_tmp9_ = _g_object_ref0 (_tmp8_);
			_g_object_unref0 (first_persona);
			first_persona = _tmp9_;
			_g_object_unref0 (p);
			break;
		}
		_g_object_unref0 (_p_it);
	}
	_tmp11_ = i;
	_tmp12_ = folks_name_details_get_full_name ((FolksNameDetails*) _tmp11_);
	_tmp13_ = _tmp12_;
	_tmp14_ = self->priv->_persona_fullname_1;
	if (g_strcmp0 (_tmp13_, _tmp14_) == 0) {
		const gchar* _tmp15_;
		_tmp15_ = self->priv->_persona_iid_1;
		_tmp10_ = g_strcmp0 (_tmp15_, "") == 0;
	} else {
		_tmp10_ = FALSE;
	}
	_tmp16_ = _tmp10_;
	if (_tmp16_) {
		FolksPersona* _tmp17_;
		const gchar* _tmp18_;
		const gchar* _tmp19_;
		gchar* _tmp20_;
		GeeHashSet* _tmp21_;
		FolksPersona* _tmp22_;
		_tmp17_ = first_persona;
		_tmp18_ = folks_persona_get_iid (_tmp17_);
		_tmp19_ = _tmp18_;
		_tmp20_ = g_strdup (_tmp19_);
		_g_free0 (self->priv->_persona_iid_1);
		self->priv->_persona_iid_1 = _tmp20_;
		_tmp21_ = self->priv->_personas;
		_tmp22_ = first_persona;
		gee_abstract_collection_add ((GeeAbstractCollection*) _tmp21_, _tmp22_);
	} else {
		gboolean _tmp23_ = FALSE;
		FolksIndividual* _tmp24_;
		const gchar* _tmp25_;
		const gchar* _tmp26_;
		const gchar* _tmp27_;
		gboolean _tmp29_;
		_tmp24_ = i;
		_tmp25_ = folks_name_details_get_full_name ((FolksNameDetails*) _tmp24_);
		_tmp26_ = _tmp25_;
		_tmp27_ = self->priv->_persona_fullname_2;
		if (g_strcmp0 (_tmp26_, _tmp27_) == 0) {
			const gchar* _tmp28_;
			_tmp28_ = self->priv->_persona_iid_2;
			_tmp23_ = g_strcmp0 (_tmp28_, "") == 0;
		} else {
			_tmp23_ = FALSE;
		}
		_tmp29_ = _tmp23_;
		if (_tmp29_) {
			FolksPersona* _tmp30_;
			const gchar* _tmp31_;
			const gchar* _tmp32_;
			gchar* _tmp33_;
			GeeHashSet* _tmp34_;
			FolksPersona* _tmp35_;
			_tmp30_ = first_persona;
			_tmp31_ = folks_persona_get_iid (_tmp30_);
			_tmp32_ = _tmp31_;
			_tmp33_ = g_strdup (_tmp32_);
			_g_free0 (self->priv->_persona_iid_2);
			self->priv->_persona_iid_2 = _tmp33_;
			_tmp34_ = self->priv->_personas;
			_tmp35_ = first_persona;
			gee_abstract_collection_add ((GeeAbstractCollection*) _tmp34_, _tmp35_);
		} else {
			FolksIndividual* _tmp36_;
			GeeSet* _tmp37_;
			GeeSet* _tmp38_;
			gint _tmp39_;
			gint _tmp40_;
			_tmp36_ = i;
			_tmp37_ = folks_individual_get_personas (_tmp36_);
			_tmp38_ = _tmp37_;
			_tmp39_ = gee_collection_get_size ((GeeCollection*) _tmp38_);
			_tmp40_ = _tmp39_;
			if (_tmp40_ > 1) {
				GeeHashMap* _tmp79_;
				gint _tmp80_;
				gint _tmp81_;
				{
					FolksIndividual* _tmp41_;
					GeeMultiMap* _tmp42_;
					GeeMultiMap* _tmp43_;
					GeeSet* _tmp44_ = NULL;
					GeeSet* _tmp45_;
					GeeIterator* _tmp46_ = NULL;
					GeeIterator* _tmp47_;
					GeeIterator* _proto_it;
					_tmp41_ = i;
					_tmp42_ = folks_im_details_get_im_addresses ((FolksImDetails*) _tmp41_);
					_tmp43_ = _tmp42_;
					_tmp44_ = gee_multi_map_get_keys (_tmp43_);
					_tmp45_ = _tmp44_;
					_tmp46_ = gee_iterable_iterator ((GeeIterable*) _tmp45_);
					_tmp47_ = _tmp46_;
					_g_object_unref0 (_tmp45_);
					_proto_it = _tmp47_;
					while (TRUE) {
						GeeIterator* _tmp48_;
						gboolean _tmp49_ = FALSE;
						GeeIterator* _tmp50_;
						gpointer _tmp51_ = NULL;
						gchar* proto;
						FolksIndividual* _tmp52_;
						GeeMultiMap* _tmp53_;
						GeeMultiMap* _tmp54_;
						const gchar* _tmp55_;
						GeeCollection* _tmp56_ = NULL;
						GeeCollection* addrs;
						_tmp48_ = _proto_it;
						_tmp49_ = gee_iterator_next (_tmp48_);
						if (!_tmp49_) {
							break;
						}
						_tmp50_ = _proto_it;
						_tmp51_ = gee_iterator_get (_tmp50_);
						proto = (gchar*) _tmp51_;
						_tmp52_ = i;
						_tmp53_ = folks_im_details_get_im_addresses ((FolksImDetails*) _tmp52_);
						_tmp54_ = _tmp53_;
						_tmp55_ = proto;
						_tmp56_ = gee_multi_map_get (_tmp54_, _tmp55_);
						addrs = _tmp56_;
						{
							GeeCollection* _tmp57_;
							GeeIterator* _tmp58_ = NULL;
							GeeIterator* _a_it;
							_tmp57_ = addrs;
							_tmp58_ = gee_iterable_iterator ((GeeIterable*) _tmp57_);
							_a_it = _tmp58_;
							while (TRUE) {
								GeeIterator* _tmp59_;
								gboolean _tmp60_ = FALSE;
								GeeIterator* _tmp61_;
								gpointer _tmp62_ = NULL;
								FolksImFieldDetails* a;
								FolksImFieldDetails* _tmp63_;
								gconstpointer _tmp64_;
								const gchar* _tmp65_;
								GeeHashMap* _tmp66_;
								gpointer _tmp67_ = NULL;
								gchar* _tmp68_;
								gboolean _tmp69_;
								_tmp59_ = _a_it;
								_tmp60_ = gee_iterator_next (_tmp59_);
								if (!_tmp60_) {
									break;
								}
								_tmp61_ = _a_it;
								_tmp62_ = gee_iterator_get (_tmp61_);
								a = (FolksImFieldDetails*) _tmp62_;
								_tmp63_ = a;
								_tmp64_ = folks_abstract_field_details_get_value ((FolksAbstractFieldDetails*) _tmp63_);
								_tmp65_ = _tmp64_;
								_tmp66_ = self->priv->_linking_props;
								_tmp67_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp66_, "prop1");
								_tmp68_ = (gchar*) _tmp67_;
								_tmp69_ = g_strcmp0 ((const gchar*) _tmp65_, _tmp68_) == 0;
								_g_free0 (_tmp68_);
								if (_tmp69_) {
									GeeHashMap* _tmp70_;
									_tmp70_ = self->priv->_linking_props;
									gee_abstract_map_unset ((GeeAbstractMap*) _tmp70_, "prop1", NULL);
								} else {
									FolksImFieldDetails* _tmp71_;
									gconstpointer _tmp72_;
									const gchar* _tmp73_;
									GeeHashMap* _tmp74_;
									gpointer _tmp75_ = NULL;
									gchar* _tmp76_;
									gboolean _tmp77_;
									_tmp71_ = a;
									_tmp72_ = folks_abstract_field_details_get_value ((FolksAbstractFieldDetails*) _tmp71_);
									_tmp73_ = _tmp72_;
									_tmp74_ = self->priv->_linking_props;
									_tmp75_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp74_, "prop2");
									_tmp76_ = (gchar*) _tmp75_;
									_tmp77_ = g_strcmp0 ((const gchar*) _tmp73_, _tmp76_) == 0;
									_g_free0 (_tmp76_);
									if (_tmp77_) {
										GeeHashMap* _tmp78_;
										_tmp78_ = self->priv->_linking_props;
										gee_abstract_map_unset ((GeeAbstractMap*) _tmp78_, "prop2", NULL);
									}
								}
								_g_object_unref0 (a);
							}
							_g_object_unref0 (_a_it);
						}
						_g_object_unref0 (addrs);
						_g_free0 (proto);
					}
					_g_object_unref0 (_proto_it);
				}
				_tmp79_ = self->priv->_linking_props;
				_tmp80_ = gee_map_get_size ((GeeMap*) _tmp79_);
				_tmp81_ = _tmp80_;
				if (_tmp81_ == 0) {
					GMainLoop* _tmp82_;
					_tmp82_ = self->priv->_main_loop;
					g_main_loop_quit (_tmp82_);
				}
			}
		}
	}
	_tmp84_ = self->priv->_personas;
	_tmp85_ = gee_collection_get_size ((GeeCollection*) _tmp84_);
	_tmp86_ = _tmp85_;
	if (_tmp86_ == 2) {
		gboolean _tmp87_;
		_tmp87_ = self->priv->_linking_fired;
		_tmp83_ = _tmp87_ == FALSE;
	} else {
		_tmp83_ = FALSE;
	}
	_tmp88_ = _tmp83_;
	if (_tmp88_) {
		self->priv->_linking_fired = TRUE;
		g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, (guint) 2, __lambda0__gsource_func, g_object_ref (self), g_object_unref);
	}
	_g_object_unref0 (first_persona);
}


static void link_personas_tests_class_init (LinkPersonasTestsClass * klass) {
	link_personas_tests_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (LinkPersonasTestsPrivate));
	FOLKS_TEST_CASE_CLASS (klass)->set_up = link_personas_tests_real_set_up;
	FOLKS_TEST_CASE_CLASS (klass)->tear_down = link_personas_tests_real_tear_down;
	G_OBJECT_CLASS (klass)->finalize = link_personas_tests_finalize;
}


static void link_personas_tests_instance_init (LinkPersonasTests * self) {
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	self->priv = LINK_PERSONAS_TESTS_GET_PRIVATE (self);
	_tmp0_ = g_strdup ("jabber");
	self->priv->_proto = _tmp0_;
	_tmp1_ = g_strdup ("someone-1@jabber.example.org");
	self->priv->_im_address_1 = _tmp1_;
	_tmp2_ = g_strdup ("someone-2@jabber.example.org");
	self->priv->_im_address_2 = _tmp2_;
	_tmp3_ = g_strdup ("");
	self->priv->_persona_iid_1 = _tmp3_;
	_tmp4_ = g_strdup ("");
	self->priv->_persona_iid_2 = _tmp4_;
	self->priv->_removed_individuals = 0;
	_tmp5_ = g_strdup ("/system/folks/backends/primary_store");
	self->priv->_folks_config_key = _tmp5_;
}


static void link_personas_tests_finalize (GObject* obj) {
	LinkPersonasTests * self;
	self = LINK_PERSONAS_TESTS (obj);
	_g_main_loop_unref0 (self->priv->_main_loop);
	_tracker_test_backend_unref0 (self->priv->_tracker_backend);
	_g_object_unref0 (self->priv->_aggregator);
	_g_free0 (self->priv->_persona_fullname_1);
	_g_free0 (self->priv->_persona_fullname_2);
	_g_free0 (self->priv->_proto);
	_g_free0 (self->priv->_im_address_1);
	_g_free0 (self->priv->_im_address_2);
	_g_free0 (self->priv->_persona_iid_1);
	_g_free0 (self->priv->_persona_iid_2);
	_g_object_unref0 (self->priv->_personas);
	_g_free0 (self->priv->_folks_config_key);
	_g_object_unref0 (self->priv->_linking_props);
	G_OBJECT_CLASS (link_personas_tests_parent_class)->finalize (obj);
}


GType link_personas_tests_get_type (void) {
	static volatile gsize link_personas_tests_type_id__volatile = 0;
	if (g_once_init_enter (&link_personas_tests_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (LinkPersonasTestsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) link_personas_tests_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (LinkPersonasTests), 0, (GInstanceInitFunc) link_personas_tests_instance_init, NULL };
		GType link_personas_tests_type_id;
		link_personas_tests_type_id = g_type_register_static (FOLKS_TYPE_TEST_CASE, "LinkPersonasTests", &g_define_type_info, 0);
		g_once_init_leave (&link_personas_tests_type_id__volatile, link_personas_tests_type_id);
	}
	return link_personas_tests_type_id__volatile;
}


gint _vala_main (gchar** args, int args_length1) {
	gint result = 0;
	GTestSuite* _tmp0_ = NULL;
	GTestSuite* root;
	GTestSuite* _tmp1_;
	LinkPersonasTests* _tmp2_;
	LinkPersonasTests* _tmp3_;
	GTestSuite* _tmp4_ = NULL;
	g_test_init (&args_length1, &args, NULL);
	_tmp0_ = g_test_get_root ();
	root = _tmp0_;
	_tmp1_ = root;
	_tmp2_ = link_personas_tests_new ();
	_tmp3_ = _tmp2_;
	_tmp4_ = folks_test_case_get_suite ((FolksTestCase*) _tmp3_);
	g_test_suite_add_suite (_tmp1_, _tmp4_);
	_g_object_unref0 (_tmp3_);
	g_test_run ();
	result = 0;
	return result;
}


int main (int argc, char ** argv) {
	g_type_init ();
	return _vala_main (argv, argc);
}



