Skip to content

Commit

Permalink
Utility: Fix the storage string to display terabytes.
Browse files Browse the repository at this point in the history
Signed-off-by: Camila <[email protected]>
  • Loading branch information
Camila authored and backportbot-nextcloud[bot] committed Jan 19, 2024
1 parent 872e0b4 commit 58461bc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/common/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ QString Utility::octetsToString(qint64 octets)
static const qint64 kb = THE_FACTOR;
static const qint64 mb = THE_FACTOR * kb;
static const qint64 gb = THE_FACTOR * mb;
static const qint64 tb = THE_FACTOR * gb;

QString s;
qreal value = octets;
Expand All @@ -128,11 +129,10 @@ QString Utility::octetsToString(qint64 octets)
// if it's less than 10 units.
bool round = true;

// do not display terra byte with the current units, as when
// the MB, GB and KB units were made, there was no TB,
// see the JEDEC standard
// https://en.wikipedia.org/wiki/JEDEC_memory_standards
if (octets >= gb) {
if (octets >= tb) {
s = QCoreApplication::translate("Utility", "%L1 TB");
value /= tb;
} else if (octets >= gb) {
s = QCoreApplication::translate("Utility", "%L1 GB");
value /= gb;
round = false;
Expand Down
4 changes: 4 additions & 0 deletions test/testutility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ private slots:
QLocale::setDefault(QLocale("en"));
QCOMPARE(octetsToString(999) , QString("999 B"));
QCOMPARE(octetsToString(1024) , QString("1 KB"));
QCOMPARE(octetsToString(1110) , QString("1 KB"));
QCOMPARE(octetsToString(1364) , QString("1 KB"));

QCOMPARE(octetsToString(9110) , QString("9 KB"));
QCOMPARE(octetsToString(9910) , QString("10 KB"));
QCOMPARE(octetsToString(9999) , QString("10 KB"));
QCOMPARE(octetsToString(10240) , QString("10 KB"));

QCOMPARE(octetsToString(123456) , QString("121 KB"));
Expand All @@ -54,6 +56,8 @@ private slots:
QCOMPARE(octetsToString(1024), QString("1 KB"));
QCOMPARE(octetsToString(1024*1024), QString("1 MB"));
QCOMPARE(octetsToString(1024LL*1024*1024), QString("1 GB"));
QCOMPARE(octetsToString(1024LL*1024*1024*1024), QString("1 TB"));
QCOMPARE(octetsToString(1024LL*1024*1024*1024 * 5), QString("5 TB"));
}

void testLaunchOnStartup()
Expand Down

0 comments on commit 58461bc

Please sign in to comment.