/* testatparser.c generated by valac 0.14.2, the Vala compiler
 * generated from testatparser.vala, do not modify */


#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <fsogsm.h>
#include <fsotransport.h>

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


extern gboolean haveCommand;
gboolean haveCommand = FALSE;
extern gboolean expectedPrefix;
gboolean expectedPrefix = FALSE;
extern gchar** solicitedResponse;
extern gint solicitedResponse_length1;
gchar** solicitedResponse = NULL;
gint solicitedResponse_length1 = 0;
static gint _solicitedResponse_size_ = 0;
extern gchar** unsolicitedResponse;
extern gint unsolicitedResponse_length1;
gchar** unsolicitedResponse = NULL;
gint unsolicitedResponse_length1 = 0;
static gint _unsolicitedResponse_size_ = 0;

gboolean hcf (void);
gboolean epf (void);
void soli (gchar** response, int response_length1);
void unsoli (gchar** response, int response_length1);
void test_parser_1_solicited (void);
static gboolean _hcf_fso_framework_parser_have_command_func (gpointer self);
static gboolean _epf_fso_framework_parser_expected_prefix_func (const gchar* line, gpointer self);
static void _soli_fso_framework_parser_solicited_completed_func (gchar** response, int response_length1, gpointer self);
static void _unsoli_fso_framework_parser_unsolicited_completed_func (gchar** response, int response_length1, gpointer self);
void test_parser_1_unsolicited (void);
void test_parser_2_solicited (void);
void test_parser_2_unsolicited (void);
void test_parser_2_unsolicited_pdu (void);
void test_parser_multiline_solicited (void);
void _vala_main (gchar** args, int args_length1);
static void _test_parser_1_solicited_gcallback (void);
static void _test_parser_1_unsolicited_gcallback (void);
static void _test_parser_2_solicited_gcallback (void);
static void _test_parser_2_unsolicited_gcallback (void);
static void _test_parser_2_unsolicited_pdu_gcallback (void);
static void _test_parser_multiline_solicited_gcallback (void);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);


gboolean hcf (void) {
	gboolean result = FALSE;
	gboolean _tmp0_;
	_tmp0_ = haveCommand;
	result = _tmp0_;
	return result;
}


gboolean epf (void) {
	gboolean result = FALSE;
	gboolean _tmp0_;
	_tmp0_ = expectedPrefix;
	result = _tmp0_;
	return result;
}


void soli (gchar** response, int response_length1) {
	gboolean _tmp0_;
	gchar** _tmp1_;
	gint _tmp1__length1;
	gchar** _tmp2_;
	gint _tmp2__length1;
	_tmp0_ = haveCommand;
	g_assert (_tmp0_);
	_tmp1_ = solicitedResponse;
	_tmp1__length1 = solicitedResponse_length1;
	_tmp2_ = response;
	_tmp2__length1 = response_length1;
	g_assert (_tmp1__length1 == _tmp2__length1);
	{
		gint i;
		i = 0;
		{
			gboolean _tmp3_;
			_tmp3_ = TRUE;
			while (TRUE) {
				gboolean _tmp4_;
				gint _tmp6_;
				gchar** _tmp7_;
				gint _tmp7__length1;
				gint _tmp8_;
				gchar** _tmp9_;
				gint _tmp9__length1;
				gint _tmp10_;
				const gchar* _tmp11_;
				gchar** _tmp12_;
				gint _tmp12__length1;
				gint _tmp13_;
				const gchar* _tmp14_;
				gchar** _tmp15_;
				gint _tmp15__length1;
				gint _tmp16_;
				const gchar* _tmp17_;
				_tmp4_ = _tmp3_;
				if (!_tmp4_) {
					gint _tmp5_;
					_tmp5_ = i;
					i = _tmp5_ + 1;
				}
				_tmp3_ = FALSE;
				_tmp6_ = i;
				_tmp7_ = response;
				_tmp7__length1 = response_length1;
				if (!(_tmp6_ < _tmp7__length1)) {
					break;
				}
				_tmp8_ = i;
				_tmp9_ = response;
				_tmp9__length1 = response_length1;
				_tmp10_ = i;
				_tmp11_ = _tmp9_[_tmp10_];
				g_debug ("testatparser.vala:45: line %d = '%s'", _tmp8_, _tmp11_);
				_tmp12_ = response;
				_tmp12__length1 = response_length1;
				_tmp13_ = i;
				_tmp14_ = _tmp12_[_tmp13_];
				_tmp15_ = solicitedResponse;
				_tmp15__length1 = solicitedResponse_length1;
				_tmp16_ = i;
				_tmp17_ = _tmp15_[_tmp16_];
				g_assert (g_strcmp0 (_tmp14_, _tmp17_) == 0);
			}
		}
	}
}


