diff options
Diffstat (limited to 'tests/auto/gui/image/qicon/tst_qicon.cpp')
-rw-r--r-- | tests/auto/gui/image/qicon/tst_qicon.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/auto/gui/image/qicon/tst_qicon.cpp b/tests/auto/gui/image/qicon/tst_qicon.cpp index 9ed3873682..afa72f6922 100644 --- a/tests/auto/gui/image/qicon/tst_qicon.cpp +++ b/tests/auto/gui/image/qicon/tst_qicon.cpp @@ -63,6 +63,7 @@ private slots: void streamAvailableSizes_data(); void streamAvailableSizes(); void fromTheme(); + void fromThemeCache(); #ifndef QT_NO_WIDGETS void task184901_badCache(); @@ -633,6 +634,69 @@ void tst_QIcon::fromTheme() QVERIFY(abIcon.isNull()); } +void tst_QIcon::fromThemeCache() +{ + QTemporaryDir dir; + QVERIFY(QDir().mkpath(dir.path() + QLatin1String("/testcache/16x16/actions"))); + QVERIFY(QFile(QStringLiteral(":/styles/commonstyle/images/standardbutton-open-16.png")) + .copy( dir.path() + QLatin1String("/testcache/16x16/actions/button-open.png"))); + + { + QFile index(dir.path() + QLatin1String("/testcache/index.theme")); + QVERIFY(index.open(QFile::WriteOnly)); + index.write("[Icon Theme]\nDirectories=16x16/actions\n[16x16/actions]\nSize=16\nContext=Actions\nType=Fixed\n"); + } + QIcon::setThemeSearchPaths(QStringList() << dir.path()); + QIcon::setThemeName("testcache"); + + // We just created a theme with that icon, it must exist + QVERIFY(!QIcon::fromTheme("button-open").isNull()); + + QString cacheName = dir.path() + QLatin1String("/testcache/icon-theme.cache"); + + // An invalid cache should not prevent lookup + { + QFile cacheFile(cacheName); + QVERIFY(cacheFile.open(QFile::WriteOnly)); + QDataStream(&cacheFile) << quint16(1) << quint16(0) << "invalid corrupted stuff in there\n"; + } + QIcon::setThemeSearchPaths(QStringList() << dir.path()); // reload themes + QVERIFY(!QIcon::fromTheme("button-open").isNull()); + + // An empty cache should prevent the lookup + { + QFile cacheFile(cacheName); + QVERIFY(cacheFile.open(QFile::WriteOnly)); + QDataStream ds(&cacheFile); + ds << quint16(1) << quint16(0); // 0: version + ds << quint32(12) << quint32(20); // 4: hash offset / dir list offset + ds << quint32(1) << quint32(0xffffffff); // 12: one empty bucket + ds << quint32(1) << quint32(28); // 20: list with one element + ds.writeRawData("16x16/actions", sizeof("16x16/actions")); // 28 + } + QIcon::setThemeSearchPaths(QStringList() << dir.path()); // reload themes + QVERIFY(QIcon::fromTheme("button-open").isNull()); // The icon was not in the cache, it should not be found + + // Adding an icon should be changing the modification date of one sub directory which should make the cache ignored + QTest::qWait(1000); // wait enough to have a different modification time in seconds + QVERIFY(QFile(QStringLiteral(":/styles/commonstyle/images/standardbutton-save-16.png")) + .copy(dir.path() + QLatin1String("/testcache/16x16/actions/button-save.png"))); + QVERIFY(QFileInfo(cacheName).lastModified() < QFileInfo(dir.path() + QLatin1String("/testcache/16x16/actions")).lastModified()); + QIcon::setThemeSearchPaths(QStringList() << dir.path()); // reload themes + QVERIFY(!QIcon::fromTheme("button-open").isNull()); + + // Try to run the actual gtk-update-icon-cache and make sure that icons are still found + QProcess process; + process.start(QStringLiteral("gtk-update-icon-cache"), + QStringList() << QStringLiteral("-f") << QStringLiteral("-t") << (dir.path() + QLatin1String("/testcache"))); + if (!process.waitForFinished()) + QSKIP("gtk-update-icon-cache not run"); + QVERIFY(QFileInfo(cacheName).lastModified() >= QFileInfo(dir.path() + QLatin1String("/testcache/16x16/actions")).lastModified()); + QIcon::setThemeSearchPaths(QStringList() << dir.path()); // reload themes + QVERIFY(!QIcon::fromTheme("button-open").isNull()); + QVERIFY(!QIcon::fromTheme("button-open-fallback").isNull()); + QVERIFY(QIcon::fromTheme("notexist-fallback").isNull()); +} void tst_QIcon::task223279_inconsistentAddFile() { |