/* init.c generated by valac 0.15.1.20-908e, the Vala compiler
 * generated from init.vala, do not modify */

/*
 * Copyright (C) 2012 Philip Withnall
 *
 * 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: Philip Withnall <philip@tecnocode.co.uk>
 */

#include <glib.h>
#include <glib-object.h>
#include <folks-test.h>
#include <tp-test-contactlist.h>
#include <folks/folks.h>
#include <gio/gio.h>
#include <gee.h>
#include <stdlib.h>
#include <string.h>


#define TYPE_INIT_TESTS (init_tests_get_type ())
#define INIT_TESTS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_INIT_TESTS, InitTests))
#define INIT_TESTS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_INIT_TESTS, InitTestsClass))
#define IS_INIT_TESTS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_INIT_TESTS))
#define IS_INIT_TESTS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_INIT_TESTS))
#define INIT_TESTS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_INIT_TESTS, InitTestsClass))

typedef struct _InitTests InitTests;
typedef struct _InitTestsClass InitTestsClass;
typedef struct _InitTestsPrivate InitTestsPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block1Data Block1Data;
#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _InitTests {
	FolksTestCase parent_instance;
	InitTestsPrivate * priv;
};

struct _InitTestsClass {
	FolksTestCaseClass parent_class;
};

struct _InitTestsPrivate {
	TpTestBackend* _tp_backend;
	gint _test_timeout;
};

struct _Block1Data {
	int _ref_count_;
	InitTests * self;
	GMainLoop* main_loop;
	FolksIndividualAggregator* aggregator;
};


static gpointer init_tests_parent_class = NULL;

GType init_tests_get_type (void) G_GNUC_CONST;
#define INIT_TESTS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_INIT_TESTS, InitTestsPrivate))
enum  {
	INIT_TESTS_DUMMY_PROPERTY
};
InitTests* init_tests_new (void);
InitTests* init_tests_construct (GType object_type);
void init_tests_test_quiescence (InitTests* self);
static void _init_tests_test_quiescence_folks_test_case_test_method (gpointer self);
static void init_tests_real_set_up (FolksTestCase* base);
static void init_tests_real_tear_down (FolksTestCase* base);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (Block1Data* _data1_);
static gboolean __lambda2_ (Block1Data* _data1_);
static void __lambda3_ (Block1Data* _data1_, GObject* obj, GAsyncResult* res);
static void ___lambda3__gasync_ready_callback (GObject* source_object, GAsyncResult* res, gpointer self);
static gboolean ___lambda2__gsource_func (gpointer self);
static gboolean __lambda4_ (Block1Data* _data1_);
static gboolean ___lambda4__gsource_func (gpointer self);
static void init_tests_finalize (GObject* obj);
gint _vala_main (gchar** args, int args_length1);


static void _init_tests_test_quiescence_folks_test_case_test_method (gpointer self) {
#line 35 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	init_tests_test_quiescence (self);
#line 100 "init.c"
}


InitTests* init_tests_construct (GType object_type) {
	InitTests * self = NULL;
	TpTestBackend* _tmp0_;
#line 30 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	self = (InitTests*) folks_test_case_construct (object_type, "Init");
#line 32 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_tmp0_ = tp_test_backend_new ();
#line 32 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_g_object_unref0 (self->priv->_tp_backend);
#line 32 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	self->priv->_tp_backend = _tmp0_;
#line 35 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	folks_test_case_add_test ((FolksTestCase*) self, "quiescence", _init_tests_test_quiescence_folks_test_case_test_method, self);
#line 28 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	return self;
#line 119 "init.c"
}


InitTests* init_tests_new (void) {
#line 28 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	return init_tests_construct (TYPE_INIT_TESTS);
#line 126 "init.c"
}


static void init_tests_real_set_up (FolksTestCase* base) {
	InitTests * self;
	TpTestBackend* _tmp0_;
#line 38 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	self = (InitTests*) base;
#line 40 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_tmp0_ = self->priv->_tp_backend;
#line 40 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	tp_test_backend_set_up (_tmp0_);
#line 139 "init.c"
}


static void init_tests_real_tear_down (FolksTestCase* base) {
	InitTests * self;
	TpTestBackend* _tmp0_;
#line 43 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	self = (InitTests*) base;
#line 45 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_tmp0_ = self->priv->_tp_backend;
#line 45 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	tp_test_backend_tear_down (_tmp0_);
#line 152 "init.c"
}