void unsoli (gchar** response, int response_length1) {
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_;
	gboolean _tmp3_;
	gchar** _tmp4_;
	gint _tmp4__length1;
	gchar** _tmp5_;
	gint _tmp5__length1;
	_tmp1_ = haveCommand;
	if (!_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		gboolean _tmp2_;
		_tmp2_ = expectedPrefix;
		_tmp0_ = !_tmp2_;
	}
	_tmp3_ = _tmp0_;
	g_assert (_tmp3_);
	_tmp4_ = unsolicitedResponse;
	_tmp4__length1 = unsolicitedResponse_length1;
	_tmp5_ = response;
	_tmp5__length1 = response_length1;
	g_assert (_tmp4__length1 == _tmp5__length1);
	{
		gint i;
		i = 0;
		{
			gboolean _tmp6_;
			_tmp6_ = TRUE;
			while (TRUE) {
				gboolean _tmp7_;
				gint _tmp9_;
				gchar** _tmp10_;
				gint _tmp10__length1;
				gint _tmp11_;
				gchar** _tmp12_;
				gint _tmp12__length1;
				gint _tmp13_;
				const gchar* _tmp14_;
				gchar** _tmp15_;
				gint _tmp15__length1;
				gint _tmp16_;
				const gchar* _tmp17_;
				gchar** _tmp18_;
				gint _tmp18__length1;
				gint _tmp19_;
				const gchar* _tmp20_;
				_tmp7_ = _tmp6_;
				if (!_tmp7_) {
					gint _tmp8_;
					_tmp8_ = i;
					i = _tmp8_ + 1;
				}
				_tmp6_ = FALSE;
				_tmp9_ = i;
				_tmp10_ = response;
				_tmp10__length1 = response_length1;
				if (!(_tmp9_ < _tmp10__length1)) {
					break;
				}
				_tmp11_ = i;
				_tmp12_ = response;
				_tmp12__length1 = response_length1;
				_tmp13_ = i;
				_tmp14_ = _tmp12_[_tmp13_];
				g_debug ("testatparser.vala:56: line %d = '%s'", _tmp11_, _tmp14_);
				_tmp15_ = response;
				_tmp15__length1 = response_length1;
				_tmp16_ = i;
				_tmp17_ = _tmp15_[_tmp16_];
				_tmp18_ = unsolicitedResponse;
				_tmp18__length1 = unsolicitedResponse_length1;
				_tmp19_ = i;
				_tmp20_ = _tmp18_[_tmp19_];
				g_assert (g_strcmp0 (_tmp17_, _tmp20_) == 0);
			}
		}
	}
}


static gboolean _hcf_fso_framework_parser_have_command_func (gpointer self) {
	gboolean result;
	result = hcf ();
	return result;
}


static gboolean _epf_fso_framework_parser_expected_prefix_func (const gchar* line, gpointer self) {
	gboolean result;
	result = epf ();
	return result;
}


static void _soli_fso_framework_parser_solicited_completed_func (gchar** response, int response_length1, gpointer self) {
	soli (response, response_length1);
}


static void _unsoli_fso_framework_parser_unsolicited_completed_func (gchar** response, int response_length1, gpointer self) {
	unsoli (response, response_length1);
}


