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

[WIP] Allow AppStream to parse recommendations #45

Closed
wants to merge 8 commits into from
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<components version="0.8" origin="jessie">
<component type="desktop">
<id>test.desktop</id>

This comment has been minimized.

Copy link
@ximion

ximion Aug 9, 2016

Owner

Merge components need some component to merge their data into - otherwise they don't exist in the pool.
Since there is no test.desktop, this would fail.

<pkgname>test</pkgname>
<name>Test</name>
<suggests type="heuristic">
<id>test1.desktop</id>
<id>test2.desktop</id>
</suggests>
</component>
<component type="desktop">
<id>test1.desktop</id>
<pkgname>test</pkgname>
<name>Test</name>
</component>
<component type="desktop">
<id>test1.desktop</id>
<suggests type="heuristic">
<id>test5.desktop</id>
<id>test6.desktop</id>
</suggests>
</component>
</components>
@@ -193,6 +193,70 @@ test_pool_read ()
g_assert_cmpuint (as_release_get_size (rel, AS_SIZE_KIND_DOWNLOAD), ==, 0);
}

void
test_merge_components ()
{
guint i;

g_autoptr(GPtrArray) cpts = NULL;

This comment has been minimized.

Copy link
@ximion

ximion Aug 9, 2016

Owner

Unused variable - weird that the CI didn't complain about this...

g_autoptr(AsDataPool) dpool = NULL;
g_autoptr(GError) error = NULL;
g_auto(GStrv) strv = NULL;
g_auto(GStrv) expected_cpts_id = NULL;
g_autoptr(GPtrArray) suggestions = NULL;

GPtrArray* cpts_id = NULL;
AsComponent *cpt = NULL;
AsSuggested *suggested = NULL;
AsSuggestedKind suggested_kind;
gchar *cpt_id = NULL;

dpool = as_data_pool_new ();

strv = g_new0 (gchar*, 2);
strv[0] = g_build_filename (datadir, "distro", NULL);

as_data_pool_set_metadata_locations (dpool, strv);
as_data_pool_load_metadata (dpool);

cpt = as_data_pool_get_component_by_id (dpool, "test.desktop");
suggestions = as_component_get_suggestions (cpt);
suggested = (AsSuggested *) g_ptr_array_index (suggestions, 0);
cpts_id = as_suggested_get_components_id (suggested);
suggested_kind = as_suggested_get_kind (suggested);

expected_cpts_id = g_new0 (gchar*, 3);
expected_cpts_id[0] = g_strdup ("test1.desktop");
expected_cpts_id[1] = g_strdup ("test2.desktop");

g_assert_cmpint (suggestions->len, ==, 2);
g_assert_cmpint (suggested_kind, ==, AS_SUGGESTED_KIND_HEURISTIC);

for (i = 0; i < cpts_id->len; i++) {
cpt_id = (gchar*) g_ptr_array_index (cpts_id, i);
g_assert_cmpstr (cpt_id, ==, expected_cpts_id[i]);
}

cpt = as_data_pool_get_component_by_id (dpool, "test1.desktop");
suggestions = as_component_get_suggestions (cpt);
suggested = (AsSuggested *) g_ptr_array_index (suggestions, 0);
cpts_id = as_suggested_get_components_id (suggested);
suggested_kind = as_suggested_get_kind (suggested);

expected_cpts_id = g_new0 (gchar*, 3);

This comment has been minimized.

Copy link
@ximion

ximion Aug 9, 2016

Owner

Memory leak... You need to free the strv first.

expected_cpts_id[0] = g_strdup ("test5.desktop");
expected_cpts_id[1] = g_strdup ("test6.desktop");

g_assert_cmpint (suggestions->len, ==, 2);
g_assert_cmpint (suggested_kind, ==, AS_SUGGESTED_KIND_HEURISTIC);

for (i = 0; i < cpts_id->len; i++) {
cpt_id = (gchar*) g_ptr_array_index (cpts_id, i);
g_assert_cmpstr (cpt_id, ==, expected_cpts_id[i]);
}

}

int
main (int argc, char **argv)
{
@@ -216,6 +280,7 @@ main (int argc, char **argv)

g_test_add_func ("/AppStream/Cache", test_cache);
g_test_add_func ("/AppStream/PoolRead", test_pool_read);
g_test_add_func ("/AppStream/ComponentMerge", test_merge_components);

ret = g_test_run ();
g_free (datadir);
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.