/* individual-retrieval.c generated by valac 0.12.0, the Vala compiler
 * generated from individual-retrieval.vala, do not modify */


#include <glib.h>
#include <glib-object.h>
#include <folks-test.h>
#include <kf-test.h>
#include <gee.h>
#include <stdlib.h>
#include <string.h>
#include <folks/folks.h>


#define TYPE_INDIVIDUAL_RETRIEVAL_TESTS (individual_retrieval_tests_get_type ())
#define INDIVIDUAL_RETRIEVAL_TESTS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_INDIVIDUAL_RETRIEVAL_TESTS, IndividualRetrievalTests))
#define INDIVIDUAL_RETRIEVAL_TESTS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_INDIVIDUAL_RETRIEVAL_TESTS, IndividualRetrievalTestsClass))
#define IS_INDIVIDUAL_RETRIEVAL_TESTS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_INDIVIDUAL_RETRIEVAL_TESTS))
#define IS_INDIVIDUAL_RETRIEVAL_TESTS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_INDIVIDUAL_RETRIEVAL_TESTS))
#define INDIVIDUAL_RETRIEVAL_TESTS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_INDIVIDUAL_RETRIEVAL_TESTS, IndividualRetrievalTestsClass))

typedef struct _IndividualRetrievalTests IndividualRetrievalTests;
typedef struct _IndividualRetrievalTestsClass IndividualRetrievalTestsClass;
typedef struct _IndividualRetrievalTestsPrivate IndividualRetrievalTestsPrivate;
#define _kf_test_backend_unref0(var) ((var == NULL) ? NULL : (var = (kf_test_backend_unref (var), NULL)))
typedef struct _Block1Data Block1Data;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL)))
typedef struct _Block2Data Block2Data;

struct _IndividualRetrievalTests {
	FolksTestCase parent_instance;
	IndividualRetrievalTestsPrivate * priv;
};

struct _IndividualRetrievalTestsClass {
	FolksTestCaseClass parent_class;
};

struct _IndividualRetrievalTestsPrivate {
	KfTestBackend* kf_backend;
	gint _test_timeout;
};

struct _Block1Data {
	int _ref_count_;
	IndividualRetrievalTests * self;
	GMainLoop* main_loop;
	GeeHashSet* expected_individuals;
};

struct _Block2Data {
	int _ref_count_;
	IndividualRetrievalTests * self;
	GMainLoop* main_loop;
	guint individuals_changed_count;
};


static gpointer individual_retrieval_tests_parent_class = NULL;

GType individual_retrieval_tests_get_type (void) G_GNUC_CONST;
#define INDIVIDUAL_RETRIEVAL_TESTS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_INDIVIDUAL_RETRIEVAL_TESTS, IndividualRetrievalTestsPrivate))
enum  {
	INDIVIDUAL_RETRIEVAL_TESTS_DUMMY_PROPERTY
};
IndividualRetrievalTests* individual_retrieval_tests_new (void);
IndividualRetrievalTests* individual_retrieval_tests_construct (GType object_type);
void individual_retrieval_tests_test_singleton_individuals (IndividualRetrievalTests* self);
static void _individual_retrieval_tests_test_singleton_individuals_folks_test_case_test_method (gpointer self);
void individual_retrieval_tests_test_aliases (IndividualRetrievalTests* self);
static void _individual_retrieval_tests_test_aliases_folks_test_case_test_method (gpointer self);
static void individual_retrieval_tests_real_set_up (FolksTestCase* base);
static void individual_retrieval_tests_real_tear_down (FolksTestCase* base);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (Block1Data* _data1_);
static void _lambda0_ (GeeSet* added, GeeSet* removed, const gchar* m, FolksPersona* a, FolksGroupDetailsChangeReason r, Block1Data* _data1_);
static void __lambda0__folks_individual_aggregator_individuals_changed (FolksIndividualAggregator* _sender, GeeSet* added, GeeSet* removed, const gchar* message, FolksPersona* actor, FolksGroupDetailsChangeReason reason, gpointer self);
static gboolean _lambda1_ (Block1Data* _data1_);
static gboolean __lambda1__gsource_func (gpointer self);
static Block2Data* block2_data_ref (Block2Data* _data2_);
static void block2_data_unref (Block2Data* _data2_);
static void _lambda2_ (GeeSet* added, GeeSet* removed, const gchar* m, FolksPersona* a, FolksGroupDetailsChangeReason r, Block2Data* _data2_);
static void __lambda2__folks_individual_aggregator_individuals_changed (FolksIndividualAggregator* _sender, GeeSet* added, GeeSet* removed, const gchar* message, FolksPersona* actor, FolksGroupDetailsChangeReason reason, gpointer self);
static gboolean _lambda3_ (Block2Data* _data2_);
static gboolean __lambda3__gsource_func (gpointer self);
static void individual_retrieval_tests_finalize (GObject* obj);
gint _vala_main (gchar** args, int args_length1);


