mirror of
https://github.com/redis/RedisDesktopManager.git
synced 2026-10-17 04:31:27 +08:00
Fix #5129
This commit is contained in:
@@ -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
@@ -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
@@ -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 \
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user