From dd4cb6b278172598ce7ff152196d8ab756bd12e7 Mon Sep 17 00:00:00 2001 From: Srikavin Ramkumar Date: Tue, 10 Dec 2019 22:09:13 -0500 Subject: [PATCH 1/2] Copy Python tests for Modulemd.ModuleStream.components into C --- modulemd/tests/test-modulemd-modulestream.c | 161 ++++++++++++++++++++ 1 file changed, 161 insertions(+) diff --git a/modulemd/tests/test-modulemd-modulestream.c b/modulemd/tests/test-modulemd-modulestream.c index b6f995be2..5f0282006 100644 --- a/modulemd/tests/test-modulemd-modulestream.c +++ b/modulemd/tests/test-modulemd-modulestream.c @@ -331,6 +331,153 @@ module_stream_v2_test_documentation (ModuleStreamFixture *fixture, g_clear_object (&stream); } +static void +module_stream_v1_test_components (ModuleStreamFixture *fixture, + gconstpointer user_data) +{ + g_autoptr (ModulemdModuleStreamV1) stream = NULL; + g_autoptr (ModulemdComponentRpm) rpm_component = NULL; + g_autoptr (ModulemdComponentModule) module_component = NULL; + ModulemdComponent *retrieved_component = NULL; + g_autofree gchar *component_name = NULL; + g_auto (GStrv) component_names = NULL; + + stream = modulemd_module_stream_v1_new (NULL, NULL); + + // Add a RPM component to a stream + rpm_component = modulemd_component_rpm_new ("rpmcomponent"); + modulemd_module_stream_v1_add_component (stream, + (ModulemdComponent *)rpm_component); + component_names = + modulemd_module_stream_v1_get_rpm_component_names_as_strv (stream); + g_assert_true ( + g_strv_contains ((const gchar *const *)component_names, "rpmcomponent")); + + retrieved_component = + (ModulemdComponent *)modulemd_module_stream_v1_get_rpm_component ( + stream, "rpmcomponent"); + g_assert_nonnull (retrieved_component); + g_object_get (retrieved_component, "name", &component_name, NULL); + g_assert_cmpstr (component_name, ==, "rpmcomponent"); + + g_clear_pointer (&component_name, g_free); + g_clear_pointer (&component_names, g_strfreev); + + // Add a Module component to a stream + module_component = modulemd_component_module_new ("modulecomponent"); + modulemd_module_stream_v1_add_component ( + stream, (ModulemdComponent *)module_component); + component_names = + modulemd_module_stream_v1_get_module_component_names_as_strv (stream); + g_assert_true (g_strv_contains ((const gchar *const *)component_names, + "modulecomponent")); + + retrieved_component = + (ModulemdComponent *)modulemd_module_stream_v1_get_module_component ( + stream, "modulecomponent"); + g_assert_nonnull (retrieved_component); + g_object_get (retrieved_component, "name", &component_name, NULL); + g_assert_cmpstr (component_name, ==, "modulecomponent"); + + g_clear_pointer (&component_name, g_free); + g_clear_pointer (&component_names, g_strfreev); + + // Remove an RPM component from a stream + modulemd_module_stream_v1_remove_rpm_component (stream, "rpmcomponent"); + component_names = + modulemd_module_stream_v1_get_rpm_component_names_as_strv (stream); + g_assert_cmpint (g_strv_length (component_names), ==, 0); + + g_clear_pointer (&component_names, g_strfreev); + + // Remove a Module component from a stream + modulemd_module_stream_v1_remove_module_component (stream, + "modulecomponent"); + component_names = + modulemd_module_stream_v1_get_module_component_names_as_strv (stream); + g_assert_cmpint (g_strv_length (component_names), ==, 0); + + g_clear_pointer (&component_names, g_strfreev); + + g_clear_object (&module_component); + g_clear_object (&rpm_component); + g_clear_object (&stream); +} + + +static void +module_stream_v2_test_components (ModuleStreamFixture *fixture, + gconstpointer user_data) +{ + g_autoptr (ModulemdModuleStreamV2) stream = NULL; + g_autoptr (ModulemdComponentRpm) rpm_component = NULL; + g_autoptr (ModulemdComponentModule) module_component = NULL; + ModulemdComponent *retrieved_component = NULL; + g_autofree gchar *component_name = NULL; + g_auto (GStrv) component_names = NULL; + + stream = modulemd_module_stream_v2_new (NULL, NULL); + + // Add a RPM component to a stream + rpm_component = modulemd_component_rpm_new ("rpmcomponent"); + modulemd_module_stream_v2_add_component (stream, + (ModulemdComponent *)rpm_component); + component_names = + modulemd_module_stream_v2_get_rpm_component_names_as_strv (stream); + g_assert_true ( + g_strv_contains ((const gchar *const *)component_names, "rpmcomponent")); + + retrieved_component = + (ModulemdComponent *)modulemd_module_stream_v2_get_rpm_component ( + stream, "rpmcomponent"); + g_assert_nonnull (retrieved_component); + g_object_get (retrieved_component, "name", &component_name, NULL); + g_assert_cmpstr (component_name, ==, "rpmcomponent"); + + g_clear_pointer (&component_name, g_free); + g_clear_pointer (&component_names, g_strfreev); + + // Add a Module component to a stream + module_component = modulemd_component_module_new ("modulecomponent"); + modulemd_module_stream_v2_add_component ( + stream, (ModulemdComponent *)module_component); + component_names = + modulemd_module_stream_v2_get_module_component_names_as_strv (stream); + g_assert_true (g_strv_contains ((const gchar *const *)component_names, + "modulecomponent")); + + retrieved_component = + (ModulemdComponent *)modulemd_module_stream_v2_get_module_component ( + stream, "modulecomponent"); + g_assert_nonnull (retrieved_component); + g_object_get (retrieved_component, "name", &component_name, NULL); + g_assert_cmpstr (component_name, ==, "modulecomponent"); + + g_clear_pointer (&component_name, g_free); + g_clear_pointer (&component_names, g_strfreev); + + // Remove an RPM component from a stream + modulemd_module_stream_v2_remove_rpm_component (stream, "rpmcomponent"); + component_names = + modulemd_module_stream_v2_get_rpm_component_names_as_strv (stream); + g_assert_cmpint (g_strv_length (component_names), ==, 0); + + g_clear_pointer (&component_names, g_strfreev); + + // Remove a Module component from a stream + modulemd_module_stream_v2_remove_module_component (stream, + "modulecomponent"); + component_names = + modulemd_module_stream_v2_get_module_component_names_as_strv (stream); + g_assert_cmpint (g_strv_length (component_names), ==, 0); + + g_clear_pointer (&component_names, g_strfreev); + + g_clear_object (&module_component); + g_clear_object (&rpm_component); + g_clear_object (&stream); +} + static void module_stream_test_copy (ModuleStreamFixture *fixture, gconstpointer user_data) { @@ -1802,6 +1949,20 @@ main (int argc, char *argv[]) module_stream_v2_test_profiles, NULL); + g_test_add ("/modulemd/v2/modulestream/v1/components", + ModuleStreamFixture, + NULL, + NULL, + module_stream_v1_test_components, + NULL); + + g_test_add ("/modulemd/v2/modulestream/v2/components", + ModuleStreamFixture, + NULL, + NULL, + module_stream_v2_test_components, + NULL); + g_test_add ("/modulemd/v2/modulestream/copy", ModuleStreamFixture, NULL, From cea197f8794237643eba324bfa48b85194c47ebb Mon Sep 17 00:00:00 2001 From: Srikavin Ramkumar Date: Thu, 12 Dec 2019 10:41:02 -0500 Subject: [PATCH 2/2] Compare components using modulemd_component_equals and added check for adding components in module_stream_test_components --- modulemd/tests/test-modulemd-modulestream.c | 26 ++++++++++----------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/modulemd/tests/test-modulemd-modulestream.c b/modulemd/tests/test-modulemd-modulestream.c index 5f0282006..5da2229a2 100644 --- a/modulemd/tests/test-modulemd-modulestream.c +++ b/modulemd/tests/test-modulemd-modulestream.c @@ -339,7 +339,6 @@ module_stream_v1_test_components (ModuleStreamFixture *fixture, g_autoptr (ModulemdComponentRpm) rpm_component = NULL; g_autoptr (ModulemdComponentModule) module_component = NULL; ModulemdComponent *retrieved_component = NULL; - g_autofree gchar *component_name = NULL; g_auto (GStrv) component_names = NULL; stream = modulemd_module_stream_v1_new (NULL, NULL); @@ -352,15 +351,15 @@ module_stream_v1_test_components (ModuleStreamFixture *fixture, modulemd_module_stream_v1_get_rpm_component_names_as_strv (stream); g_assert_true ( g_strv_contains ((const gchar *const *)component_names, "rpmcomponent")); + g_assert_cmpint (g_strv_length (component_names), ==, 1); retrieved_component = (ModulemdComponent *)modulemd_module_stream_v1_get_rpm_component ( stream, "rpmcomponent"); g_assert_nonnull (retrieved_component); - g_object_get (retrieved_component, "name", &component_name, NULL); - g_assert_cmpstr (component_name, ==, "rpmcomponent"); + g_assert_true (modulemd_component_equals ( + retrieved_component, (ModulemdComponent *)rpm_component)); - g_clear_pointer (&component_name, g_free); g_clear_pointer (&component_names, g_strfreev); // Add a Module component to a stream @@ -371,15 +370,15 @@ module_stream_v1_test_components (ModuleStreamFixture *fixture, modulemd_module_stream_v1_get_module_component_names_as_strv (stream); g_assert_true (g_strv_contains ((const gchar *const *)component_names, "modulecomponent")); + g_assert_cmpint (g_strv_length (component_names), ==, 1); retrieved_component = (ModulemdComponent *)modulemd_module_stream_v1_get_module_component ( stream, "modulecomponent"); g_assert_nonnull (retrieved_component); - g_object_get (retrieved_component, "name", &component_name, NULL); - g_assert_cmpstr (component_name, ==, "modulecomponent"); + g_assert_true (modulemd_component_equals ( + retrieved_component, (ModulemdComponent *)module_component)); - g_clear_pointer (&component_name, g_free); g_clear_pointer (&component_names, g_strfreev); // Remove an RPM component from a stream @@ -413,7 +412,6 @@ module_stream_v2_test_components (ModuleStreamFixture *fixture, g_autoptr (ModulemdComponentRpm) rpm_component = NULL; g_autoptr (ModulemdComponentModule) module_component = NULL; ModulemdComponent *retrieved_component = NULL; - g_autofree gchar *component_name = NULL; g_auto (GStrv) component_names = NULL; stream = modulemd_module_stream_v2_new (NULL, NULL); @@ -426,15 +424,15 @@ module_stream_v2_test_components (ModuleStreamFixture *fixture, modulemd_module_stream_v2_get_rpm_component_names_as_strv (stream); g_assert_true ( g_strv_contains ((const gchar *const *)component_names, "rpmcomponent")); + g_assert_cmpint (g_strv_length (component_names), ==, 1); retrieved_component = (ModulemdComponent *)modulemd_module_stream_v2_get_rpm_component ( stream, "rpmcomponent"); g_assert_nonnull (retrieved_component); - g_object_get (retrieved_component, "name", &component_name, NULL); - g_assert_cmpstr (component_name, ==, "rpmcomponent"); + g_assert_true (modulemd_component_equals ( + retrieved_component, (ModulemdComponent *)rpm_component)); - g_clear_pointer (&component_name, g_free); g_clear_pointer (&component_names, g_strfreev); // Add a Module component to a stream @@ -445,15 +443,15 @@ module_stream_v2_test_components (ModuleStreamFixture *fixture, modulemd_module_stream_v2_get_module_component_names_as_strv (stream); g_assert_true (g_strv_contains ((const gchar *const *)component_names, "modulecomponent")); + g_assert_cmpint (g_strv_length (component_names), ==, 1); retrieved_component = (ModulemdComponent *)modulemd_module_stream_v2_get_module_component ( stream, "modulecomponent"); g_assert_nonnull (retrieved_component); - g_object_get (retrieved_component, "name", &component_name, NULL); - g_assert_cmpstr (component_name, ==, "modulecomponent"); + g_assert_true (modulemd_component_equals ( + retrieved_component, (ModulemdComponent *)module_component)); - g_clear_pointer (&component_name, g_free); g_clear_pointer (&component_names, g_strfreev); // Remove an RPM component from a stream