Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy Python tests for Modulemd.ModuleStream.components into C #402

Merged
merged 2 commits into from
Dec 12, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 159 additions & 0 deletions modulemd/tests/test-modulemd-modulestream.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,151 @@ 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_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"));
srikavin marked this conversation as resolved.
Show resolved Hide resolved
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_assert_true (modulemd_component_equals (
retrieved_component, (ModulemdComponent *)rpm_component));

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"));
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_assert_true (modulemd_component_equals (
retrieved_component, (ModulemdComponent *)module_component));

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,
srikavin marked this conversation as resolved.
Show resolved Hide resolved
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_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"));
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_assert_true (modulemd_component_equals (
retrieved_component, (ModulemdComponent *)rpm_component));

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"));
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_assert_true (modulemd_component_equals (
retrieved_component, (ModulemdComponent *)module_component));

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)
{
Expand Down Expand Up @@ -1802,6 +1947,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,
Expand Down