/* test-umockdev-vala.c generated by valac 0.18.1, the Vala compiler
 * generated from test-umockdev-vala.vala, do not modify */

/*
 * test-umockdev.vala
 *
 * Copyright (C) 2012 Canonical Ltd.
 * Author: Martin Pitt <martin.pitt@ubuntu.com>
 *
 * umockdev 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.
 *
 * umockdev 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 program; If not, see <http://www.gnu.org/licenses/>.
 */

#include <glib.h>
#include <glib-object.h>
#include <umockdev.h>
#include <gudev/gudev.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include "linux/usbdevice_fs.h"
#include <errno.h>
#include <unistd.h>
#include <glib/gstdio.h>

#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define __g_list_free__g_object_unref0_0(var) ((var == NULL) ? NULL : (var = (_g_list_free__g_object_unref0_ (var), NULL)))
#define _g_free0(var) (var = (g_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);



void t_testbed_empty (void);
static void _g_object_unref0_ (gpointer var);
static void _g_list_free__g_object_unref0_ (GList* self);
void t_testbed_add_device (void);
void t_testbed_gudev_query_list (void);
void t_usbfs_ioctl_static (void);
void t_usbfs_ioctl_tree (void);
static guint8* _vala_array_dup1 (guint8* self, int length);
void t_usbfs_ioctl_tree_xz (void);
gint _vala_main (gchar** args, int args_length1);
static void _t_testbed_empty_gcallback (void);
static void _t_testbed_add_device_gcallback (void);
static void _t_testbed_gudev_query_list_gcallback (void);
static void _t_usbfs_ioctl_static_gcallback (void);
static void _t_usbfs_ioctl_tree_gcallback (void);
static void _t_usbfs_ioctl_tree_xz_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);


static void _g_object_unref0_ (gpointer var) {
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}


static void _g_list_free__g_object_unref0_ (GList* self) {
	g_list_foreach (self, (GFunc) _g_object_unref0_, NULL);
	g_list_free (self);
}


void t_testbed_empty (void) {
	UMockdevTestbed* _tmp0_;
	UMockdevTestbed* tb;
	GUdevClient* _tmp1_;
	GUdevClient* _tmp2_;
	GUdevEnumerator* _tmp3_;
	GUdevEnumerator* _tmp4_;
	GUdevEnumerator* enumerator;
	GList* _tmp5_ = NULL;
	GList* devices;
	guint _tmp6_ = 0U;
	_tmp0_ = umockdev_testbed_new ();
	tb = _tmp0_;
	_vala_assert (tb != NULL, "tb != null");
	_tmp1_ = g_udev_client_new (NULL);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_udev_enumerator_new (_tmp2_);
	_tmp4_ = _tmp3_;
	_g_object_unref0 (_tmp2_);
	enumerator = _tmp4_;
	_tmp5_ = g_udev_enumerator_execute (enumerator);
	devices = _tmp5_;
	_tmp6_ = g_list_length (devices);
	g_assert_cmpuint (_tmp6_, ==, (guint) 0);
	__g_list_free__g_object_unref0_0 (devices);
	_g_object_unref0 (enumerator);
	_g_object_unref0 (tb);
}


static gpointer _g_object_ref0 (gpointer self) {
	return self ? g_object_ref (self) : NULL;
}


