gplugin/gplugin

Update test-core so it's easier to read
bugfix/valgrind-catchup
2020-02-27, Gary Kramlich
7fcc318d3d11
Parents 1a8c4e5ee1ea
Children 06d9506c1030
Update test-core so it's easier to read
--- a/gplugin/tests/test-core.c Mon Mar 09 03:03:39 2020 +0000
+++ b/gplugin/tests/test-core.c Thu Feb 27 02:36:58 2020 -0600
@@ -20,6 +20,39 @@
#include <gplugin.h>
/******************************************************************************
+ * Helpers
+ *****************************************************************************/
+static void
+test_gplugin_count_ids_and_plugins(gint *n_ids, gint *n_plugins)
+{
+ GList *l_ids = NULL, *l_id = NULL;
+ gint ids = 0, plugins = 0;
+
+ l_ids = gplugin_manager_list_plugins();
+ for(l_id = l_ids; l_id; l_id = l_id->next) {
+ GSList *l_plugins = NULL, *l_plugin = NULL;
+ const gchar *id = (const gchar *)l_id->data;
+
+ ids += 1;
+
+ l_plugins = gplugin_manager_find_plugins(id);
+ for(l_plugin = l_plugins; l_plugin; l_plugin = l_plugin->next) {
+ plugins += 1;
+ }
+ g_slist_free_full(l_plugins, g_object_unref);
+ }
+ g_list_free(l_ids);
+
+ if(n_ids) {
+ *n_ids = ids;
+ }
+
+ if(n_plugins) {
+ *n_plugins = plugins;
+ }
+}
+
+/******************************************************************************
* Tests
*****************************************************************************/
static void
@@ -57,8 +90,6 @@
static void
test_gplugin_init_uninit_with_double_refresh_plugins(void)
{
- GList *l = NULL;
- GSList *sl = NULL;
gint f_ids = 0, s_ids = 0, f_plugins = 0, s_plugins = 0;
gplugin_init();
@@ -67,25 +98,11 @@
/* run the first refresh and count everything */
gplugin_manager_refresh();
- for(l = gplugin_manager_list_plugins(); l; l = l->next) {
- const gchar *id = (const gchar *)l->data;
-
- f_ids += 1;
-
- for(sl = gplugin_manager_find_plugins(id); sl; sl = sl->next)
- f_plugins += 1;
- }
+ test_gplugin_count_ids_and_plugins(&f_ids, &f_plugins);
/* now run the second refresh and make sure the counts match */
gplugin_manager_refresh();
- for(l = gplugin_manager_list_plugins(); l; l = l->next) {
- const gchar *id = (const gchar *)l->data;
-
- s_ids += 1;
-
- for(sl = gplugin_manager_find_plugins(id); sl; sl = sl->next)
- s_plugins += 1;
- }
+ test_gplugin_count_ids_and_plugins(&s_ids, &s_plugins);
g_assert_cmpint(f_ids, >, 0);
g_assert_cmpint(f_plugins, >, 0);