void test_parser_1_solicited (void) {
	FsoGsmStateBasedAtParser* _tmp0_;
	FsoFrameworkParser* parser;
	gchar* _tmp1_;
	gchar** _tmp2_ = NULL;
	gchar** _tmp3_ = NULL;
	_tmp0_ = fso_gsm_state_based_at_parser_new ();
	parser = (FsoFrameworkParser*) _tmp0_;
	fso_framework_parser_setDelegates (parser, _hcf_fso_framework_parser_have_command_func, NULL, _epf_fso_framework_parser_expected_prefix_func, NULL, _soli_fso_framework_parser_solicited_completed_func, NULL, _unsoli_fso_framework_parser_unsolicited_completed_func, NULL);
	haveCommand = TRUE;
	expectedPrefix = FALSE;
	_tmp1_ = g_strdup ("OK");
	_tmp2_ = g_new0 (gchar*, 1 + 1);
	_tmp2_[0] = _tmp1_;
	solicitedResponse = (_vala_array_free (solicitedResponse, solicitedResponse_length1, (GDestroyNotify) g_free), NULL);
	solicitedResponse = _tmp2_;
	solicitedResponse_length1 = 1;
	_solicitedResponse_size_ = solicitedResponse_length1;
	_tmp3_ = g_new0 (gchar*, 0 + 1);
	unsolicitedResponse = (_vala_array_free (unsolicitedResponse, unsolicitedResponse_length1, (GDestroyNotify) g_free), NULL);
	unsolicitedResponse = _tmp3_;
	unsolicitedResponse_length1 = 0;
	_unsolicitedResponse_size_ = unsolicitedResponse_length1;
	fso_framework_parser_feed (parser, "\r\nOK\r\n", 6);
	_g_object_unref0 (parser);
}


void test_parser_1_unsolicited (void) {
	FsoGsmStateBasedAtParser* _tmp0_;
	FsoFrameworkParser* parser;
	gchar** _tmp1_ = NULL;
	gchar* _tmp2_;
	gchar** _tmp3_ = NULL;
	_tmp0_ = fso_gsm_state_based_at_parser_new ();
	parser = (FsoFrameworkParser*) _tmp0_;
	fso_framework_parser_setDelegates (parser, _hcf_fso_framework_parser_have_command_func, NULL, _epf_fso_framework_parser_expected_prefix_func, NULL, _soli_fso_framework_parser_solicited_completed_func, NULL, _unsoli_fso_framework_parser_unsolicited_completed_func, NULL);
	haveCommand = FALSE;
	expectedPrefix = FALSE;
	_tmp1_ = g_new0 (gchar*, 0 + 1);
	solicitedResponse = (_vala_array_free (solicitedResponse, solicitedResponse_length1, (GDestroyNotify) g_free), NULL);
	solicitedResponse = _tmp1_;
	solicitedResponse_length1 = 0;
	_solicitedResponse_size_ = solicitedResponse_length1;
	_tmp2_ = g_strdup ("+FOO: Yo Kurt");
	_tmp3_ = g_new0 (gchar*, 1 + 1);
	_tmp3_[0] = _tmp2_;
	unsolicitedResponse = (_vala_array_free (unsolicitedResponse, unsolicitedResponse_length1, (GDestroyNotify) g_free), NULL);
	unsolicitedResponse = _tmp3_;
	unsolicitedResponse_length1 = 1;
	_unsolicitedResponse_size_ = unsolicitedResponse_length1;
	fso_framework_parser_feed (parser, "\r\n+FOO: Yo Kurt\r\n", 17);
	_g_object_unref0 (parser);
}


void test_parser_2_solicited (void) {
	FsoGsmStateBasedAtParser* _tmp0_;
	FsoFrameworkParser* parser;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar** _tmp3_ = NULL;
	gchar** _tmp4_ = NULL;
	_tmp0_ = fso_gsm_state_based_at_parser_new ();
	parser = (FsoFrameworkParser*) _tmp0_;
	fso_framework_parser_setDelegates (parser, _hcf_fso_framework_parser_have_command_func, NULL, _epf_fso_framework_parser_expected_prefix_func, NULL, _soli_fso_framework_parser_solicited_completed_func, NULL, _unsoli_fso_framework_parser_unsolicited_completed_func, NULL);
	haveCommand = TRUE;
	expectedPrefix = TRUE;
	_tmp1_ = g_strdup ("+CPIN: \"READY\"");
	_tmp2_ = g_strdup ("OK");
	_tmp3_ = g_new0 (gchar*, 2 + 1);
	_tmp3_[0] = _tmp1_;
	_tmp3_[1] = _tmp2_;
	solicitedResponse = (_vala_array_free (solicitedResponse, solicitedResponse_length1, (GDestroyNotify) g_free), NULL);
	solicitedResponse = _tmp3_;
	solicitedResponse_length1 = 2;
	_solicitedResponse_size_ = solicitedResponse_length1;
	_tmp4_ = g_new0 (gchar*, 0 + 1);
	unsolicitedResponse = (_vala_array_free (unsolicitedResponse, unsolicitedResponse_length1, (GDestroyNotify) g_free), NULL);
	unsolicitedResponse = _tmp4_;
	unsolicitedResponse_length1 = 0;
	_unsolicitedResponse_size_ = unsolicitedResponse_length1;
	fso_framework_parser_feed (parser, "\r\n+CPIN: \"READY\"\r\n", 18);
	fso_framework_parser_feed (parser, "\r\nOK\r\n", 6);
	_g_object_unref0 (parser);
}


