https://gitlab.com/libosinfo/osinfo-db/issues/13 Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx> --- tests/test-devicelinklist.c | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tests/test-devicelinklist.c b/tests/test-devicelinklist.c index fd2531b..f13f0b8 100644 --- a/tests/test-devicelinklist.c +++ b/tests/test-devicelinklist.c @@ -226,6 +226,67 @@ test_filter(void) } +static void +test_get_devices(void) +{ + OsinfoDeviceLinkList *devlink_list = osinfo_devicelinklist_new(); + OsinfoDevice *dev1 = osinfo_device_new("wibble1"); + OsinfoDevice *dev2 = osinfo_device_new("wibble2"); + OsinfoDevice *dev3 = osinfo_device_new("wibble3"); + OsinfoDevice *dev4 = osinfo_device_new("wibble4"); + OsinfoDeviceLink *ent1 = osinfo_devicelink_new(dev1); + OsinfoDeviceLink *ent2 = osinfo_devicelink_new(dev2); + OsinfoDeviceLink *ent3 = osinfo_devicelink_new(dev3); + OsinfoDeviceLink *ent4 = osinfo_devicelink_new(dev4); + OsinfoDeviceList *dev_list; + + osinfo_list_add(OSINFO_LIST(devlink_list), OSINFO_ENTITY(ent1)); + osinfo_list_add(OSINFO_LIST(devlink_list), OSINFO_ENTITY(ent2)); + osinfo_list_add(OSINFO_LIST(devlink_list), OSINFO_ENTITY(ent3)); + osinfo_list_add(OSINFO_LIST(devlink_list), OSINFO_ENTITY(ent4)); + g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(devlink_list)), ==, 4); + + dev_list = osinfo_devicelinklist_get_devices(devlink_list, NULL); + g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(dev_list)), ==, 4); + + gboolean has1 = FALSE; + gboolean has2 = FALSE; + gboolean has3 = FALSE; + gboolean has4 = FALSE; + gboolean hasBad = FALSE; + for (int i = 0; i < osinfo_list_get_length(OSINFO_LIST(dev_list)); i++) { + OsinfoDevice *dev = OSINFO_DEVICE(osinfo_list_get_nth(OSINFO_LIST(dev_list), i)); + if (dev == dev1) + has1 = TRUE; + else if (dev == dev2) + has2 = TRUE; + else if (dev == dev3) + has3 = TRUE; + else if (dev == dev4) + has4 = TRUE; + else + hasBad = TRUE; + } + g_assert_true(has1); + g_assert_true(has2); + g_assert_true(has3); + g_assert_true(has3); + g_assert_true(has4); + g_assert_false(hasBad); + + g_object_unref(dev1); + g_object_unref(dev2); + g_object_unref(dev3); + g_object_unref(dev4); + g_object_unref(ent1); + g_object_unref(ent2); + g_object_unref(ent3); + g_object_unref(ent4); + g_object_unref(dev_list); + g_object_unref(devlink_list); +} + + int main(int argc, char *argv[]) { @@ -234,6 +295,7 @@ main(int argc, char *argv[]) g_test_add_func("/devicelinklist/union", test_union); g_test_add_func("/devicelinklist/intersect", test_intersect); g_test_add_func("/devicelinklist/filter", test_filter); + g_test_add_func("/devicelinklist/get_devices", test_get_devices); /* Upfront so we don't confuse valgrind */ osinfo_device_get_type(); -- 2.19.1 _______________________________________________ Libosinfo mailing list Libosinfo@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libosinfo