1 /* Copyright (C) 2016 Erik Quaeghebeur <trojita@equaeghe.nospammail.net>
2
3 This file is part of the Trojita Qt IMAP e-mail client,
4 http://trojita.flaska.net/
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of
9 the License or (at your option) version 3 or any later version
10 accepted by the membership of KDE e.V. (or its successor approved
11 by the membership of KDE e.V.), which shall act as a proxy
12 defined in Section 14 of version 3 of the license.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 #include <QTest>
24 #include "test_prettySize.h"
25
26 #include "UiUtils/Formatting.h"
27
28 /** @short Test correctness of pretty sizes generated */
testPrettySize()29 void PrettySizeTest::testPrettySize()
30 {
31 QFETCH(quint64, bytes);
32 QFETCH(QString, formatted);
33
34 QCOMPARE(UiUtils::Formatting::prettySize(bytes), formatted);
35 }
36
testPrettySize_data()37 void PrettySizeTest::testPrettySize_data()
38 {
39 QTest::addColumn<quint64>("bytes");
40 QTest::addColumn<QString>("formatted");
41
42 QTest::newRow("order 0, magnitude 0, zero") << Q_UINT64_C(0)
43 << "0 B";
44 QTest::newRow("order 0, magnitude 0") << Q_UINT64_C(1)
45 << "1 B";
46 QTest::newRow("order 0, magnitude 1") << Q_UINT64_C(12)
47 << "12 B";
48 QTest::newRow("order 0, magnitude 2") << Q_UINT64_C(123)
49 << "123 B";
50
51 QTest::newRow("order 1, magnitude 0, round down") << Q_UINT64_C(1234)
52 << "1.23 kB";
53 QTest::newRow("order 1, magnitude 0, round up") << Q_UINT64_C(1236)
54 << "1.24 kB";
55 QTest::newRow("order 1, magnitude 1, round down") << Q_UINT64_C(12345)
56 << "12.3 kB";
57 QTest::newRow("order 1, magnitude 1, round up") << Q_UINT64_C(12365)
58 << "12.4 kB";
59 QTest::newRow("order 1, magnitude 2, round down") << Q_UINT64_C(123456)
60 << "123 kB";
61 QTest::newRow("order 1, magnitude 2, round up") << Q_UINT64_C(123654)
62 << "124 kB";
63 QTest::newRow("order 1/2, magnitude 2, round down") << Q_UINT64_C(999456)
64 << "999 kB";
65 QTest::newRow("order 1/2, magnitude 2, round up") << Q_UINT64_C(999654)
66 << "1.00 MB";
67
68 QTest::newRow("order 2, magnitude 0, round down") << Q_UINT64_C(1234000)
69 << "1.23 MB";
70 QTest::newRow("order 2, magnitude 0, round up") << Q_UINT64_C(1236000)
71 << "1.24 MB";
72 QTest::newRow("order 2, magnitude 1, round down") << Q_UINT64_C(12345000)
73 << "12.3 MB";
74 QTest::newRow("order 2, magnitude 1, round up") << Q_UINT64_C(12365000)
75 << "12.4 MB";
76 QTest::newRow("order 2, magnitude 2, round down") << Q_UINT64_C(123456000)
77 << "123 MB";
78 QTest::newRow("order 2, magnitude 2, round up") << Q_UINT64_C(123654000)
79 << "124 MB";
80 QTest::newRow("order 2/3, magnitude 2, round down") << Q_UINT64_C(999456000)
81 << "999 MB";
82 QTest::newRow("order 2/3, magnitude 2, round up") << Q_UINT64_C(999654000)
83 << "1.00 GB";
84
85 QTest::newRow("order 3, magnitude 0, round down") << Q_UINT64_C(1234000000)
86 << "1.23 GB";
87 QTest::newRow("order 3, magnitude 0, round up") << Q_UINT64_C(1236000000)
88 << "1.24 GB";
89 QTest::newRow("order 3, magnitude 1, round down") << Q_UINT64_C(12345000000)
90 << "12.3 GB";
91 QTest::newRow("order 3, magnitude 1, round up") << Q_UINT64_C(12365000000)
92 << "12.4 GB";
93 QTest::newRow("order 3, magnitude 2, round down") << Q_UINT64_C(123456000000)
94 << "123 GB";
95 QTest::newRow("order 3, magnitude 2, round up") << Q_UINT64_C(123654000000)
96 << "124 GB";
97 QTest::newRow("order 3/4, magnitude 2, round down") << Q_UINT64_C(999456000000)
98 << "999 GB";
99 QTest::newRow("order 3/4, magnitude 2, round up") << Q_UINT64_C(999654000000)
100 << "1.00 TB";
101
102 QTest::newRow("order 4, magnitude 0, round down") << Q_UINT64_C(1234000000000)
103 << "1.23 TB";
104 QTest::newRow("order 4, magnitude 0, round up") << Q_UINT64_C(1236000000000)
105 << "1.24 TB";
106 QTest::newRow("order 4, magnitude 1, round down") << Q_UINT64_C(12345000000000)
107 << "12.3 TB";
108 QTest::newRow("order 4, magnitude 1, round up") << Q_UINT64_C(12365000000000)
109 << "12.4 TB";
110 QTest::newRow("order 4, magnitude 2, round down") << Q_UINT64_C(123456000000000)
111 << "123 TB";
112 QTest::newRow("order 4, magnitude 2, round up") << Q_UINT64_C(123654000000000)
113 << "124 TB";
114 QTest::newRow("order 4/5, magnitude 2, round down") << Q_UINT64_C(999456000000000)
115 << "999 TB";
116 QTest::newRow("order 4/5, magnitude 2, round up") << Q_UINT64_C(999654000000000)
117 << "1000 TB";
118
119 QTest::newRow("order 5, magnitude 0, round down") << Q_UINT64_C(1234000000000000)
120 << "1230 TB";
121 QTest::newRow("order 5, magnitude 0, round up") << Q_UINT64_C(1236000000000000)
122 << "1240 TB";
123 QTest::newRow("order 5, magnitude 1, round down") << Q_UINT64_C(12345000000000000)
124 << "12300 TB";
125 QTest::newRow("order 5, magnitude 1, round up") << Q_UINT64_C(12365000000000000)
126 << "12400 TB";
127 QTest::newRow("order 5, magnitude 2, round down") << Q_UINT64_C(123456000000000000)
128 << "123000 TB";
129 QTest::newRow("order 5, magnitude 2, round up") << Q_UINT64_C(123654000000000000)
130 << "124000 TB";
131 QTest::newRow("order 5/6, magnitude 2, round down") << Q_UINT64_C(999456000000000000)
132 << "999000 TB";
133 QTest::newRow("order 5/6, magnitude 2, round up") << Q_UINT64_C(999654000000000000)
134 << "1000000 TB";
135 }
136
137 QTEST_GUILESS_MAIN(PrettySizeTest)
138