static Block1Data* block1_data_ref (Block1Data* _data1_) {
#line 50 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	g_atomic_int_inc (&_data1_->_ref_count_);
#line 50 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	return _data1_;
#line 161 "init.c"
}


static void block1_data_unref (Block1Data* _data1_) {
#line 50 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
#line 168 "init.c"
		InitTests * self;
#line 50 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
		self = _data1_->self;
#line 50 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
		_g_object_unref0 (_data1_->aggregator);
#line 50 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
		_g_main_loop_unref0 (_data1_->main_loop);
#line 50 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
		_g_object_unref0 (self);
#line 50 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
		g_slice_free (Block1Data, _data1_);
#line 180 "init.c"
	}
}


static void __lambda3_ (Block1Data* _data1_, GObject* obj, GAsyncResult* res) {
	InitTests * self;
	GError * _inner_error_ = NULL;
#line 63 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	self = _data1_->self;
#line 63 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	g_return_if_fail (res != NULL);
#line 192 "init.c"
	{
		GAsyncResult* _tmp0_;
#line 67 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
		_tmp0_ = res;
#line 67 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
		folks_test_utils_aggregator_prepare_and_wait_for_quiescence_finish (_tmp0_, &_inner_error_);
#line 67 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
		if (_inner_error_ != NULL) {
#line 201 "init.c"
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e1 = NULL;
		GError* _tmp1_;
		const gchar* _tmp2_;
#line 65 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
		e1 = _inner_error_;
#line 65 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
		_inner_error_ = NULL;
#line 72 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
		_tmp1_ = e1;
#line 72 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
		_tmp2_ = _tmp1_->message;
#line 72 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
		g_critical ("init.vala:72: Error preparing aggregator: %s", _tmp2_);
#line 65 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
		_g_error_free0 (e1);
#line 223 "init.c"
	}
	__finally0:
#line 65 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	if (_inner_error_ != NULL) {
#line 65 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
		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);
#line 65 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
		g_clear_error (&_inner_error_);
#line 65 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
		return;
#line 234 "init.c"
	}
#line 75 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	g_main_loop_quit (_data1_->main_loop);
#line 238 "init.c"
}


static void ___lambda3__gasync_ready_callback (GObject* source_object, GAsyncResult* res, gpointer self) {
#line 62 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	__lambda3_ (self, source_object, res);
#line 62 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	block1_data_unref (self);
#line 247 "init.c"
}


static gboolean __lambda2_ (Block1Data* _data1_) {
	InitTests * self;
	gboolean result = FALSE;
#line 60 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	self = _data1_->self;
#line 62 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	folks_test_utils_aggregator_prepare_and_wait_for_quiescence (_data1_->aggregator, ___lambda3__gasync_ready_callback, block1_data_ref (_data1_));
#line 78 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	result = FALSE;
#line 78 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	return result;
#line 262 "init.c"
}


static gboolean ___lambda2__gsource_func (gpointer self) {
	gboolean result;
	result = __lambda2_ (self);
#line 60 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	return result;
#line 271 "init.c"
}


static gboolean __lambda4_ (Block1Data* _data1_) {
	InitTests * self;
	gboolean result = FALSE;
#line 82 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	self = _data1_->self;
#line 84 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	g_main_loop_quit (_data1_->main_loop);
#line 85 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	result = FALSE;
#line 85 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	return result;
#line 286 "init.c"
}


static gboolean ___lambda4__gsource_func (gpointer self) {
	gboolean result;
	result = __lambda4_ (self);
#line 82 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	return result;
#line 295 "init.c"
}