void test_parser_2_unsolicited (void) {
	FsoGsmStateBasedAtParser* _tmp0_;
	FsoFrameworkParser* parser;
	gchar** _tmp1_ = NULL;
	gchar* _tmp2_;
	gchar** _tmp3_ = NULL;
	gchar* _tmp4_;
	gchar** _tmp5_ = NULL;
	_tmp0_ = fso_gsm_state_based_at_parser_new ();
	parser = (FsoFrameworkParser*) _tmp0_;
	fso_framework_parser_setDelegates (parser, _hcf_fso_framework_parser_have_command_func, NULL, _epf_fso_framework_parser_expected_prefix_func, NULL, _soli_fso_framework_parser_solicited_completed_func, NULL, _unsoli_fso_framework_parser_unsolicited_completed_func, NULL);
	haveCommand = FALSE;
	expectedPrefix = FALSE;
	_tmp1_ = g_new0 (gchar*, 0 + 1);
	solicitedResponse = (_vala_array_free (solicitedResponse, solicitedResponse_length1, (GDestroyNotify) g_free), NULL);
	solicitedResponse = _tmp1_;
	solicitedResponse_length1 = 0;
	_solicitedResponse_size_ = solicitedResponse_length1;
	_tmp2_ = g_strdup ("+FOO: Yo Kurt");
	_tmp3_ = g_new0 (gchar*, 1 + 1);
	_tmp3_[0] = _tmp2_;
	unsolicitedResponse = (_vala_array_free (unsolicitedResponse, unsolicitedResponse_length1, (GDestroyNotify) g_free), NULL);
	unsolicitedResponse = _tmp3_;
	unsolicitedResponse_length1 = 1;
	_unsolicitedResponse_size_ = unsolicitedResponse_length1;
	fso_framework_parser_feed (parser, "\r\n+FOO: Yo Kurt\r\n", 17);
	_tmp4_ = g_strdup ("+BAR: Yo Kurt");
	_tmp5_ = g_new0 (gchar*, 1 + 1);
	_tmp5_[0] = _tmp4_;
	unsolicitedResponse = (_vala_array_free (unsolicitedResponse, unsolicitedResponse_length1, (GDestroyNotify) g_free), NULL);
	unsolicitedResponse = _tmp5_;
	unsolicitedResponse_length1 = 1;
	_unsolicitedResponse_size_ = unsolicitedResponse_length1;
	fso_framework_parser_feed (parser, "\r\n+BAR: Yo Kurt\r\n", 17);
	_g_object_unref0 (parser);
}


void test_parser_2_unsolicited_pdu (void) {
	FsoGsmStateBasedAtParser* _tmp0_;
	FsoFrameworkParser* parser;
	gchar** _tmp1_ = NULL;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar** _tmp4_ = NULL;
	_tmp0_ = fso_gsm_state_based_at_parser_new ();
	parser = (FsoFrameworkParser*) _tmp0_;
	fso_framework_parser_setDelegates (parser, _hcf_fso_framework_parser_have_command_func, NULL, _epf_fso_framework_parser_expected_prefix_func, NULL, _soli_fso_framework_parser_solicited_completed_func, NULL, _unsoli_fso_framework_parser_unsolicited_completed_func, NULL);
	haveCommand = FALSE;
	expectedPrefix = FALSE;
	_tmp1_ = g_new0 (gchar*, 0 + 1);
	solicitedResponse = (_vala_array_free (solicitedResponse, solicitedResponse_length1, (GDestroyNotify) g_free), NULL);
	solicitedResponse = _tmp1_;
	solicitedResponse_length1 = 0;
	_solicitedResponse_size_ = solicitedResponse_length1;
	_tmp2_ = g_strdup ("+CMT: 120");
	_tmp3_ = g_strdup ("1234567890");
	_tmp4_ = g_new0 (gchar*, 2 + 1);
	_tmp4_[0] = _tmp2_;
	_tmp4_[1] = _tmp3_;
	unsolicitedResponse = (_vala_array_free (unsolicitedResponse, unsolicitedResponse_length1, (GDestroyNotify) g_free), NULL);
	unsolicitedResponse = _tmp4_;
	unsolicitedResponse_length1 = 2;
	_unsolicitedResponse_size_ = unsolicitedResponse_length1;
	fso_framework_parser_feed (parser, "\r\n+CMT: 120\r\n", 13);
	fso_framework_parser_feed (parser, "1234567890\r\n", 12);
	_g_object_unref0 (parser);
}


