[gnome-software] trivial: Split out the common tests functionality
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] trivial: Split out the common tests functionality
- Date: Tue, 7 Mar 2017 17:04:09 +0000 (UTC)
commit 215465becf9726a0312127417f75466844e14a0c
Author: Richard Hughes <richard hughsie com>
Date: Tue Mar 7 10:43:17 2017 +0000
trivial: Split out the common tests functionality
We want to split up the tests long term, so this should help us on the journey.
lib/Makefile.am | 2 +
lib/gs-self-test.c | 61 +++++++++++++++------------------------------------
lib/gs-test.c | 52 ++++++++++++++++++++++++++++++++++++++++++++
lib/gs-test.h | 37 +++++++++++++++++++++++++++++++
4 files changed, 109 insertions(+), 43 deletions(-)
---
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 7ea2898..a9a6065 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -54,6 +54,8 @@ libgnomesoftware_a_SOURCES = \
gs-plugin-private.h \
gs-plugin-types.h \
gs-plugin-vfuncs.h \
+ gs-test.c \
+ gs-test.h \
gs-utils.c \
gs-utils.h
diff --git a/lib/gs-self-test.c b/lib/gs-self-test.c
index bf3d391..5cb8624 100644
--- a/lib/gs-self-test.c
+++ b/lib/gs-self-test.c
@@ -33,32 +33,7 @@
#include "gs-plugin-loader.h"
#include "gs-plugin-loader-sync.h"
#include "gs-utils.h"
-
-static gchar *
-gs_test_get_filename (const gchar *filename)
-{
- gchar *tmp;
- char full_tmp[PATH_MAX];
- g_autofree gchar *path = NULL;
- path = g_build_filename (TESTDATADIR, filename, NULL);
- tmp = realpath (path, full_tmp);
- if (tmp == NULL)
- return NULL;
- return g_strdup (full_tmp);
-}
-
-static void
-gs_test_flush_main_context (void)
-{
- guint cnt = 0;
- while (g_main_context_iteration (NULL, FALSE)) {
- if (cnt == 0)
- g_debug ("clearing pending events...");
- cnt++;
- }
- if (cnt > 0)
- g_debug ("cleared %u events", cnt);
-}
+#include "gs-test.h"
static gboolean
gs_app_list_filter_cb (GsApp *app, gpointer user_data)
@@ -109,7 +84,7 @@ gs_os_release_func (void)
g_autoptr(GError) error = NULL;
g_autoptr(GsOsRelease) os_release = NULL;
- fn = gs_test_get_filename ("tests/os-release");
+ fn = gs_test_get_filename (TESTDATADIR, "tests/os-release");
g_assert (fn != NULL);
g_setenv ("GS_SELF_TEST_OS_RELEASE_FILENAME", fn, TRUE);
@@ -905,7 +880,7 @@ gs_plugin_loader_dpkg_func (GsPluginLoader *plugin_loader)
return;
/* load local file */
- fn = gs_test_get_filename ("tests/chiron-1.1-1.deb");
+ fn = gs_test_get_filename (TESTDATADIR, "tests/chiron-1.1-1.deb");
g_assert (fn != NULL);
file = g_file_new_for_path (fn);
app = gs_plugin_loader_file_to_app (plugin_loader,
@@ -942,7 +917,7 @@ gs_plugin_loader_packagekit_local_func (GsPluginLoader *plugin_loader)
return;
/* load local file */
- fn = gs_test_get_filename ("tests/chiron-1.1-1.fc24.x86_64.rpm");
+ fn = gs_test_get_filename (TESTDATADIR, "tests/chiron-1.1-1.fc24.x86_64.rpm");
g_assert (fn != NULL);
file = g_file_new_for_path (fn);
app = gs_plugin_loader_file_to_app (plugin_loader,
@@ -978,7 +953,7 @@ gs_plugin_loader_fwupd_func (GsPluginLoader *plugin_loader)
return;
/* load local file */
- fn = gs_test_get_filename ("tests/chiron-0.2.cab");
+ fn = gs_test_get_filename (TESTDATADIR, "tests/chiron-0.2.cab");
g_assert (fn != NULL);
file = g_file_new_for_path (fn);
app = gs_plugin_loader_file_to_app (plugin_loader,
@@ -1054,7 +1029,7 @@ gs_plugin_loader_flatpak_repo_func (GsPluginLoader *plugin_loader)
return;
/* get a resolvable */
- testdir = gs_test_get_filename ("tests/flatpak/app-with-runtime");
+ testdir = gs_test_get_filename (TESTDATADIR, "tests/flatpak/app-with-runtime");
if (testdir == NULL)
return;
testdir_repourl = g_strdup_printf ("file://%s/repo", testdir);
@@ -1183,7 +1158,7 @@ gs_plugin_loader_flatpak_app_with_runtime_func (GsPluginLoader *plugin_loader)
return;
/* no files to use */
- repodir_fn = gs_test_get_filename ("tests/flatpak/app-with-runtime/repo");
+ repodir_fn = gs_test_get_filename (TESTDATADIR, "tests/flatpak/app-with-runtime/repo");
if (repodir_fn == NULL ||
!g_file_test (repodir_fn, G_FILE_TEST_EXISTS)) {
g_test_skip ("no flatpak test repo");
@@ -1206,7 +1181,7 @@ gs_plugin_loader_flatpak_app_with_runtime_func (GsPluginLoader *plugin_loader)
/* add a remote */
app_source = gs_app_new ("test");
- testdir = gs_test_get_filename ("tests/flatpak/app-with-runtime");
+ testdir = gs_test_get_filename (TESTDATADIR, "tests/flatpak/app-with-runtime");
if (testdir == NULL)
return;
testdir_repourl = g_strdup_printf ("file://%s/repo", testdir);
@@ -1434,7 +1409,7 @@ gs_plugin_loader_flatpak_app_missing_runtime_func (GsPluginLoader *plugin_loader
return;
/* no files to use */
- repodir_fn = gs_test_get_filename ("tests/flatpak/app-missing-runtime/repo");
+ repodir_fn = gs_test_get_filename (TESTDATADIR, "tests/flatpak/app-missing-runtime/repo");
if (repodir_fn == NULL ||
!g_file_test (repodir_fn, G_FILE_TEST_EXISTS)) {
g_test_skip ("no flatpak test repo");
@@ -1443,7 +1418,7 @@ gs_plugin_loader_flatpak_app_missing_runtime_func (GsPluginLoader *plugin_loader
/* add a remote */
app_source = gs_app_new ("test");
- testdir = gs_test_get_filename ("tests/flatpak/app-missing-runtime");
+ testdir = gs_test_get_filename (TESTDATADIR, "tests/flatpak/app-missing-runtime");
if (testdir == NULL)
return;
testdir_repourl = g_strdup_printf ("file://%s/repo", testdir);
@@ -1581,7 +1556,7 @@ gs_plugin_loader_flatpak_runtime_repo_func (GsPluginLoader *plugin_loader)
gs_plugin_loader_setup_again (plugin_loader);
/* write a flatpakrepo file */
- testdir = gs_test_get_filename ("tests/flatpak/only-runtime");
+ testdir = gs_test_get_filename (TESTDATADIR, "tests/flatpak/only-runtime");
if (testdir == NULL)
return;
testdir_repourl = g_strdup_printf ("file://%s/repo", testdir);
@@ -1596,7 +1571,7 @@ gs_plugin_loader_flatpak_runtime_repo_func (GsPluginLoader *plugin_loader)
/* write a flatpakref file */
fn_repourl = g_strdup_printf ("file://%s", fn_repo);
- testdir2 = gs_test_get_filename ("tests/flatpak/app-missing-runtime");
+ testdir2 = gs_test_get_filename (TESTDATADIR, "tests/flatpak/app-missing-runtime");
if (testdir2 == NULL)
return;
testdir2_repourl = g_strdup_printf ("file://%s/repo", testdir2);
@@ -1737,7 +1712,7 @@ gs_plugin_loader_flatpak_ref_func (GsPluginLoader *plugin_loader)
/* add a remote with only the runtime in */
app_source = gs_app_new ("test");
- testdir = gs_test_get_filename ("tests/flatpak/only-runtime");
+ testdir = gs_test_get_filename (TESTDATADIR, "tests/flatpak/only-runtime");
if (testdir == NULL)
return;
testdir_repourl = g_strdup_printf ("file://%s/repo", testdir);
@@ -1793,7 +1768,7 @@ gs_plugin_loader_flatpak_ref_func (GsPluginLoader *plugin_loader)
g_assert_cmpint (gs_app_get_state (runtime), ==, AS_APP_STATE_INSTALLED);
/* write a flatpakref file */
- testdir2 = gs_test_get_filename ("tests/flatpak/app-with-runtime");
+ testdir2 = gs_test_get_filename (TESTDATADIR, "tests/flatpak/app-with-runtime");
if (testdir2 == NULL)
return;
testdir2_repourl = g_strdup_printf ("file://%s/repo", testdir2);
@@ -1929,13 +1904,13 @@ gs_plugin_loader_flatpak_app_update_func (GsPluginLoader *plugin_loader)
return;
/* no files to use */
- repodir1_fn = gs_test_get_filename ("tests/flatpak/app-with-runtime/repo");
+ repodir1_fn = gs_test_get_filename (TESTDATADIR, "tests/flatpak/app-with-runtime/repo");
if (repodir1_fn == NULL ||
!g_file_test (repodir1_fn, G_FILE_TEST_EXISTS)) {
g_test_skip ("no flatpak test repo");
return;
}
- repodir2_fn = gs_test_get_filename ("tests/flatpak/app-update/repo");
+ repodir2_fn = gs_test_get_filename (TESTDATADIR, "tests/flatpak/app-update/repo");
if (repodir2_fn == NULL ||
!g_file_test (repodir2_fn, G_FILE_TEST_EXISTS)) {
g_test_skip ("no flatpak test repo");
@@ -2339,11 +2314,11 @@ main (int argc, char **argv)
}
/* dummy data */
- reposdir = gs_test_get_filename ("tests/yum.repos.d");
+ reposdir = gs_test_get_filename (TESTDATADIR, "tests/yum.repos.d");
g_assert (reposdir != NULL);
g_setenv ("GS_SELF_TEST_REPOS_DIR", reposdir, TRUE);
- fn = gs_test_get_filename ("icons/hicolor/48x48/org.gnome.Software.png");
+ fn = gs_test_get_filename (TESTDATADIR, "icons/hicolor/48x48/org.gnome.Software.png");
g_assert (fn != NULL);
xml = g_strdup_printf ("<?xml version=\"1.0\"?>\n"
"<components version=\"0.9\">\n"
diff --git a/lib/gs-test.c b/lib/gs-test.c
new file mode 100644
index 0000000..ef0cc89
--- /dev/null
+++ b/lib/gs-test.c
@@ -0,0 +1,52 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2013-2016 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdlib.h>
+
+#include "gs-test.h"
+
+gchar *
+gs_test_get_filename (const gchar *testdatadir, const gchar *filename)
+{
+ gchar *tmp;
+ char full_tmp[PATH_MAX];
+ g_autofree gchar *path = NULL;
+ path = g_build_filename (testdatadir, filename, NULL);
+ tmp = realpath (path, full_tmp);
+ if (tmp == NULL)
+ return NULL;
+ return g_strdup (full_tmp);
+}
+
+void
+gs_test_flush_main_context (void)
+{
+ guint cnt = 0;
+ while (g_main_context_iteration (NULL, FALSE)) {
+ if (cnt == 0)
+ g_debug ("clearing pending events...");
+ cnt++;
+ }
+ if (cnt > 0)
+ g_debug ("cleared %u events", cnt);
+}
+
+/* vim: set noexpandtab: */
diff --git a/lib/gs-test.h b/lib/gs-test.h
new file mode 100644
index 0000000..f312e1e
--- /dev/null
+++ b/lib/gs-test.h
@@ -0,0 +1,37 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2013-2016 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __GS_TEST_H
+#define __GS_TEST_H
+
+#include "gs-app.h"
+
+G_BEGIN_DECLS
+
+void gs_test_flush_main_context (void);
+gchar *gs_test_get_filename (const gchar *testdatadir,
+ const gchar *filename);
+
+G_END_DECLS
+
+#endif /* __GS_TEST_H */
+
+/* vim: set noexpandtab: */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]