Changeset View
Changeset View
Standalone View
Standalone View
autotests/filemetadatawidgettest.cpp
Show All 32 Lines | |||||
33 | 33 | | |||
34 | #include <KFileItem> | 34 | #include <KFileItem> | ||
35 | #include <KRatingWidget> | 35 | #include <KRatingWidget> | ||
36 | #include <KConfig> | 36 | #include <KConfig> | ||
37 | #include <KConfigGroup> | 37 | #include <KConfigGroup> | ||
38 | 38 | | |||
39 | void initLocale() | 39 | void initLocale() | ||
40 | { | 40 | { | ||
41 | QLocale::setDefault(QLocale("en_US")); | 41 | QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates)); | ||
42 | } | 42 | } | ||
43 | Q_CONSTRUCTOR_FUNCTION(initLocale) | 43 | Q_CONSTRUCTOR_FUNCTION(initLocale) | ||
44 | 44 | | |||
45 | QTEST_MAIN(FileMetadataWidgetTest) | 45 | QTEST_MAIN(FileMetadataWidgetTest) | ||
46 | 46 | | |||
47 | void FileMetadataWidgetTest::initTestCase() | 47 | void FileMetadataWidgetTest::initTestCase() | ||
48 | { | 48 | { | ||
49 | qRegisterMetaType<KFileItemList>("KFileItemList"); | 49 | qRegisterMetaType<KFileItemList>("KFileItemList"); | ||
50 | 50 | | |||
51 | QStandardPaths::setTestModeEnabled(true); | 51 | QStandardPaths::setTestModeEnabled(true); | ||
52 | 52 | | |||
53 | KConfig balooConfig("baloofilerc", KConfig::NoGlobals); | 53 | KConfig balooConfig(QStringLiteral("baloofilerc"), KConfig::NoGlobals); | ||
54 | KConfigGroup balooSettings = balooConfig.group("General"); | 54 | KConfigGroup balooSettings = balooConfig.group("General"); | ||
55 | // If we use .writePathEntry here, the test will fail. | 55 | // If we use .writePathEntry here, the test will fail. | ||
56 | balooSettings.writeEntry(QStringLiteral("folders"), QString()); | 56 | balooSettings.writeEntry(QStringLiteral("folders"), QString()); | ||
57 | 57 | | |||
58 | // Ensure show configuration | 58 | // Ensure show configuration | ||
59 | KConfig config("baloofileinformationrc", KConfig::NoGlobals); | 59 | KConfig config(QStringLiteral("baloofileinformationrc"), KConfig::NoGlobals); | ||
60 | KConfigGroup settings = config.group("Show"); | 60 | KConfigGroup settings = config.group("Show"); | ||
61 | const auto keys = settings.keyList(); | 61 | const auto keys = settings.keyList(); | ||
62 | for (const auto &key: keys) { | 62 | for (const auto &key: keys) { | ||
63 | settings.writeEntry(key, true); | 63 | settings.writeEntry(key, true); | ||
64 | } | 64 | } | ||
65 | 65 | | |||
66 | const QString exe = QStandardPaths::findExecutable(QStringLiteral("setfattr")); | 66 | const QString exe = QStandardPaths::findExecutable(QStringLiteral("setfattr")); | ||
67 | 67 | | |||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Line(s) | 135 | { | |||
137 | m_widget->setItems(KFileItemList() | 137 | m_widget->setItems(KFileItemList() | ||
138 | << QUrl::fromLocalFile(QFINDTESTDATA("samplefiles/testtagged.mp3")) | 138 | << QUrl::fromLocalFile(QFINDTESTDATA("samplefiles/testtagged.mp3")) | ||
139 | ); | 139 | ); | ||
140 | 140 | | |||
141 | QVERIFY(spy.wait()); | 141 | QVERIFY(spy.wait()); | ||
142 | QCOMPARE(spy.count(), 1); | 142 | QCOMPARE(spy.count(), 1); | ||
143 | 143 | | |||
144 | // simple property | 144 | // simple property | ||
145 | QLabel* valueWidget = m_widget->findChild<QLabel*>("kfileitem#type"); | 145 | QLabel* valueWidget = m_widget->findChild<QLabel*>(QStringLiteral("kfileitem#type")); | ||
146 | QVERIFY2(valueWidget, "Type data missing"); | 146 | QVERIFY2(valueWidget, "Type data missing"); | ||
147 | QCOMPARE(valueWidget->text(), QLatin1String("MP3 audio")); | 147 | QCOMPARE(valueWidget->text(), QLatin1String("MP3 audio")); | ||
148 | 148 | | |||
149 | if (m_mayTestRating) { | 149 | if (m_mayTestRating) { | ||
150 | // editable property | 150 | // editable property | ||
151 | KRatingWidget* ratingWidget = m_widget->findChild<KRatingWidget*>("rating"); | 151 | KRatingWidget* ratingWidget = m_widget->findChild<KRatingWidget*>(QStringLiteral("rating")); | ||
152 | QVERIFY2(ratingWidget, "Rating data missing"); | 152 | QVERIFY2(ratingWidget, "Rating data missing"); | ||
153 | QCOMPARE(ratingWidget->rating(), 5u); | 153 | QCOMPARE(ratingWidget->rating(), 5u); | ||
154 | } else { | 154 | } else { | ||
155 | qDebug() << "Skipped 'Rating' test"; | 155 | qDebug() << "Skipped 'Rating' test"; | ||
156 | } | 156 | } | ||
157 | // async property | 157 | // async property | ||
158 | valueWidget = m_widget->findChild<QLabel*>("albumArtist"); | 158 | valueWidget = m_widget->findChild<QLabel*>(QStringLiteral("albumArtist")); | ||
159 | QVERIFY2(valueWidget, "albumArtist data was not found"); | 159 | QVERIFY2(valueWidget, "albumArtist data was not found"); | ||
160 | QCOMPARE(valueWidget->text(), QLatin1String("Bill Laswell")); | 160 | QCOMPARE(valueWidget->text(), QLatin1String("Bill Laswell")); | ||
161 | 161 | | |||
162 | } | 162 | } | ||
163 | 163 | | |||
164 | void FileMetadataWidgetTest::shouldShowCommonProperties() | 164 | void FileMetadataWidgetTest::shouldShowCommonProperties() | ||
165 | { | 165 | { | ||
166 | QSignalSpy spy(m_widget, &Baloo::FileMetaDataWidget::metaDataRequestFinished); | 166 | QSignalSpy spy(m_widget, &Baloo::FileMetaDataWidget::metaDataRequestFinished); | ||
167 | m_widget->setItems(KFileItemList() | 167 | m_widget->setItems(KFileItemList() | ||
168 | << QUrl::fromLocalFile(QFINDTESTDATA("samplefiles/testtagged.mp3")) | 168 | << QUrl::fromLocalFile(QFINDTESTDATA("samplefiles/testtagged.mp3")) | ||
169 | << QUrl::fromLocalFile(QFINDTESTDATA("samplefiles/testtagged.m4a")) | 169 | << QUrl::fromLocalFile(QFINDTESTDATA("samplefiles/testtagged.m4a")) | ||
170 | ); | 170 | ); | ||
171 | QVERIFY(spy.wait()); | 171 | QVERIFY(spy.wait()); | ||
172 | QCOMPARE(spy.count(), 1); | 172 | QCOMPARE(spy.count(), 1); | ||
173 | 173 | | |||
174 | // simple property | 174 | // simple property | ||
175 | QLabel* valueWidget = m_widget->findChild<QLabel*>("kfileitem#type"); | 175 | QLabel* valueWidget = m_widget->findChild<QLabel*>(QStringLiteral("kfileitem#type")); | ||
176 | QVERIFY(!valueWidget); | 176 | QVERIFY(!valueWidget); | ||
177 | 177 | | |||
178 | valueWidget = m_widget->findChild<QLabel*>("kfileitem#totalSize"); | 178 | valueWidget = m_widget->findChild<QLabel*>(QStringLiteral("kfileitem#totalSize")); | ||
179 | // circumvent i18n formatting | 179 | // circumvent i18n formatting | ||
180 | QCOMPARE(valueWidget->text().left(3), QLatin1String("153")); | 180 | QCOMPARE(valueWidget->text().left(3), QLatin1String("153")); | ||
181 | 181 | | |||
182 | // editable property | 182 | // editable property | ||
183 | if (m_mayTestRating) { | 183 | if (m_mayTestRating) { | ||
184 | KRatingWidget* ratingWidget = m_widget->findChild<KRatingWidget*>("rating"); | 184 | KRatingWidget* ratingWidget = m_widget->findChild<KRatingWidget*>(QStringLiteral("rating")); | ||
185 | QVERIFY2(ratingWidget, "Rating data missing"); | 185 | QVERIFY2(ratingWidget, "Rating data missing"); | ||
186 | QCOMPARE(ratingWidget->rating(), 5u); | 186 | QCOMPARE(ratingWidget->rating(), 5u); | ||
187 | } else { | 187 | } else { | ||
188 | qDebug() << "Skipped 'Rating' test"; | 188 | qDebug() << "Skipped 'Rating' test"; | ||
189 | } | 189 | } | ||
190 | // async property | 190 | // async property | ||
191 | // FIXME: Make this pass | 191 | // FIXME: Make this pass | ||
192 | // QCOMPARE( map->value("Album Artist:"), QLatin1String("Bill Laswell")); | 192 | // QCOMPARE( map->value("Album Artist:"), QLatin1String("Bill Laswell")); | ||
193 | } | 193 | } | ||
194 | 194 | | |||
195 | void FileMetadataWidgetTest::shouldShowMultiValueProperties() | 195 | void FileMetadataWidgetTest::shouldShowMultiValueProperties() | ||
196 | { | 196 | { | ||
197 | QSignalSpy spy(m_widget, &Baloo::FileMetaDataWidget::metaDataRequestFinished); | 197 | QSignalSpy spy(m_widget, &Baloo::FileMetaDataWidget::metaDataRequestFinished); | ||
198 | m_widget->setItems(KFileItemList() | 198 | m_widget->setItems(KFileItemList() | ||
199 | << QUrl::fromLocalFile(QFINDTESTDATA("samplefiles/test_multivalue.ogg")) | 199 | << QUrl::fromLocalFile(QFINDTESTDATA("samplefiles/test_multivalue.ogg")) | ||
200 | ); | 200 | ); | ||
201 | QVERIFY(spy.wait()); | 201 | QVERIFY(spy.wait()); | ||
202 | QCOMPARE(spy.count(), 1); | 202 | QCOMPARE(spy.count(), 1); | ||
203 | auto artistWidget = m_widget->findChild<QLabel*>(QStringLiteral("artist")); | 203 | auto artistWidget = m_widget->findChild<QLabel*>(QStringLiteral("artist")); | ||
204 | QVERIFY2(artistWidget, "artist not found"); | 204 | QVERIFY2(artistWidget, "artist not found"); | ||
205 | QCOMPARE(artistWidget->text(), "Artist1 and Artist2"); | 205 | QCOMPARE(artistWidget->text(), QStringLiteral("Artist1 and Artist2")); | ||
206 | auto genreWidget = m_widget->findChild<QLabel*>(QStringLiteral("genre")); | 206 | auto genreWidget = m_widget->findChild<QLabel*>(QStringLiteral("genre")); | ||
207 | QVERIFY2(genreWidget, "genre not found"); | 207 | QVERIFY2(genreWidget, "genre not found"); | ||
208 | QCOMPARE(genreWidget->text(), "Genre1, Genre2, and Genre3"); | 208 | QCOMPARE(genreWidget->text(), QStringLiteral("Genre1, Genre2, and Genre3")); | ||
209 | } | 209 | } |