void t_testbed_add_device (void) {
	UMockdevTestbed* _tmp0_;
	UMockdevTestbed* tb;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar** _tmp5_ = NULL;
	gchar** _tmp6_;
	gint _tmp6__length1;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gchar** _tmp11_ = NULL;
	gchar** _tmp12_;
	gint _tmp12__length1;
	gchar* _tmp13_ = NULL;
	gchar* _tmp14_;
	gchar* syspath;
	GUdevClient* _tmp15_;
	GUdevClient* _tmp16_;
	GUdevEnumerator* _tmp17_;
	GUdevEnumerator* _tmp18_;
	GUdevEnumerator* enumerator;
	GList* _tmp19_ = NULL;
	GList* devices;
	guint _tmp20_ = 0U;
	gconstpointer _tmp21_ = NULL;
	GUdevDevice* _tmp22_;
	GUdevDevice* device;
	const gchar* _tmp23_ = NULL;
	const gchar* _tmp24_ = NULL;
	const gchar* _tmp25_ = NULL;
	const gchar* _tmp26_ = NULL;
	const gchar* _tmp27_ = NULL;
	const gchar* _tmp28_ = NULL;
	const gchar* _tmp29_ = NULL;
	const gchar* _tmp30_ = NULL;
	const gchar* _tmp31_ = NULL;
	const gchar* _tmp32_ = NULL;
	const gchar* _tmp33_ = NULL;
	_tmp0_ = umockdev_testbed_new ();
	tb = _tmp0_;
	_tmp1_ = g_strdup ("idVendor");
	_tmp2_ = g_strdup ("0815");
	_tmp3_ = g_strdup ("idProduct");
	_tmp4_ = g_strdup ("AFFE");
	_tmp5_ = g_new0 (gchar*, 4 + 1);
	_tmp5_[0] = _tmp1_;
	_tmp5_[1] = _tmp2_;
	_tmp5_[2] = _tmp3_;
	_tmp5_[3] = _tmp4_;
	_tmp6_ = _tmp5_;
	_tmp6__length1 = 4;
	_tmp7_ = g_strdup ("ID_INPUT");
	_tmp8_ = g_strdup ("1");
	_tmp9_ = g_strdup ("ID_INPUT_KEYBOARD");
	_tmp10_ = g_strdup ("1");
	_tmp11_ = g_new0 (gchar*, 4 + 1);
	_tmp11_[0] = _tmp7_;
	_tmp11_[1] = _tmp8_;
	_tmp11_[2] = _tmp9_;
	_tmp11_[3] = _tmp10_;
	_tmp12_ = _tmp11_;
	_tmp12__length1 = 4;
	_tmp13_ = umockdev_testbed_add_devicev (tb, "usb", "extkeyboard1", NULL, _tmp6_, _tmp12_);
	_tmp14_ = _tmp13_;
	_tmp12_ = (_vala_array_free (_tmp12_, _tmp12__length1, (GDestroyNotify) g_free), NULL);
	_tmp6_ = (_vala_array_free (_tmp6_, _tmp6__length1, (GDestroyNotify) g_free), NULL);
	syspath = _tmp14_;
	g_assert_cmpstr (syspath, ==, "/sys/devices/extkeyboard1");
	_tmp15_ = g_udev_client_new (NULL);
	_tmp16_ = _tmp15_;
	_tmp17_ = g_udev_enumerator_new (_tmp16_);
	_tmp18_ = _tmp17_;
	_g_object_unref0 (_tmp16_);
	enumerator = _tmp18_;
	_tmp19_ = g_udev_enumerator_execute (enumerator);
	devices = _tmp19_;
	_tmp20_ = g_list_length (devices);
	g_assert_cmpuint (_tmp20_, ==, (guint) 1);
	_tmp21_ = g_list_nth_data (devices, (guint) 0);
	_tmp22_ = _g_object_ref0 ((GUdevDevice*) _tmp21_);
	device = _tmp22_;
	_tmp23_ = g_udev_device_get_name (device);
	g_assert_cmpstr (_tmp23_, ==, "extkeyboard1");
	_tmp24_ = g_udev_device_get_sysfs_path (device);
	g_assert_cmpstr (_tmp24_, ==, "/sys/devices/extkeyboard1");
	_tmp25_ = g_udev_device_get_subsystem (device);
	g_assert_cmpstr (_tmp25_, ==, "usb");
	_tmp26_ = g_udev_device_get_sysfs_attr (device, "idVendor");
	g_assert_cmpstr (_tmp26_, ==, "0815");
	_tmp27_ = g_udev_device_get_sysfs_attr (device, "idProduct");
	g_assert_cmpstr (_tmp27_, ==, "AFFE");
	_tmp28_ = g_udev_device_get_sysfs_attr (device, "noSuchAttr");
	g_assert_cmpstr (_tmp28_, ==, NULL);
	_tmp29_ = g_udev_device_get_property (device, "DEVPATH");
	g_assert_cmpstr (_tmp29_, ==, "/devices/extkeyboard1");
	_tmp30_ = g_udev_device_get_property (device, "SUBSYSTEM");
	g_assert_cmpstr (_tmp30_, ==, "usb");
	_tmp31_ = g_udev_device_get_property (device, "ID_INPUT");
	g_assert_cmpstr (_tmp31_, ==, "1");
	_tmp32_ = g_udev_device_get_property (device, "ID_INPUT_KEYBOARD");
	g_assert_cmpstr (_tmp32_, ==, "1");
	_tmp33_ = g_udev_device_get_property (device, "NO_SUCH_PROP");
	g_assert_cmpstr (_tmp33_, ==, NULL);
	_g_object_unref0 (device);
	__g_list_free__g_object_unref0_0 (devices);
	_g_object_unref0 (enumerator);
	_g_free0 (syspath);
	_g_object_unref0 (tb);
}


