gplugin/gplugin

38052a6cb999
Merged in feature/fix-gplugin-version-compare (pull request #63)

gplugin_version_compare's logic was inverted, this fixes it as well as some errors in the unit tests.

Approved-by: Elliott Sales de Andrade
--- a/gplugin/gplugin-manager.c Mon Feb 24 01:30:29 2020 +0000
+++ b/gplugin/gplugin-manager.c Tue Feb 25 04:06:52 2020 +0000
@@ -1339,21 +1339,12 @@
}
if(result < 0) {
- /* negative values mean that the first version is larger than the
- * second, so we need check for > and >=.
- */
- keep = (g_strcmp0(op, ">") == 0 || g_strcmp0(op, ">=") == 0);
+ keep = (g_strcmp0(op, "<") == 0 || g_strcmp0(op, "<=") == 0);
} else if(result == 0) {
- /* 0 values mean we need to check for = and ==, as well as <= and
- * >= as they need to match too.
- */
keep = (g_strcmp0(op, "=") == 0 || g_strcmp0(op, "==") == 0 ||
g_strcmp0(op, "<=") == 0 || g_strcmp0(op, ">=") == 0);
} else if(result > 0) {
- /* positive values mean that the first version is smaller than the
- * second, so we need to check for < and <=.
- */
- keep = (g_strcmp0(op, "<") == 0 || g_strcmp0(op, "<=") == 0);
+ keep = (g_strcmp0(op, ">") == 0 || g_strcmp0(op, ">=") == 0);
}
if(keep) {
--- a/gplugin/gplugin-version.c Mon Feb 24 01:30:29 2020 +0000
+++ b/gplugin/gplugin-version.c Tue Feb 25 04:06:52 2020 +0000
@@ -211,8 +211,8 @@
* A semantic version checker which ignores any characters after the micro
* version.
*
- * Returns: -1 if @v1 is greater than @v2, 0 if @v1 is equal to @v1, and 1 if
- * @v1 is less than @v2.
+ * Returns: less than 0 if @v1 is less than @v2, 0 if @v1 is equal to @v1, and
+ * greater than 0 if @v1 is greater than @v2.
*/
gint
gplugin_version_compare(const gchar *v1, const gchar *v2, GError **error) {
@@ -228,20 +228,20 @@
/* make sure v1 matches the regex */
if(!gplugin_version_parser(v1, &v1_maj, &v1_min, &v1_mic, NULL, error))
- return 1;
+ return -1;
/* make sure v2 matches the regex */
if(!gplugin_version_parser(v2, &v2_maj, &v2_min, &v2_mic, NULL, error))
- return -1;
+ return 1;
/* now figure out if they match */
- t = v2_maj - v1_maj;
+ t = v1_maj - v2_maj;
if(t != 0)
return t;
- t = v2_min - v1_min;
+ t = v1_min - v2_min;
if(t != 0)
return t;
- return v2_mic - v1_mic;
+ return v1_mic - v2_mic;
}
--- a/gplugin/tests/test-version-compare.c Mon Feb 24 01:30:29 2020 +0000
+++ b/gplugin/tests/test-version-compare.c Tue Feb 25 04:06:52 2020 +0000
@@ -101,7 +101,7 @@
/* 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), ==, -1);
+ g_assert_cmpint(gplugin_version_compare("1.0.0", "0.0.0", NULL), >, 0);
}
static void
@@ -111,13 +111,13 @@
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), ==, 1);
+ g_assert_cmpint(gplugin_version_compare("0.0.0", "1.0.0", NULL), <, 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), ==, -1);
+ g_assert_cmpint(gplugin_version_compare("0.1.0", "0.0.0", NULL), >, 0);
}
static void
@@ -127,28 +127,28 @@
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), ==, 1);
+ g_assert_cmpint(gplugin_version_compare("0.0.0", "0.1.0", NULL), <, 0);
}
/* micro version tests */
static void
test_gplugin_version_0_0_1__0_0_0(void) {
- g_assert_cmpint(gplugin_version_compare("0.1.0", "0.0.0", NULL), ==, -1);
+ g_assert_cmpint(gplugin_version_compare("0.0.1", "0.0.0", NULL), >, 0);
}
static void
test_gplugin_version_0_0_1__0_0_1(void) {
- g_assert_cmpint(gplugin_version_compare("0.1.0", "0.1.0", NULL), ==, 0);
+ g_assert_cmpint(gplugin_version_compare("0.0.1", "0.0.1", NULL), ==, 0);
}
static void
test_gplugin_version_0_0_0__0_0_1(void) {
- g_assert_cmpint(gplugin_version_compare("0.0.0", "0.1.0", NULL), ==, 1);
+ g_assert_cmpint(gplugin_version_compare("0.0.0", "0.0.1", NULL), <, 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), ==, -1);
+ g_assert_cmpint(gplugin_version_compare("1.0", "0.1", NULL), >, 0);
}
static void test_gplugin_version_1_0__1_0(void) {
@@ -156,12 +156,12 @@
}
static void test_gplugin_version_0_1__1_0(void) {
- g_assert_cmpint(gplugin_version_compare("0.1", "1.0", NULL), ==, 1);
+ g_assert_cmpint(gplugin_version_compare("0.1", "1.0", NULL), <, 0);
}
/* major tests */
static void test_gplugin_version_1__0(void) {
- g_assert_cmpint(gplugin_version_compare("1", "0", NULL), ==, -1);
+ g_assert_cmpint(gplugin_version_compare("1", "0", NULL), >, 0);
}
static void test_gplugin_version_1__1(void) {
@@ -169,7 +169,7 @@
}
static void test_gplugin_version_0__1(void) {
- g_assert_cmpint(gplugin_version_compare("0", "1", NULL), ==, 1);
+ g_assert_cmpint(gplugin_version_compare("0", "1", NULL), <, 0);
}
/******************************************************************************