+ /* 2. add another non-default association */
+ g_app_info_add_supports_type (appinfo2, contenttype, &error);
+ g_assert_no_error (error);
+
+ def = g_app_info_get_default_for_type (contenttype, FALSE);
+ list = g_app_info_get_recommended_for_type (contenttype);
+ g_assert (g_app_info_equal (def, appinfo));
+ g_assert_cmpint (g_list_length (list), ==, 2);
+ g_assert (g_app_info_equal ((GAppInfo*)list->data, appinfo));
+ g_assert (g_app_info_equal ((GAppInfo*)list->next->data, appinfo2));
+ g_object_unref (def);
+ g_list_free_full (list, g_object_unref);
+
+ /* 3. make the first app the default */
+ g_app_info_set_as_default_for_type (appinfo, contenttype, &error);
+ g_assert_no_error (error);
+
+ def = g_app_info_get_default_for_type (contenttype, FALSE);
+ list = g_app_info_get_recommended_for_type (contenttype);
+ g_assert (g_app_info_equal (def, appinfo));
+ g_assert_cmpint (g_list_length (list), ==, 2);
+ g_assert (g_app_info_equal ((GAppInfo*)list->data, appinfo));
+ g_assert (g_app_info_equal ((GAppInfo*)list->next->data, appinfo2));
+ g_object_unref (def);
+ g_list_free_full (list, g_object_unref);
+
+ /* 4. make the second app the last used one */
+ g_app_info_set_as_last_used_for_type (appinfo2, contenttype, &error);
+ g_assert_no_error (error);
+
+ def = g_app_info_get_default_for_type (contenttype, FALSE);
+ list = g_app_info_get_recommended_for_type (contenttype);
+ g_assert (g_app_info_equal (def, appinfo));
+ g_assert_cmpint (g_list_length (list), ==, 2);
+ g_assert (g_app_info_equal ((GAppInfo*)list->data, appinfo2));
+ g_assert (g_app_info_equal ((GAppInfo*)list->next->data, appinfo));
+ g_object_unref (def);
+ g_list_free_full (list, g_object_unref);
+
+ /* 5. reset everything */
+ g_app_info_reset_type_associations (contenttype);
+
+ def = g_app_info_get_default_for_type (contenttype, FALSE);
+ list = g_app_info_get_recommended_for_type (contenttype);
+ g_assert (def == NULL);
+ g_assert (list == NULL);
+
+ g_object_unref (appinfo);
+ g_object_unref (appinfo2);
+}
+
+/* Repeat the same tests, this time checking that we handle
+ * mimeapps.list as expected. These tests are different from
+ * the ones in test_mime_api() in that we directly parse
+ * mimeapps.list to verify the results.
+ */
+static void
+test_mime_file (void)
+{
+ gchar **assoc;
+ GAppInfo *appinfo;
+ GAppInfo *appinfo2;
+ GError *error = NULL;
+ GKeyFile *keyfile;
+ gchar *str;
+ gboolean res;
+ GAppInfo *def;
+ GList *list;
+ gchar *mimeapps;
+ gchar *dir;
+ const gchar *contenttype = "application/pdf";
+
+ dir = g_get_current_dir ();
+ mimeapps = g_build_filename (dir, "xdgdatahome", "applications", "mimeapps.list", NULL);
+
+ /* clear things out */
+ g_app_info_reset_type_associations (contenttype);
+
+ appinfo = (GAppInfo*)g_desktop_app_info_new ("myapp.desktop");
+ appinfo2 = (GAppInfo*)g_desktop_app_info_new ("myapp2.desktop");
+
+ def = g_app_info_get_default_for_type (contenttype, FALSE);
+ list = g_app_info_get_recommended_for_type (contenttype);
+ g_assert (def == NULL);
+ g_assert (list == NULL);
+
+ /* 1. add a non-default association */
+ g_app_info_add_supports_type (appinfo, contenttype, &error);
+ g_assert_no_error (error);
+