| 1 |
// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-3.0-or-later |
| 4 |
|
| 5 |
#include <gtest/gtest.h> |
| 6 |
#include "util/dtimeunitformatter.h" |
| 7 |
#include "filesystem/dtrashmanager.h" |
| 8 |
|
| 9 |
DCORE_USE_NAMESPACE |
| 10 |
|
| 11 |
class ut_DTimeUnitFormatter : public testing::Test |
| 12 |
{ |
| 13 |
protected: |
| 14 |
void SetUp() override; |
| 15 |
void TearDown() override; |
| 16 |
DTimeUnitFormatter timeUnitFormatter; |
| 17 |
}; |
| 18 |
|
| 19 |
void ut_DTimeUnitFormatter::SetUp() |
| 20 |
{ |
| 21 |
} |
| 22 |
|
| 23 |
void ut_DTimeUnitFormatter::TearDown() |
| 24 |
{ |
| 25 |
} |
| 26 |
|
| 27 |
TEST_F(ut_DTimeUnitFormatter, testDTimeUnitFormatterFormatAs) |
| 28 |
{ |
| 29 |
qreal result0 = timeUnitFormatter.formatAs(120, DTimeUnitFormatter::Seconds, DTimeUnitFormatter::Minute); |
| 30 |
ASSERT_TRUE(qFuzzyCompare(result0, 2)); |
| 31 |
qreal result1 = timeUnitFormatter.formatAs(2, DTimeUnitFormatter::Minute, DTimeUnitFormatter::Seconds); |
| 32 |
ASSERT_TRUE(qFuzzyCompare(result1, 120)); |
| 33 |
qreal result2 = timeUnitFormatter.formatAs(2, DTimeUnitFormatter::Seconds, DTimeUnitFormatter::Seconds); |
| 34 |
ASSERT_TRUE(qFuzzyCompare(result2, 2)); |
| 35 |
} |
| 36 |
|
| 37 |
TEST_F(ut_DTimeUnitFormatter, testDTimeUnitFormatterFormat) |
| 38 |
{ |
| 39 |
QPair<double, int> result = timeUnitFormatter.format(120, DTimeUnitFormatter::Seconds); |
| 40 |
ASSERT_TRUE(qFuzzyCompare(result.first, 2)); |
| 41 |
ASSERT_EQ(result.second, DTimeUnitFormatter::Minute); |
| 42 |
} |
| 43 |
|
| 44 |
TEST_F(ut_DTimeUnitFormatter, testDTimeUnitFormatterFormatAsUnitList) |
| 45 |
{ |
| 46 |
QList<QPair<double, int>> result = timeUnitFormatter.formatAsUnitList(121, DTimeUnitFormatter::Seconds); |
| 47 |
ASSERT_TRUE(qFuzzyCompare(result[0].first, 121)); |
| 48 |
ASSERT_EQ(result[0].second, DTimeUnitFormatter::Seconds); |
| 49 |
} |
| 50 |
|
| 51 |
TEST_F(ut_DTimeUnitFormatter, testDTimeUnitFormatterUnitStr) |
| 52 |
{ |
| 53 |
ASSERT_EQ(timeUnitFormatter.unitStr(DTimeUnitFormatter::Seconds), "s"); |
| 54 |
ASSERT_EQ(timeUnitFormatter.unitStr(DTimeUnitFormatter::Minute), "m"); |
| 55 |
ASSERT_EQ(timeUnitFormatter.unitStr(DTimeUnitFormatter::Hour), "h"); |
| 56 |
ASSERT_EQ(timeUnitFormatter.unitStr(DTimeUnitFormatter::Day), "d"); |
| 57 |
} |