/* remove-persona.c generated by valac 0.13.1.106-1068, the Vala compiler
 * generated from remove-persona.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 <gio/gio.h>
#include <gee.h>


#define TYPE_REMOVE_PERSONA_TESTS (remove_persona_tests_get_type ())
#define REMOVE_PERSONA_TESTS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_REMOVE_PERSONA_TESTS, RemovePersonaTests))
#define REMOVE_PERSONA_TESTS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_REMOVE_PERSONA_TESTS, RemovePersonaTestsClass))
#define IS_REMOVE_PERSONA_TESTS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_REMOVE_PERSONA_TESTS))
#define IS_REMOVE_PERSONA_TESTS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_REMOVE_PERSONA_TESTS))
#define REMOVE_PERSONA_TESTS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_REMOVE_PERSONA_TESTS, RemovePersonaTestsClass))

typedef struct _RemovePersonaTests RemovePersonaTests;
typedef struct _RemovePersonaTestsClass RemovePersonaTestsClass;
typedef struct _RemovePersonaTestsPrivate RemovePersonaTestsPrivate;
#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 _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _RemovePersonaTestsTestRemovePersonaAsyncData RemovePersonaTestsTestRemovePersonaAsyncData;
#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 _RemovePersonaTestsAddPersonaData RemovePersonaTestsAddPersonaData;

struct _RemovePersonaTests {
	FolksTestCase parent_instance;
	RemovePersonaTestsPrivate * priv;
};

struct _RemovePersonaTestsClass {
	FolksTestCaseClass parent_class;
};

struct _RemovePersonaTestsPrivate {
	GMainLoop* _main_loop;
	TrackerTestBackend* _tracker_backend;
	FolksIndividualAggregator* _aggregator;
	gchar* _persona_fullname;
	gboolean _persona_removed;
	gboolean _individual_removed;
	gchar* _individual_id;
	FolksPersonaStore* _pstore;
	gchar* _persona_id;
	FolksIndividual* _individual;
	gboolean _added_persona;
};

struct _RemovePersonaTestsTestRemovePersonaAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	RemovePersonaTests* self;
	FolksBackendStore* _tmp0_;
	FolksBackendStore* store;
	FolksBackendStore* _tmp1_;
	FolksIndividualAggregator* _tmp2_;
	FolksIndividualAggregator* _tmp3_;
	FolksIndividualAggregator* _tmp4_;
	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 _RemovePersonaTestsAddPersonaData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	RemovePersonaTests* self;
	GHashFunc _tmp0_;
	GEqualFunc _tmp1_;
	GHashTable* _tmp2_;
	GHashTable* details;
	GValue _tmp3_;
	GValue _tmp4_;
	GValue _tmp5_;
	GValue* _tmp6_;
	GValue* _tmp7_;
	GValue* v1;
	GValue* _tmp8_;
	const gchar* _tmp9_;
	GHashTable* _tmp10_;
	const gchar* _tmp11_;
	gchar* _tmp12_;
	GValue* _tmp13_;
	GValue _tmp14_;
	GValue _tmp15_;
	GValue _tmp16_;
	GValue* _tmp17_;
	GValue* _tmp18_;
	GValue* v2;
	GeeHashSet* _tmp19_;
	GeeHashSet* emails;
	FolksEmailFieldDetails* _tmp20_;
	FolksEmailFieldDetails* email_1;
	GeeHashSet* _tmp21_;
	FolksEmailFieldDetails* _tmp22_;
	FolksEmailFieldDetails* _tmp23_;
	FolksEmailFieldDetails* email_2;
	GeeHashSet* _tmp24_;
	FolksEmailFieldDetails* _tmp25_;
	GValue* _tmp26_;
	GeeHashSet* _tmp27_;
	GHashTable* _tmp28_;
	const gchar* _tmp29_;
	gchar* _tmp30_;
	GValue* _tmp31_;
	FolksIndividualAggregator* _tmp32_;
	FolksPersonaStore* _tmp33_;
	GHashTable* _tmp34_;
	FolksPersona* _tmp35_;
	FolksPersona* _tmp36_;
	GError* e;
	GError* _tmp37_;
	const gchar* _tmp38_;
	GError * _inner_error_;
};


static gpointer remove_persona_tests_parent_class = NULL;

GType remove_persona_tests_get_type (void) G_GNUC_CONST;
#define REMOVE_PERSONA_TESTS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_REMOVE_PERSONA_TESTS, RemovePersonaTestsPrivate))
enum  {
	REMOVE_PERSONA_TESTS_DUMMY_PROPERTY
};
RemovePersonaTests* remove_persona_tests_new (void);
RemovePersonaTests* remove_persona_tests_construct (GType object_type);
void remove_persona_tests_test_remove_persona (RemovePersonaTests* self);
static void _remove_persona_tests_test_remove_persona_folks_test_case_test_method (gpointer self);
static void remove_persona_tests_real_set_up (FolksTestCase* base);
static void remove_persona_tests_real_tear_down (FolksTestCase* base);
static void _remove_persona_tests_test_remove_persona_async (RemovePersonaTests* self, GAsyncReadyCallback _callback_, gpointer _user_data_);
static void _remove_persona_tests_test_remove_persona_finish (RemovePersonaTests* self, GAsyncResult* _res_);
static gboolean _lambda0_ (RemovePersonaTests* self);
static gboolean __lambda0__gsource_func (gpointer self);
static void _remove_persona_tests_test_remove_persona_async_data_free (gpointer _data);
static gboolean _remove_persona_tests_test_remove_persona_async_co (RemovePersonaTestsTestRemovePersonaAsyncData* _data_);
static void _remove_persona_tests_test_remove_persona_async_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
static void _remove_persona_tests_individuals_changed_cb (RemovePersonaTests* self, GeeSet* added, GeeSet* removed, const gchar* message, FolksPersona* actor, FolksGroupDetailsChangeReason reason);
static void __remove_persona_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 _remove_persona_tests_notify_pstore_cb (RemovePersonaTests* self, GObject* _pstore, GParamSpec* ps);
static void __remove_persona_tests_notify_pstore_cb_g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self);
static void _remove_persona_tests_try_to_add (RemovePersonaTests* self);
static void _remove_persona_tests_add_persona (RemovePersonaTests* self, GAsyncReadyCallback _callback_, gpointer _user_data_);
static void _remove_persona_tests_add_persona_finish (RemovePersonaTests* self, GAsyncResult* _res_);
static void _remove_persona_tests_add_persona_data_free (gpointer _data);
static gboolean _remove_persona_tests_add_persona_co (RemovePersonaTestsAddPersonaData* _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 _remove_persona_tests_add_persona_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
static void _remove_persona_tests_personas_cb (RemovePersonaTests* self);
static void __remove_persona_tests_personas_cb_folks_persona_store_personas_changed (FolksPersonaStore* _sender, GeeSet* added, GeeSet* removed, const gchar* message, FolksPersona* actor, FolksGroupDetailsChangeReason reason, gpointer self);
static void remove_persona_tests_finalize (GObject* obj);
gint _vala_main (gchar** args, int args_length1);


static void _remove_persona_tests_test_remove_persona_folks_test_case_test_method (gpointer self) {
	remove_persona_tests_test_remove_persona (self);
}


RemovePersonaTests* remove_persona_tests_construct (GType object_type) {
	RemovePersonaTests * self = NULL;
	TrackerTestBackend* _tmp0_;
	self = (RemovePersonaTests*) folks_test_case_construct (object_type, "RemovePersonaTests");
	_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 adding personas to Tracker ", _remove_persona_tests_test_remove_persona_folks_test_case_test_method, self);
	return self;
}


RemovePersonaTests* remove_persona_tests_new (void) {
	return remove_persona_tests_construct (TYPE_REMOVE_PERSONA_TESTS);
}


static void remove_persona_tests_real_set_up (FolksTestCase* base) {
	RemovePersonaTests * self;
	self = (RemovePersonaTests*) base;
}


static void remove_persona_tests_real_tear_down (FolksTestCase* base) {
	RemovePersonaTests * self;
	self = (RemovePersonaTests*) base;
}


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


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


void remove_persona_tests_test_remove_persona (RemovePersonaTests* self) {
	GMainLoop* _tmp0_;
	gchar* _tmp1_;
	GMainLoop* _tmp2_;
	gboolean _tmp3_;
	gboolean _tmp4_;
	TrackerTestBackend* _tmp5_;
	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);
	self->priv->_persona_fullname = _tmp1_;
	self->priv->_persona_removed = FALSE;
	self->priv->_individual_removed = FALSE;
	_remove_persona_tests_test_remove_persona_async (self, NULL, NULL);
	g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, (guint) 5, __lambda0__gsource_func, g_object_ref (self), g_object_unref);
	_tmp2_ = self->priv->_main_loop;
	g_main_loop_run (_tmp2_);
	_tmp3_ = self->priv->_persona_removed;
	g_assert (_tmp3_ == TRUE);
	_tmp4_ = self->priv->_individual_removed;
	g_assert (_tmp4_ == TRUE);
	_tmp5_ = self->priv->_tracker_backend;
	tracker_test_backend_tear_down (_tmp5_);
}


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


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


static void _remove_persona_tests_test_remove_persona_async (RemovePersonaTests* self, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	RemovePersonaTestsTestRemovePersonaAsyncData* _data_;
	RemovePersonaTests* _tmp0_;
	_data_ = g_slice_new0 (RemovePersonaTestsTestRemovePersonaAsyncData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, _remove_persona_tests_test_remove_persona_async);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, _remove_persona_tests_test_remove_persona_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_remove_persona_tests_test_remove_persona_async_co (_data_);
}


static void _remove_persona_tests_test_remove_persona_finish (RemovePersonaTests* self, GAsyncResult* _res_) {
	RemovePersonaTestsTestRemovePersonaAsyncData* _data_;
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
}


static void _remove_persona_tests_test_remove_persona_async_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	RemovePersonaTestsTestRemovePersonaAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	_remove_persona_tests_test_remove_persona_async_co (_data_);
}


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


static void __remove_persona_tests_notify_pstore_cb_g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self) {
	_remove_persona_tests_notify_pstore_cb (self, _sender, pspec);
}


static gboolean _remove_persona_tests_test_remove_persona_async_co (RemovePersonaTestsTestRemovePersonaAsyncData* _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_ = NULL;
	_data_->_tmp0_ = folks_backend_store_dup ();
	_data_->store = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->store;
	_data_->_state_ = 1;
	folks_backend_store_prepare (_data_->_tmp1_, _remove_persona_tests_test_remove_persona_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) __remove_persona_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_, _remove_persona_tests_test_remove_persona_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 __catch0_g_error;
		}
		_g_object_unref0 (_data_->self->priv->_pstore);
		_data_->self->priv->_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_->self->priv->_pstore);
				_data_->self->priv->_pstore = (FolksPersonaStore*) _data_->_tmp20_;
				_data_->_tmp21_ = _data_->self->priv->_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_->self->priv->_pstore;
		g_assert (_data_->_tmp22_ != NULL);
		_data_->_tmp23_ = _data_->self->priv->_pstore;
		g_signal_connect_object ((GObject*) _data_->_tmp23_, "notify::is-prepared", (GCallback) __remove_persona_tests_notify_pstore_cb_g_object_notify, _data_->self, 0);
		_remove_persona_tests_try_to_add (_data_->self);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error_;
		_data_->_inner_error_ = NULL;
		_data_->_tmp24_ = _data_->e;
		_data_->_tmp25_ = _data_->_tmp24_->message;
		g_warning ("remove-persona.vala:106: Error when calling prepare: %s\n", _data_->_tmp25_);
		_g_error_free0 (_data_->e);
	}
	__finally0:
	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 _remove_persona_tests_notify_pstore_cb (RemovePersonaTests* self, GObject* _pstore, GParamSpec* ps) {
	g_return_if_fail (self != NULL);
	g_return_if_fail (_pstore != NULL);
	g_return_if_fail (ps != NULL);
	_remove_persona_tests_try_to_add (self);
}


static void _remove_persona_tests_try_to_add (RemovePersonaTests* self) {
	gboolean _tmp0_ = FALSE;
	FolksPersonaStore* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	gboolean _tmp5_;
	g_return_if_fail (self != NULL);
	_tmp1_ = self->priv->_pstore;
	_tmp2_ = folks_persona_store_get_is_prepared (_tmp1_);
	_tmp3_ = _tmp2_;
	if (_tmp3_) {
		gboolean _tmp4_;
		_tmp4_ = self->priv->_added_persona;
		_tmp0_ = _tmp4_ == FALSE;
	} else {
		_tmp0_ = FALSE;
	}
	_tmp5_ = _tmp0_;
	if (_tmp5_) {
		self->priv->_added_persona = TRUE;
		_remove_persona_tests_add_persona (self, NULL, NULL);
	}
}


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


static void _remove_persona_tests_add_persona (RemovePersonaTests* self, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	RemovePersonaTestsAddPersonaData* _data_;
	RemovePersonaTests* _tmp0_;
	_data_ = g_slice_new0 (RemovePersonaTestsAddPersonaData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, _remove_persona_tests_add_persona);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, _remove_persona_tests_add_persona_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_remove_persona_tests_add_persona_co (_data_);
}


static void _remove_persona_tests_add_persona_finish (RemovePersonaTests* self, GAsyncResult* _res_) {
	RemovePersonaTestsAddPersonaData* _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 _remove_persona_tests_add_persona_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	RemovePersonaTestsAddPersonaData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	_remove_persona_tests_add_persona_co (_data_);
}


static gboolean _remove_persona_tests_add_persona_co (RemovePersonaTestsAddPersonaData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		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_->details = _data_->_tmp2_;
	memset (&_data_->_tmp3_, 0, sizeof (GValue));
	g_value_init (&_data_->_tmp3_, G_TYPE_STRING);
	_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_ = _data_->v1;
	_data_->_tmp9_ = _data_->self->priv->_persona_fullname;
	g_value_set_string (_data_->_tmp8_, _data_->_tmp9_);
	_data_->_tmp10_ = _data_->details;
	_data_->_tmp11_ = NULL;
	_data_->_tmp11_ = folks_persona_store_detail_key (FOLKS_PERSONA_DETAIL_FULL_NAME);
	_data_->_tmp12_ = g_strdup (_data_->_tmp11_);
	_data_->_tmp13_ = _data_->v1;
	_data_->v1 = NULL;
	g_hash_table_insert (_data_->_tmp10_, _data_->_tmp12_, _data_->_tmp13_);
	memset (&_data_->_tmp14_, 0, sizeof (GValue));
	g_value_init (&_data_->_tmp14_, GEE_TYPE_SET);
	_data_->_tmp15_ = _data_->_tmp14_;
	_data_->_tmp16_ = _data_->_tmp15_;
	_data_->_tmp17_ = __g_value_dup0 (&_data_->_tmp16_);
	_data_->_tmp18_ = _data_->_tmp17_;
	G_IS_VALUE (&_data_->_tmp16_) ? (g_value_unset (&_data_->_tmp16_), NULL) : NULL;
	_data_->v2 = _data_->_tmp18_;
	_data_->_tmp19_ = gee_hash_set_new (FOLKS_TYPE_EMAIL_FIELD_DETAILS, (GBoxedCopyFunc) g_object_ref, g_object_unref, (GHashFunc) folks_abstract_field_details_hash, (GEqualFunc) folks_abstract_field_details_equal);
	_data_->emails = _data_->_tmp19_;
	_data_->_tmp20_ = folks_email_field_details_new ("test-1@example.org", NULL);
	_data_->email_1 = _data_->_tmp20_;
	_data_->_tmp21_ = _data_->emails;
	_data_->_tmp22_ = _data_->email_1;
	gee_abstract_collection_add ((GeeAbstractCollection*) _data_->_tmp21_, _data_->_tmp22_);
	_data_->_tmp23_ = folks_email_field_details_new ("test-2@example.org", NULL);
	_data_->email_2 = _data_->_tmp23_;
	_data_->_tmp24_ = _data_->emails;
	_data_->_tmp25_ = _data_->email_2;
	gee_abstract_collection_add ((GeeAbstractCollection*) _data_->_tmp24_, _data_->_tmp25_);
	_data_->_tmp26_ = _data_->v2;
	_data_->_tmp27_ = _data_->emails;
	g_value_set_object (_data_->_tmp26_, (GObject*) _data_->_tmp27_);
	_data_->_tmp28_ = _data_->details;
	_data_->_tmp29_ = NULL;
	_data_->_tmp29_ = folks_persona_store_detail_key (FOLKS_PERSONA_DETAIL_EMAIL_ADDRESSES);
	_data_->_tmp30_ = g_strdup (_data_->_tmp29_);
	_data_->_tmp31_ = _data_->v2;
	_data_->v2 = NULL;
	g_hash_table_insert (_data_->_tmp28_, _data_->_tmp30_, _data_->_tmp31_);
	{
		_data_->_tmp32_ = _data_->self->priv->_aggregator;
		_data_->_tmp33_ = _data_->self->priv->_pstore;
		_data_->_tmp34_ = _data_->details;
		_data_->_state_ = 1;
		folks_individual_aggregator_add_persona_from_details (_data_->_tmp32_, NULL, _data_->_tmp33_, _data_->_tmp34_, _remove_persona_tests_add_persona_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp35_ = NULL;
		_data_->_tmp35_ = folks_individual_aggregator_add_persona_from_details_finish (_data_->_tmp32_, _data_->_res_, &_data_->_inner_error_);
		_data_->_tmp36_ = _data_->_tmp35_;
		_g_object_unref0 (_data_->_tmp36_);
		if (_data_->_inner_error_ != NULL) {
			if (_data_->_inner_error_->domain == FOLKS_INDIVIDUAL_AGGREGATOR_ERROR) {
				goto __catch1_folks_individual_aggregator_error;
			}
			_g_object_unref0 (_data_->email_2);
			_g_object_unref0 (_data_->email_1);
			_g_object_unref0 (_data_->emails);
			__vala_GValue_free0 (_data_->v2);
			__vala_GValue_free0 (_data_->v1);
			_g_hash_table_unref0 (_data_->details);
			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 __finally1;
	__catch1_folks_individual_aggregator_error:
	{
		_data_->e = _data_->_inner_error_;
		_data_->_inner_error_ = NULL;
		_data_->_tmp37_ = _data_->e;
		_data_->_tmp38_ = _data_->_tmp37_->message;
		g_warning ("remove-persona.vala:154: [RemovePersonaError] add_persona_from_details" \
": %s\n", _data_->_tmp38_);
		_g_error_free0 (_data_->e);
	}
	__finally1:
	if (_data_->_inner_error_ != NULL) {
		_g_object_unref0 (_data_->email_2);
		_g_object_unref0 (_data_->email_1);
		_g_object_unref0 (_data_->emails);
		__vala_GValue_free0 (_data_->v2);
		__vala_GValue_free0 (_data_->v1);
		_g_hash_table_unref0 (_data_->details);
		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_->email_2);
	_g_object_unref0 (_data_->email_1);
	_g_object_unref0 (_data_->emails);
	__vala_GValue_free0 (_data_->v2);
	__vala_GValue_free0 (_data_->v1);
	_g_hash_table_unref0 (_data_->details);
	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 __remove_persona_tests_personas_cb_folks_persona_store_personas_changed (FolksPersonaStore* _sender, GeeSet* added, GeeSet* removed, const gchar* message, FolksPersona* actor, FolksGroupDetailsChangeReason reason, gpointer self) {
	_remove_persona_tests_personas_cb (self);
}


static void _remove_persona_tests_individuals_changed_cb (RemovePersonaTests* self, GeeSet* added, GeeSet* removed, const gchar* message, FolksPersona* actor, FolksGroupDetailsChangeReason reason) {
	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_;
			const gchar* _tmp7_;
			const gchar* _tmp8_;
			const gchar* _tmp9_;
			_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_name_details_get_full_name ((FolksNameDetails*) _tmp6_);
			_tmp8_ = _tmp7_;
			_tmp9_ = self->priv->_persona_fullname;
			if (g_strcmp0 (_tmp8_, _tmp9_) == 0) {
				FolksIndividual* _tmp10_;
				const gchar* _tmp11_;
				const gchar* _tmp12_;
				gchar* _tmp13_;
				FolksIndividual* _tmp26_;
				FolksIndividual* _tmp27_;
				FolksPersonaStore* _tmp28_;
				GeeMap* _tmp29_;
				GeeMap* _tmp30_;
				const gchar* _tmp31_;
				gboolean _tmp32_ = FALSE;
				_tmp10_ = i;
				_tmp11_ = folks_individual_get_id (_tmp10_);
				_tmp12_ = _tmp11_;
				_tmp13_ = g_strdup (_tmp12_);
				_g_free0 (self->priv->_individual_id);
				self->priv->_individual_id = _tmp13_;
				{
					FolksIndividual* _tmp14_;
					GeeSet* _tmp15_;
					GeeSet* _tmp16_;
					GeeIterator* _tmp17_ = NULL;
					GeeIterator* _p_it;
					_tmp14_ = i;
					_tmp15_ = folks_individual_get_personas (_tmp14_);
					_tmp16_ = _tmp15_;
					_tmp17_ = gee_iterable_iterator ((GeeIterable*) _tmp16_);
					_p_it = _tmp17_;
					while (TRUE) {
						GeeIterator* _tmp18_;
						gboolean _tmp19_ = FALSE;
						GeeIterator* _tmp20_;
						gpointer _tmp21_ = NULL;
						FolksPersona* p;
						FolksPersona* _tmp22_;
						const gchar* _tmp23_;
						const gchar* _tmp24_;
						gchar* _tmp25_;
						_tmp18_ = _p_it;
						_tmp19_ = gee_iterator_next (_tmp18_);
						if (!_tmp19_) {
							break;
						}
						_tmp20_ = _p_it;
						_tmp21_ = gee_iterator_get (_tmp20_);
						p = (FolksPersona*) _tmp21_;
						_tmp22_ = p;
						_tmp23_ = folks_persona_get_iid (_tmp22_);
						_tmp24_ = _tmp23_;
						_tmp25_ = g_strdup (_tmp24_);
						_g_free0 (self->priv->_persona_id);
						self->priv->_persona_id = _tmp25_;
						_g_object_unref0 (p);
						break;
					}
					_g_object_unref0 (_p_it);
				}
				_tmp26_ = i;
				_tmp27_ = _g_object_ref0 (_tmp26_);
				_g_object_unref0 (self->priv->_individual);
				self->priv->_individual = _tmp27_;
				_tmp28_ = self->priv->_pstore;
				_tmp29_ = folks_persona_store_get_personas (_tmp28_);
				_tmp30_ = _tmp29_;
				_tmp31_ = self->priv->_persona_id;
				_tmp32_ = gee_map_has_key (_tmp30_, _tmp31_);
				if (_tmp32_ == TRUE) {
					FolksPersonaStore* _tmp33_;
					FolksIndividualAggregator* _tmp34_;
					FolksIndividual* _tmp35_;
					_tmp33_ = self->priv->_pstore;
					g_signal_connect_object (_tmp33_, "personas-changed", (GCallback) __remove_persona_tests_personas_cb_folks_persona_store_personas_changed, self, 0);
					_tmp34_ = self->priv->_aggregator;
					_tmp35_ = self->priv->_individual;
					folks_individual_aggregator_remove_individual (_tmp34_, _tmp35_, NULL, NULL);
				}
			}
			_g_object_unref0 (i);
		}
		_g_object_unref0 (_i_it);
	}
	{
		GeeSet* _tmp36_;
		GeeIterator* _tmp37_ = NULL;
		GeeIterator* _i_it;
		_tmp36_ = removed;
		_tmp37_ = gee_iterable_iterator ((GeeIterable*) _tmp36_);
		_i_it = _tmp37_;
		while (TRUE) {
			GeeIterator* _tmp38_;
			gboolean _tmp39_ = FALSE;
			GeeIterator* _tmp40_;
			gpointer _tmp41_ = NULL;
			FolksIndividual* i;
			FolksIndividual* _tmp42_;
			const gchar* _tmp43_;
			const gchar* _tmp44_;
			const gchar* _tmp45_;
			_tmp38_ = _i_it;
			_tmp39_ = gee_iterator_next (_tmp38_);
			if (!_tmp39_) {
				break;
			}
			_tmp40_ = _i_it;
			_tmp41_ = gee_iterator_get (_tmp40_);
			i = (FolksIndividual*) _tmp41_;
			_tmp42_ = i;
			_tmp43_ = folks_individual_get_id (_tmp42_);
			_tmp44_ = _tmp43_;
			_tmp45_ = self->priv->_individual_id;
			if (g_strcmp0 (_tmp44_, _tmp45_) == 0) {
				self->priv->_individual_removed = TRUE;
			}
			_g_object_unref0 (i);
		}
		_g_object_unref0 (_i_it);
	}
}


static void _remove_persona_tests_personas_cb (RemovePersonaTests* self) {
	FolksPersonaStore* _tmp0_;
	GeeMap* _tmp1_;
	GeeMap* _tmp2_;
	const gchar* _tmp3_;
	gboolean _tmp4_ = FALSE;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_pstore;
	_tmp1_ = folks_persona_store_get_personas (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = self->priv->_persona_id;
	_tmp4_ = gee_map_has_key (_tmp2_, _tmp3_);
	if (_tmp4_ == FALSE) {
		GMainLoop* _tmp5_;
		self->priv->_persona_removed = TRUE;
		_tmp5_ = self->priv->_main_loop;
		g_main_loop_quit (_tmp5_);
	}
}


static void remove_persona_tests_class_init (RemovePersonaTestsClass * klass) {
	remove_persona_tests_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (RemovePersonaTestsPrivate));
	FOLKS_TEST_CASE_CLASS (klass)->set_up = remove_persona_tests_real_set_up;
	FOLKS_TEST_CASE_CLASS (klass)->tear_down = remove_persona_tests_real_tear_down;
	G_OBJECT_CLASS (klass)->finalize = remove_persona_tests_finalize;
}


static void remove_persona_tests_instance_init (RemovePersonaTests * self) {
	self->priv = REMOVE_PERSONA_TESTS_GET_PRIVATE (self);
	self->priv->_added_persona = FALSE;
}


static void remove_persona_tests_finalize (GObject* obj) {
	RemovePersonaTests * self;
	self = REMOVE_PERSONA_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);
	_g_free0 (self->priv->_individual_id);
	_g_object_unref0 (self->priv->_pstore);
	_g_free0 (self->priv->_persona_id);
	_g_object_unref0 (self->priv->_individual);
	G_OBJECT_CLASS (remove_persona_tests_parent_class)->finalize (obj);
}


GType remove_persona_tests_get_type (void) {
	static volatile gsize remove_persona_tests_type_id__volatile = 0;
	if (g_once_init_enter (&remove_persona_tests_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (RemovePersonaTestsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) remove_persona_tests_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RemovePersonaTests), 0, (GInstanceInitFunc) remove_persona_tests_instance_init, NULL };
		GType remove_persona_tests_type_id;
		remove_persona_tests_type_id = g_type_register_static (FOLKS_TYPE_TEST_CASE, "RemovePersonaTests", &g_define_type_info, 0);
		g_once_init_leave (&remove_persona_tests_type_id__volatile, remove_persona_tests_type_id);
	}
	return remove_persona_tests_type_id__volatile;
}


gint _vala_main (gchar** args, int args_length1) {
	gint result = 0;
	GTestSuite* _tmp0_ = NULL;
	GTestSuite* root;
	GTestSuite* _tmp1_;
	RemovePersonaTests* _tmp2_;
	RemovePersonaTests* _tmp3_;
	GTestSuite* _tmp4_ = NULL;
	g_test_init (&args_length1, &args, NULL);
	_tmp0_ = g_test_get_root ();
	root = _tmp0_;
	_tmp1_ = root;
	_tmp2_ = remove_persona_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);
}