static void _individual_retrieval_tests_test_singleton_individuals_folks_test_case_test_method (gpointer self) {
	individual_retrieval_tests_test_singleton_individuals (self);
}


static void _individual_retrieval_tests_test_aliases_folks_test_case_test_method (gpointer self) {
	individual_retrieval_tests_test_aliases (self);
}


IndividualRetrievalTests* individual_retrieval_tests_construct (GType object_type) {
	IndividualRetrievalTests * self = NULL;
	KfTestBackend* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	self = (IndividualRetrievalTests*) folks_test_case_construct (object_type, "IndividualRetrieval");
	_tmp0_ = kf_test_backend_new ();
	_kf_test_backend_unref0 (self->priv->kf_backend);
	self->priv->kf_backend = _tmp0_;
	folks_test_case_add_test ((FolksTestCase*) self, "singleton individuals", _individual_retrieval_tests_test_singleton_individuals_folks_test_case_test_method, self);
	folks_test_case_add_test ((FolksTestCase*) self, "aliases", _individual_retrieval_tests_test_aliases_folks_test_case_test_method, self);
	_tmp1_ = g_getenv ("FOLKS_TEST_VALGRIND");
	if (_tmp1_ != NULL) {
		self->priv->_test_timeout = 10;
	}
	return self;
}


IndividualRetrievalTests* individual_retrieval_tests_new (void) {
	return individual_retrieval_tests_construct (TYPE_INDIVIDUAL_RETRIEVAL_TESTS);
}


static void individual_retrieval_tests_real_set_up (FolksTestCase* base) {
	IndividualRetrievalTests * self;
	self = (IndividualRetrievalTests*) base;
}


static void individual_retrieval_tests_real_tear_down (FolksTestCase* base) {
	IndividualRetrievalTests * self;
	self = (IndividualRetrievalTests*) base;
}


static Block1Data* block1_data_ref (Block1Data* _data1_) {
	g_atomic_int_inc (&_data1_->_ref_count_);
	return _data1_;
}


static void block1_data_unref (Block1Data* _data1_) {
	if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
		_g_object_unref0 (_data1_->self);
		_g_object_unref0 (_data1_->expected_individuals);
		_g_main_loop_unref0 (_data1_->main_loop);
		g_slice_free (Block1Data, _data1_);
	}
}


static void _lambda0_ (GeeSet* added, GeeSet* removed, const gchar* m, FolksPersona* a, FolksGroupDetailsChangeReason r, Block1Data* _data1_) {
	IndividualRetrievalTests * self;
	gint _tmp10_;
	self = _data1_->self;
	g_return_if_fail (added != NULL);
	g_return_if_fail (removed != NULL);
	{
		GeeIterator* _tmp0_ = NULL;
		GeeIterator* _i_it;
		_tmp0_ = gee_iterable_iterator ((GeeIterable*) added);
		_i_it = _tmp0_;
		while (TRUE) {
			gboolean _tmp1_;
			gpointer _tmp2_ = NULL;
			FolksIndividual* i;
			GeeSet* _tmp3_ = NULL;
			gint _tmp4_;
			_tmp1_ = gee_iterator_next (_i_it);
			if (!_tmp1_) {
				break;
			}
			_tmp2_ = gee_iterator_get (_i_it);
			i = (FolksIndividual*) _tmp2_;
			_tmp3_ = folks_individual_get_personas (i);
			_tmp4_ = gee_collection_get_size ((GeeCollection*) _tmp3_);
			g_assert (_tmp4_ == 1);
			{
				GeeSet* _tmp5_ = NULL;
				GeeIterator* _tmp6_ = NULL;
				GeeIterator* _persona_it;
				_tmp5_ = folks_individual_get_personas (i);
				_tmp6_ = gee_iterable_iterator ((GeeIterable*) _tmp5_);
				_persona_it = _tmp6_;
				while (TRUE) {
					gboolean _tmp7_;
					gpointer _tmp8_ = NULL;
					FolksPersona* persona;
					const gchar* _tmp9_ = NULL;
					_tmp7_ = gee_iterator_next (_persona_it);
					if (!_tmp7_) {
						break;
					}
					_tmp8_ = gee_iterator_get (_persona_it);
					persona = (FolksPersona*) _tmp8_;
					_tmp9_ = folks_persona_get_display_id (persona);
					gee_abstract_collection_remove ((GeeAbstractCollection*) _data1_->expected_individuals, _tmp9_);
					_g_object_unref0 (persona);
				}
				_g_object_unref0 (_persona_it);
			}
			_g_object_unref0 (i);
		}
		_g_object_unref0 (_i_it);
	}
	_tmp10_ = gee_collection_get_size ((GeeCollection*) removed);
	g_assert (_tmp10_ == 0);
}


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


