Utility: Fix the size display back to JEDEC standard.
authorKlaas Freitag <freitag@owncloud.com>
Thu, 10 Sep 2015 15:31:44 +0000 (17:31 +0200)
committerKlaas Freitag <freitag@owncloud.com>
Thu, 10 Sep 2015 15:36:28 +0000 (17:36 +0200)
Also updated the test.

src/libsync/utility.cpp
test/testutility.h

index 98dc63d41765d4ac6175d823c7dcafdffc890bfc..459889817d296ced5b71b3af73ff1c3b37be462c 100644 (file)
@@ -107,21 +107,22 @@ 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;
-    if (octets >= tb) {
-        s = QCoreApplication::translate("Utility", "%L1 TB");
-        value /= tb;
-    } else if (octets >= gb) {
+
+    // 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) {
         s = QCoreApplication::translate("Utility", "%L1 GB");
         value /= gb;
     } else if (octets >= mb) {
         s = QCoreApplication::translate("Utility", "%L1 MB");
         value /= mb;
     } else if (octets >= kb) {
-        s = QCoreApplication::translate("Utility", "%L1 kB");
+        s = QCoreApplication::translate("Utility", "%L1 KB");
         value /= kb;
     } else  {
         s = QCoreApplication::translate("Utility", "%L1 B");
index e88ba671bf2d3720eba467f19c8a119c0338e159..8635a984a3c268800281c5e3e663d0396e51e8bf 100644 (file)
@@ -30,26 +30,24 @@ private slots:
     {
         QLocale::setDefault(QLocale("en"));
         QCOMPARE(octetsToString(999) , QString("999 B"));
-        QCOMPARE(octetsToString(1024) , QString("1 kB"));
-        QCOMPARE(octetsToString(1110) , QString("1.1 kB"));
+        QCOMPARE(octetsToString(1024) , QString("1 KB"));
+        QCOMPARE(octetsToString(1364) , QString("1.3 KB"));
 
-        QCOMPARE(octetsToString(9110) , QString("9.1 kB"));
-        QCOMPARE(octetsToString(9910) , QString("9.9 kB"));
-        QCOMPARE(octetsToString(9999) , QString("10 kB"));
-        QCOMPARE(octetsToString(10240) , QString("10 kB"));
+        QCOMPARE(octetsToString(9110) , QString("8.9 KB"));
+        QCOMPARE(octetsToString(9910) , QString("9.7 KB"));
+        QCOMPARE(octetsToString(10240) , QString("10 KB"));
 
-        QCOMPARE(octetsToString(123456) , QString("123 kB"));
+        QCOMPARE(octetsToString(123456) , QString("121 KB"));
         QCOMPARE(octetsToString(1234567) , QString("1.2 MB"));
         QCOMPARE(octetsToString(12345678) , QString("12 MB"));
-        QCOMPARE(octetsToString(123456789) , QString("123 MB"));
-        QCOMPARE(octetsToString(1000LL*1000*1000 * 5) , QString("5 GB"));
+        QCOMPARE(octetsToString(123456789) , QString("118 MB"));
+        QCOMPARE(octetsToString(1000LL*1000*1000 * 5) , QString("4.7 GB"));
 
         QCOMPARE(octetsToString(1), QString("1 B"));
         QCOMPARE(octetsToString(2), QString("2 B"));
-        QCOMPARE(octetsToString(1000), QString("1 kB"));
-        QCOMPARE(octetsToString(1000*1000), QString("1 MB"));
-        QCOMPARE(octetsToString(1000LL*1000*1000), QString("1 GB"));
-        QCOMPARE(octetsToString(1000LL*1000*1000*1000), QString("1 TB"));
+        QCOMPARE(octetsToString(1024), QString("1 KB"));
+        QCOMPARE(octetsToString(1024*1024), QString("1 MB"));
+        QCOMPARE(octetsToString(1024LL*1024*1024), QString("1 GB"));
     }
 
     void testLaunchOnStartup()