Changeset View
Changeset View
Standalone View
Standalone View
tests/auto/thumbnailprovidertest.cpp
Show First 20 Lines • Show All 116 Lines • ▼ Show 20 Line(s) | |||||
117 | void ThumbnailProviderTest::testLoadLocal() | 117 | void ThumbnailProviderTest::testLoadLocal() | ||
118 | { | 118 | { | ||
119 | QDir dir(mSandBox.mPath); | 119 | QDir dir(mSandBox.mPath); | ||
120 | 120 | | |||
121 | // Create a list of items which will be thumbnailed | 121 | // Create a list of items which will be thumbnailed | ||
122 | KFileItemList list; | 122 | KFileItemList list; | ||
123 | Q_FOREACH(const QFileInfo & info, dir.entryInfoList(QDir::Files)) { | 123 | Q_FOREACH(const QFileInfo & info, dir.entryInfoList(QDir::Files)) { | ||
124 | QUrl url("file://" + info.absoluteFilePath()); | 124 | QUrl url("file://" + info.absoluteFilePath()); | ||
125 | KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url); | 125 | KFileItem item(url); | ||
126 | list << item; | 126 | list << item; | ||
127 | } | 127 | } | ||
128 | 128 | | |||
129 | // Generate the thumbnails | 129 | // Generate the thumbnails | ||
130 | ThumbnailProvider provider; | 130 | ThumbnailProvider provider; | ||
131 | provider.setThumbnailGroup(ThumbnailGroup::Normal); | 131 | provider.setThumbnailGroup(ThumbnailGroup::Normal); | ||
132 | provider.appendItems(list); | 132 | provider.appendItems(list); | ||
133 | QSignalSpy spy(&provider, SIGNAL(thumbnailLoaded(KFileItem,QPixmap,QSize,qulonglong))); | 133 | QSignalSpy spy(&provider, SIGNAL(thumbnailLoaded(KFileItem,QPixmap,QSize,qulonglong))); | ||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | 191 | { | |||
193 | QPixmap thumbnailPix; | 193 | QPixmap thumbnailPix; | ||
194 | SandBox sandBox; | 194 | SandBox sandBox; | ||
195 | sandBox.initDir(); | 195 | sandBox.initDir(); | ||
196 | // This image is red (0xfe0000) and 256x128 but contains a white 128x64 thumbnail | 196 | // This image is red (0xfe0000) and 256x128 but contains a white 128x64 thumbnail | ||
197 | sandBox.copyTestImage("embedded-thumbnail.jpg", 256, 128); | 197 | sandBox.copyTestImage("embedded-thumbnail.jpg", 256, 128); | ||
198 | 198 | | |||
199 | KFileItemList list; | 199 | KFileItemList list; | ||
200 | QUrl url("file://" + QDir(sandBox.mPath).absoluteFilePath("embedded-thumbnail.jpg")); | 200 | QUrl url("file://" + QDir(sandBox.mPath).absoluteFilePath("embedded-thumbnail.jpg")); | ||
201 | list << KFileItem(KFileItem::Unknown, KFileItem::Unknown, url); | 201 | list << KFileItem(url); | ||
202 | 202 | | |||
203 | // Loading a normal thumbnail should bring the white one | 203 | // Loading a normal thumbnail should bring the white one | ||
204 | { | 204 | { | ||
205 | ThumbnailProvider provider; | 205 | ThumbnailProvider provider; | ||
206 | provider.setThumbnailGroup(ThumbnailGroup::Normal); | 206 | provider.setThumbnailGroup(ThumbnailGroup::Normal); | ||
207 | provider.appendItems(list); | 207 | provider.appendItems(list); | ||
208 | QSignalSpy spy(&provider, SIGNAL(thumbnailLoaded(KFileItem,QPixmap,QSize,qulonglong))); | 208 | QSignalSpy spy(&provider, SIGNAL(thumbnailLoaded(KFileItem,QPixmap,QSize,qulonglong))); | ||
209 | syncRun(&provider); | 209 | syncRun(&provider); | ||
Show All 24 Lines | 233 | { | |||
234 | QUrl url = setUpRemoteTestDir("test.png"); | 234 | QUrl url = setUpRemoteTestDir("test.png"); | ||
235 | if (!url.isValid()) { | 235 | if (!url.isValid()) { | ||
236 | QSKIP("Not running this test: failed to setup remote test dir."); | 236 | QSKIP("Not running this test: failed to setup remote test dir."); | ||
237 | } | 237 | } | ||
238 | url = url.adjusted(QUrl::StripTrailingSlash); | 238 | url = url.adjusted(QUrl::StripTrailingSlash); | ||
239 | url.setPath(url.path() + '/' + "test.png"); | 239 | url.setPath(url.path() + '/' + "test.png"); | ||
240 | 240 | | |||
241 | KFileItemList list; | 241 | KFileItemList list; | ||
242 | KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url); | 242 | KFileItem item(url); | ||
243 | list << item; | 243 | list << item; | ||
244 | 244 | | |||
245 | ThumbnailProvider provider; | 245 | ThumbnailProvider provider; | ||
246 | provider.setThumbnailGroup(ThumbnailGroup::Normal); | 246 | provider.setThumbnailGroup(ThumbnailGroup::Normal); | ||
247 | provider.appendItems(list); | 247 | provider.appendItems(list); | ||
248 | syncRun(&provider); | 248 | syncRun(&provider); | ||
249 | while (!ThumbnailProvider::isThumbnailWriterEmpty()) { | 249 | while (!ThumbnailProvider::isThumbnailWriterEmpty()) { | ||
250 | QTest::qWait(100); | 250 | QTest::qWait(100); | ||
251 | } | 251 | } | ||
252 | 252 | | |||
253 | QDir thumbnailDir = ThumbnailProvider::thumbnailBaseDir(ThumbnailGroup::Normal); | 253 | QDir thumbnailDir = ThumbnailProvider::thumbnailBaseDir(ThumbnailGroup::Normal); | ||
254 | QStringList entryList = thumbnailDir.entryList(QStringList("*.png")); | 254 | QStringList entryList = thumbnailDir.entryList(QStringList("*.png")); | ||
255 | QCOMPARE(entryList.count(), 1); | 255 | QCOMPARE(entryList.count(), 1); | ||
256 | } | 256 | } | ||
257 | 257 | | |||
258 | void ThumbnailProviderTest::testRemoveItemsWhileGenerating() | 258 | void ThumbnailProviderTest::testRemoveItemsWhileGenerating() | ||
259 | { | 259 | { | ||
260 | QDir dir(mSandBox.mPath); | 260 | QDir dir(mSandBox.mPath); | ||
261 | 261 | | |||
262 | // Create a list of items which will be thumbnailed | 262 | // Create a list of items which will be thumbnailed | ||
263 | KFileItemList list; | 263 | KFileItemList list; | ||
264 | Q_FOREACH(const QFileInfo & info, dir.entryInfoList(QDir::Files)) { | 264 | Q_FOREACH(const QFileInfo & info, dir.entryInfoList(QDir::Files)) { | ||
265 | QUrl url("file://" + info.absoluteFilePath()); | 265 | QUrl url("file://" + info.absoluteFilePath()); | ||
266 | KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url); | 266 | KFileItem item(url); | ||
267 | list << item; | 267 | list << item; | ||
268 | } | 268 | } | ||
269 | 269 | | |||
270 | // Start generating thumbnails for items | 270 | // Start generating thumbnails for items | ||
271 | ThumbnailProvider provider; | 271 | ThumbnailProvider provider; | ||
272 | provider.setThumbnailGroup(ThumbnailGroup::Normal); | 272 | provider.setThumbnailGroup(ThumbnailGroup::Normal); | ||
273 | provider.appendItems(list); | 273 | provider.appendItems(list); | ||
274 | QEventLoop loop; | 274 | QEventLoop loop; | ||
275 | connect(&provider, SIGNAL(finished()), &loop, SLOT(quit())); | 275 | connect(&provider, SIGNAL(finished()), &loop, SLOT(quit())); | ||
276 | 276 | | |||
277 | // Remove items, it should not crash | 277 | // Remove items, it should not crash | ||
278 | provider.removeItems(list); | 278 | provider.removeItems(list); | ||
279 | loop.exec(); | 279 | loop.exec(); | ||
280 | } | 280 | } |