void t_testbed_gudev_query_list (void) {
	UMockdevTestbed* _tmp0_;
	UMockdevTestbed* tb;
	GUdevClient* _tmp1_;
	GUdevClient* client;
	GUdevClient* _tmp2_;
	GList* _tmp3_ = NULL;
	GList* devices;
	GList* _tmp4_;
	guint _tmp5_ = 0U;
	GList* _tmp6_;
	GError * _inner_error_ = NULL;
	_tmp0_ = umockdev_testbed_new ();
	tb = _tmp0_;
	umockdev_testbed_add_from_string (tb, "P: /devices/myusbhub/cam\n" \
"N: bus/usb/001/002\n" \
"E: SUBSYSTEM=usb\n" \
"E: DEVTYPE=usb_device\n" \
"E: DEVNAME=/dev/bus/usb/001/002\n" \
"\n" \
"P: /devices/myusbhub\n" \
"N: bus/usb/001/001\n" \
"E: SUBSYSTEM=usb\n" \
"E: DEVTYPE=usb_device\n" \
"E: DEVNAME=/dev/bus/usb/001/001\n", &_inner_error_);
	if (_inner_error_ != NULL) {
		_g_object_unref0 (tb);
		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;
	}
	_tmp1_ = g_udev_client_new (NULL);
	client = _tmp1_;
	_tmp2_ = client;
	_tmp3_ = g_udev_client_query_by_subsystem (_tmp2_, NULL);
	devices = _tmp3_;
	_tmp4_ = devices;
	_tmp5_ = g_list_length (_tmp4_);
	g_assert_cmpuint (_tmp5_, ==, (guint) 2);
	_tmp6_ = devices;
	{
		GList* dev_collection = NULL;
		GList* dev_it = NULL;
		dev_collection = _tmp6_;
		for (dev_it = dev_collection; dev_it != NULL; dev_it = dev_it->next) {
			GUdevDevice* _tmp7_;
			GUdevDevice* dev = NULL;
			_tmp7_ = _g_object_ref0 ((GUdevDevice*) dev_it->data);
			dev = _tmp7_;
			{
				GUdevDevice* _tmp8_;
				const gchar* _tmp9_ = NULL;
				GUdevDevice* _tmp10_;
				const gchar* _tmp11_ = NULL;
				_tmp8_ = dev;
				_tmp9_ = g_udev_device_get_subsystem (_tmp8_);
				g_assert_cmpstr (_tmp9_, ==, "usb");
				_tmp10_ = dev;
				_tmp11_ = g_udev_device_get_sysfs_path (_tmp10_);
				if (g_strcmp0 (_tmp11_, "/sys/devices/myusbhub") == 0) {
					GUdevDevice* _tmp12_;
					const gchar* _tmp13_ = NULL;
					GUdevDevice* _tmp14_;
					const gchar* _tmp15_ = NULL;
					_tmp12_ = dev;
					_tmp13_ = g_udev_device_get_name (_tmp12_);
					g_assert_cmpstr (_tmp13_, ==, "myusbhub");
					_tmp14_ = dev;
					_tmp15_ = g_udev_device_get_device_file (_tmp14_);
					g_assert_cmpstr (_tmp15_, ==, "/dev/bus/usb/001/001");
				} else {
					GUdevDevice* _tmp16_;
					const gchar* _tmp17_ = NULL;
					GUdevDevice* _tmp18_;
					const gchar* _tmp19_ = NULL;
					GUdevDevice* _tmp20_;
					const gchar* _tmp21_ = NULL;
					_tmp16_ = dev;
					_tmp17_ = g_udev_device_get_sysfs_path (_tmp16_);
					g_assert_cmpstr (_tmp17_, ==, "/sys/devices/myusbhub/cam");
					_tmp18_ = dev;
					_tmp19_ = g_udev_device_get_name (_tmp18_);
					g_assert_cmpstr (_tmp19_, ==, "cam");
					_tmp20_ = dev;
					_tmp21_ = g_udev_device_get_device_file (_tmp20_);
					g_assert_cmpstr (_tmp21_, ==, "/dev/bus/usb/001/002");
				}
				_g_object_unref0 (dev);
			}
		}
	}
	__g_list_free__g_object_unref0_0 (devices);
	_g_object_unref0 (client);
	_g_object_unref0 (tb);
}