void test_parser_multiline_solicited (void) {
	FsoGsmStateBasedAtParser* _tmp0_;
	FsoFrameworkParser* parser;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar** _tmp4_ = NULL;
	gchar** _tmp5_ = NULL;
	_tmp0_ = fso_gsm_state_based_at_parser_new ();
	parser = (FsoFrameworkParser*) _tmp0_;
	fso_framework_parser_setDelegates (parser, _hcf_fso_framework_parser_have_command_func, NULL, _epf_fso_framework_parser_expected_prefix_func, NULL, _soli_fso_framework_parser_solicited_completed_func, NULL, _unsoli_fso_framework_parser_unsolicited_completed_func, NULL);
	haveCommand = TRUE;
	expectedPrefix = TRUE;
	_tmp1_ = g_strdup ("+FOO: 123456");
	_tmp2_ = g_strdup ("+BAR: 123456");
	_tmp3_ = g_strdup ("OK");
	_tmp4_ = g_new0 (gchar*, 3 + 1);
	_tmp4_[0] = _tmp1_;
	_tmp4_[1] = _tmp2_;
	_tmp4_[2] = _tmp3_;
	solicitedResponse = (_vala_array_free (solicitedResponse, solicitedResponse_length1, (GDestroyNotify) g_free), NULL);
	solicitedResponse = _tmp4_;
	solicitedResponse_length1 = 3;
	_solicitedResponse_size_ = solicitedResponse_length1;
	_tmp5_ = g_new0 (gchar*, 0 + 1);
	unsolicitedResponse = (_vala_array_free (unsolicitedResponse, unsolicitedResponse_length1, (GDestroyNotify) g_free), NULL);
	unsolicitedResponse = _tmp5_;
	unsolicitedResponse_length1 = 0;
	_unsolicitedResponse_size_ = unsolicitedResponse_length1;
	fso_framework_parser_feed (parser, "\r\n+FOO: 123456", 14);
	fso_framework_parser_feed (parser, "\r\n+BAR: 123456", 14);
	fso_framework_parser_feed (parser, "\r\nOK\r\n", 6);
	_g_object_unref0 (parser);
}


static void _test_parser_1_solicited_gcallback (void) {
	test_parser_1_solicited ();
}


static void _test_parser_1_unsolicited_gcallback (void) {
	test_parser_1_unsolicited ();
}


static void _test_parser_2_solicited_gcallback (void) {
	test_parser_2_solicited ();
}


static void _test_parser_2_unsolicited_gcallback (void) {
	test_parser_2_unsolicited ();
}


static void _test_parser_2_unsolicited_pdu_gcallback (void) {
	test_parser_2_unsolicited_pdu ();
}


static void _test_parser_multiline_solicited_gcallback (void) {
	test_parser_multiline_solicited ();
}


void _vala_main (gchar** args, int args_length1) {
	g_test_init (&args_length1, &args, NULL);
	g_test_add_func ("/Parser/1/Solicited", _test_parser_1_solicited_gcallback);
	g_test_add_func ("/Parser/1/Unsolicited", _test_parser_1_unsolicited_gcallback);
	g_test_add_func ("/Parser/2/Solicited", _test_parser_2_solicited_gcallback);
	g_test_add_func ("/Parser/2/Unsolicited", _test_parser_2_unsolicited_gcallback);
	g_test_add_func ("/Parser/2/Unsolicited/PDU", _test_parser_2_unsolicited_pdu_gcallback);
	g_test_add_func ("/Parser/Multiline/Solicited", _test_parser_multiline_solicited_gcallback);
	g_test_run ();
}


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


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}


static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}



