Changeset View
Changeset View
Standalone View
Standalone View
autotests/kformattest.cpp
Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Line(s) | 52 | #endif | |||
---|---|---|---|---|---|
84 | QCOMPARE(format.formatByteSize(2.3e22, 2, KFormat::MetricBinaryDialect), QStringLiteral("23.00 ZB")); | 84 | QCOMPARE(format.formatByteSize(2.3e22, 2, KFormat::MetricBinaryDialect), QStringLiteral("23.00 ZB")); | ||
85 | QCOMPARE(format.formatByteSize(1.0e27, 1, KFormat::MetricBinaryDialect), QStringLiteral("1,000.0 YB")); | 85 | QCOMPARE(format.formatByteSize(1.0e27, 1, KFormat::MetricBinaryDialect), QStringLiteral("1,000.0 YB")); | ||
86 | 86 | | |||
87 | // Spattering of specific units | 87 | // Spattering of specific units | ||
88 | QCOMPARE(format.formatByteSize(823000, 3, KFormat::IECBinaryDialect, KFormat::UnitMegaByte), QStringLiteral("0.785 MiB")); | 88 | QCOMPARE(format.formatByteSize(823000, 3, KFormat::IECBinaryDialect, KFormat::UnitMegaByte), QStringLiteral("0.785 MiB")); | ||
89 | QCOMPARE(format.formatByteSize(1234034.0, 4, KFormat::JEDECBinaryDialect, KFormat::UnitByte), QStringLiteral("1,234,034 B")); | 89 | QCOMPARE(format.formatByteSize(1234034.0, 4, KFormat::JEDECBinaryDialect, KFormat::UnitByte), QStringLiteral("1,234,034 B")); | ||
90 | } | 90 | } | ||
91 | 91 | | |||
92 | void KFormatTest::formatValue() | ||||
93 | { | ||||
94 | QLocale locale(QLocale::c()); | ||||
95 | locale.setNumberOptions(QLocale::DefaultNumberOptions); // Qt >= 5.6 sets QLocale::OmitGroupSeparator for the C locale | ||||
96 | KFormat format(locale); | ||||
97 | | ||||
98 | // Check examples from the documentation | ||||
99 | QCOMPARE(format.formatValue(1000, KFormat::Unit::Byte, 1, KFormat::UnitPrefix::Kilo, KFormat::MetricBinaryDialect), QStringLiteral("1.0 kB")); | ||||
100 | QCOMPARE(format.formatValue(1000, KFormat::Unit::Byte, 1, KFormat::UnitPrefix::Kilo, KFormat::IECBinaryDialect), QStringLiteral("1.0 KiB")); | ||||
101 | QCOMPARE(format.formatValue(1000, KFormat::Unit::Byte, 1, KFormat::UnitPrefix::Kilo, KFormat::JEDECBinaryDialect), QStringLiteral("1.0 KB")); | ||||
102 | | ||||
103 | // Check examples from the documentation | ||||
104 | QCOMPARE(format.formatValue(1000, KFormat::Unit::Bit, 1, KFormat::UnitPrefix::Kilo, KFormat::MetricBinaryDialect), QStringLiteral("1.0 kbit")); | ||||
105 | QCOMPARE(format.formatValue(1000, QStringLiteral("bit"), 1, KFormat::UnitPrefix::Kilo), QStringLiteral("1.0 kbit")); | ||||
106 | QCOMPARE(format.formatValue(1000, QStringLiteral("bit/s"), 1, KFormat::UnitPrefix::Kilo), QStringLiteral("1.0 kbit/s")); | ||||
107 | | ||||
108 | QCOMPARE(format.formatValue(100, QStringLiteral("bit/s")), QStringLiteral("100.0 bit/s")); | ||||
109 | QCOMPARE(format.formatValue(1000, QStringLiteral("bit/s")), QStringLiteral("1.0 kbit/s")); | ||||
110 | QCOMPARE(format.formatValue(10e3, QStringLiteral("bit/s")), QStringLiteral("10.0 kbit/s")); | ||||
111 | QCOMPARE(format.formatValue(10e6, QStringLiteral("bit/s")), QStringLiteral("10.0 Mbit/s")); | ||||
112 | } | ||||
113 | | ||||
92 | enum TimeConstants { | 114 | enum TimeConstants { | ||
93 | MSecsInDay = 86400000, | 115 | MSecsInDay = 86400000, | ||
94 | MSecsInHour = 3600000, | 116 | MSecsInHour = 3600000, | ||
95 | MSecsInMinute = 60000, | 117 | MSecsInMinute = 60000, | ||
96 | MSecsInSecond = 1000 | 118 | MSecsInSecond = 1000 | ||
97 | }; | 119 | }; | ||
98 | 120 | | |||
99 | void KFormatTest::formatDuration() | 121 | void KFormatTest::formatDuration() | ||
▲ Show 20 Lines • Show All 251 Lines • Show Last 20 Lines |