Blame tests/test-enumerator-filter.c

rpm-build 07bc2b
/* umockdev example: use libumockdev in C to fake a battery
rpm-build 07bc2b
 * Build with:
rpm-build 07bc2b
 * gcc battery.c -Wall `pkg-config --cflags --libs umockdev-1.0 gio-2.0` -o /tmp/battery
rpm-build 07bc2b
 * Run with:
rpm-build 07bc2b
 * umockdev-wrapper /tmp/battery
rpm-build 07bc2b
 *
rpm-build 07bc2b
 * Copyright (C) 2013 Canonical Ltd.
rpm-build 07bc2b
 * Author: Martin Pitt <martin.pitt@ubuntu.com>
rpm-build 07bc2b
 *
rpm-build 07bc2b
 * umockdev is free software; you can redistribute it and/or
rpm-build 07bc2b
 * modify it under the terms of the GNU Lesser General Public
rpm-build 07bc2b
 * License as published by the Free Software Foundation; either
rpm-build 07bc2b
 * version 2.1 of the License, or (at your option) any later version.
rpm-build 07bc2b
 *
rpm-build 07bc2b
 * umockdev is distributed in the hope that it will be useful, but
rpm-build 07bc2b
 * WITHOUT ANY WARRANTY; without even the implied warranty of
rpm-build 07bc2b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
rpm-build 07bc2b
 * Lesser General Public License for more details.
rpm-build 07bc2b
 *
rpm-build 07bc2b
 * You should have received a copy of the GNU Lesser General Public License
rpm-build 07bc2b
 * along with this program; If not, see <http://www.gnu.org/licenses/>.
rpm-build 07bc2b
 */
rpm-build 07bc2b
rpm-build 07bc2b
#include <locale.h>
rpm-build 07bc2b
#include <unistd.h>
rpm-build 07bc2b
#include <stdio.h>
rpm-build 07bc2b
#include <sys/wait.h>
rpm-build 07bc2b
#include <glib.h>
rpm-build 07bc2b
#include <gio/gio.h>
rpm-build 07bc2b
#include <umockdev.h>
rpm-build 07bc2b
rpm-build 07bc2b
#include <gudev/gudev.h>
rpm-build 07bc2b
rpm-build 07bc2b
static void
rpm-build 07bc2b
test_enumerator_filter (void)
rpm-build 07bc2b
{
rpm-build 07bc2b
	/* create test bed */
rpm-build 07bc2b
	UMockdevTestbed *testbed = umockdev_testbed_new ();
rpm-build 07bc2b
rpm-build 07bc2b
	/* Add 2 devices in the USB subsystem, and one in the DRM subsystem */
rpm-build 07bc2b
	umockdev_testbed_add_device (testbed, "usb", "dev1", NULL,
rpm-build 07bc2b
				     "idVendor", "0815", "idProduct", "AFFE", NULL,
rpm-build 07bc2b
				     "ID_MODEL", "KoolGadget", NULL);
rpm-build 07bc2b
rpm-build 07bc2b
	umockdev_testbed_add_device (testbed, "usb", "dev2", NULL,
rpm-build 07bc2b
				     "idVendor", "0815", "idProduct", "AFFF", NULL,
rpm-build 07bc2b
				     "ID_MODEL", "KoolGadget 2", NULL);
rpm-build 07bc2b
rpm-build 07bc2b
	umockdev_testbed_add_device (testbed, "drm", "dev3", NULL,
rpm-build 07bc2b
				     "ID_FOR_SEAT", "drm-pci-0000_00_02_0", NULL,
rpm-build 07bc2b
				     NULL);
rpm-build 07bc2b
rpm-build 07bc2b
	/* Check the number of items in GUdevClient */
rpm-build 07bc2b
	const gchar *subsystems[] = { "drm", NULL};
rpm-build 07bc2b
	GUdevClient *client = g_udev_client_new (subsystems);
rpm-build 07bc2b
rpm-build 07bc2b
	GList *devices = g_udev_client_query_by_subsystem (client, NULL);
rpm-build 07bc2b
	g_assert_cmpint (g_list_length (devices), ==, 3);
rpm-build 07bc2b
	g_list_free_full (devices, g_object_unref);
rpm-build 07bc2b
rpm-build 07bc2b
	devices = g_udev_client_query_by_subsystem (client, "usb");
rpm-build 07bc2b
	g_assert_cmpint (g_list_length (devices), ==, 2);
rpm-build 07bc2b
	g_list_free_full (devices, g_object_unref);
rpm-build 07bc2b
rpm-build 07bc2b
	/* Check the number of items in GUdevEnumerator */
rpm-build 07bc2b
	GUdevEnumerator *enumerator = g_udev_enumerator_new (client);
rpm-build 07bc2b
	devices = g_udev_enumerator_execute (enumerator);
rpm-build 07bc2b
	g_assert_cmpint (g_list_length (devices), ==, 1);
rpm-build 07bc2b
	g_list_free_full (devices, g_object_unref);
rpm-build 07bc2b
}
rpm-build 07bc2b
rpm-build 07bc2b
int main(int argc, char **argv)
rpm-build 07bc2b
{
rpm-build 07bc2b
	setlocale (LC_ALL, NULL);
rpm-build 07bc2b
	g_test_init (&argc, &argv, NULL);
rpm-build 07bc2b
rpm-build 07bc2b
	g_assert (umockdev_in_mock_environment ());
rpm-build 07bc2b
rpm-build 07bc2b
	g_test_add_func ("/gudev/enumerator_filter", test_enumerator_filter);
rpm-build 07bc2b
rpm-build 07bc2b
	return g_test_run ();
rpm-build 07bc2b
}