aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2016-04-14 01:23:54 +0200
committerPetr Mrázek <peterix@gmail.com>2016-05-01 00:02:15 +0200
commit771dd6f9abe29c1d24c5ea8f0e7ca949bc24f84d (patch)
tree52962ddf547b3227f1b637dd1da2b3d0b5a5a766 /api
parente8ba5dafc63de65ed8a469353b808e391633f0fc (diff)
downloadPrismLauncher-771dd6f9abe29c1d24c5ea8f0e7ca949bc24f84d.tar.gz
PrismLauncher-771dd6f9abe29c1d24c5ea8f0e7ca949bc24f84d.tar.bz2
PrismLauncher-771dd6f9abe29c1d24c5ea8f0e7ca949bc24f84d.zip
NOISSUE reorganize unit tests to be placed next to the code they test. Nuke more dead tests.
Diffstat (limited to 'api')
-rw-r--r--api/gui/CMakeLists.txt2
-rw-r--r--api/logic/CMakeLists.txt220
-rw-r--r--api/logic/FileSystem_test.cpp164
-rw-r--r--api/logic/GZip_test.cpp57
-rw-r--r--api/logic/Version_test.cpp123
-rw-r--r--api/logic/java/JavaVersion_test.cpp116
-rw-r--r--api/logic/minecraft/GradleSpecifier_test.cpp77
-rw-r--r--api/logic/minecraft/Library_test.cpp195
-rw-r--r--api/logic/minecraft/ModList_test.cpp53
-rw-r--r--api/logic/minecraft/MojangVersionFormat_test.cpp55
-rw-r--r--api/logic/minecraft/ParseUtils_test.cpp45
-rw-r--r--api/logic/minecraft/testdata/1.9-simple.json198
-rw-r--r--api/logic/minecraft/testdata/1.9.json529
-rw-r--r--api/logic/minecraft/testdata/lib-native-arch.json46
-rw-r--r--api/logic/minecraft/testdata/lib-native.json52
-rw-r--r--api/logic/minecraft/testdata/lib-simple.json11
-rw-r--r--api/logic/settings/INIFile_test.cpp62
-rwxr-xr-xapi/logic/testdata/FileSystem-test_createShortcut-unix6
-rw-r--r--api/logic/testdata/test_folder/assets/minecraft/textures/blah.txt1
-rw-r--r--api/logic/testdata/test_folder/pack.mcmeta6
-rw-r--r--api/logic/testdata/test_folder/pack.nfo1
-rw-r--r--api/logic/updater/DownloadTask_test.cpp214
-rw-r--r--api/logic/updater/UpdateChecker_test.cpp146
-rw-r--r--api/logic/updater/testdata/1.json43
-rw-r--r--api/logic/updater/testdata/2.json31
-rw-r--r--api/logic/updater/testdata/channels.json23
-rw-r--r--api/logic/updater/testdata/errorChannels.json23
-rw-r--r--api/logic/updater/testdata/fileOneA1
-rw-r--r--api/logic/updater/testdata/fileOneB3
-rw-r--r--api/logic/updater/testdata/fileThree1
-rw-r--r--api/logic/updater/testdata/fileTwo1
-rw-r--r--api/logic/updater/testdata/garbageChannels.json22
-rw-r--r--api/logic/updater/testdata/index.json9
-rw-r--r--api/logic/updater/testdata/noChannels.json5
-rw-r--r--api/logic/updater/testdata/oneChannel.json11
-rw-r--r--api/logic/updater/testdata/tst_DownloadTask-test_writeInstallScript.xml17
-rw-r--r--api/logic/wonko/WonkoIndex_test.cpp50
37 files changed, 2568 insertions, 51 deletions
diff --git a/api/gui/CMakeLists.txt b/api/gui/CMakeLists.txt
index 1551a927..39cd5895 100644
--- a/api/gui/CMakeLists.txt
+++ b/api/gui/CMakeLists.txt
@@ -1,4 +1,4 @@
-project(MultiMC_logic)
+project(MultiMC_gui LANGUAGES CXX)
set(GUI_SOURCES
DesktopServices.h
diff --git a/api/logic/CMakeLists.txt b/api/logic/CMakeLists.txt
index abae7b90..b534f970 100644
--- a/api/logic/CMakeLists.txt
+++ b/api/logic/CMakeLists.txt
@@ -1,6 +1,8 @@
project(MultiMC_logic)
-set(LOGIC_SOURCES
+include (UnitTest)
+
+set(CORE_SOURCES
# LOGIC - Base classes and infrastructure
BaseInstaller.h
BaseInstaller.cpp
@@ -42,12 +44,6 @@ set(LOGIC_SOURCES
# a smart pointer wrapper intended for safer use with Qt signal/slot mechanisms
QObjectPtr.h
- # Path matchers
- pathmatcher/FSTreeMatcher.h
- pathmatcher/IPathMatcher.h
- pathmatcher/MultiMatcher.h
- pathmatcher/RegexpMatcher.h
-
# Compression support
GZip.h
GZip.cpp
@@ -60,6 +56,31 @@ set(LOGIC_SOURCES
Version.h
Version.cpp
+ # A Recursive file system watcher
+ RecursiveFileSystemWatcher.h
+ RecursiveFileSystemWatcher.cpp
+)
+
+add_unit_test(FileSystem
+ SOURCES FileSystem_test.cpp
+ LIBS MultiMC_logic
+ DATA testdata
+ )
+
+add_unit_test(GZip
+ SOURCES GZip_test.cpp
+ LIBS MultiMC_logic
+ )
+
+set(PATHMATCHER_SOURCES
+ # Path matchers
+ pathmatcher/FSTreeMatcher.h
+ pathmatcher/IPathMatcher.h
+ pathmatcher/MultiMatcher.h
+ pathmatcher/RegexpMatcher.h
+)
+
+set(NET_SOURCES
# network stuffs
net/NetAction.h
net/MD5EtagDownload.h
@@ -76,24 +97,10 @@ set(LOGIC_SOURCES
net/PasteUpload.cpp
net/URLConstants.h
net/URLConstants.cpp
+)
- # Yggdrasil login stuff
- minecraft/auth/AuthSession.h
- minecraft/auth/AuthSession.cpp
- minecraft/auth/MojangAccountList.h
- minecraft/auth/MojangAccountList.cpp
- minecraft/auth/MojangAccount.h
- minecraft/auth/MojangAccount.cpp
- minecraft/auth/YggdrasilTask.h
- minecraft/auth/YggdrasilTask.cpp
- minecraft/auth/flows/AuthenticateTask.h
- minecraft/auth/flows/AuthenticateTask.cpp
- minecraft/auth/flows/RefreshTask.cpp
- minecraft/auth/flows/RefreshTask.cpp
- minecraft/auth/flows/ValidateTask.h
- minecraft/auth/flows/ValidateTask.cpp
-
- # Game launch logic
+# Game launch logic
+set(LAUNCH_SOURCES
launch/steps/PostLaunchCommand.cpp
launch/steps/PostLaunchCommand.h
launch/steps/PreLaunchCommand.cpp
@@ -110,30 +117,70 @@ set(LOGIC_SOURCES
launch/LoggedProcess.h
launch/MessageLevel.cpp
launch/MessageLevel.h
+)
- # Update system
+# Old update system
+set(UPDATE_SOURCES
updater/GoUpdate.h
updater/GoUpdate.cpp
updater/UpdateChecker.h
updater/UpdateChecker.cpp
updater/DownloadTask.h
updater/DownloadTask.cpp
+)
+
+add_unit_test(UpdateChecker
+ SOURCES updater/UpdateChecker_test.cpp
+ LIBS MultiMC_logic
+ DATA updater/testdata
+ )
+
+add_unit_test(DownloadTask
+ SOURCES updater/DownloadTask_test.cpp
+ LIBS MultiMC_logic
+ DATA updater/testdata
+ )
+# Rarely used notifications
+set(NOTIFICATIONS_SOURCES
# Notifications - short warning messages
notifications/NotificationChecker.h
notifications/NotificationChecker.cpp
+)
+# Backend for the news bar... there's usually no news.
+set(NEWS_SOURCES
# News System
news/NewsChecker.h
news/NewsChecker.cpp
news/NewsEntry.h
news/NewsEntry.cpp
+)
+# Minecraft services status checker
+set(STATUS_SOURCES
# Status system
status/StatusChecker.h
status/StatusChecker.cpp
+)
+# Support for Minecraft instances and launch
+set(MINECRAFT_SOURCES
# Minecraft support
+ minecraft/auth/AuthSession.h
+ minecraft/auth/AuthSession.cpp
+ minecraft/auth/MojangAccountList.h
+ minecraft/auth/MojangAccountList.cpp
+ minecraft/auth/MojangAccount.h
+ minecraft/auth/MojangAccount.cpp
+ minecraft/auth/YggdrasilTask.h
+ minecraft/auth/YggdrasilTask.cpp
+ minecraft/auth/flows/AuthenticateTask.h
+ minecraft/auth/flows/AuthenticateTask.cpp
+ minecraft/auth/flows/RefreshTask.cpp
+ minecraft/auth/flows/RefreshTask.cpp
+ minecraft/auth/flows/ValidateTask.h
+ minecraft/auth/flows/ValidateTask.cpp
minecraft/onesix/OneSixUpdate.h
minecraft/onesix/OneSixUpdate.cpp
minecraft/onesix/OneSixInstance.h
@@ -201,17 +248,67 @@ set(LOGIC_SOURCES
minecraft/ftb/FTBPlugin.h
minecraft/ftb/FTBPlugin.cpp
- # A Recursive file system watcher
- RecursiveFileSystemWatcher.h
- RecursiveFileSystemWatcher.cpp
+ # Assets
+ minecraft/AssetsUtils.h
+ minecraft/AssetsUtils.cpp
- # the screenshots feature
+ # Forge and all things forge related
+ minecraft/forge/ForgeVersion.h
+ minecraft/forge/ForgeVersion.cpp
+ minecraft/forge/ForgeVersionList.h
+ minecraft/forge/ForgeVersionList.cpp
+ minecraft/forge/ForgeXzDownload.h
+ minecraft/forge/ForgeXzDownload.cpp
+ minecraft/forge/LegacyForge.h
+ minecraft/forge/LegacyForge.cpp
+ minecraft/forge/ForgeInstaller.h
+ minecraft/forge/ForgeInstaller.cpp
+
+ # Liteloader and related things
+ minecraft/liteloader/LiteLoaderInstaller.h
+ minecraft/liteloader/LiteLoaderInstaller.cpp
+ minecraft/liteloader/LiteLoaderVersionList.h
+ minecraft/liteloader/LiteLoaderVersionList.cpp
+)
+
+add_unit_test(GradleSpecifier
+ SOURCES minecraft/GradleSpecifier_test.cpp
+ LIBS MultiMC_logic
+ )
+
+add_unit_test(MojangVersionFormat
+ SOURCES minecraft/MojangVersionFormat_test.cpp
+ LIBS MultiMC_logic
+ DATA minecraft/testdata
+ )
+
+add_unit_test(Library
+ SOURCES minecraft/Library_test.cpp
+ LIBS MultiMC_logic
+ )
+
+# FIXME: shares data with FileSystem test
+add_unit_test(ModList
+ SOURCES minecraft/ModList_test.cpp
+ DATA testdata
+ LIBS MultiMC_logic
+ )
+
+add_unit_test(ParseUtils
+ SOURCES minecraft/ParseUtils_test.cpp
+ LIBS MultiMC_logic
+ )
+
+# the screenshots feature
+set(SCREENSHOTS_SOURCES
screenshots/Screenshot.h
screenshots/ImgurUpload.h
screenshots/ImgurUpload.cpp
screenshots/ImgurAlbumCreation.h
screenshots/ImgurAlbumCreation.cpp
+)
+set(TASKS_SOURCES
# Tasks
tasks/Task.h
tasks/Task.cpp
@@ -219,7 +316,9 @@ set(LOGIC_SOURCES
tasks/ThreadTask.cpp
tasks/SequentialTask.h
tasks/SequentialTask.cpp
+)
+set(SETTINGS_SOURCES
# Settings
settings/INIFile.cpp
settings/INIFile.h
@@ -233,7 +332,14 @@ set(LOGIC_SOURCES
settings/Setting.h
settings/SettingsObject.cpp
settings/SettingsObject.h
+)
+
+add_unit_test(INIFile
+ SOURCES settings/INIFile_test.cpp
+ LIBS MultiMC_logic
+ )
+set(JAVA_SOURCES
# Java related code
java/launch/CheckJava.cpp
java/launch/CheckJava.h
@@ -249,33 +355,20 @@ set(LOGIC_SOURCES
java/JavaUtils.cpp
java/JavaVersion.h
java/JavaVersion.cpp
+)
- # Assets
- minecraft/AssetsUtils.h
- minecraft/AssetsUtils.cpp
-
- # Forge and all things forge related
- minecraft/forge/ForgeVersion.h
- minecraft/forge/ForgeVersion.cpp
- minecraft/forge/ForgeVersionList.h
- minecraft/forge/ForgeVersionList.cpp
- minecraft/forge/ForgeXzDownload.h
- minecraft/forge/ForgeXzDownload.cpp
- minecraft/forge/LegacyForge.h
- minecraft/forge/LegacyForge.cpp
- minecraft/forge/ForgeInstaller.h
- minecraft/forge/ForgeInstaller.cpp
-
- # Liteloader and related things
- minecraft/liteloader/LiteLoaderInstaller.h
- minecraft/liteloader/LiteLoaderInstaller.cpp
- minecraft/liteloader/LiteLoaderVersionList.h
- minecraft/liteloader/LiteLoaderVersionList.cpp
+add_unit_test(JavaVersion
+ SOURCES java/JavaVersion_test.cpp
+ LIBS MultiMC_logic
+ )
+set(TRANSLATIONS_SOURCES
# Translations
trans/TranslationDownloader.h
trans/TranslationDownloader.cpp
+)
+set(TOOLS_SOURCES
# Tools
tools/BaseExternalTool.cpp
tools/BaseExternalTool.h
@@ -287,7 +380,9 @@ set(LOGIC_SOURCES
tools/JVisualVM.h
tools/MCEditTool.cpp
tools/MCEditTool.h
+)
+set(WONKO_SOURCES
# Wonko
wonko/tasks/BaseWonkoEntityRemoteLoadTask.cpp
wonko/tasks/BaseWonkoEntityRemoteLoadTask.h
@@ -310,11 +405,36 @@ set(LOGIC_SOURCES
wonko/WonkoReference.cpp
wonko/WonkoReference.h
)
+
+add_unit_test(WonkoIndex
+ SOURCES wonko/WonkoIndex_test.cpp
+ LIBS MultiMC_logic
+ )
+
################################ COMPILE ################################
# we need zlib
find_package(ZLIB REQUIRED)
+set(LOGIC_SOURCES
+ ${CORE_SOURCES}
+ ${PATHMATCHER_SOURCES}
+ ${NET_SOURCES}
+ ${LAUNCH_SOURCES}
+ ${UPDATE_SOURCES}
+ ${NOTIFICATIONS_SOURCES}
+ ${NEWS_SOURCES}
+ ${STATUS_SOURCES}
+ ${MINECRAFT_SOURCES}
+ ${SCREENSHOTS_SOURCES}
+ ${TASKS_SOURCES}
+ ${SETTINGS_SOURCES}
+ ${JAVA_SOURCES}
+ ${TRANSLATIONS_SOURCES}
+ ${TOOLS_SOURCES}
+ ${WONKO_SOURCES}
+)
+
add_library(MultiMC_logic SHARED ${LOGIC_SOURCES})
set_target_properties(MultiMC_logic PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN 1)
diff --git a/api/logic/FileSystem_test.cpp b/api/logic/FileSystem_test.cpp
new file mode 100644
index 00000000..d5e1eedb
--- /dev/null
+++ b/api/logic/FileSystem_test.cpp
@@ -0,0 +1,164 @@
+#include <QTest>
+#include <QTemporaryDir>
+#include <QStandardPaths>
+#include "TestUtil.h"
+
+#include "FileSystem.h"
+
+class FileSystemTest : public QObject
+{
+ Q_OBJECT
+
+ const QString bothSlash = "/foo/";
+ const QString trailingSlash = "foo/";
+ const QString leadingSlash = "/foo";
+
+private
+slots:
+ void test_pathCombine()
+ {
+ QCOMPARE(QString("/foo/foo"), FS::PathCombine(bothSlash, bothSlash));
+ QCOMPARE(QString("foo/foo"), FS::PathCombine(trailingSlash, trailingSlash));
+ QCOMPARE(QString("/foo/foo"), FS::PathCombine(leadingSlash, leadingSlash));
+
+ QCOMPARE(QString("/foo/foo/foo"), FS::PathCombine(bothSlash, bothSlash, bothSlash));
+ QCOMPARE(QString("foo/foo/foo"), FS::PathCombine(trailingSlash, trailingSlash, trailingSlash));
+ QCOMPARE(QString("/foo/foo/foo"), FS::PathCombine(leadingSlash, leadingSlash, leadingSlash));
+ }
+
+ void test_PathCombine1_data()
+ {
+ QTest::addColumn<QString>("result");
+ QTest::addColumn<QString>("path1");
+ QTest::addColumn<QString>("path2");
+
+ QTest::newRow("qt 1") << "/abc/def/ghi/jkl" << "/abc/def" << "ghi/jkl";
+ QTest::newRow("qt 2") << "/abc/def/ghi/jkl" << "/abc/def/" << "ghi/jkl";
+#if defined(Q_OS_WIN)
+ QTest::newRow("win native, from C:") << "C:/abc" << "C:" << "abc";
+ QTest::newRow("win native 1") << "C:/abc/def/ghi/jkl" << "C:\\abc\\def" << "ghi\\jkl";
+ QTest::newRow("win native 2") << "C:/abc/def/ghi/jkl" << "C:\\abc\\def\\" << "ghi\\jkl";
+#endif
+ }
+
+ void test_PathCombine1()
+ {
+ QFETCH(QString, result);
+ QFETCH(QString, path1);
+ QFETCH(QString, path2);
+
+ QCOMPARE(FS::PathCombine(path1, path2), result);
+ }
+
+ void test_PathCombine2_data()
+ {
+ QTest::addColumn<QString>("result");
+ QTest::addColumn<QString>("path1");
+ QTest::addColumn<QString>("path2");
+ QTest::addColumn<QString>("path3");
+
+ QTest::newRow("qt 1") << "/abc/def/ghi/jkl" << "/abc" << "def" << "ghi/jkl";
+ QTest::newRow("qt 2") << "/abc/def/ghi/jkl" << "/abc/" << "def" << "ghi/jkl";
+ QTest::newRow("qt 3") << "/abc/def/ghi/jkl" << "/abc" << "def/" << "ghi/jkl";
+ QTest::newRow("qt 4") << "/abc/def/ghi/jkl" << "/abc/" << "def/" << "ghi/jkl";
+#if defined(Q_OS_WIN)
+ QTest::newRow("win 1") << "C:/abc/def/ghi/jkl" << "C:\\abc" << "def" << "ghi\\jkl";
+ QTest::newRow("win 2") << "C:/abc/def/ghi/jkl" << "C:\\abc\\" << "def" << "ghi\\jkl";
+ QTest::newRow("win 3") << "C:/abc/def/ghi/jkl" << "C:\\abc" << "def\\" << "ghi\\jkl";
+ QTest::newRow("win 4") << "C:/abc/def/ghi/jkl" << "C:\\abc\\" << "def" << "ghi\\jkl";
+#endif
+ }
+
+ void test_PathCombine2()
+ {
+ QFETCH(QString, result);
+ QFETCH(QString, path1);
+ QFETCH(QString, path2);
+ QFETCH(QString, path3);
+
+ QCOMPARE(FS::PathCombine(path1, path2, path3), result);
+ }
+
+ void test_copy()
+ {
+ QString folder = QFINDTESTDATA("data/test_folder");
+ auto f = [&folder]()
+ {
+ QTemporaryDir tempDir;
+ tempDir.setAutoRemove(true);
+ qDebug() << "From:" << folder << "To:" << tempDir.path();
+
+ QDir target_dir(FS::PathCombine(tempDir.path(), "test_folder"));
+ qDebug() << tempDir.path();
+ qDebug() << target_dir.path();
+ FS::copy c(folder, target_dir.path());
+ c();
+
+ for(auto entry: target_dir.entryList())
+ {
+ qDebug() << entry;
+ }
+ QVERIFY(target_dir.entryList().contains("pack.mcmeta"));
+ QVERIFY(target_dir.entryList().contains("assets"));
+ };
+
+ // first try variant without trailing /
+ QVERIFY(!folder.endsWith('/'));
+ f();
+
+ // then variant with trailing /
+ folder.append('/');
+ QVERIFY(folder.endsWith('/'));
+ f();
+ }
+
+ void test_getDesktop()
+ {
+ QCOMPARE(FS::getDesktopDir(), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation));
+ }
+
+// this is only valid on linux
+// FIXME: implement on windows, OSX, then test.
+#if defined(Q_OS_LINUX)
+ void test_createShortcut_data()
+ {
+ QTest::addColumn<QString>("location");
+ QTest::addColumn<QString>("dest");
+ QTest::addColumn<QStringList>("args");
+ QTest::addColumn<QString>("name");
+ QTest::addColumn<QString>("iconLocation");
+ QTest::addColumn<QByteArray>("result");
+
+ QTest::newRow("unix") << QDir::currentPath()
+ << "asdfDest"
+ << (QStringList() << "arg1" << "arg2")
+ << "asdf"
+ << QString()
+ #if defined(Q_OS_LINUX)
+ << MULTIMC_GET_TEST_FILE("data/FileSystem-test_createShortcut-unix")
+ #elif defined(Q_OS_WIN)
+ << QByteArray()
+ #endif
+ ;
+ }
+
+ void test_createShortcut()
+ {
+ QFETCH(QString, location);
+ QFETCH(QString, dest);
+ QFETCH(QStringList, args);
+ QFETCH(QString, name);
+ QFETCH(QString, iconLocation);
+ QFETCH(QByteArray, result);
+
+ QVERIFY(FS::createShortCut(location, dest, args, name, iconLocation));
+ QCOMPARE(QString::fromLocal8Bit(TestsInternal::readFile(location + QDir::separator() + name + ".desktop")), QString::fromLocal8Bit(result));
+
+ //QDir().remove(location);
+ }
+#endif
+};
+
+QTEST_GUILESS_MAIN(FileSystemTest)
+
+#include "FileSystem_test.moc"
diff --git a/api/logic/GZip_test.cpp b/api/logic/GZip_test.cpp
new file mode 100644
index 00000000..f4c9214c
--- /dev/null
+++ b/api/logic/GZip_test.cpp
@@ -0,0 +1,57 @@
+#include <QTest>
+#include "TestUtil.h"
+
+#include "GZip.h"
+#include <random>
+
+void fib(int &prev, int &cur)
+{
+ auto ret = prev + cur;
+ prev = cur;
+ cur = ret;
+}
+
+class GZipTest : public QObject
+{
+ Q_OBJECT
+private
+slots:
+
+ void test_Through()
+ {
+ // test up to 10 MB
+ static const int size = 10 * 1024 * 1024;
+ QByteArray random;
+ QByteArray compressed;
+ QByteArray decompressed;
+ std::default_random_engine eng((std::random_device())());
+ std::uniform_int_distribution<uint8_t> idis(0, std::numeric_limits<uint8_t>::max());
+
+ // initialize random buffer
+ for(int i = 0; i < size; i++)
+ {
+ random.append((char)idis(eng));
+ }
+
+ // initialize fibonacci
+ int prev = 1;
+ int cur = 1;
+
+ // test if fibonacci long random buffers pass through GZip
+ do
+ {
+ QByteArray copy = random;
+ copy.resize(cur);
+ compressed.clear();
+ decompressed.clear();
+ QVERIFY(GZip::zip(copy, compressed));
+ QVERIFY(GZip::unzip(compressed, decompressed));
+ QCOMPARE(decompressed, copy);
+ fib(prev, cur);
+ } while (cur < size);
+ }
+};
+
+QTEST_GUILESS_MAIN(GZipTest)
+
+#include "GZip_test.moc"
diff --git a/api/logic/Version_test.cpp b/api/logic/Version_test.cpp
new file mode 100644
index 00000000..4c083934
--- /dev/null
+++ b/api/logic/Version_test.cpp
@@ -0,0 +1,123 @@
+/* Copyright 2013-2015 MultiMC Contributors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <QTest>
+
+#include "TestUtil.h"
+#include <Version.h>
+
+class ModUtilsTest : public QObject
+{
+ Q_OBJECT
+ void setupVersions()
+ {
+ QTest::addColumn<QString>("first");
+ QTest::addColumn<QString>("second");
+ QTest::addColumn<bool>("lessThan");
+ QTest::addColumn<bool>("equal");
+
+ QTest::newRow("equal, explicit") << "1.2.0" << "1.2.0" << false << true;
+ QTest::newRow("equal, implicit 1") << "1.2" << "1.2.0" << false << true;
+ QTest::newRow("equal, implicit 2") << "1.2.0" << "1.2" << false << true;
+ QTest::newRow("equal, two-digit") << "1.42" << "1.42" << false << true;
+
+ QTest::newRow("lessThan, explicit 1") << "1.2.0" << "1.2.1" << true << false;
+ QTest::newRow("lessThan, explicit 2") << "1.2.0" << "1.3.0" << true << false;
+ QTest::newRow("lessThan, explicit 3") << "1.2.0" << "2.2.0" << true << false;
+ QTest::newRow("lessThan, implicit 1") << "1.2" << "1.2.1" << true << false;
+ QTest::newRow("lessThan, implicit 2") << "1.2" << "1.3.0" << true << false;
+ QTest::newRow("lessThan, implicit 3") << "1.2" << "2.2.0" << true << false;
+ QTest::newRow("lessThan, two-digit") << "1.41" << "1.42" << true << false;
+
+ QTest::newRow("greaterThan, explicit 1") << "1.2.1" << "1.2.0" << false << false;
+ QTest::newRow("greaterThan, explicit 2") << "1.3.0" << "1.2.0" << false << false;
+ QTest::newRow("greaterThan, explicit 3") << "2.2.0" << "1.2.0" << false << false;
+ QTest::newRow("greaterThan, implicit 1") << "1.2.1" << "1.2" << false << false;
+ QTest::newRow("greaterThan, implicit 2") << "1.3.0" << "1.2" << false << false;
+ QTest::newRow("greaterThan, implicit 3") << "2.2.0" << "1.2" << false << false;
+ QTest::newRow("greaterThan, two-digit") << "1.42" << "1.41" << false << false;
+ }
+
+private slots:
+ void initTestCase()
+ {
+
+ }
+ void cleanupTestCase()
+ {
+
+ }
+
+ void test_versionIsInInterval_data()
+ {
+ QTest::addColumn<QString>("version");
+ QTest::addColumn<QString>("interval");
+ QTest::addColumn<bool>("result");
+
+ QTest::newRow("empty, true") << "1.2.3" << "" << true;
+ QTest::newRow("one version, true") << "1.2.3" << "1.2.3" << true;
+ QTest::newRow("one version, false") << "1.2.3" << "1.2.2" << false;
+
+ QTest::newRow("one version inclusive <-> infinity, true") << "1.2.3" << "[1.2.3,)" << true;
+ QTest::newRow("one version exclusive <-> infinity, true") << "1.2.3" << "(1.2.2,)" << true;
+ QTest::newRow("one version inclusive <-> infitity, false") << "1.2.3" << "[1.2.4,)" << false;
+ QTest::newRow("one version exclusive <-> infinity, false") << "1.2.3" << "(1.2.3,)" << false;
+
+ QTest::newRow("infinity <-> one version inclusive, true") << "1.2.3" << "(,1.2.3]" << true;
+ QTest::newRow("infinity <-> one version exclusive, true") << "1.2.3" << "(,1.2.4)" << true;
+ QTest::newRow("infinity <-> one version inclusive, false") << "1.2.3" << "(,1.2.2]" << false;
+ QTest::newRow("infinity <-> one version exclusive, false") << "1.2.3" << "(,1.2.3)" << false;
+
+ QTest::newRow("inclusive <-> inclusive, true") << "1.2.3" << "[1.2.2,1.2.3]" << true;
+ QTest::newRow("inclusive <-> exclusive, true") << "1.2.3" << "[1.2.3,1.2.4)" << true;
+ QTest::newRow("exclusive <-> inclusive, true") << "1.2.3" << "(1.2.2,1.2.3]" << true;
+ QTest::newRow("exclusive <-> exclusive, true") << "1.2.3" << "(1.2.2,1.2.4)" << true;
+ QTest::newRow("inclusive <-> inclusive, false") << "1.2.3" << "[1.0.0,1.2.2]" << false;
+ QTest::newRow("inclusive <-> exclusive, false") << "1.2.3" << "[1.0.0,1.2.3)" << false;
+ QTest::newRow("exclusive <-> inclusive, false") << "1.2.3" << "(1.2.3,2.0.0]" << false;
+ QTest::newRow("exclusive <-> exclusive, false") << "1.2.3" << "(1.0.0,1.2.3)" << false;
+ }
+ void test_versionIsInInterval()
+ {
+ QFETCH(QString, version);
+ QFETCH(QString, interval);
+ QFETCH(bool, result);
+
+ QCOMPARE(versionIsInInterval(version, interval), result);
+ }
+
+ void test_versionCompare_data()
+ {
+ setupVersions();
+ }
+ void test_versionCompare()
+ {
+ QFETCH(QString, first);
+ QFETCH(QString, second);
+ QFETCH(bool, lessThan);
+ QFETCH(bool, equal);
+
+ const auto v1 = Version(first);
+ const auto v2 = Version(second);
+
+ QCOMPARE(v1 < v2, lessThan);
+ QCOMPARE(v1 > v2, !lessThan && !equal);
+ QCOMPARE(v1 == v2, equal);
+ }
+};
+
+QTEST_GUILESS_MAIN(ModUtilsTest)
+
+#include "Version_test.moc"
diff --git a/api/logic/java/JavaVersion_test.cpp b/api/logic/java/JavaVersion_test.cpp
new file mode 100644
index 00000000..9dae0ba6
--- /dev/null
+++ b/api/logic/java/JavaVersion_test.cpp
@@ -0,0 +1,116 @@
+#include <QTest>
+#include "TestUtil.h"
+
+#include "java/JavaVersion.h"
+
+class JavaVersionTest : public QObject
+{
+ Q_OBJECT
+private
+slots:
+ void test_Parse_data()
+ {
+ QTest::addColumn<QString>("string");
+ QTest::addColumn<int>("major");
+ QTest::addColumn<int>("minor");
+ QTest::addColumn<int>("security");
+ QTest::addColumn<QString>("prerelease");
+
+ QTest::newRow("old format") << "1.6.0_33" << 6 << 0 << 33 << QString();
+ QTest::newRow("old format prerelease") << "1.9.0_1-ea" << 9 << 0 << 1 << "ea";
+
+ QTest::newRow("new format major") << "9" << 9 << 0 << 0 << QString();
+ QTest::newRow("new format minor") << "9.1" << 9 << 1 << 0 << QString();
+ QTest::newRow("new format security") << "9.0.1" << 9 << 0 << 1 << QString();
+ QTest::newRow("new format prerelease") << "9-ea" << 9 << 0 << 0 << "ea";
+ QTest::newRow("new format long prerelease") << "9.0.1-ea" << 9 << 0 << 1 << "ea";
+ }
+ void test_Parse()
+ {
+ QFETCH(QString, string);
+ QFETCH(int, major);
+ QFETCH(int, minor);
+ QFETCH(int, security);
+ QFETCH(QString, prerelease);
+
+ JavaVersion test(string);
+ QCOMPARE(test.string, string);
+ QCOMPARE(test.toString(), string);
+ QCOMPARE(test.major, major);
+ QCOMPARE(test.minor, minor);
+ QCOMPARE(test.security, security);
+ QCOMPARE(test.prerelease, prerelease);
+ }
+
+ void test_Sort_data()
+ {
+ QTest::addColumn<QString>("lhs");
+ QTest::addColumn<QString>("rhs");
+ QTest::addColumn<bool>("smaller");
+ QTest::addColumn<bool>("equal");
+ QTest::addColumn<bool>("bigger");
+
+ // old format and new format equivalence
+ QTest::newRow("1.6.0_33 == 6.0.33") << "1.6.0_33" << "6.0.33" << false << true << false;
+ // old format major version
+ QTest::newRow("1.5.0_33 < 1.6.0_33") << "1.5.0_33" << "1.6.0_33" << true << false << false;
+ // new format - first release vs first security patch
+ QTest::newRow("9 < 9.0.1") << "9" << "9.0.1" << true << false << false;
+ QTest::newRow("9.0.1 > 9") << "9.0.1" << "9" << false << false << true;
+ // new format - first minor vs first release/security patch
+ QTest::newRow("9.1 > 9.0.1") << "9.1" << "9.0.1" &l