From 0e8895ed119c49db747a3c0c39de4257db07f4ac Mon Sep 17 00:00:00 2001 From: Camila Date: Mon, 11 Dec 2023 18:29:33 +0100 Subject: [PATCH] Utility: Fix the storage string to display terabytes. Signed-off-by: Camila --- src/common/utility.cpp | 10 +++++----- test/testutility.cpp | 4 ++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/common/utility.cpp b/src/common/utility.cpp index 607bb0414ec7c..bc2681ecd6c58 100644 --- a/src/common/utility.cpp +++ b/src/common/utility.cpp @@ -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; @@ -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; diff --git a/test/testutility.cpp b/test/testutility.cpp index 67030d7384a11..89b54f5d607fe 100644 --- a/test/testutility.cpp +++ b/test/testutility.cpp @@ -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")); @@ -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()