gplugin/gplugin

Parents a04d093ba0f6
Children ac386374379f
Added gplugin_manager_find_plugin_with_newest_version so clients aren't left with the task of figuring out which plugin to load.
--- a/ChangeLog Sun Apr 12 01:27:32 2020 +0000
+++ b/ChangeLog Sun Apr 12 02:45:51 2020 -0500
@@ -18,6 +18,7 @@
* Renamed the GPluginManager::load-failed signal to
GPluginManager::load-plugin-failed and added the error, if any, that the
plugin returned. (Gary Kramlich)
+ * Added gplugin_manager_find_plugin_with_newest_version.
Lua Loader
* Removed the moonscript support from the Lua loader. (Gary Kramlich)
--- a/gplugin/gplugin-manager.c Sun Apr 12 01:27:32 2020 +0000
+++ b/gplugin/gplugin-manager.c Sun Apr 12 02:45:51 2020 -0500
@@ -1649,7 +1649,6 @@
for(l = plugins; l; l = l->next) {
GPluginPlugin *plugin = GPLUGIN_PLUGIN(l->data);
GPluginPluginInfo *info = NULL;
- GError *error = NULL;
const gchar *found_version = NULL;
gint result = 0;
gboolean keep = FALSE;
@@ -1657,23 +1656,15 @@
/* get the plugin's version from it's info */
info = gplugin_plugin_get_info(plugin);
found_version = gplugin_plugin_info_get_version(info);
- g_object_unref(G_OBJECT(info));
/* now compare the version of the plugin to passed in version. This
* should be done in this order so it's easier to track the operators.
* IE: we want to keep the inequality the same.
*/
- result = gplugin_version_compare(found_version, version, &error);
- if(error != NULL) {
- g_warning(
- "failed to compare versions for %s: %s",
- id,
- error->message ? error->message : _("unknown error"));
+ result = gplugin_version_compare(found_version, version);
- g_clear_error(&error);
-
- continue;
- }
+ /* we need to keep info around until we're done using found_version */
+ g_object_unref(G_OBJECT(info));
if(result < 0) {
keep = (g_strcmp0(op, "<") == 0 || g_strcmp0(op, "<=") == 0);
@@ -1753,6 +1744,81 @@
}
/**
+ * gplugin_manager_find_plugin_with_newest_version:
+ * @id: The id of the plugin to find.
+ *
+ * Calls gplugin_manager_find_plugins() with @id, and then returns the Plugins
+ * with the highest version number or %NULL if no plugins with @id are found.
+ *
+ * Returns: (transfer full): The #GPluginPlugin with an id of @id that has the
+ * highest version number, or %NULL if no plugins were found with @id.
+ */
+GPluginPlugin *
+gplugin_manager_find_plugin_with_newest_version(const gchar *id)
+{
+ GPluginPlugin *plugin_a = NULL;
+ GPluginPluginInfo *info_a = NULL;
+ const gchar *version_a = NULL;
+ GSList *l = NULL;
+
+ g_return_val_if_fail(id != NULL, NULL);
+
+ l = gplugin_manager_find_plugins(id);
+ for(; l != NULL; l = g_slist_delete_link(l, l)) {
+ GPluginPlugin *plugin_b = NULL;
+ GPluginPluginInfo *info_b = NULL;
+ const gchar *version_b = NULL;
+ gint cmp = 0;
+
+ if(!GPLUGIN_IS_PLUGIN(l->data)) {
+ continue;
+ }
+
+ plugin_b = GPLUGIN_PLUGIN(l->data);
+ info_b = gplugin_plugin_get_info(plugin_b);
+
+ /* if this is the first plugin we've found, set the a values and
+ * continue.
+ */
+ if(!GPLUGIN_IS_PLUGIN(plugin_a)) {
+ plugin_a = plugin_b;
+ info_a = info_b;
+
+ version_a = gplugin_plugin_info_get_version(info_a);
+
+ continue;
+ }
+
+ /* at this point, we've seen another plugin, so we need to compare
+ * their versions.
+ */
+ version_b = gplugin_plugin_info_get_version(info_b);
+
+ cmp = gplugin_version_compare(version_a, version_b);
+ if(cmp < 0) {
+ /* plugin_b has a newer version */
+
+ /* unref the old objects */
+ g_clear_object(&plugin_a);
+ g_clear_object(&info_a);
+
+ /* now point the pointers to the plugin_b pointers */
+ plugin_a = plugin_b;
+ info_a = info_b;
+ version_a = version_b;
+ } else {
+ /* plugin_b has an older or equal to version so we keep plugin_a */
+ g_clear_object(&plugin_b);
+ g_clear_object(&info_b);
+ }
+ }
+
+ g_clear_object(&info_a);
+
+ return plugin_a;
+}
+
+/**
* gplugin_manager_get_plugin_dependencies:
* @plugin: The #GPluginPlugin whose dependencies to get.
* @error: (out) (nullable): Return address for a #GError.
--- a/gplugin/gplugin-manager.h Sun Apr 12 01:27:32 2020 +0000
+++ b/gplugin/gplugin-manager.h Sun Apr 12 02:45:51 2020 -0500
@@ -59,6 +59,7 @@
GSList *gplugin_manager_find_plugins_with_state(GPluginPluginState state);
GPluginPlugin *gplugin_manager_find_plugin(const gchar *id);
+GPluginPlugin *gplugin_manager_find_plugin_with_newest_version(const gchar *id);
GSList *gplugin_manager_get_plugin_dependencies(
GPluginPlugin *plugin,
--- a/gplugin/gplugin-version.c Sun Apr 12 01:27:32 2020 +0000
+++ b/gplugin/gplugin-version.c Sun Apr 12 02:45:51 2020 -0500
@@ -66,29 +66,52 @@
}
}
-static gboolean
+/*< private >
+ * gplugin_version_parser:
+ * @version: The string version to parse.
+ * @major: (out) (nullable): A return gint pointer for the major version.
+ * @minor: (out) (nullable): A return gint pointer for the minor version.
+ * @micro: (out) (nullable): A return gint pointer for the micro version.
+ * @extra: (out) (nullable): A return gchar * pointer for any extra version
+ * info.
+ *
+ * Attempts to parse a version string into its @major, @minor, @micro, and
+ * @extra parts. If @version doesn't match a semantic version string, @major
+ * will be set to %-1, @minor will be set to %0, and @micro will be set to %0.
+ */
+static void
gplugin_version_parser(
- const gchar *v,
+ const gchar *version,
gint *major,
gint *minor,
gint *micro,
- gchar **extra,
- GError **error)
+ gchar **extra)
{
GMatchInfo *info = NULL;
gboolean matches = FALSE;
gchar *temp = NULL;
- matches = g_regex_match(regex, v, 0, &info);
+ /* initialize everything to our failed state */
+ if(major != NULL) {
+ *major = -1;
+ }
+
+ if(minor != NULL) {
+ *minor = 0;
+ }
+
+ if(micro != NULL) {
+ *micro = 0;
+ }
+
+ if(version == NULL) {
+ /* if a version was not provided, return our failed values */
+ return;
+ }
+
+ matches = g_regex_match(regex, version, 0, &info);
if(!matches) {
- g_set_error(
- error,
- GPLUGIN_DOMAIN,
- 0,
- _("%s does not match the version regex"),
- v);
-
- return FALSE;
+ /* if we failed to match the regex, just return our failed values */
}
/* grab the major version */
@@ -113,12 +136,11 @@
}
/* grab the extra version */
- if(extra)
+ if(extra) {
*extra = g_match_info_fetch_named(info, "extra");
+ }
g_match_info_unref(info);
-
- return TRUE;
}
/******************************************************************************
@@ -216,7 +238,6 @@
* gplugin_version_compare:
* @v1: The first version to compare.
* @v2: The second version to compare.
- * @error: (out) (nullable): A #GError return address if there are any errors.
*
* A semantic version checker which ignores any characters after the micro
* version.
@@ -225,25 +246,21 @@
* greater than 0 if @v1 is greater than @v2.
*/
gint
-gplugin_version_compare(const gchar *v1, const gchar *v2, GError **error)
+gplugin_version_compare(const gchar *v1, const gchar *v2)
{
gint v1_maj = 0, v1_min = 0, v1_mic = 0;
gint v2_maj = 0, v2_min = 0, v2_mic = 0;
gint t = 0;
- g_return_val_if_fail(v1 != NULL, 1);
- g_return_val_if_fail(v2 != NULL, 2);
-
- if(regex == NULL)
+ if(regex == NULL) {
gplugin_version_lazy_init();
+ }
- /* make sure v1 matches the regex */
- if(!gplugin_version_parser(v1, &v1_maj, &v1_min, &v1_mic, NULL, error))
- return -1;
+ /* parse v1 */
+ gplugin_version_parser(v1, &v1_maj, &v1_min, &v1_mic, NULL);
- /* make sure v2 matches the regex */
- if(!gplugin_version_parser(v2, &v2_maj, &v2_min, &v2_mic, NULL, error))
- return 1;
+ /* parse v2 */
+ gplugin_version_parser(v2, &v2_maj, &v2_min, &v2_mic, NULL);
/* now figure out if they match */
t = v1_maj - v2_maj;
--- a/gplugin/gplugin-version.h.in Sun Apr 12 01:27:32 2020 +0000
+++ b/gplugin/gplugin-version.h.in Sun Apr 12 02:45:51 2020 -0500
@@ -40,7 +40,7 @@
const gchar *gplugin_version_check(guint major, guint minor, guint micro);
-gint gplugin_version_compare(const gchar *v1, const gchar *v2, GError **error);
+gint gplugin_version_compare(const gchar *v1, const gchar *v2);
G_END_DECLS
--- a/gplugin/tests/meson.build Sun Apr 12 01:27:32 2020 +0000
+++ b/gplugin/tests/meson.build Sun Apr 12 02:45:51 2020 -0500
@@ -1,15 +1,16 @@
###############################################################################
# Subdirectories
###############################################################################
-subdir('plugins')
subdir('bad-plugins')
+subdir('bind-local')
subdir('dynamic-type')
subdir('id-collision')
+subdir('load-on-query-fail')
subdir('load-on-query-pass')
-subdir('load-on-query-fail')
+subdir('newest-version')
+subdir('plugins')
+subdir('unresolved-symbol')
subdir('versioned-dependencies')
-subdir('bind-local')
-subdir('unresolved-symbol')
###############################################################################
# Tests
@@ -37,6 +38,11 @@
dependencies : [gplugin_dep, GLIB, GOBJECT])
test('Loader Registration', e)
+e = executable('test-newest-version', 'test-newest-version.c',
+ c_args : ['-DTEST_DIR="@0@/newest-version/"'.format(meson.current_build_dir())],
+ dependencies : [gplugin_dep, GLIB, GOBJECT])
+test('Find Plugins Newest Version', e)
+
e = executable('test-option-group', 'test-option-group.c',
dependencies : [gplugin_dep, GLIB, GOBJECT])
test('Option Group', e)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplugin/tests/newest-version/meson.build Sun Apr 12 02:45:51 2020 -0500
@@ -0,0 +1,35 @@
+shared_module('multiple-semantic-1.0.0', 'multiple-semantic-1.0.0.c',
+ name_prefix : '',
+ dependencies : [gplugin_dep, GLIB])
+
+shared_module('multiple-semantic-1.1.0', 'multiple-semantic-1.1.0.c',
+ name_prefix : '',
+ dependencies : [gplugin_dep, GLIB])
+
+shared_module('no-version-and-semantic-no-version',
+ 'no-version-and-semantic-no-version.c',
+ name_prefix : '',
+ dependencies : [gplugin_dep, GLIB])
+
+shared_module('no-version-and-semantic-semantic',
+ 'no-version-and-semantic-semantic.c',
+ name_prefix : '',
+ dependencies : [gplugin_dep, GLIB])
+
+shared_module('non-semantic-and-semantic-non-semantic',
+ 'non-semantic-and-semantic-non-semantic.c',
+ name_prefix : '',
+ dependencies : [gplugin_dep, GLIB])
+
+shared_module('non-semantic-and-semantic-semantic',
+ 'non-semantic-and-semantic-semantic.c',
+ name_prefix : '',
+ dependencies : [gplugin_dep, GLIB])
+
+shared_module('solo-no-version', 'solo-no-version.c',
+ name_prefix : '',
+ dependencies : [gplugin_dep, GLIB])
+
+shared_module('solo-non-semantic', 'solo-non-semantic.c',
+ name_prefix : '',
+ dependencies : [gplugin_dep, GLIB])
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplugin/tests/newest-version/multiple-semantic-1.0.0.c Sun Apr 12 02:45:51 2020 -0500
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2011-2020 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gplugin.h>
+#include <gplugin-native.h>
+
+G_MODULE_EXPORT GPluginPluginInfo *
+gplugin_query(G_GNUC_UNUSED GError **error)
+{
+ /* clang-format off */
+ return gplugin_plugin_info_new(
+ "gplugin/test-newest-version/multiple-semantic",
+ 0x04030201,
+ "version", "1.0.0",
+ NULL);
+ /* clang-format on */
+}
+
+G_MODULE_EXPORT gboolean
+gplugin_load(
+ G_GNUC_UNUSED GPluginNativePlugin *plugin,
+ G_GNUC_UNUSED GError **error)
+{
+ return TRUE;
+}
+
+G_MODULE_EXPORT gboolean
+gplugin_unload(
+ G_GNUC_UNUSED GPluginNativePlugin *plugin,
+ G_GNUC_UNUSED GError **error)
+{
+ return TRUE;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplugin/tests/newest-version/multiple-semantic-1.1.0.c Sun Apr 12 02:45:51 2020 -0500
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2011-2020 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gplugin.h>
+#include <gplugin-native.h>
+
+G_MODULE_EXPORT GPluginPluginInfo *
+gplugin_query(G_GNUC_UNUSED GError **error)
+{
+ /* clang-format off */
+ return gplugin_plugin_info_new(
+ "gplugin/test-newest-version/multiple-semantic",
+ 0x04030201,
+ "version", "1.1.0",
+ NULL);
+ /* clang-format on */
+}
+
+G_MODULE_EXPORT gboolean
+gplugin_load(
+ G_GNUC_UNUSED GPluginNativePlugin *plugin,
+ G_GNUC_UNUSED GError **error)
+{
+ return TRUE;
+}
+
+G_MODULE_EXPORT gboolean
+gplugin_unload(
+ G_GNUC_UNUSED GPluginNativePlugin *plugin,
+ G_GNUC_UNUSED GError **error)
+{
+ return TRUE;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplugin/tests/newest-version/no-version-and-semantic-no-version.c Sun Apr 12 02:45:51 2020 -0500
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2011-2020 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gplugin.h>
+#include <gplugin-native.h>
+
+G_MODULE_EXPORT GPluginPluginInfo *
+gplugin_query(G_GNUC_UNUSED GError **error)
+{
+ /* clang-format off */
+ return gplugin_plugin_info_new(
+ "gplugin/test-newest-version/no-version-and-semantic",
+ 0x04030201,
+ NULL);
+ /* clang-format on */
+}
+
+G_MODULE_EXPORT gboolean
+gplugin_load(
+ G_GNUC_UNUSED GPluginNativePlugin *plugin,
+ G_GNUC_UNUSED GError **error)
+{
+ return TRUE;
+}
+
+G_MODULE_EXPORT gboolean
+gplugin_unload(
+ G_GNUC_UNUSED GPluginNativePlugin *plugin,
+ G_GNUC_UNUSED GError **error)
+{
+ return TRUE;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplugin/tests/newest-version/no-version-and-semantic-semantic.c Sun Apr 12 02:45:51 2020 -0500
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2011-2020 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gplugin.h>
+#include <gplugin-native.h>
+
+G_MODULE_EXPORT GPluginPluginInfo *
+gplugin_query(G_GNUC_UNUSED GError **error)
+{
+ /* clang-format off */
+ return gplugin_plugin_info_new(
+ "gplugin/test-newest-version/no-version-and-semantic",
+ 0x04030201,
+ "version", "1.0.0",
+ NULL);
+ /* clang-format on */
+}
+
+G_MODULE_EXPORT gboolean
+gplugin_load(
+ G_GNUC_UNUSED GPluginNativePlugin *plugin,
+ G_GNUC_UNUSED GError **error)
+{
+ return TRUE;
+}
+
+G_MODULE_EXPORT gboolean
+gplugin_unload(
+ G_GNUC_UNUSED GPluginNativePlugin *plugin,
+ G_GNUC_UNUSED GError **error)
+{
+ return TRUE;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplugin/tests/newest-version/non-semantic-and-semantic-non-semantic.c Sun Apr 12 02:45:51 2020 -0500
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2011-2020 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gplugin.h>
+#include <gplugin-native.h>
+
+G_MODULE_EXPORT GPluginPluginInfo *
+gplugin_query(G_GNUC_UNUSED GError **error)
+{
+ /* clang-format off */
+ return gplugin_plugin_info_new(
+ "gplugin/test-newest-version/non-semantic-and-semantic",
+ 0x04030201,
+ "version", "abc123",
+ NULL);
+ /* clang-format on */
+}
+
+G_MODULE_EXPORT gboolean
+gplugin_load(
+ G_GNUC_UNUSED GPluginNativePlugin *plugin,
+ G_GNUC_UNUSED GError **error)
+{
+ return TRUE;
+}
+
+G_MODULE_EXPORT gboolean
+gplugin_unload(
+ G_GNUC_UNUSED GPluginNativePlugin *plugin,
+ G_GNUC_UNUSED GError **error)
+{
+ return TRUE;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplugin/tests/newest-version/non-semantic-and-semantic-semantic.c Sun Apr 12 02:45:51 2020 -0500
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2011-2020 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gplugin.h>
+#include <gplugin-native.h>
+
+G_MODULE_EXPORT GPluginPluginInfo *
+gplugin_query(G_GNUC_UNUSED GError **error)
+{
+ /* clang-format off */
+ return gplugin_plugin_info_new(
+ "gplugin/test-newest-version/non-semantic-and-semantic",
+ 0x04030201,
+ "version", "1.0.0",
+ NULL);
+ /* clang-format on */
+}
+
+G_MODULE_EXPORT gboolean
+gplugin_load(
+ G_GNUC_UNUSED GPluginNativePlugin *plugin,
+ G_GNUC_UNUSED GError **error)
+{
+ return TRUE;
+}
+
+G_MODULE_EXPORT gboolean
+gplugin_unload(
+ G_GNUC_UNUSED GPluginNativePlugin *plugin,
+ G_GNUC_UNUSED GError **error)
+{
+ return TRUE;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplugin/tests/newest-version/solo-no-version.c Sun Apr 12 02:45:51 2020 -0500
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2011-2020 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gplugin.h>
+#include <gplugin-native.h>
+
+G_MODULE_EXPORT GPluginPluginInfo *
+gplugin_query(G_GNUC_UNUSED GError **error)
+{
+ /* clang-format off */
+ return gplugin_plugin_info_new(
+ "gplugin/test-newest-version/solo-no-version",
+ 0x04030201,
+ NULL);
+ /* clang-format on */
+}
+
+G_MODULE_EXPORT gboolean
+gplugin_load(
+ G_GNUC_UNUSED GPluginNativePlugin *plugin,
+ G_GNUC_UNUSED GError **error)
+{
+ return TRUE;
+}
+
+G_MODULE_EXPORT gboolean
+gplugin_unload(
+ G_GNUC_UNUSED GPluginNativePlugin *plugin,
+ G_GNUC_UNUSED GError **error)
+{
+ return TRUE;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplugin/tests/newest-version/solo-non-semantic.c Sun Apr 12 02:45:51 2020 -0500
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2011-2020 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gplugin.h>
+#include <gplugin-native.h>
+
+G_MODULE_EXPORT GPluginPluginInfo *
+gplugin_query(G_GNUC_UNUSED GError **error)
+{
+ /* clang-format off */
+ return gplugin_plugin_info_new(
+ "gplugin/test-newest-version/solo-non-semantic",
+ 0x04030201,
+ "version", "abc123",
+ NULL);
+ /* clang-format on */
+}
+
+G_MODULE_EXPORT gboolean
+gplugin_load(
+ G_GNUC_UNUSED GPluginNativePlugin *plugin,
+ G_GNUC_UNUSED GError **error)
+{
+ return TRUE;
+}
+
+G_MODULE_EXPORT gboolean
+gplugin_unload(
+ G_GNUC_UNUSED GPluginNativePlugin *plugin,
+ G_GNUC_UNUSED GError **error)
+{
+ return TRUE;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplugin/tests/test-newest-version.c Sun Apr 12 02:45:51 2020 -0500
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2011-2020 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib.h>
+
+#include <gplugin.h>
+
+/******************************************************************************
+ * Helpers
+ *****************************************************************************/
+static void
+test_newest_version(const gchar *id, const gchar *version)
+{
+ GPluginPlugin *plugin = NULL;
+ GPluginPluginInfo *info = NULL;
+
+ gplugin_manager_append_path(TEST_DIR);
+ gplugin_manager_refresh();
+
+ plugin = gplugin_manager_find_plugin_with_newest_version(id);
+ g_assert_nonnull(plugin);
+ g_assert_true(GPLUGIN_IS_PLUGIN(plugin));
+
+ info = gplugin_plugin_get_info(plugin);
+ g_assert_nonnull(info);
+ g_assert_true(GPLUGIN_IS_PLUGIN_INFO(info));
+
+ g_assert_cmpstr(gplugin_plugin_info_get_version(info), ==, version);
+
+ g_clear_object(&info);
+ g_clear_object(&plugin);
+}
+
+/******************************************************************************
+ * Tests
+ *****************************************************************************/
+static void
+test_newest_version_multiple_semantic(void)
+{
+ test_newest_version(
+ "gplugin/test-newest-version/multiple-semantic",
+ "1.1.0");
+}
+
+static void
+test_newest_version_solo_non_semantic(void)
+{
+ test_newest_version(
+ "gplugin/test-newest-version/solo-non-semantic",
+ "abc123");
+}
+
+static void
+test_newest_version_non_semantic_and_semantic(void)
+{
+ test_newest_version(
+ "gplugin/test-newest-version/non-semantic-and-semantic",
+ "1.0.0");
+}
+
+static void
+test_newest_version_solo_no_version(void)
+{
+ test_newest_version("gplugin/test-newest-version/solo-no-version", NULL);
+}
+
+static void
+test_newest_version_no_version_and_semantic(void)
+{
+ test_newest_version(
+ "gplugin/test-newest-version/no-version-and-semantic",
+ "1.0.0");
+}
+
+/******************************************************************************
+ * Main
+ *****************************************************************************/
+gint
+main(gint argc, gchar **argv)
+{
+
+ g_test_init(&argc, &argv, NULL);
+
+ gplugin_init();
+
+ g_test_add_func(
+ "/manager/find_plugin_newest_version/multiple-semantic",
+ test_newest_version_multiple_semantic);
+ g_test_add_func(
+ "/manager/find_plugin_newest_version/no-version-and-semantic",
+ test_newest_version_no_version_and_semantic);
+ g_test_add_func(
+ "/manager/find_plugin_newest_version/non-semantic-and-semantic",
+ test_newest_version_non_semantic_and_semantic);
+ g_test_add_func(
+ "/manager/find_plugin_newest_version/solo-no-version",
+ test_newest_version_solo_no_version);
+ g_test_add_func(
+ "/manager/find_plugin_newest_version/solo-non-semantic",
+ test_newest_version_solo_non_semantic);
+
+ return g_test_run();
+}
--- a/gplugin/tests/test-version-compare.c Sun Apr 12 01:27:32 2020 +0000
+++ b/gplugin/tests/test-version-compare.c Sun Apr 12 02:45:51 2020 -0500
@@ -22,185 +22,128 @@
*****************************************************************************/
/* bad versions */
static void
-test_gplugin_version_null__null_subprocess(void)
-{
- gplugin_version_compare(NULL, NULL, NULL);
-}
-
-static void
test_gplugin_version_null__null(void)
{
- g_test_trap_subprocess("/version-compare/null__null/subprocess", 0, 0);
-
- g_test_trap_assert_failed();
- g_test_trap_assert_stderr("*gplugin_version_compare*assertion*");
-}
-
-static void
-test_gplugin_version_null__1_2_3_subprocess(void)
-{
- gplugin_version_compare(NULL, "1.2.3", NULL);
+ g_assert_cmpint(gplugin_version_compare(NULL, NULL), ==, 0);
}
static void
test_gplugin_version_null__1_2_3(void)
{
- g_test_trap_subprocess("/version-compare/null__1_2_3/subprocess", 0, 0);
-
- g_test_trap_assert_failed();
- g_test_trap_assert_stderr("*gplugin_version_compare*assertion*");
-}
-
-static void
-test_gplugin_version_1_2_3__null_subprocess(void)
-{
- gplugin_version_compare("1.2.3", NULL, NULL);
+ g_assert_cmpint(gplugin_version_compare(NULL, "1.2.3"), <, 0);
}
static void
test_gplugin_version_1_2_3__null(void)
{
- g_test_trap_subprocess("/version-compare/1_2_3__null/subprocess", 0, 0);
-
- g_test_trap_assert_failed();
- g_test_trap_assert_stderr("*gplugin_version_compare*assertion*");
-}
-
-static void
-test_gplugin_version_abc__1_2_3_subprocess(void)
-{
- GError *error = NULL;
- gint t = 0;
-
- t = gplugin_version_compare("abc", "1.2.3", &error);
-
- g_assert_cmpint(t, ==, 1);
- g_assert_no_error(error);
+ g_assert_cmpint(gplugin_version_compare("1.2.3", NULL), >, 0);
}
static void
test_gplugin_version_abc__1_2_3(void)
{
- g_test_trap_subprocess("/version-compare/abc__1_2_3/subprocess", 0, 0);
-
- g_test_trap_assert_failed();
- g_test_trap_assert_stderr("*assertion*");
-}
-
-static void
-test_gplugin_version_1_2_3__abc_subprocess(void)
-{
- GError *error = NULL;
- gint t = 0;
-
- t = gplugin_version_compare("1.2.3", "abc", &error);
-
- g_assert_cmpint(t, ==, -1);
- g_assert_no_error(error);
+ g_assert_cmpint(gplugin_version_compare("abc", "1.2.3"), <, 0);
}
static void
test_gplugin_version_1_2_3__abc(void)
{
- g_test_trap_subprocess("/version-compare/1_2_3__abc/subprocess", 0, 0);
-
- g_test_trap_assert_failed();
- g_test_trap_assert_stderr("*assertion*");
+ g_assert_cmpint(gplugin_version_compare("1.2.3", "abc"), >, 0);
}
/* major version tests */
static void
test_gplugin_version_1_0_0__0_0_0(void)
{
- g_assert_cmpint(gplugin_version_compare("1.0.0", "0.0.0", NULL), >, 0);
+ g_assert_cmpint(gplugin_version_compare("1.0.0", "0.0.0"), >, 0);
}
static void
test_gplugin_version_1_0_0__1_0_0(void)
{
- g_assert_cmpint(gplugin_version_compare("1.0.0", "1.0.0", NULL), ==, 0);
+ g_assert_cmpint(gplugin_version_compare("1.0.0", "1.0.0"), ==, 0);
}
static void
test_gplugin_version_0_0_0__1_0_0(void)
{
- g_assert_cmpint(gplugin_version_compare("0.0.0", "1.0.0", NULL), <, 0);
+ g_assert_cmpint(gplugin_version_compare("0.0.0", "1.0.0"), <, 0);
}
/* minor version tests */
static void
test_gplugin_version_0_1_0__0_0_0(void)
{
- g_assert_cmpint(gplugin_version_compare("0.1.0", "0.0.0", NULL), >, 0);
+ g_assert_cmpint(gplugin_version_compare("0.1.0", "0.0.0"), >, 0);
}
static void
test_gplugin_version_0_1_0__0_1_0(void)
{
- g_assert_cmpint(gplugin_version_compare("0.1.0", "0.1.0", NULL), ==, 0);
+ g_assert_cmpint(gplugin_version_compare("0.1.0", "0.1.0"), ==, 0);
}
static void
test_gplugin_version_0_0_0__0_1_0(void)
{
- g_assert_cmpint(gplugin_version_compare("0.0.0", "0.1.0", NULL), <, 0);
+ g_assert_cmpint(gplugin_version_compare("0.0.0", "0.1.0"), <, 0);
}
/* micro version tests */
static void
test_gplugin_version_0_0_1__0_0_0(void)
{
- g_assert_cmpint(gplugin_version_compare("0.0.1", "0.0.0", NULL), >, 0);
+ g_assert_cmpint(gplugin_version_compare("0.0.1", "0.0.0"), >, 0);
}
static void
test_gplugin_version_0_0_1__0_0_1(void)
{
- g_assert_cmpint(gplugin_version_compare("0.0.1", "0.0.1", NULL), ==, 0);
+ g_assert_cmpint(gplugin_version_compare("0.0.1", "0.0.1"), ==, 0);
}
static void
test_gplugin_version_0_0_0__0_0_1(void)
{
- g_assert_cmpint(gplugin_version_compare("0.0.0", "0.0.1", NULL), <, 0);
+ g_assert_cmpint(gplugin_version_compare("0.0.0", "0.0.1"), <, 0);
}
/* major-minor tests */
static void
test_gplugin_version_1_0__0_1(void)
{
- g_assert_cmpint(gplugin_version_compare("1.0", "0.1", NULL), >, 0);
+ g_assert_cmpint(gplugin_version_compare("1.0", "0.1"), >, 0);
}
static void
test_gplugin_version_1_0__1_0(void)
{
- g_assert_cmpint(gplugin_version_compare("1.0", "1.0", NULL), ==, 0);
+ g_assert_cmpint(gplugin_version_compare("1.0", "1.0"), ==, 0);
}
static void
test_gplugin_version_0_1__1_0(void)
{
- g_assert_cmpint(gplugin_version_compare("0.1", "1.0", NULL), <, 0);
+ g_assert_cmpint(gplugin_version_compare("0.1", "1.0"), <, 0);
}
/* major tests */
static void
test_gplugin_version_1__0(void)
{
- g_assert_cmpint(gplugin_version_compare("1", "0", NULL), >, 0);
+ g_assert_cmpint(gplugin_version_compare("1", "0"), >, 0);
}
static void
test_gplugin_version_1__1(void)
{
- g_assert_cmpint(gplugin_version_compare("1", "1", NULL), ==, 0);
+ g_assert_cmpint(gplugin_version_compare("1", "1"), ==, 0);
}
static void
test_gplugin_version_0__1(void)
{
- g_assert_cmpint(gplugin_version_compare("0", "1", NULL), <, 0);
+ g_assert_cmpint(gplugin_version_compare("0", "1"), <, 0);
}
/******************************************************************************
@@ -229,21 +172,6 @@
g_test_add_func(
"/version-compare/1_2_3__abc",
test_gplugin_version_1_2_3__abc);
- g_test_add_func(
- "/version-compare/null__null/subprocess",
- test_gplugin_version_null__null_subprocess);
- g_test_add_func(
- "/version-compare/null__1_2_3/subprocess",
- test_gplugin_version_null__1_2_3_subprocess);
- g_test_add_func(
- "/version-compare/1_2_3__null/subprocess",
- test_gplugin_version_1_2_3__null_subprocess);
- g_test_add_func(
- "/version-compare/abc__1_2_3/subprocess",
- test_gplugin_version_abc__1_2_3_subprocess);
- g_test_add_func(
- "/version-compare/1_2_3__abc/subprocess",
- test_gplugin_version_1_2_3__abc_subprocess);
/* major version */
g_test_add_func(