summaryrefslogtreecommitdiff
path: root/libappstream-glib
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2017-12-09 15:37:59 +0000
committerRichard Hughes <richard@hughsie.com>2017-12-09 15:38:53 +0000
commit2884b9927f76856053125a1679e2bd3a01ce5166 (patch)
treed999b8cfe6b832755769a8556eb932546a852ed5 /libappstream-glib
parent1eb3f32d6b004a5534c2136e7c72f9cb745c1c49 (diff)
downloadappstream-glib-2884b9927f76856053125a1679e2bd3a01ce5166.tar.gz
Never change the default screenshot when processing AppData
Fixes https://github.com/hughsie/appstream-glib/issues/210
Diffstat (limited to 'libappstream-glib')
-rw-r--r--libappstream-glib/as-app.c4
-rw-r--r--libappstream-glib/as-self-test.c27
2 files changed, 31 insertions, 0 deletions
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c
index 1ab64d1..1027704 100644
--- a/libappstream-glib/as-app.c
+++ b/libappstream-glib/as-app.c
@@ -3283,6 +3283,10 @@ as_app_sort_screenshots (gconstpointer a, gconstpointer b)
{
AsScreenshot *ss1 = *((AsScreenshot **) a);
AsScreenshot *ss2 = *((AsScreenshot **) b);
+ if (as_screenshot_get_kind (ss1) < as_screenshot_get_kind (ss2))
+ return 1;
+ if (as_screenshot_get_kind (ss1) > as_screenshot_get_kind (ss2))
+ return -1;
if (as_screenshot_get_priority (ss1) < as_screenshot_get_priority (ss2))
return 1;
if (as_screenshot_get_priority (ss1) > as_screenshot_get_priority (ss2))
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index d05cc52..9be843c 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -2978,6 +2978,32 @@ as_test_app_subsume_func (void)
}
static void
+as_test_app_screenshot_func (void)
+{
+ AsScreenshot *ss;
+ GPtrArray *screenshots;
+ g_autoptr(AsApp) app = as_app_new ();
+ g_autoptr(AsScreenshot) ss1 = as_screenshot_new ();
+ g_autoptr(AsScreenshot) ss2 = as_screenshot_new ();
+
+ as_screenshot_set_kind (ss1, AS_SCREENSHOT_KIND_DEFAULT);
+ as_screenshot_set_caption (ss1, NULL, "bbb");
+ as_app_add_screenshot (app, ss1);
+
+ as_screenshot_set_kind (ss2, AS_SCREENSHOT_KIND_NORMAL);
+ as_screenshot_set_caption (ss2, NULL, "aaa");
+ as_app_add_screenshot (app, ss2);
+
+ screenshots = as_app_get_screenshots (app);
+ ss = g_ptr_array_index (screenshots, 0);
+ g_assert (ss == ss1);
+ g_assert_cmpint (as_screenshot_get_kind (ss), ==, AS_SCREENSHOT_KIND_DEFAULT);
+ ss = g_ptr_array_index (screenshots, 1);
+ g_assert (ss == ss2);
+ g_assert_cmpint (as_screenshot_get_kind (ss), ==, AS_SCREENSHOT_KIND_NORMAL);
+}
+
+static void
as_test_app_search_func (void)
{
const gchar *all[] = { "gnome", "install", "software", NULL };
@@ -5510,6 +5536,7 @@ main (int argc, char **argv)
g_test_add_func ("/AppStream/app{no-markup}", as_test_app_no_markup_func);
g_test_add_func ("/AppStream/app{subsume}", as_test_app_subsume_func);
g_test_add_func ("/AppStream/app{search}", as_test_app_search_func);
+ g_test_add_func ("/AppStream/app{screenshot}", as_test_app_screenshot_func);
g_test_add_func ("/AppStream/markup{import-html}", as_test_markup_import_html);
g_test_add_func ("/AppStream/node", as_test_node_func);
g_test_add_func ("/AppStream/node{reflow}", as_test_node_reflow_text_func);