void t_usbfs_ioctl_static (void) {
	UMockdevTestbed* _tmp0_;
	UMockdevTestbed* tb;
	gint _tmp1_ = 0;
	gint fd;
	gint _tmp2_;
	gint i;
	gint _tmp3_;
	gint _tmp4_ = 0;
	gint _tmp5_;
	gint _tmp6_;
	gint _tmp7_ = 0;
	gint _tmp8_;
	struct usbdevfs_connectinfo ci = {0};
	gint _tmp9_;
	gint _tmp10_ = 0;
	gint _tmp11_;
	gint _tmp12_;
	GError * _inner_error_ = NULL;
	_tmp0_ = umockdev_testbed_new ();
	tb = _tmp0_;
	umockdev_testbed_add_from_string (tb, "P: /devices/mycam\nN: 001\nE: SUBSYSTEM=usb\n", &_inner_error_);
	if (_inner_error_ != NULL) {
		_g_object_unref0 (tb);
		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;
	}
	_tmp1_ = open ("/dev/001", O_RDWR, (mode_t) 0);
	fd = _tmp1_;
	_tmp2_ = fd;
	g_assert_cmpint (_tmp2_, >=, 0);
	i = 1;
	_tmp3_ = fd;
	_tmp4_ = ioctl (_tmp3_, USBDEVFS_CLAIMINTERFACE, &i);
	g_assert_cmpint (_tmp4_, ==, 0);
	_tmp5_ = errno;
	g_assert_cmpint (_tmp5_, ==, 0);
	_tmp6_ = fd;
	_tmp7_ = ioctl (_tmp6_, USBDEVFS_GETDRIVER, &i);
	g_assert_cmpint (_tmp7_, ==, -1);
	_tmp8_ = errno;
	g_assert_cmpint (_tmp8_, ==, ENODATA);
	errno = 0;
	memset (&ci, 0, sizeof (struct usbdevfs_connectinfo));
	_tmp9_ = fd;
	_tmp10_ = ioctl (_tmp9_, USBDEVFS_CONNECTINFO, &ci);
	g_assert_cmpint (_tmp10_, ==, -1);
	_tmp11_ = errno;
	g_assert_cmpint (_tmp11_, ==, ENOTTY);
	errno = 0;
	_tmp12_ = fd;
	close (_tmp12_);
	_g_object_unref0 (tb);
}


static guint8* _vala_array_dup1 (guint8* self, int length) {
	return g_memdup (self, length * sizeof (guint8));
}


