Same deal as with the kiconloader test.

I started down the route David suggested of having the icon theme in the
test dir and not copying it, but I couldn't come up with a
cross-platform way of convincing KIconLoader to look at it (passing the
path to KIconLoader::global()->reconfigure() is not sufficient, and
setting XDG_DATA_DIRS is not cross-platform).  So I ended up copying
files around anyway.

Alex
diff --git a/autotests/icons/oxygen/22x22/actions/go-up.png b/autotests/icons/oxygen/22x22/actions/go-up.png
new file mode 100644
index 0000000..4459024
Binary files /dev/null and b/autotests/icons/oxygen/22x22/actions/go-up.png differ
diff --git a/autotests/icons/oxygen/32x32/actions/go-up.png b/autotests/icons/oxygen/32x32/actions/go-up.png
new file mode 100644
index 0000000..86d1f71
Binary files /dev/null and b/autotests/icons/oxygen/32x32/actions/go-up.png differ
diff --git a/autotests/icons/oxygen/48x48/actions/go-up.png b/autotests/icons/oxygen/48x48/actions/go-up.png
new file mode 100644
index 0000000..7174fa8
Binary files /dev/null and b/autotests/icons/oxygen/48x48/actions/go-up.png differ
diff --git a/autotests/icons/oxygen/64x64/actions/go-up.png b/autotests/icons/oxygen/64x64/actions/go-up.png
new file mode 100644
index 0000000..e44c37a
Binary files /dev/null and b/autotests/icons/oxygen/64x64/actions/go-up.png differ
diff --git a/autotests/icons/oxygen/index.theme b/autotests/icons/oxygen/index.theme
new file mode 100644
index 0000000..f2d2ecc
--- /dev/null
+++ b/autotests/icons/oxygen/index.theme
@@ -0,0 +1,47 @@
+[Icon Theme]
+Name=Oxygen
+Comment=Oxygen Team
+
+DisplayDepth=32
+
+Inherits=hicolor
+
+DesktopDefault=48
+DesktopSizes=16,22,32,48,64
+ToolbarDefault=22
+ToolbarSizes=16,22,32,48
+MainToolbarDefault=22
+MainToolbarSizes=16,22,32,48
+SmallDefault=16
+SmallSizes=16,22,32,48
+PanelDefault=32
+PanelSizes=16,22,32,48,64
+DialogDefault=32
+DialogSizes=16,22,32,48,64
+
+Directories=16x16/actions,22x22/actions,32x32/actions,48x48/actions,64x64/actions
+
+[16x16/actions]
+Size=16
+Context=Actions
+Type=Threshold
+
+[22x22/actions]
+Size=22
+Context=Actions
+Type=Threshold
+
+[32x32/actions]
+Size=32
+Context=Actions
+Type=Threshold
+
+[48x48/actions]
+Size=48
+Context=Actions
+Type=Threshold
+
+[64x64/actions]
+Size=64
+Context=Actions
+Type=Threshold
diff --git a/autotests/ktoolbar_unittest.cpp b/autotests/ktoolbar_unittest.cpp
index 152cff6..3f69847 100644
--- a/autotests/ktoolbar_unittest.cpp
+++ b/autotests/ktoolbar_unittest.cpp
@@ -21,9 +21,13 @@
 #include "testxmlguiwindow.h"
 #include "testguiclient.h"
 
-#include <QTest>
-#include <QSignalSpy>
 #include <QDBusConnection>
+#include <QDir>
+#include <QFile>
+#include <QFileInfo>
+#include <QSignalSpy>
+#include <QStandardPaths>
+#include <QTest>
 #include <QToolButton>
 
 #include <ktoolbar.h>
@@ -79,10 +83,34 @@ private:
 
 QTEST_MAIN(tst_KToolBar)
 
+static void copy_dir(const QString &from, const QDir &to)
+{
+    QDir src = QDir(from);
+    QDir dest = QDir(to.filePath(src.dirName()));
+    to.mkpath(src.dirName());
+    foreach (const QFileInfo &fileInfo, src.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot)) {
+        if (fileInfo.isDir()) {
+            copy_dir(fileInfo.filePath(), dest);
+        } else {
+            QFile::copy(fileInfo.filePath(), dest.filePath(fileInfo.fileName()));
+        }
+    }
+}
+
 // This will be called before the first test function is executed.
 // It is only called once.
 void tst_KToolBar::initTestCase()
 {
+    QStandardPaths::setTestModeEnabled(true);
+
+    // copy a minimal icon theme to where KIconTheme will find it, in case oxygen-icons is not
+    // installed
+    QDir testDataDir = QDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation));
+    QDir testIconsDir = QDir(testDataDir.absoluteFilePath(QStringLiteral("icons")));
+    QVERIFY(testIconsDir.absolutePath().contains(QStringLiteral("qttest")));
+    testIconsDir.removeRecursively();
+    copy_dir(QFINDTESTDATA("icons"), testDataDir);
+
     m_xml =
         "<?xml version = '1.0'?>\n"
         "<!DOCTYPE gui SYSTEM \"kpartgui.dtd\">\n"
@@ -120,6 +148,10 @@ void tst_KToolBar::initTestCase()
 // It is only called once.
 void tst_KToolBar::cleanupTestCase()
 {
+    QDir testDataDir = QDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation));
+    QDir testIconsDir = QDir(testDataDir.absoluteFilePath(QStringLiteral("icons")));
+    QVERIFY(testIconsDir.absolutePath().contains(QStringLiteral("qttest")));
+    testIconsDir.removeRecursively();
 }
 
 // This will be called before each test function is executed.
_______________________________________________
Kde-frameworks-devel mailing list
Kde-frameworks-devel@kde.org
https://mail.kde.org/mailman/listinfo/kde-frameworks-devel

Reply via email to