Просмотр исходного кода

Utility: Fix the size display back to JEDEC standard.

Also updated the test.
Klaas Freitag 10 лет назад
Родитель
Сommit
9004fd6d11
2 измененных файлов с 18 добавлено и 19 удалено
  1. 7 6
      src/libsync/utility.cpp
  2. 11 13
      test/testutility.h

+ 7 - 6
src/libsync/utility.cpp

@@ -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");

+ 11 - 13
test/testutility.h

@@ -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()