void t_usbfs_ioctl_tree (void) {
	UMockdevTestbed* _tmp0_;
	UMockdevTestbed* tb;
	UMockdevTestbed* _tmp1_;
	gchar* _tmp2_;
	gchar* test_tree;
	gchar* tmppath = NULL;
	gchar* _tmp3_ = NULL;
	gint _tmp4_ = 0;
	gint fd;
	gint _tmp5_;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	gint _tmp8_;
	gint _tmp9_;
	gssize _tmp10_ = 0L;
	gint i;
	gint _tmp11_;
	gint _tmp12_ = 0;
	gint _tmp13_;
	gint _tmp14_;
	UMockdevTestbed* _tmp15_;
	const gchar* _tmp16_;
	const gchar* _tmp17_;
	gint _tmp18_ = 0;
	gint _tmp19_;
	gint _tmp20_;
	gint _tmp21_ = 0;
	gint _tmp22_;
	struct usbdevfs_connectinfo ci = {0};
	gint _tmp23_;
	gint _tmp24_ = 0;
	gint _tmp25_;
	struct usbdevfs_connectinfo _tmp26_;
	guint _tmp27_;
	struct usbdevfs_connectinfo _tmp28_;
	guint _tmp29_;
	guint8* _tmp30_ = NULL;
	guint8* urb_buffer;
	gint urb_buffer_length1;
	gint _urb_buffer_size_;
	guint8* _tmp31_;
	gint _tmp31__length1;
	guint8* _tmp32_;
	gint _tmp32__length1;
	struct usbdevfs_urb _tmp33_ = {0};
	struct usbdevfs_urb urb;
	gint _tmp34_;
	gint _tmp35_ = 0;
	gint _tmp36_;
	struct usbdevfs_urb _tmp37_;
	gint _tmp38_;
	guint8* _tmp39_;
	gint _tmp39__length1;
	guint8 _tmp40_;
	struct usbdevfs_urb* urb_reap;
	gint _tmp41_;
	gint _tmp42_ = 0;
	gint _tmp43_;
	struct usbdevfs_urb* _tmp44_;
	struct usbdevfs_urb _tmp45_;
	gint _tmp46_;
	struct usbdevfs_urb _tmp47_;
	guint8* _tmp48_;
	gint _tmp48__length1;
	guint8 _tmp49_;
	struct usbdevfs_urb _tmp50_;
	guint8* _tmp51_;
	gint _tmp51__length1;
	guint8 _tmp52_;
	struct usbdevfs_urb _tmp53_;
	guint8* _tmp54_;
	gint _tmp54__length1;
	guint8 _tmp55_;
	struct usbdevfs_urb _tmp56_;
	guint8* _tmp57_;
	gint _tmp57__length1;
	guint8 _tmp58_;
	gint _tmp59_ = 0;
	gint fd2;
	gint _tmp60_;
	gint _tmp61_;
	gint _tmp62_ = 0;
	gint _tmp63_;
	struct usbdevfs_connectinfo _tmp64_;
	guint _tmp65_;
	struct usbdevfs_connectinfo _tmp66_;
	guint _tmp67_;
	gint _tmp68_;
	gint _tmp69_ = 0;
	gint _tmp70_;
	struct usbdevfs_connectinfo _tmp71_;
	guint _tmp72_;
	struct usbdevfs_connectinfo _tmp73_;
	guint _tmp74_;
	gint _tmp75_;
	gint _tmp76_;
	gint _tmp77_ = 0;
	gint _tmp78_;
	struct usbdevfs_connectinfo _tmp79_;
	guint _tmp80_;
	struct usbdevfs_connectinfo _tmp81_;
	guint _tmp82_;
	gint _tmp83_;
	GError * _inner_error_ = NULL;
	_tmp0_ = umockdev_testbed_new ();
	tb = _tmp0_;
	_tmp1_ = tb;
	umockdev_testbed_add_from_string (_tmp1_, "P: /devices/mycam\nN: 001\nE: SUBSYSTEM=usb\n", &_inner_error_);
	if (_inner_error_ != NULL) {
		_g_object_unref0 (tb);
		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;
	}
	_tmp2_ = g_strdup ("USBDEVFS_CONNECTINFO 0 0B00000000000000\n" \
"USBDEVFS_REAPURB 0 1 129 -1 0 4 4 0 9902AAFF\n" \
"USBDEVFS_CONNECTINFO 42 0C00000001000000\n");
	test_tree = _tmp2_;
	_tmp4_ = g_file_open_tmp ("test_ioctl_tree.XXXXXX", &_tmp3_, &_inner_error_);
	_g_free0 (tmppath);
	tmppath = _tmp3_;
	fd = _tmp4_;
	if (_inner_error_ != NULL) {
		_g_free0 (tmppath);
		_g_free0 (test_tree);
		_g_object_unref0 (tb);
		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;
	}
	_tmp5_ = fd;
	_tmp6_ = test_tree;
	_tmp7_ = test_tree;
	_tmp8_ = strlen (_tmp7_);
	_tmp9_ = _tmp8_;
	_tmp10_ = write (_tmp5_, _tmp6_, (gsize) _tmp9_);
	g_assert_cmpint ((gint) _tmp10_, >, 20);
	i = 1;
	_tmp11_ = fd;
	_tmp12_ = ioctl (_tmp11_, USBDEVFS_CLAIMINTERFACE, &i);
	g_assert_cmpint (_tmp12_, ==, -1);
	_tmp13_ = errno;
	g_assert_cmpint (_tmp13_, ==, ENOTTY);
	_tmp14_ = fd;
	close (_tmp14_);
	_tmp15_ = tb;
	_tmp16_ = tmppath;
	umockdev_testbed_load_ioctl (_tmp15_, "/dev/001", _tmp16_, &_inner_error_);
	if (_inner_error_ != NULL) {
		_g_free0 (tmppath);
		_g_free0 (test_tree);
		_g_object_unref0 (tb);
		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;
	}
	_tmp17_ = tmppath;
	g_unlink (_tmp17_);
	_tmp18_ = open ("/dev/001", O_RDWR, (mode_t) 0);
	fd = _tmp18_;
	_tmp19_ = fd;
	g_assert_cmpint (_tmp19_, >=, 0);
	_tmp20_ = fd;
	_tmp21_ = ioctl (_tmp20_, USBDEVFS_CLAIMINTERFACE, &i);
	g_assert_cmpint (_tmp21_, ==, 0);
	_tmp22_ = errno;
	g_assert_cmpint (_tmp22_, ==, 0);
	memset (&ci, 0, sizeof (struct usbdevfs_connectinfo));
	_tmp23_ = fd;
	_tmp24_ = ioctl (_tmp23_, USBDEVFS_CONNECTINFO, &ci);
	g_assert_cmpint (_tmp24_, ==, 0);
	_tmp25_ = errno;
	g_assert_cmpint (_tmp25_, ==, 0);
	_tmp26_ = ci;
	_tmp27_ = _tmp26_.devnum;
	g_assert_cmpuint (_tmp27_, ==, (guint) 11);
	_tmp28_ = ci;
	_tmp29_ = _tmp28_.slow;
	g_assert_cmpuint (_tmp29_, ==, (guint) 0);
	_tmp30_ = g_new0 (guint8, 4);
	urb_buffer = _tmp30_;
	urb_buffer_length1 = 4;
	_urb_buffer_size_ = urb_buffer_length1;
	_tmp31_ = urb_buffer;
	_tmp31__length1 = urb_buffer_length1;
	_tmp32_ = (_tmp31_ != NULL) ? _vala_array_dup1 (_tmp31_, _tmp31__length1) : ((gpointer) _tmp31_);
	_tmp32__length1 = _tmp31__length1;
	_tmp33_.type = (guint8) 1;
	_tmp33_.endpoint = (guint8) 129;
	_tmp33_.status = 0;
	_tmp33_.flags = (guint) 0;
	_tmp33_.buffer = (g_free (_tmp33_.buffer), NULL);
	_tmp33_.buffer = _tmp32_;
	_tmp33_.buffer_length = 4;
	_tmp33_.actual_length = 0;
	urb = _tmp33_;
	_tmp34_ = fd;
	_tmp35_ = ioctl (_tmp34_, USBDEVFS_SUBMITURB, &urb);
	g_assert_cmpint (_tmp35_, ==, 0);
	_tmp36_ = errno;
	g_assert_cmpint (_tmp36_, ==, 0);
	_tmp37_ = urb;
	_tmp38_ = _tmp37_.status;
	g_assert_cmpuint ((guint) _tmp38_, ==, (guint) 0);
	_tmp39_ = urb_buffer;
	_tmp39__length1 = urb_buffer_length1;
	_tmp40_ = _tmp39_[0];
	g_assert_cmpint ((gint) _tmp40_, ==, 0);
	urb_reap = NULL;
	_tmp41_ = fd;
	_tmp42_ = ioctl (_tmp41_, USBDEVFS_REAPURB, &urb_reap);
	g_assert_cmpint (_tmp42_, ==, 0);
	_tmp43_ = errno;
	g_assert_cmpint (_tmp43_, ==, 0);
	_tmp44_ = urb_reap;
	_vala_assert (_tmp44_ == (&urb), "urb_reap == &urb");
	_tmp45_ = urb;
	_tmp46_ = _tmp45_.status;
	g_assert_cmpint (_tmp46_, ==, -1);
	_tmp47_ = urb;
	_tmp48_ = _tmp47_.buffer;
	_tmp48__length1 = -1;
	_tmp49_ = _tmp48_[0];
	g_assert_cmpuint ((guint) _tmp49_, ==, (guint) 0x99);
	_tmp50_ = urb;
	_tmp51_ = _tmp50_.buffer;
	_tmp51__length1 = -1;
	_tmp52_ = _tmp51_[1];
	g_assert_cmpuint ((guint) _tmp52_, ==, (guint) 0x02);
	_tmp53_ = urb;
	_tmp54_ = _tmp53_.buffer;
	_tmp54__length1 = -1;
	_tmp55_ = _tmp54_[2];
	g_assert_cmpuint ((guint) _tmp55_, ==, (guint) 0xAA);
	_tmp56_ = urb;
	_tmp57_ = _tmp56_.buffer;
	_tmp57__length1 = -1;
	_tmp58_ = _tmp57_[3];
	g_assert_cmpuint ((guint) _tmp58_, ==, (guint) 0xFF);
	_tmp59_ = open ("/dev/001", O_RDWR, (mode_t) 0);
	fd2 = _tmp59_;
	_tmp60_ = fd2;
	g_assert_cmpint (_tmp60_, >=, 0);
	ci.devnum = (guint) 99;
	ci.slow = (guint) 99;
	_tmp61_ = fd2;
	_tmp62_ = ioctl (_tmp61_, USBDEVFS_CONNECTINFO, &ci);
	g_assert_cmpint (_tmp62_, ==, 0);
	_tmp63_ = errno;
	g_assert_cmpint (_tmp63_, ==, 0);
	_tmp64_ = ci;
	_tmp65_ = _tmp64_.devnum;
	g_assert_cmpuint (_tmp65_, ==, (guint) 11);
	_tmp66_ = ci;
	_tmp67_ = _tmp66_.slow;
	g_assert_cmpuint (_tmp67_, ==, (guint) 0);
	ci.devnum = (guint) 99;
	ci.slow = (guint) 99;
	_tmp68_ = fd;
	_tmp69_ = ioctl (_tmp68_, USBDEVFS_CONNECTINFO, &ci);
	g_assert_cmpint (_tmp69_, ==, 42);
	_tmp70_ = errno;
	g_assert_cmpint (_tmp70_, ==, 0);
	_tmp71_ = ci;
	_tmp72_ = _tmp71_.devnum;
	g_assert_cmpuint (_tmp72_, ==, (guint) 12);
	_tmp73_ = ci;
	_tmp74_ = _tmp73_.slow;
	g_assert_cmpuint (_tmp74_, ==, (guint) 1);
	_tmp75_ = fd;
	close (_tmp75_);
	ci.devnum = (guint) 99;
	ci.slow = (guint) 99;
	_tmp76_ = fd2;
	_tmp77_ = ioctl (_tmp76_, USBDEVFS_CONNECTINFO, &ci);
	g_assert_cmpint (_tmp77_, ==, 42);
	_tmp78_ = errno;
	g_assert_cmpint (_tmp78_, ==, 0);
	_tmp79_ = ci;
	_tmp80_ = _tmp79_.devnum;
	g_assert_cmpuint (_tmp80_, ==, (guint) 12);
	_tmp81_ = ci;
	_tmp82_ = _tmp81_.slow;
	g_assert_cmpuint (_tmp82_, ==, (guint) 1);
	_tmp83_ = fd2;
	close (_tmp83_);
	 (&urb);
	urb_buffer = (g_free (urb_buffer), NULL);
	_g_free0 (tmppath);
	_g_free0 (test_tree);
	_g_object_unref0 (tb);
}


