/* add-contacts-stress-test.c generated by valac 0.13.1.106-1068, the Vala compiler
 * generated from add-contacts-stress-test.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 <eds-test.h>
#include <folks/folks.h>
#include <folks/folks-eds.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <stdio.h>
#include <gee.h>


#define TYPE_ADD_CONTACTS_STRESS_TEST_TESTS (add_contacts_stress_test_tests_get_type ())
#define ADD_CONTACTS_STRESS_TEST_TESTS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_ADD_CONTACTS_STRESS_TEST_TESTS, AddContactsStressTestTests))
#define ADD_CONTACTS_STRESS_TEST_TESTS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_ADD_CONTACTS_STRESS_TEST_TESTS, AddContactsStressTestTestsClass))
#define IS_ADD_CONTACTS_STRESS_TEST_TESTS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_ADD_CONTACTS_STRESS_TEST_TESTS))
#define IS_ADD_CONTACTS_STRESS_TEST_TESTS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_ADD_CONTACTS_STRESS_TEST_TESTS))
#define ADD_CONTACTS_STRESS_TEST_TESTS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_ADD_CONTACTS_STRESS_TEST_TESTS, AddContactsStressTestTestsClass))

typedef struct _AddContactsStressTestTests AddContactsStressTestTests;
typedef struct _AddContactsStressTestTestsClass AddContactsStressTestTestsClass;
typedef struct _AddContactsStressTestTestsPrivate AddContactsStressTestTestsPrivate;
#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL)))
#define _eds_test_backend_unref0(var) ((var == NULL) ? NULL : (var = (eds_test_backend_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_list_free0(var) ((var == NULL) ? NULL : (var = (g_list_free (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _AddContactsStressTestTestsTestAddPersonaAsyncData AddContactsStressTestTestsTestAddPersonaAsyncData;
#define __vala_GValue_free0(var) ((var == NULL) ? NULL : (var = (_vala_GValue_free (var), NULL)))
typedef struct _AddContactsStressTestTestsAddContactsData AddContactsStressTestTestsAddContactsData;

struct _AddContactsStressTestTests {
	FolksTestCase parent_instance;
	AddContactsStressTestTestsPrivate * priv;
};

struct _AddContactsStressTestTestsClass {
	FolksTestCaseClass parent_class;
};

struct _AddContactsStressTestTestsPrivate {
	GMainLoop* _main_loop;
	EdsTestBackend* _eds_backend;
	FolksIndividualAggregator* _aggregator;
	EdsfPersonaStore* _pstore;
	gboolean _added_contacts;
	GStaticRecMutex __lock__added_contacts;
	GHashTable* _contacts_found;
	gint _contacts_cnt;
	GDateTime* _start_time;
};

struct _AddContactsStressTestTestsTestAddPersonaAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	AddContactsStressTestTests* 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_;
	EdsfPersonaStore* _tmp21_;
	EdsfPersonaStore* _tmp22_;
	EdsfPersonaStore* _tmp23_;
	GError* e;
	GError* _tmp24_;
	const gchar* _tmp25_;
	GError * _inner_error_;
};

struct _AddContactsStressTestTestsAddContactsData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	AddContactsStressTestTests* self;
	gint i;
	gboolean _tmp0_;
	gboolean _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	gchar* _tmp6_;
	gchar* persona_name;
	GHashFunc _tmp7_;
	GEqualFunc _tmp8_;
	GHashTable* _tmp9_;
	GHashTable* details;
	GValue _tmp10_;
	GValue _tmp11_;
	GValue _tmp12_;
	GValue* _tmp13_;
	GValue* _tmp14_;
	GValue* v1;
	GValue* _tmp15_;
	const gchar* _tmp16_;
	GHashTable* _tmp17_;
	const gchar* _tmp18_;
	gchar* _tmp19_;
	GValue* _tmp20_;
	FolksIndividualAggregator* _tmp21_;
	EdsfPersonaStore* _tmp22_;
	GHashTable* _tmp23_;
	FolksPersona* _tmp24_;
	FolksPersona* _tmp25_;
	GError* e;
	gint _tmp26_;
	GError* _tmp27_;
	const gchar* _tmp28_;
	GError * _inner_error_;
};


static gpointer add_contacts_stress_test_tests_parent_class = NULL;

GType add_contacts_stress_test_tests_get_type (void) G_GNUC_CONST;
#define ADD_CONTACTS_STRESS_TEST_TESTS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_ADD_CONTACTS_STRESS_TEST_TESTS, AddContactsStressTestTestsPrivate))
enum  {
	ADD_CONTACTS_STRESS_TEST_TESTS_DUMMY_PROPERTY
};
AddContactsStressTestTests* add_contacts_stress_test_tests_new (void);
AddContactsStressTestTests* add_contacts_stress_test_tests_construct (GType object_type);
void add_contacts_stress_test_tests_test_add_contacts (AddContactsStressTestTests* self);
static void _add_contacts_stress_test_tests_test_add_contacts_folks_test_case_test_method (gpointer self);
static void add_contacts_stress_test_tests_real_set_up (FolksTestCase* base);
static void add_contacts_stress_test_tests_real_tear_down (FolksTestCase* base);
static void _g_free0_ (gpointer var);
static void _add_contacts_stress_test_tests_test_add_persona_async (AddContactsStressTestTests* self, GAsyncReadyCallback _callback_, gpointer _user_data_);
static void _add_contacts_stress_test_tests_test_add_persona_finish (AddContactsStressTestTests* self, GAsyncResult* _res_);
static void _add_contacts_stress_test_tests_test_add_persona_async_data_free (gpointer _data);
static gboolean _add_contacts_stress_test_tests_test_add_persona_async_co (AddContactsStressTestTestsTestAddPersonaAsyncData* _data_);
static void _add_contacts_stress_test_tests_test_add_persona_async_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
static void _add_contacts_stress_test_tests_individuals_changed_cb (AddContactsStressTestTests* self, GeeSet* added, GeeSet* removed, const gchar* message, FolksPersona* actor, FolksGroupDetailsChangeReason reason);
static void __add_contacts_stress_test_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 _add_contacts_stress_test_tests_notify_pstore_cb (AddContactsStressTestTests* self, GObject* _pstore, GParamSpec* ps);
static void __add_contacts_stress_test_tests_notify_pstore_cb_g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self);
static void _add_contacts_stress_test_tests_try_to_add (AddContactsStressTestTests* self);
static void _add_contacts_stress_test_tests_add_contacts_data_free (gpointer _data);
static void _add_contacts_stress_test_tests_add_contacts (AddContactsStressTestTests* self, GAsyncReadyCallback _callback_, gpointer _user_data_);
static void _add_contacts_stress_test_tests_add_contacts_finish (AddContactsStressTestTests* self, GAsyncResult* _res_);
static gboolean _add_contacts_stress_test_tests_add_contacts_co (AddContactsStressTestTestsAddContactsData* _data_);
static void _vala_GValue_free (GValue* self);
static void __vala_GValue_free0_ (gpointer var);
static GValue* _g_value_dup (GValue* self);
static void _add_contacts_stress_test_tests_add_contacts_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
static void _add_contacts_stress_test_tests_exit_if_all_contacts_found (AddContactsStressTestTests* self);
static void add_contacts_stress_test_tests_finalize (GObject* obj);
gint _vala_main (gchar** args, int args_length1);


static void _add_contacts_stress_test_tests_test_add_contacts_folks_test_case_test_method (gpointer self) {
	add_contacts_stress_test_tests_test_add_contacts (self);
}


AddContactsStressTestTests* add_contacts_stress_test_tests_construct (GType object_type) {
	AddContactsStressTestTests * self = NULL;
	EdsTestBackend* _tmp0_;
	gint _tmp1_;
	gchar* _tmp2_ = NULL;
	gchar* test_desc;
	const gchar* _tmp3_;
	self = (AddContactsStressTestTests*) folks_test_case_construct (object_type, "AddContactsStressTestTests");
	_tmp0_ = eds_test_backend_new ();
	_eds_test_backend_unref0 (self->priv->_eds_backend);
	self->priv->_eds_backend = _tmp0_;
	_tmp1_ = self->priv->_contacts_cnt;
	_tmp2_ = g_strdup_printf ("stress testing adding (%d) contacts to e-d-s ", _tmp1_);
	test_desc = _tmp2_;
	_tmp3_ = test_desc;
	folks_test_case_add_test ((FolksTestCase*) self, _tmp3_, _add_contacts_stress_test_tests_test_add_contacts_folks_test_case_test_method, self);
	_g_free0 (test_desc);
	return self;
}


AddContactsStressTestTests* add_contacts_stress_test_tests_new (void) {
	return add_contacts_stress_test_tests_construct (TYPE_ADD_CONTACTS_STRESS_TEST_TESTS);
}


static void add_contacts_stress_test_tests_real_set_up (FolksTestCase* base) {
	AddContactsStressTestTests * self;
	EdsTestBackend* _tmp0_;
	self = (AddContactsStressTestTests*) base;
	_tmp0_ = self->priv->_eds_backend;
	eds_test_backend_set_up (_tmp0_);
}


static void add_contacts_stress_test_tests_real_tear_down (FolksTestCase* base) {
	AddContactsStressTestTests * self;
	EdsTestBackend* _tmp0_;
	self = (AddContactsStressTestTests*) base;
	_tmp0_ = self->priv->_eds_backend;
	eds_test_backend_tear_down (_tmp0_);
}


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


void add_contacts_stress_test_tests_test_add_contacts (AddContactsStressTestTests* self) {
	GMainLoop* _tmp0_;
	GHashFunc _tmp1_;
	GEqualFunc _tmp2_;
	GHashTable* _tmp3_;
	GDateTime* _tmp14_;
	GMainLoop* _tmp15_;
	GDateTime* _tmp16_;
	GDateTime* now;
	GDateTime* _tmp17_;
	GDateTime* _tmp18_;
	GTimeSpan _tmp19_ = 0LL;
	GTimeSpan difference;
	GTimeSpan _tmp20_;
	GTimeSpan diff;
	FILE* _tmp21_;
	GTimeSpan _tmp22_;
	GTimeSpan _tmp23_;
	gint found;
	GHashTable* _tmp24_;
	GList* _tmp25_ = NULL;
	gint _tmp28_;
	gint _tmp29_;
	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_str_hash;
	_tmp2_ = g_str_equal;
	_tmp3_ = g_hash_table_new_full (_tmp1_, _tmp2_, _g_free0_, NULL);
	_g_hash_table_unref0 (self->priv->_contacts_found);
	self->priv->_contacts_found = _tmp3_;
	{
		gint i;
		i = 0;
		{
			gboolean _tmp4_;
			_tmp4_ = TRUE;
			while (TRUE) {
				gboolean _tmp5_;
				gint _tmp7_;
				gint _tmp8_;
				gint _tmp9_;
				gchar* _tmp10_ = NULL;
				gchar* persona_name;
				GHashTable* _tmp11_;
				const gchar* _tmp12_;
				gchar* _tmp13_;
				_tmp5_ = _tmp4_;
				if (!_tmp5_) {
					gint _tmp6_;
					_tmp6_ = i;
					i = _tmp6_ + 1;
				}
				_tmp4_ = FALSE;
				_tmp7_ = i;
				_tmp8_ = self->priv->_contacts_cnt;
				if (!(_tmp7_ < _tmp8_)) {
					break;
				}
				_tmp9_ = i;
				_tmp10_ = g_strdup_printf ("full_name -%d", _tmp9_);
				persona_name = _tmp10_;
				_tmp11_ = self->priv->_contacts_found;
				_tmp12_ = persona_name;
				_tmp13_ = g_strdup (_tmp12_);
				g_hash_table_insert (_tmp11_, _tmp13_, GINT_TO_POINTER (FALSE));
				_g_free0 (persona_name);
			}
		}
	}
	_tmp14_ = g_date_time_new_now_utc ();
	_g_date_time_unref0 (self->priv->_start_time);
	self->priv->_start_time = _tmp14_;
	_add_contacts_stress_test_tests_test_add_persona_async (self, NULL, NULL);
	_tmp15_ = self->priv->_main_loop;
	g_main_loop_run (_tmp15_);
	_tmp16_ = g_date_time_new_now_utc ();
	now = _tmp16_;
	_tmp17_ = now;
	_tmp18_ = self->priv->_start_time;
	_tmp19_ = g_date_time_difference (_tmp17_, _tmp18_);
	difference = _tmp19_;
	_tmp20_ = difference;
	diff = _tmp20_ / G_TIME_SPAN_SECOND;
	_tmp21_ = stdout;
	_tmp22_ = diff;
	_tmp23_ = diff;
	fprintf (_tmp21_, "(Elapsed time: %" G_GINT64_FORMAT " secs) ", _tmp23_);
	found = 0;
	_tmp24_ = self->priv->_contacts_found;
	_tmp25_ = g_hash_table_get_values (_tmp24_);
	{
		GList* k_collection = NULL;
		GList* k_it = NULL;
		k_collection = _tmp25_;
		for (k_it = k_collection; k_it != NULL; k_it = k_it->next) {
			gboolean k = FALSE;
			k = GPOINTER_TO_INT (k_it->data);
			{
				gboolean _tmp26_;
				_tmp26_ = k;
				if (_tmp26_) {
					gint _tmp27_;
					_tmp27_ = found;
					found = _tmp27_ + 1;
				}
			}
		}
		_g_list_free0 (k_collection);
	}
	_tmp28_ = found;
	_tmp29_ = self->priv->_contacts_cnt;
	g_assert (_tmp28_ == _tmp29_);
	_g_date_time_unref0 (now);
}


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


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


static void _add_contacts_stress_test_tests_test_add_persona_async (AddContactsStressTestTests* self, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	AddContactsStressTestTestsTestAddPersonaAsyncData* _data_;
	AddContactsStressTestTests* _tmp0_;
	_data_ = g_slice_new0 (AddContactsStressTestTestsTestAddPersonaAsyncData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, _add_contacts_stress_test_tests_test_add_persona_async);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, _add_contacts_stress_test_tests_test_add_persona_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_add_contacts_stress_test_tests_test_add_persona_async_co (_data_);
}


static void _add_contacts_stress_test_tests_test_add_persona_finish (AddContactsStressTestTests* self, GAsyncResult* _res_) {
	AddContactsStressTestTestsTestAddPersonaAsyncData* _data_;
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
}


static void _add_contacts_stress_test_tests_test_add_persona_async_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	AddContactsStressTestTestsTestAddPersonaAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	_add_contacts_stress_test_tests_test_add_persona_async_co (_data_);
}


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


static void __add_contacts_stress_test_tests_notify_pstore_cb_g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self) {
	_add_contacts_stress_test_tests_notify_pstore_cb (self, _sender, pspec);
}


static gboolean _add_contacts_stress_test_tests_test_add_persona_async_co (AddContactsStressTestTestsTestAddPersonaAsyncData* _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_, _add_contacts_stress_test_tests_test_add_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) __add_contacts_stress_test_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_, _add_contacts_stress_test_tests_test_add_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_, "local://test");
				_g_object_unref0 (_data_->self->priv->_pstore);
				_data_->self->priv->_pstore = EDSF_PERSONA_STORE ((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) __add_contacts_stress_test_tests_notify_pstore_cb_g_object_notify, _data_->self, 0);
		_add_contacts_stress_test_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 ("add-contacts-stress-test.vala:114: 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 _add_contacts_stress_test_tests_add_contacts_data_free (gpointer _data) {
	AddContactsStressTestTestsAddContactsData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (AddContactsStressTestTestsAddContactsData, _data_);
}


static void _add_contacts_stress_test_tests_add_contacts (AddContactsStressTestTests* self, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	AddContactsStressTestTestsAddContactsData* _data_;
	AddContactsStressTestTests* _tmp0_;
	_data_ = g_slice_new0 (AddContactsStressTestTestsAddContactsData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, _add_contacts_stress_test_tests_add_contacts);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, _add_contacts_stress_test_tests_add_contacts_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_add_contacts_stress_test_tests_add_contacts_co (_data_);
}


static void _add_contacts_stress_test_tests_add_contacts_finish (AddContactsStressTestTests* self, GAsyncResult* _res_) {
	AddContactsStressTestTestsAddContactsData* _data_;
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
}


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 _add_contacts_stress_test_tests_add_contacts_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	AddContactsStressTestTestsAddContactsData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	_add_contacts_stress_test_tests_add_contacts_co (_data_);
}


static gboolean _add_contacts_stress_test_tests_add_contacts_co (AddContactsStressTestTestsAddContactsData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	{
		_data_->i = 0;
		{
			_data_->_tmp0_ = TRUE;
			while (TRUE) {
				_data_->_tmp1_ = _data_->_tmp0_;
				if (!_data_->_tmp1_) {
					_data_->_tmp2_ = _data_->i;
					_data_->i = _data_->_tmp2_ + 1;
				}
				_data_->_tmp0_ = FALSE;
				_data_->_tmp3_ = _data_->i;
				_data_->_tmp4_ = _data_->self->priv->_contacts_cnt;
				if (!(_data_->_tmp3_ < _data_->_tmp4_)) {
					break;
				}
				_data_->_tmp5_ = _data_->i;
				_data_->_tmp6_ = NULL;
				_data_->_tmp6_ = g_strdup_printf ("full_name -%d", _data_->_tmp5_);
				_data_->persona_name = _data_->_tmp6_;
				_data_->_tmp7_ = g_str_hash;
				_data_->_tmp8_ = g_str_equal;
				_data_->_tmp9_ = g_hash_table_new_full (_data_->_tmp7_, _data_->_tmp8_, _g_free0_, __vala_GValue_free0_);
				_data_->details = _data_->_tmp9_;
				memset (&_data_->_tmp10_, 0, sizeof (GValue));
				g_value_init (&_data_->_tmp10_, G_TYPE_STRING);
				_data_->_tmp11_ = _data_->_tmp10_;
				_data_->_tmp12_ = _data_->_tmp11_;
				_data_->_tmp13_ = __g_value_dup0 (&_data_->_tmp12_);
				_data_->_tmp14_ = _data_->_tmp13_;
				G_IS_VALUE (&_data_->_tmp12_) ? (g_value_unset (&_data_->_tmp12_), NULL) : NULL;
				_data_->v1 = _data_->_tmp14_;
				_data_->_tmp15_ = _data_->v1;
				_data_->_tmp16_ = _data_->persona_name;
				g_value_set_string (_data_->_tmp15_, _data_->_tmp16_);
				_data_->_tmp17_ = _data_->details;
				_data_->_tmp18_ = NULL;
				_data_->_tmp18_ = folks_persona_store_detail_key (FOLKS_PERSONA_DETAIL_FULL_NAME);
				_data_->_tmp19_ = g_strdup (_data_->_tmp18_);
				_data_->_tmp20_ = _data_->v1;
				_data_->v1 = NULL;
				g_hash_table_insert (_data_->_tmp17_, _data_->_tmp19_, _data_->_tmp20_);
				{
					_data_->_tmp21_ = _data_->self->priv->_aggregator;
					_data_->_tmp22_ = _data_->self->priv->_pstore;
					_data_->_tmp23_ = _data_->details;
					_data_->_state_ = 1;
					folks_individual_aggregator_add_persona_from_details (_data_->_tmp21_, NULL, (FolksPersonaStore*) _data_->_tmp22_, _data_->_tmp23_, _add_contacts_stress_test_tests_add_contacts_ready, _data_);
					return FALSE;
					_state_1:
					_data_->_tmp24_ = NULL;
					_data_->_tmp24_ = folks_individual_aggregator_add_persona_from_details_finish (_data_->_tmp21_, _data_->_res_, &_data_->_inner_error_);
					_data_->_tmp25_ = _data_->_tmp24_;
					_g_object_unref0 (_data_->_tmp25_);
					if (_data_->_inner_error_ != NULL) {
						if (_data_->_inner_error_->domain == FOLKS_INDIVIDUAL_AGGREGATOR_ERROR) {
							goto __catch1_folks_individual_aggregator_error;
						}
						__vala_GValue_free0 (_data_->v1);
						_g_hash_table_unref0 (_data_->details);
						_g_free0 (_data_->persona_name);
						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_->_tmp26_ = _data_->i;
					_data_->_tmp27_ = _data_->e;
					_data_->_tmp28_ = _data_->_tmp27_->message;
					g_warning ("add-contacts-stress-test.vala:139: [AddContactsStressTest]: %d: %s\n", _data_->_tmp26_, _data_->_tmp28_);
					_g_error_free0 (_data_->e);
				}
				__finally1:
				if (_data_->_inner_error_ != NULL) {
					__vala_GValue_free0 (_data_->v1);
					_g_hash_table_unref0 (_data_->details);
					_g_free0 (_data_->persona_name);
					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_->v1);
				_g_hash_table_unref0 (_data_->details);
				_g_free0 (_data_->persona_name);
			}
		}
	}
	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 _add_contacts_stress_test_tests_individuals_changed_cb (AddContactsStressTestTests* self, GeeSet* added, GeeSet* removed, const gchar* message, FolksPersona* actor, FolksGroupDetailsChangeReason reason) {
	GeeSet* _tmp16_;
	gint _tmp17_;
	gint _tmp18_;
	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;
			GHashTable* _tmp6_;
			FolksIndividual* _tmp7_;
			const gchar* _tmp8_;
			const gchar* _tmp9_;
			gconstpointer _tmp10_ = NULL;
			GHashTable* _tmp11_;
			FolksIndividual* _tmp12_;
			const gchar* _tmp13_;
			const gchar* _tmp14_;
			gchar* _tmp15_;
			_tmp2_ = _i_it;
			_tmp3_ = gee_iterator_next (_tmp2_);
			if (!_tmp3_) {
				break;
			}
			_tmp4_ = _i_it;
			_tmp5_ = gee_iterator_get (_tmp4_);
			i = (FolksIndividual*) _tmp5_;
			_tmp6_ = self->priv->_contacts_found;
			_tmp7_ = i;
			_tmp8_ = folks_name_details_get_full_name ((FolksNameDetails*) _tmp7_);
			_tmp9_ = _tmp8_;
			_tmp10_ = g_hash_table_lookup (_tmp6_, _tmp9_);
			g_assert (GPOINTER_TO_INT (_tmp10_) == FALSE);
			_tmp11_ = self->priv->_contacts_found;
			_tmp12_ = i;
			_tmp13_ = folks_name_details_get_full_name ((FolksNameDetails*) _tmp12_);
			_tmp14_ = _tmp13_;
			_tmp15_ = g_strdup (_tmp14_);
			g_hash_table_replace (_tmp11_, _tmp15_, GINT_TO_POINTER (TRUE));
			_g_object_unref0 (i);
		}
		_g_object_unref0 (_i_it);
	}
	_tmp16_ = removed;
	_tmp17_ = gee_collection_get_size ((GeeCollection*) _tmp16_);
	_tmp18_ = _tmp17_;
	g_assert (_tmp18_ == 0);
	_add_contacts_stress_test_tests_exit_if_all_contacts_found (self);
}


static void _add_contacts_stress_test_tests_notify_pstore_cb (AddContactsStressTestTests* self, GObject* _pstore, GParamSpec* ps) {
	g_return_if_fail (self != NULL);
	g_return_if_fail (_pstore != NULL);
	g_return_if_fail (ps != NULL);
	_add_contacts_stress_test_tests_try_to_add (self);
}


static void _add_contacts_stress_test_tests_try_to_add (AddContactsStressTestTests* self) {
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	{
		gboolean _tmp0_;
		_tmp0_ = self->priv->_added_contacts;
		g_static_rec_mutex_lock (&self->priv->__lock__added_contacts);
		{
			gboolean _tmp1_ = FALSE;
			EdsfPersonaStore* _tmp2_;
			gboolean _tmp3_;
			gboolean _tmp4_;
			gboolean _tmp6_;
			_tmp2_ = self->priv->_pstore;
			_tmp3_ = folks_persona_store_get_is_prepared ((FolksPersonaStore*) _tmp2_);
			_tmp4_ = _tmp3_;
			if (_tmp4_) {
				gboolean _tmp5_;
				_tmp5_ = self->priv->_added_contacts;
				_tmp1_ = _tmp5_ == FALSE;
			} else {
				_tmp1_ = FALSE;
			}
			_tmp6_ = _tmp1_;
			if (_tmp6_) {
				self->priv->_added_contacts = TRUE;
				_add_contacts_stress_test_tests_add_contacts (self, NULL, NULL);
			}
		}
		__finally2:
		{
			gboolean _tmp7_;
			_tmp7_ = self->priv->_added_contacts;
			g_static_rec_mutex_unlock (&self->priv->__lock__added_contacts);
		}
		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 void _add_contacts_stress_test_tests_exit_if_all_contacts_found (AddContactsStressTestTests* self) {
	GHashTable* _tmp0_;
	GList* _tmp1_ = NULL;
	GMainLoop* _tmp6_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_contacts_found;
	_tmp1_ = g_hash_table_get_keys (_tmp0_);
	{
		GList* k_collection = NULL;
		GList* k_it = NULL;
		k_collection = _tmp1_;
		for (k_it = k_collection; k_it != NULL; k_it = k_it->next) {
			const gchar* k = NULL;
			k = (const gchar*) k_it->data;
			{
				GHashTable* _tmp2_;
				const gchar* _tmp3_;
				gconstpointer _tmp4_ = NULL;
				gboolean v;
				gboolean _tmp5_;
				_tmp2_ = self->priv->_contacts_found;
				_tmp3_ = k;
				_tmp4_ = g_hash_table_lookup (_tmp2_, _tmp3_);
				v = GPOINTER_TO_INT (_tmp4_);
				_tmp5_ = v;
				if (_tmp5_ == FALSE) {
					_g_list_free0 (k_collection);
					return;
				}
			}
		}
		_g_list_free0 (k_collection);
	}
	_tmp6_ = self->priv->_main_loop;
	g_main_loop_quit (_tmp6_);
}


static void add_contacts_stress_test_tests_class_init (AddContactsStressTestTestsClass * klass) {
	add_contacts_stress_test_tests_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (AddContactsStressTestTestsPrivate));
	FOLKS_TEST_CASE_CLASS (klass)->set_up = add_contacts_stress_test_tests_real_set_up;
	FOLKS_TEST_CASE_CLASS (klass)->tear_down = add_contacts_stress_test_tests_real_tear_down;
	G_OBJECT_CLASS (klass)->finalize = add_contacts_stress_test_tests_finalize;
}


static void add_contacts_stress_test_tests_instance_init (AddContactsStressTestTests * self) {
	self->priv = ADD_CONTACTS_STRESS_TEST_TESTS_GET_PRIVATE (self);
	g_static_rec_mutex_init (&self->priv->__lock__added_contacts);
	self->priv->_added_contacts = FALSE;
	self->priv->_contacts_cnt = 1000;
}


static void add_contacts_stress_test_tests_finalize (GObject* obj) {
	AddContactsStressTestTests * self;
	self = ADD_CONTACTS_STRESS_TEST_TESTS (obj);
	_g_main_loop_unref0 (self->priv->_main_loop);
	_eds_test_backend_unref0 (self->priv->_eds_backend);
	_g_object_unref0 (self->priv->_aggregator);
	_g_object_unref0 (self->priv->_pstore);
	g_static_rec_mutex_free (&self->priv->__lock__added_contacts);
	_g_hash_table_unref0 (self->priv->_contacts_found);
	_g_date_time_unref0 (self->priv->_start_time);
	G_OBJECT_CLASS (add_contacts_stress_test_tests_parent_class)->finalize (obj);
}


GType add_contacts_stress_test_tests_get_type (void) {
	static volatile gsize add_contacts_stress_test_tests_type_id__volatile = 0;
	if (g_once_init_enter (&add_contacts_stress_test_tests_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (AddContactsStressTestTestsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) add_contacts_stress_test_tests_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (AddContactsStressTestTests), 0, (GInstanceInitFunc) add_contacts_stress_test_tests_instance_init, NULL };
		GType add_contacts_stress_test_tests_type_id;
		add_contacts_stress_test_tests_type_id = g_type_register_static (FOLKS_TYPE_TEST_CASE, "AddContactsStressTestTests", &g_define_type_info, 0);
		g_once_init_leave (&add_contacts_stress_test_tests_type_id__volatile, add_contacts_stress_test_tests_type_id);
	}
	return add_contacts_stress_test_tests_type_id__volatile;
}


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



