Commit a14e8081 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Test initializing an empty resources folder

parent d92df10d
......@@ -19,6 +19,7 @@
#include "KisResourceLocator.h"
#include <QDebug>
#include <QList>
#include <QDir>
#include <QFileInfo>
......@@ -71,13 +72,13 @@ KisResourceLocator::LocatorError KisResourceLocator::initialize(const QString &i
if (!fi.exists()) {
if (!QDir().mkpath(d->resourceLocation)) {
d->errorMessages << i18n("Could not create the resource location at %1.", d->resourceLocation);
d->errorMessages << i18n("1. Could not create the resource location at %1.", d->resourceLocation);
return LocatorError::CannotCreateLocation;
}
}
if (!fi.isWritable()) {
d->errorMessages << i18n("The resource location at %1 is not writable.", d->resourceLocation);
d->errorMessages << i18n("2. The resource location at %1 is not writable.", d->resourceLocation);
return LocatorError::LocationReadOnly;
}
......@@ -91,28 +92,28 @@ KisResourceLocator::LocatorError KisResourceLocator::initialize(const QString &i
return LocatorError::Ok;
}
QStringList KisResourceLocator::errorMessages() const
{
return d->errorMessages;
}
KisResourceLocator::LocatorError KisResourceLocator::firstTimeInstallation(const QString &installationResourcesLocation)
{
Q_FOREACH(const QString &folder, resourceTypeFolders) {
QFileInfo fi(d->resourceLocation + '/' + folder + '/');
QDir dir;
if (!fi.exists()) {
if (!dir.mkpath(fi.canonicalFilePath())) {
d->errorMessages << i18n("Could not create the resource location at %1.", fi.canonicalPath());
QDir dir(d->resourceLocation + '/' + folder + '/');
if (!dir.exists()) {
if (!dir.mkpath(dir.path())) {
d->errorMessages << i18n("3. Could not create the resource location at %1.", dir.path());
return LocatorError::CannotCreateLocation;
}
}
if (!fi.isWritable()) {
d->errorMessages << i18n("The resource location at %1 is not writable.", fi.canonicalPath());
return LocatorError::LocationReadOnly;
}
}
Q_FOREACH(const QString &folder, resourceTypeFolders) {
QDir dir(installationResourcesLocation + "/share/krita" + folder + '/');
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);
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";
......
......@@ -55,7 +55,7 @@ public:
*/
LocatorError initialize(const QString &installationResourcesLocation);
QString lastErrorMessage() const;
QStringList errorMessages() const;
private:
......
......@@ -42,14 +42,16 @@ void TestResourceLocator::initTestCase()
srcLocation = QString(FILES_DATA_DIR);
QVERIFY2(QDir(srcLocation).exists(), srcLocation.toUtf8());
dstLocation = QString(FILES_DEST_DIR);
cleanDstLocation();
KConfigGroup cfg(KSharedConfig::openConfig(), "");
cfg.writeEntry(KisResourceLocator::resourceLocationKey, dstLocation);
}
void TestResourceLocator::testLocator()
{
KisResourceLocator locator;
KisResourceLocator::LocatorError r = locator.initialize(dstLocation);
if (!locator.errorMessages().isEmpty()) qDebug() << locator.errorMessages();
QVERIFY(r == KisResourceLocator::LocatorError::Ok);
QVERIFY(QDir(dstLocation).exists());
Q_FOREACH(const QString &folder, KisResourceLocator::resourceTypeFolders) {
......@@ -63,7 +65,7 @@ void TestResourceLocator::testLocator()
void TestResourceLocator::cleanupTestCase()
{
cleanDstLocation();
// cleanDstLocation();
}
bool TestResourceLocator::cleanDstLocation()
......
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