void t_usbfs_ioctl_tree_xz (void) {
	UMockdevTestbed* _tmp0_;
	UMockdevTestbed* tb;
	UMockdevTestbed* _tmp1_;
	gchar* _tmp2_;
	gchar* test_tree;
	gchar* tmppath = NULL;
	gchar* _tmp3_ = NULL;
	gint _tmp4_ = 0;
	gint _tmp5_;
	gint exit = 0;
	const gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	const gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_;
	gchar* _tmp15_;
	gint _tmp16_ = 0;
	gint _tmp17_;
	UMockdevTestbed* _tmp18_;
	const gchar* _tmp19_;
	const gchar* _tmp20_;
	gint _tmp21_ = 0;
	gint fd;
	gint _tmp22_;
	struct usbdevfs_connectinfo ci = {0};
	gint _tmp23_;
	gint _tmp24_ = 0;
	gint _tmp25_;
	struct usbdevfs_connectinfo _tmp26_;
	guint _tmp27_;
	struct usbdevfs_connectinfo _tmp28_;
	guint _tmp29_;
	gint _tmp30_;
	gint _tmp31_ = 0;
	gint _tmp32_;
	struct usbdevfs_connectinfo _tmp33_;
	guint _tmp34_;
	struct usbdevfs_connectinfo _tmp35_;
	guint _tmp36_;
	gint _tmp37_;
	GError * _inner_error_ = NULL;
	_tmp0_ = umockdev_testbed_new ();
	tb = _tmp0_;
	_tmp1_ = tb;
	umockdev_testbed_add_from_string (_tmp1_, "P: /devices/mycam\nN: 001\nE: SUBSYSTEM=usb\n", &_inner_error_);
	if (_inner_error_ != NULL) {
		_g_object_unref0 (tb);
		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;
	}
	_tmp2_ = g_strdup ("USBDEVFS_CONNECTINFO 0 0B00000000000000\n" \
"USBDEVFS_REAPURB 0 1 129 -1 0 4 4 0 9902AAFF\n" \
"USBDEVFS_CONNECTINFO 42 0C00000001000000\n");
	test_tree = _tmp2_;
	_tmp4_ = g_file_open_tmp ("test_ioctl_tree.XXXXXX.xz", &_tmp3_, &_inner_error_);
	_g_free0 (tmppath);
	tmppath = _tmp3_;
	_tmp5_ = _tmp4_;
	if (_inner_error_ != NULL) {
		_g_free0 (tmppath);
		_g_free0 (test_tree);
		_g_object_unref0 (tb);
		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;
	}
	close (_tmp5_);
	_tmp6_ = test_tree;
	_tmp7_ = g_strconcat ("sh -c 'echo \"", _tmp6_, NULL);
	_tmp8_ = _tmp7_;
	_tmp9_ = g_strconcat (_tmp8_, "\" | xz -9c > ", NULL);
	_tmp10_ = _tmp9_;
	_tmp11_ = tmppath;
	_tmp12_ = g_strconcat (_tmp10_, _tmp11_, NULL);
	_tmp13_ = _tmp12_;
	_tmp14_ = g_strconcat (_tmp13_, "; sync'", NULL);
	_tmp15_ = _tmp14_;
	g_spawn_command_line_sync (_tmp15_, NULL, NULL, &_tmp16_, &_inner_error_);
	exit = _tmp16_;
	_g_free0 (_tmp15_);
	_g_free0 (_tmp13_);
	_g_free0 (_tmp10_);
	_g_free0 (_tmp8_);
	if (_inner_error_ != NULL) {
		_g_free0 (tmppath);
		_g_free0 (test_tree);
		_g_object_unref0 (tb);
		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;
	}
	_tmp17_ = exit;
	g_assert_cmpint (_tmp17_, ==, 0);
	_tmp18_ = tb;
	_tmp19_ = tmppath;
	umockdev_testbed_load_ioctl (_tmp18_, "/dev/001", _tmp19_, &_inner_error_);
	if (_inner_error_ != NULL) {
		_g_free0 (tmppath);
		_g_free0 (test_tree);
		_g_object_unref0 (tb);
		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;
	}
	_tmp20_ = tmppath;
	g_unlink (_tmp20_);
	_tmp21_ = open ("/dev/001", O_RDWR, (mode_t) 0);
	fd = _tmp21_;
	_tmp22_ = fd;
	g_assert_cmpint (_tmp22_, >=, 0);
	memset (&ci, 0, sizeof (struct usbdevfs_connectinfo));
	_tmp23_ = fd;
	_tmp24_ = ioctl (_tmp23_, USBDEVFS_CONNECTINFO, &ci);
	g_assert_cmpint (_tmp24_, ==, 0);
	_tmp25_ = errno;
	g_assert_cmpint (_tmp25_, ==, 0);
	_tmp26_ = ci;
	_tmp27_ = _tmp26_.devnum;
	g_assert_cmpuint (_tmp27_, ==, (guint) 11);
	_tmp28_ = ci;
	_tmp29_ = _tmp28_.slow;
	g_assert_cmpuint (_tmp29_, ==, (guint) 0);
	_tmp30_ = fd;
	_tmp31_ = ioctl (_tmp30_, USBDEVFS_CONNECTINFO, &ci);
	g_assert_cmpint (_tmp31_, ==, 42);
	_tmp32_ = errno;
	g_assert_cmpint (_tmp32_, ==, 0);
	_tmp33_ = ci;
	_tmp34_ = _tmp33_.devnum;
	g_assert_cmpuint (_tmp34_, ==, (guint) 12);
	_tmp35_ = ci;
	_tmp36_ = _tmp35_.slow;
	g_assert_cmpuint (_tmp36_, ==, (guint) 1);
	_tmp37_ = fd;
	close (_tmp37_);
	_g_free0 (tmppath);
	_g_free0 (test_tree);
	_g_object_unref0 (tb);
}


static void _t_testbed_empty_gcallback (void) {
	t_testbed_empty ();
}


static void _t_testbed_add_device_gcallback (void) {
	t_testbed_add_device ();
}


static void _t_testbed_gudev_query_list_gcallback (void) {
	t_testbed_gudev_query_list ();
}


static void _t_usbfs_ioctl_static_gcallback (void) {
	t_usbfs_ioctl_static ();
}


static void _t_usbfs_ioctl_tree_gcallback (void) {
	t_usbfs_ioctl_tree ();
}


static void _t_usbfs_ioctl_tree_xz_gcallback (void) {
	t_usbfs_ioctl_tree_xz ();
}


gint _vala_main (gchar** args, int args_length1) {
	gint result = 0;
	gint _tmp0_ = 0;
	g_test_init (&args_length1, &args, NULL);
	g_test_add_func ("/umockdev-testbed-vala/empty", _t_testbed_empty_gcallback);
	g_test_add_func ("/umockdev-testbed-vala/add_devicev", _t_testbed_add_device_gcallback);
	g_test_add_func ("/umockdev-testbed-vala/gudev-query-list", _t_testbed_gudev_query_list_gcallback);
	g_test_add_func ("/umockdev-testbed-vala/usbfs_ioctl_static", _t_usbfs_ioctl_static_gcallback);
	g_test_add_func ("/umockdev-testbed-vala/usbfs_ioctl_tree", _t_usbfs_ioctl_tree_gcallback);
	g_test_add_func ("/umockdev-testbed-vala/usbfs_ioctl_tree_xz", _t_usbfs_ioctl_tree_xz_gcallback);
	_tmp0_ = g_test_run ();
	result = _tmp0_;
	return result;
}


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


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);
}



