Changeset View
Changeset View
Standalone View
Standalone View
autotests/propertyinfotest.cpp
Show All 39 Lines | 34 | for (; i <= e; i++) { | |||
---|---|---|---|---|---|
40 | QVERIFY(!pi.name().isEmpty()); | 40 | QVERIFY(!pi.name().isEmpty()); | ||
41 | QVERIFY(!pi.displayName().isEmpty()); | 41 | QVERIFY(!pi.displayName().isEmpty()); | ||
42 | 42 | | |||
43 | PropertyInfo pi2 = PropertyInfo::fromName(pi.name()); | 43 | PropertyInfo pi2 = PropertyInfo::fromName(pi.name()); | ||
44 | QCOMPARE(pi2.property(), p); | 44 | QCOMPARE(pi2.property(), p); | ||
45 | } | 45 | } | ||
46 | } | 46 | } | ||
47 | 47 | | |||
48 | void PropertyInfoTest::testFormatAsDisplayString() | 48 | void PropertyInfoTest::testFormatAsDisplayString() { | ||
49 | { | 49 | QFETCH(KFileMetaData::PropertyInfo, propertyInfo); | ||
50 | auto emptyProperty = PropertyInfo::fromName(QStringLiteral("no valid property name")); | 50 | QFETCH(QVariant, value); | ||
51 | QCOMPARE(emptyProperty.formatAsDisplayString(QVariant(QStringLiteral("empty"))), QStringLiteral("empty")); | 51 | QFETCH(QString, expected); | ||
52 | QFETCH(bool, maybeLocalized); | ||||
52 | 53 | | |||
53 | PropertyInfo year(Property::DiscNumber); | 54 | QCOMPARE(propertyInfo.formatAsDisplayString(value), expected); | ||
54 | QCOMPARE(year.formatAsDisplayString(QVariant(2018)), QStringLiteral("2018")); | 55 | } | ||
55 | 56 | | |||
56 | PropertyInfo title(Property::Title); | 57 | void PropertyInfoTest::testFormatAsDisplayString_data() | ||
57 | QCOMPARE(title.formatAsDisplayString(QVariant(QStringLiteral("Title"))), QStringLiteral("Title")); | 58 | { | ||
59 | QTest::addColumn<KFileMetaData::PropertyInfo>("propertyInfo"); | ||||
60 | QTest::addColumn<QVariant>("value"); | ||||
61 | QTest::addColumn<QString>("expected"); | ||||
62 | QTest::addColumn<bool>("maybeLocalized"); | ||||
58 | 63 | | |||
59 | QStringList artistList = {QStringLiteral("Artist1"), QStringLiteral("Artist2"), QStringLiteral("Artist3")}; | 64 | auto emptyProperty = PropertyInfo::fromName(QStringLiteral("no valid property name")); | ||
60 | PropertyInfo artist(Property::Artist); | 65 | QTest::addRow("<invalid>") | ||
61 | QCOMPARE(artist.formatAsDisplayString(QVariant(artistList)), QStringLiteral("Artist1, Artist2, and Artist3")); | 66 | << emptyProperty << QVariant(QStringLiteral("empty")) << QStringLiteral("empty") << true; | ||
62 | 67 | | |||
68 | QStringList artistList = {QStringLiteral("Artist1"), QStringLiteral("Artist2"), QStringLiteral("Artist3")}; | ||||
63 | QStringList authorList = {QStringLiteral("Author1")}; | 69 | QStringList authorList = {QStringLiteral("Author1")}; | ||
64 | PropertyInfo author(Property::Author); | | |||
65 | QCOMPARE(author.formatAsDisplayString(QVariant(authorList)), QStringLiteral("Author1")); | | |||
66 | | ||||
67 | PropertyInfo duration(Property::Duration); | | |||
68 | QCOMPARE(duration.formatAsDisplayString(QVariant(1800)), QStringLiteral("0:30:00")); | | |||
69 | | ||||
70 | PropertyInfo sampleRate(Property::SampleRate); | | |||
71 | QCOMPARE(sampleRate.formatAsDisplayString(QVariant(44100)), QString(QLocale().toString(44.1) + QStringLiteral(" kHz"))); | | |||
72 | 70 | | |||
73 | PropertyInfo bitRate(Property::BitRate); | 71 | struct { | ||
74 | QCOMPARE(bitRate.formatAsDisplayString(QVariant(128000)), QStringLiteral("128 kbit/s")); | 72 | KFileMetaData::Property::Property property; | ||
75 | QCOMPARE(bitRate.formatAsDisplayString(QVariant(1350000)), QString(QLocale().toString(1.35) + QStringLiteral(" Mbit/s"))); | 73 | bool maybeLocalized; | ||
76 | QCOMPARE(bitRate.formatAsDisplayString(QVariant(14700000)), QString(QLocale().toString(14.7) + QStringLiteral(" Mbit/s"))); | 74 | QVariant value; | ||
77 | 75 | QString expected; | |||
78 | PropertyInfo orientation(Property::ImageOrientation); | 76 | } rows[] = { | ||
79 | QCOMPARE(orientation.formatAsDisplayString(QVariant(5)), QStringLiteral("Transposed")); | 77 | { Property::DiscNumber, true, 2018, QStringLiteral("2018")}, | ||
80 | 78 | { Property::Title, false, QStringLiteral("Title"), QStringLiteral("Title")}, | |||
81 | PropertyInfo flash(Property::PhotoFlash); | 79 | { Property::Artist, true, artistList, QStringLiteral("Artist1, Artist2, and Artist3")}, | ||
82 | QCOMPARE(flash.formatAsDisplayString(QVariant(0x00)), QStringLiteral("No flash")); | 80 | { Property::Author, true, authorList, QStringLiteral("Author1")}, | ||
83 | QCOMPARE(flash.formatAsDisplayString(QVariant(0x50)), QStringLiteral("No, red-eye reduction")); | 81 | { Property::Duration, true, 1800, QStringLiteral("0:30:00")}, | ||
84 | 82 | { Property::SampleRate, true, 44100, QStringLiteral("44.1 kHz")}, | |||
85 | PropertyInfo altitude(Property::PhotoGpsAltitude); | 83 | { Property::BitRate, true, 128000, QStringLiteral("128 kbit/s")}, | ||
86 | QCOMPARE(altitude.formatAsDisplayString(QVariant(1.1)), QString(QLocale().toString(1.1) + QStringLiteral(" m"))); | 84 | { Property::BitRate, true, 1350000, QStringLiteral("1.35 Mbit/s")}, | ||
87 | 85 | { Property::BitRate, true, 14700000, QStringLiteral("14.7 Mbit/s")}, | |||
88 | PropertyInfo latitude(Property::PhotoGpsLatitude); | 86 | { Property::ImageOrientation, true, 5, QStringLiteral("Transposed")}, | ||
89 | // make tests on windows happy: QChar(0x00B0) = "°" | 87 | { Property::PhotoFlash, true, 0x00, QStringLiteral("No flash")}, | ||
90 | QCOMPARE(latitude.formatAsDisplayString(QVariant(25)), QString(QLocale().toString(25) + QChar(0x00B0))); | 88 | { Property::PhotoFlash, true, 0x50, QStringLiteral("No, red-eye reduction")}, | ||
91 | 89 | { Property::PhotoGpsAltitude, true, 1.1, QStringLiteral("1.1 m")}, | |||
92 | PropertyInfo longitude(Property::PhotoGpsLongitude); | 90 | // make VisualStudio compiler happy: QChar(0x00B0) = "°" | ||
93 | QCOMPARE(longitude.formatAsDisplayString(QVariant(13.5)), QString(QLocale().toString(13.5) + QChar(0x00B0))); | 91 | { Property::PhotoGpsLatitude, true, 25, QStringLiteral("25") + QChar(0x00B0)}, | ||
94 | 92 | { Property::PhotoGpsLongitude, true, 13.5, QStringLiteral("13.5") + QChar(0x00B0)}, | |||
95 | PropertyInfo framerate(Property::FrameRate); | 93 | { Property::FrameRate, true, 23, QStringLiteral("23 fps")}, | ||
96 | QCOMPARE(framerate.formatAsDisplayString(QVariant(23)), QStringLiteral("23 fps")); | 94 | { Property::FrameRate, true, 23.976, QStringLiteral("23.98 fps")}, | ||
97 | QCOMPARE(framerate.formatAsDisplayString(QVariant(23.976)), QStringLiteral("23.98 fps")); | 95 | { Property::AspectRatio, true, 1.77778, QStringLiteral("1.78:1")}, | ||
98 | 96 | }; | |||
99 | PropertyInfo aspectRatio(Property::AspectRatio); | 97 | | ||
100 | QCOMPARE(aspectRatio.formatAsDisplayString(QVariant(1.77778)), QStringLiteral("1.78:1")); | 98 | for (auto row : rows) { | ||
99 | PropertyInfo info(row.property); | ||||
100 | QTest::addRow("%s", info.displayName().toUtf8().constData()) | ||||
101 | << info << row.value << row.expected << row.maybeLocalized; | ||||
102 | } | ||||
apol: Is the struct really necessary?
You can be about as short by calling QTest::addRow directly for… | |||||
This saves adding the QVariant(...) around each value, and avoids the repeated formatting of the row name/data index. The property enum is used twice in each addRow. bruns: This saves adding the `QVariant(...)` around each value, and avoids the repeated formatting of… | |||||
And instead it makes you create a weird local struct and loop to feed to QTest. I don't find it very convincing. apol: And instead it makes you create a weird local struct and loop to feed to QTest. I don't find it… | |||||
First 2 rows expanded, just for you: QTest::addRow("%s", PropertyInfo(DiscNumber).displayName().toUtf8().constData()) << PropertyInfo(Property::DiscNumber) << true << QVariant(2018) << QStringLiteral("2018"); QTest::addRow("%s", PropertyInfo(Title).displayName().toUtf8().constData()) << PropertyInfo(Property::Title) << true << QVariant(QStringLiteral("Title")) << QStringLiteral("Title"); bruns: First 2 rows expanded, just for you:
```
QTest::addRow("%s", PropertyInfo(DiscNumber). | |||||
bruns: Still not convinced? | |||||
Not really, but if @mgallien, who is the maintainer, is fine with it, I'm fine too. apol: Not really, but if @mgallien, who is the maintainer, is fine with it, I'm fine too.
After all… | |||||
@mgallien has not done any coding are reviews on kfilemetadata for almost a year ... bruns: @mgallien has not done any coding are reviews on kfilemetadata for almost a year ... | |||||
101 | } | 103 | } | ||
102 | 104 | | |||
103 | QTEST_GUILESS_MAIN(PropertyInfoTest) | 105 | QTEST_GUILESS_MAIN(PropertyInfoTest) |
Is the struct really necessary?
You can be about as short by calling QTest::addRow directly for each line.