diff --git a/src/app/apputils.cpp b/src/app/apputils.cpp deleted file mode 100644 index 8561647c..00000000 --- a/src/app/apputils.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "apputils.h" -#include - -QString humanReadableSize(long size) { - double num = size; - QStringList list; - list << "KB" - << "MB" - << "GB"; - - QStringListIterator i(list); - QString unit("bytes"); - - if (size < 1024) { - return QString().setNum(num) + " " + unit; - } - - while (num >= 1024.0 && i.hasNext()) { - unit = i.next(); - num /= 1024.0; - } - - return QString().setNum(num, 'f', 2) + " " + unit; -} diff --git a/src/app/apputils.h b/src/app/apputils.h index 454cd015..5618ff0d 100644 --- a/src/app/apputils.h +++ b/src/app/apputils.h @@ -1,4 +1,7 @@ #pragma once #include +#include -QString humanReadableSize(long size); +inline QString humanReadableSize(qint64 size) { + return QLocale().formattedDataSize(size, 2, QLocale::DataSizeSIFormat); +} diff --git a/src/resp.pro b/src/resp.pro index 0b264115..f69e86a3 100644 --- a/src/resp.pro +++ b/src/resp.pro @@ -24,8 +24,7 @@ DEFINES += APP_VERSION=\\\"$$VERSION\\\" SOURCES += \ $$PWD/main.cpp \ - $$PWD/app/app.cpp \ - $$PWD/app/apputils.cpp \ + $$PWD/app/app.cpp \ $$PWD/app/events.cpp \ $$PWD/app/qmlutils.cpp \ $$PWD/app/jsonutils.cpp \ diff --git a/tests/unit_tests/main.cpp b/tests/unit_tests/main.cpp index 2855e8d6..382da9dd 100644 --- a/tests/unit_tests/main.cpp +++ b/tests/unit_tests/main.cpp @@ -8,6 +8,7 @@ #include "testcases/app/test_connectionsmanager.h" #include "testcases/app/test_keymodels.h" #include "testcases/app/test_treeoperations.h" +#include "testcases/app/test_apputils.h" #include "testcases/connections-tree/test_databaseitem.h" #include "testcases/connections-tree/test_model.h" #include "testcases/connections-tree/test_serveritem.h" @@ -34,6 +35,7 @@ int main(int argc, char *argv[]) { + QTest::qExec(new TestConfigManager, argc, argv) + QTest::qExec(new TestKeyModels, argc, argv) + QTest::qExec(new TestTreeOperations, argc, argv) + + QTest::qExec(new TestAppUtils, argc, argv) ; if (allTestsResult == 0) diff --git a/tests/unit_tests/testcases/app/app-tests.pri b/tests/unit_tests/testcases/app/app-tests.pri index 216a1e04..df8d6a00 100644 --- a/tests/unit_tests/testcases/app/app-tests.pri +++ b/tests/unit_tests/testcases/app/app-tests.pri @@ -27,8 +27,7 @@ HEADERS += \ SOURCES += \ $$files($$PWD/test_*.cpp) \ - $$APP_SRC_DIR/events.cpp \ - $$APP_SRC_DIR/apputils.cpp \ + $$APP_SRC_DIR/events.cpp \ $$APP_SRC_DIR/jsonutils.cpp \ $$APP_SRC_DIR/models/connectionsmanager.cpp \ $$APP_SRC_DIR/models/configmanager.cpp \ diff --git a/tests/unit_tests/testcases/app/test_apputils.cpp b/tests/unit_tests/testcases/app/test_apputils.cpp new file mode 100644 index 00000000..f9b75d01 --- /dev/null +++ b/tests/unit_tests/testcases/app/test_apputils.cpp @@ -0,0 +1,11 @@ +#include "test_apputils.h" + +#include "app/apputils.h" + +void TestAppUtils::testHumanReadableSize() { + long long size = 3000000000; + + QString result = humanReadableSize(size); + + QCOMPARE(result, "3.00 GB"); +} diff --git a/tests/unit_tests/testcases/app/test_apputils.h b/tests/unit_tests/testcases/app/test_apputils.h new file mode 100644 index 00000000..31ec78d1 --- /dev/null +++ b/tests/unit_tests/testcases/app/test_apputils.h @@ -0,0 +1,12 @@ +#pragma once + +#include "respbasetestcase.h" + +class TestAppUtils : public RESPBaseTestCase +{ + Q_OBJECT + +private slots: + void testHumanReadableSize(); +}; +