static gboolean _lambda1_ (Block1Data* _data1_) {
	IndividualRetrievalTests * self;
	gboolean result = FALSE;
	self = _data1_->self;
	g_main_loop_quit (_data1_->main_loop);
	result = FALSE;
	return result;
}


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


void individual_retrieval_tests_test_singleton_individuals (IndividualRetrievalTests* self) {
	Block1Data* _data1_;
	GMainLoop* _tmp0_ = NULL;
	GeeHashSet* _tmp1_ = NULL;
	FolksIndividualAggregator* _tmp2_ = NULL;
	FolksIndividualAggregator* aggregator;
	gint _tmp3_;
	g_return_if_fail (self != NULL);
	_data1_ = g_slice_new0 (Block1Data);
	_data1_->_ref_count_ = 1;
	_data1_->self = g_object_ref (self);
	_tmp0_ = g_main_loop_new (NULL, FALSE);
	_data1_->main_loop = _tmp0_;
	kf_test_backend_set_up (self->priv->kf_backend, "[0]\n" "msn=foo@hotmail.com\n" "[1]\n" "__alias=Bar McBadgerson\n" "jabber=bar@jabber.org\n");
	_tmp1_ = gee_hash_set_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, g_str_hash, g_str_equal);
	_data1_->expected_individuals = _tmp1_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _data1_->expected_individuals, "0");
	gee_abstract_collection_add ((GeeAbstractCollection*) _data1_->expected_individuals, "1");
	_tmp2_ = folks_individual_aggregator_new ();
	aggregator = _tmp2_;
	g_signal_connect_data (aggregator, "individuals-changed", (GCallback) __lambda0__folks_individual_aggregator_individuals_changed, block1_data_ref (_data1_), (GClosureNotify) block1_data_unref, 0);
	folks_individual_aggregator_prepare (aggregator, NULL, NULL);
	g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, (guint) self->priv->_test_timeout, __lambda1__gsource_func, block1_data_ref (_data1_), block1_data_unref);
	g_main_loop_run (_data1_->main_loop);
	_tmp3_ = gee_collection_get_size ((GeeCollection*) _data1_->expected_individuals);
	g_assert (_tmp3_ == 0);
	kf_test_backend_tear_down (self->priv->kf_backend);
	_g_object_unref0 (aggregator);
	block1_data_unref (_data1_);
	_data1_ = NULL;
}


static Block2Data* block2_data_ref (Block2Data* _data2_) {
	g_atomic_int_inc (&_data2_->_ref_count_);
	return _data2_;
}


static void block2_data_unref (Block2Data* _data2_) {
	if (g_atomic_int_dec_and_test (&_data2_->_ref_count_)) {
		_g_object_unref0 (_data2_->self);
		_g_main_loop_unref0 (_data2_->main_loop);
		g_slice_free (Block2Data, _data2_);
	}
}


static void _lambda2_ (GeeSet* added, GeeSet* removed, const gchar* m, FolksPersona* a, FolksGroupDetailsChangeReason r, Block2Data* _data2_) {
	IndividualRetrievalTests * self;
	gint _tmp0_;
	gint _tmp1_;
	self = _data2_->self;
	g_return_if_fail (added != NULL);
	g_return_if_fail (removed != NULL);
	_data2_->individuals_changed_count++;
	_tmp0_ = gee_collection_get_size ((GeeCollection*) added);
	g_assert (_tmp0_ == 1);
	_tmp1_ = gee_collection_get_size ((GeeCollection*) removed);
	g_assert (_tmp1_ == 0);
	{
		GeeIterator* _tmp2_ = NULL;
		GeeIterator* _i_it;
		_tmp2_ = gee_iterable_iterator ((GeeIterable*) added);
		_i_it = _tmp2_;
		while (TRUE) {
			gboolean _tmp3_;
			gpointer _tmp4_ = NULL;
			FolksIndividual* i;
			const gchar* _tmp5_ = NULL;
			_tmp3_ = gee_iterator_next (_i_it);
			if (!_tmp3_) {
				break;
			}
			_tmp4_ = gee_iterator_get (_i_it);
			i = (FolksIndividual*) _tmp4_;
			_tmp5_ = folks_alias_details_get_alias ((FolksAliasDetails*) i);
			g_assert (g_strcmp0 (_tmp5_, "Brian Briansson") == 0);
			_g_object_unref0 (i);
		}
		_g_object_unref0 (_i_it);
	}
}


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


