[gnome-software] Enforce plugin sanity



commit 9eade32dcfe84951a7fd05a554fdde32abe4516d
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Sep 1 14:45:06 2013 -0400

    Enforce plugin sanity
    
    Plugins seem to return a bunch of utter nonsense, currently.
    Add some assertions to teach them. This is clearly not something
    we can ship, but it at least shows whats wrong. We should fix
    the plugins to pass these assertions, and then turn them into
    a warning, plus filtering out bad apples.

 src/gs-plugin-loader.c |   50 ++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 46 insertions(+), 4 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index ec6907d..def4e70 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -513,6 +513,7 @@ gs_plugin_loader_get_updates_finish (GsPluginLoader *plugin_loader,
                                       GError **error)
 {
        GSimpleAsyncResult *simple;
+        GList *list, *l;
 
        g_return_val_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader), NULL);
        g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), NULL);
@@ -524,7 +525,18 @@ gs_plugin_loader_get_updates_finish (GsPluginLoader *plugin_loader,
                return NULL;
 
        /* grab detail */
-       return g_list_copy (g_simple_async_result_get_op_res_gpointer (simple));
+       list = g_simple_async_result_get_op_res_gpointer (simple);
+
+        for (l = list; l; l = l->next) {
+                GsApp *app = l->data;
+
+                g_assert_cmpint (gs_app_get_kind (app), !=, GS_APP_KIND_UNKNOWN);
+                g_assert_cmpint (gs_app_get_state (app), !=, GS_APP_STATE_UNKNOWN);
+                g_assert_cmpint (gs_app_get_state (app), !=, GS_APP_STATE_INSTALLED);
+                g_assert_cmpint (gs_app_get_state (app), !=, GS_APP_STATE_AVAILABLE);
+        }
+
+        return g_list_copy (list);
 }
 
 /******************************************************************************/
@@ -614,6 +626,7 @@ gs_plugin_loader_get_installed_finish (GsPluginLoader *plugin_loader,
                                       GError **error)
 {
        GSimpleAsyncResult *simple;
+        GList *list, *l;
 
        g_return_val_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader), NULL);
        g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), NULL);
@@ -625,7 +638,17 @@ gs_plugin_loader_get_installed_finish (GsPluginLoader *plugin_loader,
                return NULL;
 
        /* grab detail */
-       return g_list_copy (g_simple_async_result_get_op_res_gpointer (simple));
+       list = g_simple_async_result_get_op_res_gpointer (simple);
+
+        for (l = list; l; l = l->next) {
+                GsApp *app = l->data;
+
+                g_assert_cmpint (gs_app_get_kind (app), ==, GS_APP_KIND_NORMAL);
+                g_assert_cmpint (gs_app_get_state (app), !=, GS_APP_STATE_UNKNOWN);
+                g_assert_cmpint (gs_app_get_state (app), !=, GS_APP_STATE_AVAILABLE);
+        }
+
+        return g_list_copy (list);
 }
 
 /******************************************************************************/
@@ -714,6 +737,7 @@ gs_plugin_loader_get_popular_finish (GsPluginLoader *plugin_loader,
                                     GError **error)
 {
        GSimpleAsyncResult *simple;
+        GList *list, *l;
 
        g_return_val_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader), NULL);
        g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), NULL);
@@ -725,7 +749,16 @@ gs_plugin_loader_get_popular_finish (GsPluginLoader *plugin_loader,
                return NULL;
 
        /* grab detail */
-       return g_list_copy (g_simple_async_result_get_op_res_gpointer (simple));
+       list = g_simple_async_result_get_op_res_gpointer (simple);
+
+        for (l = list; l; l = l->next) {
+                GsApp *app = l->data;
+
+                g_assert_cmpint (gs_app_get_kind (app), ==, GS_APP_KIND_NORMAL);
+                g_assert_cmpint (gs_app_get_state (app), !=, GS_APP_STATE_UNKNOWN);
+        }
+
+        return g_list_copy (list);
 }
 
 /******************************************************************************/
@@ -814,6 +847,7 @@ gs_plugin_loader_get_featured_finish (GsPluginLoader *plugin_loader,
                                     GError **error)
 {
        GSimpleAsyncResult *simple;
+        GList *list, *l;
 
        g_return_val_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader), NULL);
        g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), NULL);
@@ -825,7 +859,15 @@ gs_plugin_loader_get_featured_finish (GsPluginLoader *plugin_loader,
                return NULL;
 
        /* grab detail */
-       return g_list_copy (g_simple_async_result_get_op_res_gpointer (simple));
+       list = g_simple_async_result_get_op_res_gpointer (simple);
+        for (l = list; l; l = l->next) {
+                GsApp *app = l->data;
+
+                g_assert_cmpint (gs_app_get_kind (app), ==, GS_APP_KIND_NORMAL);
+                g_assert_cmpint (gs_app_get_state (app), !=, GS_APP_STATE_UNKNOWN);
+        }
+
+        return g_list_copy (list);
 }
 
 /******************************************************************************/


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]