/* init.c generated by valac 0.24.0.16-c045, 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 <tpf-test.h>
#include <folks-test.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;
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)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

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

struct _InitTestsClass {
	TpfTestTestCaseClass parent_class;
};

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;
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 Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static gboolean __lambda3_ (Block1Data* _data1_);
static void __lambda4_ (Block1Data* _data1_, GObject* obj, GAsyncResult* res);
static void ___lambda4__gasync_ready_callback (GObject* source_object, GAsyncResult* res, gpointer self);
static gboolean ___lambda3__gsource_func (gpointer self);
gint _vala_main (gchar** args, int args_length1);


static void _init_tests_test_quiescence_folks_test_case_test_method (gpointer self) {
#line 30 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	init_tests_test_quiescence ((InitTests*) self);
#line 90 "init.c"
}


InitTests* init_tests_construct (GType object_type) {
	InitTests * self = NULL;
#line 27 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	self = (InitTests*) tpf_test_test_case_construct (object_type, "Init");
#line 30 "/opt/gnome3/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 25 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	return self;
#line 102 "init.c"
}


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


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


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


static void __lambda4_ (Block1Data* _data1_, GObject* obj, GAsyncResult* res) {
	InitTests* self;
	GError * _inner_error_ = NULL;
#line 45 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	self = _data1_->self;
#line 45 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	g_return_if_fail (res != NULL);
#line 151 "init.c"
	{
		GAsyncResult* _tmp0_ = NULL;
#line 49 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
		_tmp0_ = res;
#line 49 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
		folks_test_utils_aggregator_prepare_and_wait_for_quiescence_finish (_tmp0_, &_inner_error_);
#line 49 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
		if (_inner_error_ != NULL) {
#line 160 "init.c"
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e1 = NULL;
		GError* _tmp1_ = NULL;
		const gchar* _tmp2_ = NULL;
#line 47 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
		e1 = _inner_error_;
#line 47 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
		_inner_error_ = NULL;
#line 54 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
		_tmp1_ = e1;
#line 54 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
		_tmp2_ = _tmp1_->message;
#line 54 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
		g_critical ("init.vala:54: Error preparing aggregator: %s", _tmp2_);
#line 47 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
		_g_error_free0 (e1);
#line 182 "init.c"
	}
	__finally0:
#line 47 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	if (_inner_error_ != NULL) {
#line 47 "/opt/gnome3/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 47 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
		g_clear_error (&_inner_error_);
#line 47 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
		return;
#line 193 "init.c"
	}
#line 57 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	g_main_loop_quit (_data1_->main_loop);
#line 197 "init.c"
}


static void ___lambda4__gasync_ready_callback (GObject* source_object, GAsyncResult* res, gpointer self) {
#line 44 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	__lambda4_ (self, source_object, res);
#line 44 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	block1_data_unref (self);
#line 206 "init.c"
}


static gboolean __lambda3_ (Block1Data* _data1_) {
	InitTests* self;
	gboolean result = FALSE;
#line 42 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	self = _data1_->self;
#line 44 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	folks_test_utils_aggregator_prepare_and_wait_for_quiescence (_data1_->aggregator, ___lambda4__gasync_ready_callback, block1_data_ref (_data1_));
#line 60 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	result = FALSE;
#line 60 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	return result;
#line 221 "init.c"
}


static gboolean ___lambda3__gsource_func (gpointer self) {
	gboolean result;
	result = __lambda3_ (self);
#line 42 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	return result;
#line 230 "init.c"
}


void init_tests_test_quiescence (InitTests* self) {
	Block1Data* _data1_;
	GMainLoop* _tmp0_ = NULL;
	FolksIndividualAggregator* _tmp1_ = NULL;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	GeeMap* _tmp4_ = NULL;
	GeeMap* _tmp5_ = NULL;
	gint _tmp6_ = 0;
	gint _tmp7_ = 0;
#line 35 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	g_return_if_fail (self != NULL);
#line 35 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	_data1_ = g_slice_new0 (Block1Data);
#line 35 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	_data1_->_ref_count_ = 1;
#line 35 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	_data1_->self = g_object_ref (self);
#line 37 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	_tmp0_ = g_main_loop_new (NULL, FALSE);
#line 37 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	_data1_->main_loop = _tmp0_;
#line 40 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	_tmp1_ = folks_individual_aggregator_dup ();
#line 40 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	_data1_->aggregator = _tmp1_;
#line 42 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, ___lambda3__gsource_func, block1_data_ref (_data1_), block1_data_unref);
#line 64 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	folks_test_utils_loop_run_with_non_fatal_timeout (_data1_->main_loop, 5);
#line 67 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	_tmp2_ = folks_individual_aggregator_get_is_quiescent (_data1_->aggregator);
#line 67 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	_tmp3_ = _tmp2_;
#line 67 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	_vala_assert (_tmp3_ == TRUE, "aggregator.is_quiescent == true");
#line 68 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	_tmp4_ = folks_individual_aggregator_get_individuals (_data1_->aggregator);
#line 68 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	_tmp5_ = _tmp4_;
#line 68 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	_tmp6_ = gee_map_get_size (_tmp5_);
#line 68 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	_tmp7_ = _tmp6_;
#line 68 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	_vala_assert (_tmp7_ > 0, "aggregator.individuals.size > 0");
#line 35 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	block1_data_unref (_data1_);
#line 35 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	_data1_ = NULL;
#line 284 "init.c"
}


static void init_tests_class_init (InitTestsClass * klass) {
#line 23 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	init_tests_parent_class = g_type_class_peek_parent (klass);
#line 291 "init.c"
}


static void init_tests_instance_init (InitTests * self) {
}


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 (TPF_TEST_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;
	InitTests* tests = NULL;
	InitTests* _tmp0_ = NULL;
#line 74 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	g_test_init (&args_length1, &args, NULL);
#line 76 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	_tmp0_ = init_tests_new ();
#line 76 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	tests = _tmp0_;
#line 77 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	folks_test_case_register ((FolksTestCase*) tests);
#line 78 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	g_test_run ();
#line 79 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	folks_test_case_final_tear_down ((FolksTestCase*) tests);
#line 81 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	result = 0;
#line 81 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	_g_object_unref0 (tests);
#line 81 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	return result;
#line 333 "init.c"
}


int main (int argc, char ** argv) {
#if !GLIB_CHECK_VERSION (2,35,0)
	g_type_init ();
#endif
#line 72 "/opt/gnome3/source/folks/tests/telepathy/init.vala"
	return _vala_main (argv, argc);
#line 343 "init.c"
}



