This commit is contained in:
Igor Malinovskiy
2022-02-18 12:31:07 +02:00
parent dd5a5b86e8
commit 3c2ed75718
7 changed files with 31 additions and 29 deletions
-24
View File
@@ -1,24 +0,0 @@
#include "apputils.h"
#include <QStringList>
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;
}
+4 -1
View File
@@ -1,4 +1,7 @@
#pragma once
#include <QString>
#include <QLocale>
QString humanReadableSize(long size);
inline QString humanReadableSize(qint64 size) {
return QLocale().formattedDataSize(size, 2, QLocale::DataSizeSIFormat);
}
+1 -2
View File
@@ -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 \
+2
View File
@@ -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)
+1 -2
View File
@@ -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 \
@@ -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");
}
@@ -0,0 +1,12 @@
#pragma once
#include "respbasetestcase.h"
class TestAppUtils : public RESPBaseTestCase
{
Q_OBJECT
private slots:
void testHumanReadableSize();
};