Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Adam <dev@robert-adam.de>2022-09-06 20:58:22 +0300
committerRobert Adam <dev@robert-adam.de>2022-09-09 20:05:23 +0300
commitd14e9c4307004a31bb8b47332215c6a277026879 (patch)
treeaf7ba4f11a5681be797063307409371bd0b963b7
parent79a20243c377b5a418694cb36e6d31bf5877adb2 (diff)
TEST: Add test-cases for new Version impl
-rw-r--r--src/tests/CMakeLists.txt1
-rw-r--r--src/tests/TestVersion/CMakeLists.txt12
-rw-r--r--src/tests/TestVersion/TestVersion.cpp86
3 files changed, 99 insertions, 0 deletions
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 10cd9a069..11b5ff793 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -34,6 +34,7 @@ use_test("TestSSLLocks")
use_test("TestStdAbs")
use_test("TestTimer")
use_test("TestUnresolvedServerAddress")
+use_test("TestVersion")
if(online-tests)
message(STATUS "Including online tests - These will fail if you don't have a working internet connection when running them")
diff --git a/src/tests/TestVersion/CMakeLists.txt b/src/tests/TestVersion/CMakeLists.txt
new file mode 100644
index 000000000..7739a68bd
--- /dev/null
+++ b/src/tests/TestVersion/CMakeLists.txt
@@ -0,0 +1,12 @@
+# Copyright 2022 The Mumble Developers. All rights reserved.
+# Use of this source code is governed by a BSD-style license
+# that can be found in the LICENSE file at the root of the
+# Mumble source tree or at <https://www.mumble.info/LICENSE>.
+
+add_executable(TestVersion TestVersion.cpp)
+
+set_target_properties(TestVersion PROPERTIES AUTOMOC ON)
+
+target_link_libraries(TestVersion PRIVATE shared Qt5::Test)
+
+add_test(NAME TestVersion COMMAND $<TARGET_FILE:TestVersion>)
diff --git a/src/tests/TestVersion/TestVersion.cpp b/src/tests/TestVersion/TestVersion.cpp
new file mode 100644
index 000000000..92d8ab67d
--- /dev/null
+++ b/src/tests/TestVersion/TestVersion.cpp
@@ -0,0 +1,86 @@
+// Copyright 2022 The Mumble Developers. All rights reserved.
+// Use of this source code is governed by a BSD-style license
+// that can be found in the LICENSE file at the root of the
+// Mumble source tree or at <https://www.mumble.info/LICENSE>.
+
+#include "Version.h"
+
+#include <QObject>
+#include <QTest>
+
+#include <limits>
+
+class TestVersion : public QObject {
+ Q_OBJECT;
+private slots:
+
+ void legacy_encode() {
+ QCOMPARE(Version::toLegacyVersion(Version::fromComponents(1, 3, 5)), static_cast< std::uint32_t >(0x010305));
+ }
+
+ void legacy_decode() { QCOMPARE(Version::fromLegacyVersion(0x010305), Version::fromComponents(1, 3, 5)); }
+
+ void legacy_consistency() {
+ QCOMPARE(Version::fromLegacyVersion(Version::toLegacyVersion(Version::fromComponents(1, 3, 5))),
+ Version::fromComponents(1, 3, 5));
+ }
+
+ void general_getMajor() {
+ QCOMPARE(Version::getMajor(Version::fromComponents(1, 3, 5)), static_cast< Version::component_t >(1));
+ }
+
+ void general_getMinor() {
+ QCOMPARE(Version::getMinor(Version::fromComponents(1, 3, 5)), static_cast< Version::component_t >(3));
+ }
+
+ void general_getPatch() {
+ QCOMPARE(Version::getPatch(Version::fromComponents(1, 3, 5)), static_cast< Version::component_t >(5));
+ }
+
+ void v2_encode() { QCOMPARE(Version::fromComponents(1, 3, 5), static_cast< Version::full_t >(0x0001000300050000)); }
+
+ void v2_decode() {
+ Version::component_t major = 0, minor = 0, patch = 0;
+
+ Version::getComponents(major, minor, patch);
+ QCOMPARE(major, static_cast< Version::component_t >(MUMBLE_VERSION_MAJOR));
+ QCOMPARE(minor, static_cast< Version::component_t >(MUMBLE_VERSION_MINOR));
+ QCOMPARE(patch, static_cast< Version::component_t >(MUMBLE_VERSION_PATCH));
+
+ Version::getComponents(major, minor, patch, "2.8.42");
+ QCOMPARE(major, static_cast< Version::component_t >(2));
+ QCOMPARE(minor, static_cast< Version::component_t >(8));
+ QCOMPARE(patch, static_cast< Version::component_t >(42));
+ }
+
+ void v2_limits() {
+ Version::component_t major, minor, patch;
+ major = minor = patch = std::numeric_limits< Version::component_t >::max();
+
+ Version::full_t version = Version::fromComponents(major, minor, patch);
+
+ QCOMPARE(Version::getMajor(version), major);
+ QCOMPARE(Version::getMinor(version), minor);
+ QCOMPARE(Version::getPatch(version), patch);
+ }
+
+ void config_decoding() {
+ // Version may be given as a string (probably most common)
+ Version::full_t version = Version::fromConfig("1.8.266");
+
+ QCOMPARE(version, Version::fromComponents(1, 8, 266));
+
+ // Or as an integer (v2-encoded)
+ version = Version::fromConfig(static_cast< qulonglong >(Version::fromComponents(2, 18, 42)));
+
+ QCOMPARE(version, Version::fromComponents(2, 18, 42));
+
+ // Or as an integer (v1-encoded)
+ version = Version::fromConfig(Version::toLegacyVersion(Version::fromComponents(2, 18, 42)));
+
+ QCOMPARE(version, Version::fromComponents(2, 18, 42));
+ }
+};
+
+QTEST_MAIN(TestVersion)
+#include "TestVersion.moc"