summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qdeadlinetimer
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2023-04-20 17:35:22 -0700
committerThiago Macieira <thiago.macieira@intel.com>2023-05-06 17:54:23 +0000
commita2551c45d496c23045eb8451e080e75b2f8b42c1 (patch)
tree66ce1e4a0cb5341a34150d410484b4ff6e8009f2 /tests/auto/corelib/kernel/qdeadlinetimer
parent59f8da17e6a2989b072254970d23281301114503 (diff)
Move the formatting of <chrono> durations to QDebug & QtTest
[ChangeLog][QtCore][QDebug] Added pretty formatting of C++ <chrono> durations. [ChangeLog][QtTest] Added pretty formatting of C++ <chrono> durations for QCOMPARE expressions. Change-Id: I3b169860d8bd41e9be6bfffd1757cc087ba957fa Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/auto/corelib/kernel/qdeadlinetimer')
-rw-r--r--tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp46
1 files changed, 0 insertions, 46 deletions
diff --git a/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp b/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp
index bdf2e7a573..a584cda9fc 100644
--- a/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp
+++ b/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp
@@ -27,52 +27,6 @@ template<> char *toString(const QDeadlineTimer &dt)
dt.hasExpired() ? " (expired)" : "");
return buf;
}
-
-template <typename Rep, typename Period> char *toString(std::chrono::duration<Rep, Period> dur)
-{
- using namespace std::chrono;
- static_assert(sizeof(double) == sizeof(qlonglong));
-
- if constexpr (Period::num == 1 && sizeof(Rep) <= sizeof(qlonglong)) {
- // typical case: second or sub-multiple of second, in a representation
- // we can directly use
- char *buf = new char[128];
- if constexpr (std::is_integral_v<Rep>) {
- char unit[] = "ss";
- if constexpr (std::is_same_v<Period, std::atto>) { // from Norwegian "atten", 18
- unit[0] = 'a';
- } else if constexpr (std::is_same_v<Period, std::femto>) { // Norwegian "femten", 15
- unit[0] = 'f';
- } else if constexpr (std::is_same_v<Period, std::pico>) {
- unit[0] = 'p';
- } else if constexpr (std::is_same_v<Period, std::nano>) {
- unit[0] = 'n';
- } else if constexpr (std::is_same_v<Period, std::micro>) {
- unit[0] = 'u'; // ยต, really, but the output may not be UTF-8-safe
- } else if constexpr (std::is_same_v<Period, std::milli>) {
- unit[0] = 'm';
- } else {
- // deci, centi, cycles of something (60 Hz, 8000 Hz, etc.)
- static_assert(Period::den == 1,
- "Unsupported std::chrono::duration of a sub-multiple of second");
- unit[1] = '\0';
- }
-
- // cast to qlonglong in case Rep is not int64_t
- qsnprintf(buf, 128, "%lld %s", qlonglong(dur.count()), unit);
- } else {
- auto secs = duration_cast<duration<double>>(dur);
- qsnprintf(buf, 128, "%g s", secs.count());
- }
- return buf;
- } else if constexpr (std::is_integral_v<Rep> && Period::den == 1) {
- // multiple of second, so just print it in seconds
- return toString(std::chrono::seconds(dur));
- } else {
- // something else, use floating-point seconds
- return toString(std::chrono::duration_cast<double>(dur));
- }
-}
}
QT_END_NAMESPACE