summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2010-06-30 21:59:47 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2010-06-30 21:59:47 +0000
commit10b8e327d8c0d37b8a9f1997e33e4bf1a97bb39b (patch)
tree96787bf458cec93c63bfd37904388450ce32052a /rbutil/rbutilqt
parent35150b6dcb18089ba76a660e6b73caf1dad86579 (diff)
downloadrockbox-10b8e327d8c0d37b8a9f1997e33e4bf1a97bb39b.tar.gz
rockbox-10b8e327d8c0d37b8a9f1997e33e4bf1a97bb39b.tar.bz2
rockbox-10b8e327d8c0d37b8a9f1997e33e4bf1a97bb39b.zip
FS#11439: Fix version comparison regression.
Improve string suffix handling by distinguishing between version number separators (i.e. dots) and extended separators and additional version characters. Corrects false update information displayed for 64bit binaries of Rockbox Utility. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27201 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'rbutil/rbutilqt')
-rw-r--r--rbutil/rbutilqt/base/utils.cpp16
-rw-r--r--rbutil/rbutilqt/test/compareversion.cpp11
2 files changed, 23 insertions, 4 deletions
diff --git a/rbutil/rbutilqt/base/utils.cpp b/rbutil/rbutilqt/base/utils.cpp
index 1452ada330..bd2bce0609 100644
--- a/rbutil/rbutilqt/base/utils.cpp
+++ b/rbutil/rbutilqt/base/utils.cpp
@@ -211,9 +211,9 @@ QString Utils::checkEnvironment(bool permission)
*/
int Utils::compareVersionStrings(QString s1, QString s2)
{
+ qDebug() << "[Utils] comparing version strings" << s1 << "and" << s2;
QString a = s1.trimmed();
QString b = s2.trimmed();
- qDebug() << "[Utils] comparing version strings" << a << "and" << b;
// if strings are identical return 0.
if(a.isEmpty())
return 1;
@@ -252,8 +252,19 @@ int Utils::compareVersionStrings(QString s1, QString s2)
a.remove(QRegExp("^\\d*"));
b.remove(QRegExp("^\\d*"));
+ // If only one of the following characters is a dot that one is
+ // "greater" then anything else. Make sure it's followed by a number,
+ // Otherwise it might be the end of the string or suffix. Do this
+ // before version addon characters check to avoid stopping too early.
+ bool adot = a.contains(QRegExp("^[a-zA-Z]*\\.[0-9]"));
+ bool bdot = b.contains(QRegExp("^[a-zA-Z]*\\.[0-9]"));
+ if(adot && !bdot)
+ return -1;
+ if(!adot && bdot)
+ return 1;
// if number is immediately followed by a character consider it as
- // version addon (like 1.2.3b). In this case compare characters too.
+ // version addon (like 1.2.3b). In this case compare characters and end
+ // (version numbers like 1.2b.3 aren't handled).
QChar ltra;
QChar ltrb;
if(a.contains(QRegExp("^[a-zA-Z]")))
@@ -262,6 +273,7 @@ int Utils::compareVersionStrings(QString s1, QString s2)
ltrb = b.at(0);
if(ltra != ltrb)
return (ltra < ltrb) ? 1 : -1;
+
// both are identical or no addon characters, ignore.
// remove modifiers and following dot.
a.remove(QRegExp("^[a-zA-Z]*\\."));
diff --git a/rbutil/rbutilqt/test/compareversion.cpp b/rbutil/rbutilqt/test/compareversion.cpp
index db1c62e5d5..80bddf733a 100644
--- a/rbutil/rbutilqt/test/compareversion.cpp
+++ b/rbutil/rbutilqt/test/compareversion.cpp
@@ -62,6 +62,12 @@ const struct testvector testdata[] =
{ "test-1.2.3.tar.gz", "program-1.2.3.1.tar.bz2", 1 },
{ "program-1.2.3.zip", "program-1.2.3a.zip", 1 },
{ "program-1.2.3.tar.bz2", "2.0.0", 1 },
+ { "prog-1.2-64bit.tar.bz2", "prog-1.2.3.tar.bz2", 1 },
+ { "prog-1.2-64bit.tar.bz2", "prog-1.2-64bit.tar.bz2", 0 },
+ { "prog-1.2-64bit.tar.bz2", "prog-1.2.3-64bit.tar.bz2", 1 },
+ { "prog-1.2a-64bit.tar.bz2","prog-1.2b-64bit.tar.bz2", 1 },
+ { "prog-1.2-64bit.tar.bz2", "prog-1.2.3a-64bit.tar.bz2", 1 },
+ { "prog-1.2a-64bit.tar.bz2","prog-1.2.3-64bit.tar.bz2", 1 },
};
@@ -72,8 +78,9 @@ void TestVersionCompare::testMain()
QCOMPARE(Utils::compareVersionStrings(testdata[i].first,
testdata[i].second), testdata[i].expected);
// inverse test possible because function return values are symmetrical.
- QCOMPARE(Utils::compareVersionStrings(testdata[i].second,
- testdata[i].first), -testdata[i].expected);
+ if(testdata[i].expected != 0)
+ QCOMPARE(Utils::compareVersionStrings(testdata[i].second,
+ testdata[i].first), -testdata[i].expected);
}
}