static gboolean _lambda3_ (Block2Data* _data2_) {
	IndividualRetrievalTests * self;
	gboolean result = FALSE;
	self = _data2_->self;
	g_main_loop_quit (_data2_->main_loop);
	result = FALSE;
	return result;
}


static gboolean __lambda3__gsource_func (gpointer self) {
	gboolean result;
	result = _lambda3_ (self);
	return result;
}


void individual_retrieval_tests_test_aliases (IndividualRetrievalTests* self) {
	Block2Data* _data2_;
	GMainLoop* _tmp0_ = NULL;
	FolksIndividualAggregator* _tmp1_ = NULL;
	FolksIndividualAggregator* aggregator;
	g_return_if_fail (self != NULL);
	_data2_ = g_slice_new0 (Block2Data);
	_data2_->_ref_count_ = 1;
	_data2_->self = g_object_ref (self);
	_tmp0_ = g_main_loop_new (NULL, FALSE);
	_data2_->main_loop = _tmp0_;
	kf_test_backend_set_up (self->priv->kf_backend, "[0]\n" "__alias=Brian Briansson\n" "msn=foo@hotmail.com\n");
	_tmp1_ = folks_individual_aggregator_new ();
	aggregator = _tmp1_;
	_data2_->individuals_changed_count = (guint) 0;
	g_signal_connect_data (aggregator, "individuals-changed", (GCallback) __lambda2__folks_individual_aggregator_individuals_changed, block2_data_ref (_data2_), (GClosureNotify) block2_data_unref, 0);
	folks_individual_aggregator_prepare (aggregator, NULL, NULL);
	g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, (guint) self->priv->_test_timeout, __lambda3__gsource_func, block2_data_ref (_data2_), block2_data_unref);
	g_main_loop_run (_data2_->main_loop);
	g_assert (_data2_->individuals_changed_count == 1);
	kf_test_backend_tear_down (self->priv->kf_backend);
	_g_object_unref0 (aggregator);
	block2_data_unref (_data2_);
	_data2_ = NULL;
}


static void individual_retrieval_tests_class_init (IndividualRetrievalTestsClass * klass) {
	individual_retrieval_tests_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (IndividualRetrievalTestsPrivate));
	FOLKS_TEST_CASE_CLASS (klass)->set_up = individual_retrieval_tests_real_set_up;
	FOLKS_TEST_CASE_CLASS (klass)->tear_down = individual_retrieval_tests_real_tear_down;
	G_OBJECT_CLASS (klass)->finalize = individual_retrieval_tests_finalize;
}


static void individual_retrieval_tests_instance_init (IndividualRetrievalTests * self) {
	self->priv = INDIVIDUAL_RETRIEVAL_TESTS_GET_PRIVATE (self);
	self->priv->_test_timeout = 3;
}


static void individual_retrieval_tests_finalize (GObject* obj) {
	IndividualRetrievalTests * self;
	self = INDIVIDUAL_RETRIEVAL_TESTS (obj);
	_kf_test_backend_unref0 (self->priv->kf_backend);
	G_OBJECT_CLASS (individual_retrieval_tests_parent_class)->finalize (obj);
}


GType individual_retrieval_tests_get_type (void) {
	static volatile gsize individual_retrieval_tests_type_id__volatile = 0;
	if (g_once_init_enter (&individual_retrieval_tests_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (IndividualRetrievalTestsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) individual_retrieval_tests_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (IndividualRetrievalTests), 0, (GInstanceInitFunc) individual_retrieval_tests_instance_init, NULL };
		GType individual_retrieval_tests_type_id;
		individual_retrieval_tests_type_id = g_type_register_static (FOLKS_TYPE_TEST_CASE, "IndividualRetrievalTests", &g_define_type_info, 0);
		g_once_init_leave (&individual_retrieval_tests_type_id__volatile, individual_retrieval_tests_type_id);
	}
	return individual_retrieval_tests_type_id__volatile;
}


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


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



