Changeset View
Changeset View
Standalone View
Standalone View
autotests/propertyinfotest.cpp
Show All 19 Lines | |||||
20 | 20 | | |||
21 | #include "propertyinfotest.h" | 21 | #include "propertyinfotest.h" | ||
22 | #include "propertyinfo.h" | 22 | #include "propertyinfo.h" | ||
23 | 23 | | |||
24 | #include <QtTest> | 24 | #include <QtTest> | ||
25 | 25 | | |||
26 | using namespace KFileMetaData; | 26 | using namespace KFileMetaData; | ||
27 | 27 | | |||
28 | //QTEST_GUILESS_MAIN(PropertyInfoTest) | ||||
29 | int main(int argc, char *argv[]) | ||||
30 | { | ||||
31 | QCoreApplication app(argc, argv); | ||||
32 | PropertyInfoTest tc; | ||||
33 | | ||||
34 | auto arguments = app.arguments(); | ||||
35 | if (arguments.contains(QStringLiteral("--localized"))) { | ||||
36 | arguments.removeAll(QStringLiteral("--localized")); | ||||
37 | tc.setLocalized(true); | ||||
38 | } | ||||
39 | | ||||
40 | return QTest::qExec(&tc, arguments); | ||||
41 | } | ||||
42 | | ||||
43 | void PropertyInfoTest::setLocalized(bool localized) | ||||
44 | { | ||||
45 | m_useLocalization = localized; | ||||
46 | } | ||||
47 | | ||||
48 | void PropertyInfoTest::init() | ||||
49 | { | ||||
50 | if (!m_useLocalization) { | ||||
51 | QLocale().setDefault(QLocale::c()); | ||||
52 | } | ||||
53 | } | ||||
54 | | ||||
28 | void PropertyInfoTest::testNameIdMapping() | 55 | void PropertyInfoTest::testNameIdMapping() | ||
29 | { | 56 | { | ||
30 | // The +1 is to avoid the Empty Property | 57 | // The +1 is to avoid the Empty Property | ||
31 | int i = static_cast<int>(Property::FirstProperty) + 1; | 58 | int i = static_cast<int>(Property::FirstProperty) + 1; | ||
32 | int e = static_cast<int>(Property::LastProperty); | 59 | int e = static_cast<int>(Property::LastProperty); | ||
33 | 60 | | |||
34 | for (; i <= e; i++) { | 61 | for (; i <= e; i++) { | ||
35 | Property::Property p = static_cast<Property::Property>(i); | 62 | Property::Property p = static_cast<Property::Property>(i); | ||
Show All 10 Lines | |||||
46 | } | 73 | } | ||
47 | 74 | | |||
48 | void PropertyInfoTest::testFormatAsDisplayString() { | 75 | void PropertyInfoTest::testFormatAsDisplayString() { | ||
49 | QFETCH(KFileMetaData::PropertyInfo, propertyInfo); | 76 | QFETCH(KFileMetaData::PropertyInfo, propertyInfo); | ||
50 | QFETCH(QVariant, value); | 77 | QFETCH(QVariant, value); | ||
51 | QFETCH(QString, expected); | 78 | QFETCH(QString, expected); | ||
52 | QFETCH(bool, maybeLocalized); | 79 | QFETCH(bool, maybeLocalized); | ||
53 | 80 | | |||
81 | if (m_useLocalization && maybeLocalized) { | ||||
82 | qDebug() << "Expected:" << expected << ", formatted/localized:" << propertyInfo.formatAsDisplayString(value); | ||||
83 | if (expected != propertyInfo.formatAsDisplayString(value)) { | ||||
84 | QEXPECT_FAIL("", "Expected value not localized", Continue); | ||||
85 | } | ||||
86 | } | ||||
54 | QCOMPARE(propertyInfo.formatAsDisplayString(value), expected); | 87 | QCOMPARE(propertyInfo.formatAsDisplayString(value), expected); | ||
55 | } | 88 | } | ||
56 | 89 | | |||
57 | void PropertyInfoTest::testFormatAsDisplayString_data() | 90 | void PropertyInfoTest::testFormatAsDisplayString_data() | ||
58 | { | 91 | { | ||
59 | QTest::addColumn<KFileMetaData::PropertyInfo>("propertyInfo"); | 92 | QTest::addColumn<KFileMetaData::PropertyInfo>("propertyInfo"); | ||
60 | QTest::addColumn<QVariant>("value"); | 93 | QTest::addColumn<QVariant>("value"); | ||
61 | QTest::addColumn<QString>("expected"); | 94 | QTest::addColumn<QString>("expected"); | ||
Show All 34 Lines | |||||
96 | }; | 129 | }; | ||
97 | 130 | | |||
98 | for (auto row : rows) { | 131 | for (auto row : rows) { | ||
99 | PropertyInfo info(row.property); | 132 | PropertyInfo info(row.property); | ||
100 | QTest::addRow("%s", info.displayName().toUtf8().constData()) | 133 | QTest::addRow("%s", info.displayName().toUtf8().constData()) | ||
101 | << info << row.value << row.expected << row.maybeLocalized; | 134 | << info << row.value << row.expected << row.maybeLocalized; | ||
102 | } | 135 | } | ||
103 | } | 136 | } | ||
104 | | ||||
105 | QTEST_GUILESS_MAIN(PropertyInfoTest) | |