/* direct-query-test.c generated by valac 0.9.5.4-19a5, the Vala compiler
 * generated from direct-query-test.vala, do not modify */


#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <tracker-sparql.h>
#include <stdlib.h>
#include <string.h>

#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define TYPE_TEST_APP (test_app_get_type ())
#define TEST_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST_APP, TestApp))
#define TEST_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST_APP, TestAppClass))
#define IS_TEST_APP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST_APP))
#define IS_TEST_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST_APP))
#define TEST_APP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST_APP, TestAppClass))

typedef struct _TestApp TestApp;
typedef struct _TestAppClass TestAppClass;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _TestAsyncData TestAsyncData;
#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL)))

struct _TestAsyncData {
	int _state_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	TrackerSparqlConnection* c;
	TrackerSparqlConnection* _tmp0_;
	TrackerSparqlConnection* _tmp1_;
	TestApp* app;
	GError * e1;
	GError * e2;
	GError * _inner_error_;
};


extern gint res;
gint res = 0;
extern GMainLoop* loop;
GMainLoop* loop = NULL;

static void test_async_data_free (gpointer _data);
static void test_async_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
TestApp* test_app_new (TrackerSparqlConnection* connection);
TestApp* test_app_construct (GType object_type, TrackerSparqlConnection* connection);
GType test_app_get_type (void) G_GNUC_CONST;
gint test_app_run (TestApp* self);
void test_async (GAsyncReadyCallback _callback_, gpointer _user_data_);
void test_finish (GAsyncResult* _res_);
static gboolean test_async_co (TestAsyncData* data);
void test_sync (void);
gint _vala_main (char** args, int args_length1);



static void test_async_data_free (gpointer _data) {
	TestAsyncData* data;
	data = _data;
	g_slice_free (TestAsyncData, data);
}


void test_async (GAsyncReadyCallback _callback_, gpointer _user_data_) {
	TestAsyncData* _data_;
	_data_ = g_slice_new0 (TestAsyncData);
	_data_->_async_result = g_simple_async_result_new (g_object_newv (G_TYPE_OBJECT, 0, NULL), _callback_, _user_data_, test_async);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, test_async_data_free);
	test_async_co (_data_);
}


void test_finish (GAsyncResult* _res_) {
	TestAsyncData* _data_;
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
}


static void test_async_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	TestAsyncData* data;
	data = _user_data_;
	data->_res_ = _res_;
	test_async_co (data);
}


static gboolean test_async_co (TestAsyncData* data) {
	switch (data->_state_) {
		case 0:
		goto _state_0;
		case 3:
		goto _state_3;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	{
		g_main_loop_quit (loop);
		{
			g_print ("Getting connection asynchronously\n");
			data->_state_ = 3;
			tracker_sparql_connection_get_async (NULL, test_async_ready, data);
			return FALSE;
			_state_3:
			data->_tmp0_ = tracker_sparql_connection_get_finish (data->_res_, &data->_inner_error_);
			if (data->_inner_error_ != NULL) {
				_g_object_unref0 (data->c);
				if (data->_inner_error_->domain == G_IO_ERROR) {
					goto __catch3_g_io_error;
				}
				if (data->_inner_error_->domain == TRACKER_SPARQL_ERROR) {
					goto __catch3_tracker_sparql_error;
				}
				_g_object_unref0 (data->c);
				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;
			}
			data->c = (data->_tmp1_ = data->_tmp0_, _g_object_unref0 (data->c), data->_tmp1_);
			g_print ("Got it %p\n", data->c);
			g_print ("Creating app with connection\n");
			data->app = test_app_new (data->c);
			g_print ("Running app\n");
			res = test_app_run (data->app);
			_g_object_unref0 (data->app);
			_g_object_unref0 (data->c);
		}
		goto __finally3;
		__catch3_g_io_error:
		{
			data->e1 = data->_inner_error_;
			data->_inner_error_ = NULL;
			{
				g_warning ("direct-query-test.vala:26: Couldn't perform test: %s", data->e1->message);
				_g_error_free0 (data->e1);
			}
		}
		goto __finally3;
		__catch3_tracker_sparql_error:
		{
			data->e2 = data->_inner_error_;
			data->_inner_error_ = NULL;
			{
				g_warning ("direct-query-test.vala:28: Couldn't perform test: %s", data->e2->message);
				_g_error_free0 (data->e2);
			}
		}
		__finally3:
		if (data->_inner_error_ != NULL) {
			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_print ("\n");
	}
	{
		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;
	}
}


void test_sync (void) {
	GError * _inner_error_;
	_inner_error_ = NULL;
	{
		TrackerSparqlConnection* c;
		TrackerSparqlConnection* _tmp0_;
		TrackerSparqlConnection* _tmp1_;
		TestApp* app;
		c = NULL;
		g_print ("Getting connection synchronously\n");
		_tmp0_ = tracker_sparql_connection_get (NULL, &_inner_error_);
		if (_inner_error_ != NULL) {
			_g_object_unref0 (c);
			if (_inner_error_->domain == G_IO_ERROR) {
				goto __catch4_g_io_error;
			}
			if (_inner_error_->domain == TRACKER_SPARQL_ERROR) {
				goto __catch4_tracker_sparql_error;
			}
			_g_object_unref0 (c);
			g_critical ("file %s: line %d: unexpected 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;
		}
		c = (_tmp1_ = _tmp0_, _g_object_unref0 (c), _tmp1_);
		g_print ("Got it %p\n", c);
		g_print ("Creating app with connection\n");
		app = test_app_new (c);
		g_print ("Running app\n");
		res = test_app_run (app);
		_g_object_unref0 (app);
		_g_object_unref0 (c);
	}
	goto __finally4;
	__catch4_g_io_error:
	{
		GError * e1;
		e1 = _inner_error_;
		_inner_error_ = NULL;
		{
			g_warning ("direct-query-test.vala:50: Couldn't perform test: %s", e1->message);
			_g_error_free0 (e1);
		}
	}
	goto __finally4;
	__catch4_tracker_sparql_error:
	{
		GError * e2;
		e2 = _inner_error_;
		_inner_error_ = NULL;
		{
			g_warning ("direct-query-test.vala:52: Couldn't perform test: %s", e2->message);
			_g_error_free0 (e2);
		}
	}
	__finally4:
	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;
	}
	g_print ("\n");
}


gint _vala_main (char** args, int args_length1) {
	gint result = 0;
	GMainLoop* _tmp0_;
	g_print ("Starting...\n");
	loop = (_tmp0_ = g_main_loop_new (NULL, FALSE), _g_main_loop_unref0 (loop), _tmp0_);
	test_sync ();
	if (res < 0) {
		result = res;
		return result;
	}
	test_async (NULL, NULL);
	g_main_loop_run (loop);
	result = res;
	return result;
}


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




