Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx> --- tests/test-os.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/tests/test-os.c b/tests/test-os.c index 8c3a86c..f9fe381 100644 --- a/tests/test-os.c +++ b/tests/test-os.c @@ -550,6 +550,73 @@ static void check_duplicated_devices_cb(OsinfoProduct *product, } +static void check_duplicated_features_cb(OsinfoProduct *product, + gpointer user_data) +{ + OsinfoOs *os = OSINFO_OS(user_data); + OsinfoOs *foreach_os = OSINFO_OS(product); + OsinfoFeatureList *features_os, *features_foreach_os; + GList *list_features = NULL, *list_foreach_features = NULL, *list_duplicated = NULL; + GList *l; + + if (os == foreach_os) + return; + + features_os = osinfo_os_get_feature_list(os); + features_foreach_os = osinfo_os_get_feature_list(foreach_os); + + if (osinfo_list_get_length(OSINFO_LIST(features_os)) == 0 || + osinfo_list_get_length(OSINFO_LIST(features_foreach_os)) == 0) + goto done; + + list_features = osinfo_list_get_elements(OSINFO_LIST(features_os)); + list_foreach_features = osinfo_list_get_elements(OSINFO_LIST(features_foreach_os)); + + for (l = list_features; l != NULL; l = l->next) { + OsinfoFeature *d = OSINFO_FEATURE(l->data); + GList *ll; + + for (ll = list_foreach_features; ll != NULL; ll = ll->next) { + OsinfoFeature *dd = OSINFO_FEATURE(ll->data); + if (g_str_equal(osinfo_feature_get_name(d), osinfo_feature_get_name(dd))) + list_duplicated = g_list_prepend(list_duplicated, d); + } + } + + if (list_duplicated != NULL) { + gchar *string = NULL; + for (l = list_duplicated; l != NULL; l = l->next) { + gchar *tmp = NULL; + if (string != NULL) + tmp = g_strdup_printf("%s\n - %s\n", + string, + osinfo_feature_get_name(OSINFO_FEATURE(l->data))); + else + tmp = g_strdup_printf("\n - %s", + osinfo_feature_get_name(OSINFO_FEATURE(l->data))); + + g_free(string); + string = tmp; + } + + g_printerr("\nTesting \"%s\" against \"%s\" and found the following duplicated features: %s\n", + osinfo_product_get_short_id(OSINFO_PRODUCT(os)), + osinfo_product_get_short_id(product), + string); + g_free(string); + + g_test_fail(); + } + + done: + g_list_free(list_duplicated); + g_list_free(list_features); + g_list_free(list_foreach_features); + g_object_unref(features_os); + g_object_unref(features_foreach_os); +} + + static void test_duplication_helper(void (check_duplicated_cb)(OsinfoProduct *, gpointer)) { OsinfoLoader *loader = osinfo_loader_new(); @@ -604,6 +671,12 @@ static void test_devices_duplication(void) } +static void test_features_duplication(void) +{ + test_duplication_helper(check_duplicated_features_cb); +} + + static void devices_inheritance_basic_check(OsinfoDb *db, const gchar *os_id) @@ -971,6 +1044,7 @@ main(int argc, char *argv[]) g_test_add_func("/os/devices/inheritance/removal", test_devices_inheritance_removal); g_test_add_func("/os/features", test_features); + g_test_add_func("/os/features/duplication", test_features_duplication); g_test_add_func("/os/resources/minimum_recommended_maximum", test_resources_minimum_recommended_maximum); g_test_add_func("/os/resources/uniqueness", test_resources_uniqueness); -- 2.19.2 _______________________________________________ Libosinfo mailing list Libosinfo@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libosinfo