void init_tests_test_quiescence (InitTests* self) {
	Block1Data* _data1_;
	GMainLoop* _tmp0_;
	TpTestBackend* _tmp1_;
	void* _tmp2_ = NULL;
	void* account_handle;
	FolksIndividualAggregator* _tmp3_;
	gint _tmp4_;
	gboolean _tmp5_;
	gboolean _tmp6_;
	GeeMap* _tmp7_;
	GeeMap* _tmp8_;
	gint _tmp9_;
	gint _tmp10_;
	TpTestBackend* _tmp11_;
#line 50 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	g_return_if_fail (self != NULL);
#line 50 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_data1_ = g_slice_new0 (Block1Data);
#line 50 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_data1_->_ref_count_ = 1;
#line 50 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_data1_->self = g_object_ref (self);
#line 52 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_tmp0_ = g_main_loop_new (NULL, FALSE);
#line 52 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_data1_->main_loop = _tmp0_;
#line 54 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_tmp1_ = self->priv->_tp_backend;
#line 54 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_tmp2_ = tp_test_backend_add_account (_tmp1_, "protocol", "me@example.com", "cm", "account");
#line 54 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	account_handle = _tmp2_;
#line 58 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_tmp3_ = folks_individual_aggregator_new ();
#line 58 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_data1_->aggregator = _tmp3_;
#line 60 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, ___lambda2__gsource_func, block1_data_ref (_data1_), block1_data_unref);
#line 82 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_tmp4_ = self->priv->_test_timeout;
#line 82 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, (guint) _tmp4_, ___lambda4__gsource_func, block1_data_ref (_data1_), block1_data_unref);
#line 88 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	g_main_loop_run (_data1_->main_loop);
#line 91 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_tmp5_ = folks_individual_aggregator_get_is_quiescent (_data1_->aggregator);
#line 91 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_tmp6_ = _tmp5_;
#line 91 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	g_assert (_tmp6_ == TRUE);
#line 92 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_tmp7_ = folks_individual_aggregator_get_individuals (_data1_->aggregator);
#line 92 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_tmp8_ = _tmp7_;
#line 92 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_tmp9_ = gee_map_get_size (_tmp8_);
#line 92 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_tmp10_ = _tmp9_;
#line 92 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	g_assert (_tmp10_ > 0);
#line 95 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_tmp11_ = self->priv->_tp_backend;
#line 95 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	tp_test_backend_remove_account (_tmp11_, account_handle);
#line 50 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	block1_data_unref (_data1_);
#line 50 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_data1_ = NULL;
#line 368 "init.c"
}


static void init_tests_class_init (InitTestsClass * klass) {
#line 23 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	init_tests_parent_class = g_type_class_peek_parent (klass);
#line 23 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	g_type_class_add_private (klass, sizeof (InitTestsPrivate));
#line 23 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	FOLKS_TEST_CASE_CLASS (klass)->set_up = init_tests_real_set_up;
#line 23 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	FOLKS_TEST_CASE_CLASS (klass)->tear_down = init_tests_real_tear_down;
#line 23 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	G_OBJECT_CLASS (klass)->finalize = init_tests_finalize;
#line 383 "init.c"
}


static void init_tests_instance_init (InitTests * self) {
#line 23 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	self->priv = INIT_TESTS_GET_PRIVATE (self);
#line 26 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	self->priv->_test_timeout = 5;
#line 392 "init.c"
}


static void init_tests_finalize (GObject* obj) {
	InitTests * self;
#line 23 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	self = INIT_TESTS (obj);
#line 25 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_g_object_unref0 (self->priv->_tp_backend);
#line 23 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	G_OBJECT_CLASS (init_tests_parent_class)->finalize (obj);
#line 404 "init.c"
}


GType init_tests_get_type (void) {
	static volatile gsize init_tests_type_id__volatile = 0;
	if (g_once_init_enter (&init_tests_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (InitTestsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) init_tests_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (InitTests), 0, (GInstanceInitFunc) init_tests_instance_init, NULL };
		GType init_tests_type_id;
		init_tests_type_id = g_type_register_static (FOLKS_TYPE_TEST_CASE, "InitTests", &g_define_type_info, 0);
		g_once_init_leave (&init_tests_type_id__volatile, init_tests_type_id);
	}
	return init_tests_type_id__volatile;
}


gint _vala_main (gchar** args, int args_length1) {
	gint result = 0;
	GTestSuite* _tmp0_ = NULL;
	GTestSuite* root;
	InitTests* _tmp1_;
	InitTests* _tmp2_;
	GTestSuite* _tmp3_ = NULL;
#line 101 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	g_test_init (&args_length1, &args, NULL);
#line 103 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_tmp0_ = g_test_get_root ();
#line 103 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	root = _tmp0_;
#line 104 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_tmp1_ = init_tests_new ();
#line 104 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_tmp2_ = _tmp1_;
#line 104 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_tmp3_ = folks_test_case_get_suite ((FolksTestCase*) _tmp2_);
#line 104 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	g_test_suite_add_suite (root, _tmp3_);
#line 104 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	_g_object_unref0 (_tmp2_);
#line 106 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	g_test_run ();
#line 108 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	result = 0;
#line 108 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	return result;
#line 449 "init.c"
}


int main (int argc, char ** argv) {
#line 99 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	g_type_init ();
#line 99 "/opt/gnome2/source/folks/tests/telepathy/init.vala"
	return _vala_main (argv, argc);
#line 458 "init.c"
}



