Commit d92df10d authored by Boudewijn Rempt's avatar Boudewijn Rempt

Add dummy files for the resource locator test

parent f47871ad
......@@ -29,6 +29,7 @@
#include <ksharedconfig.h>
#include <klocalizedstring.h>
#include "KoResourcePaths.h"
#include "KisResourceStorage.h"
const QString KisResourceLocator::resourceLocationKey {"ResourceDirectory"};
......@@ -43,13 +44,7 @@ const QStringList KisResourceLocator::resourceTypeFolders = QStringList()
<< "patterns"
<< "taskset"
<< "workspaces"
<< "input"
<< "pykrita"
<< "symbols"
<< "color-schemes"
<< "preset_icons"
<< "preset_icons/tool_icons"
<< "preset_icons/emblem_icons";
<< "symbols";
class KisResourceLocator::Private {
public:
......@@ -67,7 +62,7 @@ KisResourceLocator::~KisResourceLocator()
{
}
KisResourceLocator::LocatorError KisResourceLocator::initialize()
KisResourceLocator::LocatorError KisResourceLocator::initialize(const QString &installationResourcesLocation)
{
KConfigGroup cfg(KSharedConfig::openConfig(), "");
d->resourceLocation = cfg.readEntry(resourceLocationKey, QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
......@@ -87,21 +82,19 @@ KisResourceLocator::LocatorError KisResourceLocator::initialize()
}
if (QDir(d->resourceLocation).isEmpty()) {
KisResourceLocator::LocatorError res = firstTimeInstallation();
KisResourceLocator::LocatorError res = firstTimeInstallation(installationResourcesLocation);
if (res != LocatorError::Ok) {
return res;
}
}
return LocatorError::Ok;
}
KisResourceLocator::LocatorError KisResourceLocator::firstTimeInstallation()
KisResourceLocator::LocatorError KisResourceLocator::firstTimeInstallation(const QString &installationResourcesLocation)
{
Q_FOREACH(const QString &folder, resourceTypeFolders) {
QFileInfo fi(d->resourceLocation + "/" + folder + "/");
QFileInfo fi(d->resourceLocation + '/' + folder + '/');
QDir dir;
if (!fi.exists()) {
if (!dir.mkpath(fi.canonicalFilePath())) {
......@@ -115,5 +108,18 @@ KisResourceLocator::LocatorError KisResourceLocator::firstTimeInstallation()
}
}
Q_FOREACH(const QString &folder, resourceTypeFolders) {
QDir dir(installationResourcesLocation + "/share/krita" + folder + '/');
if (dir.exists()) {
Q_FOREACH(const QString &entry, dir.entryList(QDir::Files | QDir::Readable | QDir::NoDotAndDotDot)) {
QFile f(dir.canonicalPath() + entry);
bool r = f.copy(d->resourceLocation + '/' + folder + '/' + entry);
if (!r) {
d->errorMessages << "Could not copy resource" << f.fileName() << "to the resource folder";
}
}
}
}
return LocatorError::Ok;
}
......@@ -47,13 +47,19 @@ public:
CannotCreateLocation
};
LocatorError initialize();
/**
* @brief initialize Setup the resource locator for use.
*
* @param installationResourcesLocation the place where the resources
* that come packaged with Krita reside.
*/
LocatorError initialize(const QString &installationResourcesLocation);
QString lastErrorMessage() const;
private:
LocatorError firstTimeInstallation();
LocatorError firstTimeInstallation(const QString &installationResourcesLocation);
class Private;
QScopedPointer<Private> d;
......
......@@ -88,7 +88,7 @@ QString getInstallationPrefix() {
QString appPath = qApp->applicationDirPath();
appPath.chop(QString("MacOS/").length());
bool makeInstall = QDir(appPath + "/../../../share/kritaplugins").exists();
bool inBundle = QDir(appPath + "/Resources/kritaplugins").exists();
......@@ -358,7 +358,7 @@ QStringList KoResourcePaths::findDirsInternal(const QString &type)
}
QStringList filesInDir(const QString &startdir, const QString & filter, bool recursive)
QStringList KoResourcePaths::filesInDir(const QString &startdir, const QString & filter, bool recursive)
{
QStringList result;
......
......@@ -230,6 +230,8 @@ public:
*/
static bool isReady();
static QStringList filesInDir(const QString &startdir, const QString & filter, bool recursive);
private:
void addResourceTypeInternal(const QString &type, const QString &basetype,
......
add_definitions(-DFILES_DEST_DIR="${CMAKE_CURRENT_BINARY_DIR}/data/")
set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
include(ECMAddTests)
......
......@@ -21,12 +21,65 @@
#include <QTest>
#include <kconfig.h>
#include <kconfiggroup.h>
#include <ksharedconfig.h>
#include <KisResourceLocator.h>
#ifndef FILES_DATA_DIR
#error "FILES_DATA_DIR not set. A directory with the data used for testing installing resources"
#endif
#ifndef FILES_DEST_DIR
#error "FILES_DEST_DIR not set. A directory where data will be written to for testing installing resources"
#endif
void TestResourceLocator::initTestCase()
{
srcLocation = QString(FILES_DATA_DIR);
QVERIFY2(QDir(srcLocation).exists(), srcLocation.toUtf8());
dstLocation = QString(FILES_DEST_DIR);
cleanDstLocation();
}
void TestResourceLocator::testLocator()
{
KisResourceLocator locator;
KisResourceLocator::LocatorError r = locator.initialize(dstLocation);
QVERIFY(r == KisResourceLocator::LocatorError::Ok);
QVERIFY(QDir(dstLocation).exists());
Q_FOREACH(const QString &folder, KisResourceLocator::resourceTypeFolders) {
QDir dstDir(dstLocation + '/' + folder + '/');
QDir srcDir(srcLocation + '/' + folder + '/');
QVERIFY(dstDir.exists());
QVERIFY(dstDir.entryList(QDir::NoDotAndDotDot) == srcDir.entryList(QDir::NoDotAndDotDot));
}
}
void TestResourceLocator::cleanupTestCase()
{
cleanDstLocation();
}
bool TestResourceLocator::cleanDstLocation()
{
if (QDir(dstLocation).exists()) {
Q_FOREACH(const QString &folder, KisResourceLocator::resourceTypeFolders) {
QDir dir(dstLocation + '/' + folder + '/');
if (dir.exists()) {
Q_FOREACH(const QString &entry, dir.entryList(QDir::NoDotAndDotDot)) {
QFile f(dir.canonicalPath() + '/' + entry);
f.remove();
}
}
}
}
return QDir().rmpath(dstLocation);
}
QTEST_MAIN(TestResourceLocator)
......
......@@ -26,8 +26,16 @@ class TestResourceLocator : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void testLocator();
void cleanupTestCase();
private:
bool cleanDstLocation();
QString srcLocation;
QString dstLocation;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment