Commit d80062aa authored by Boudewijn Rempt's avatar Boudewijn Rempt

Add test for KisResourceStorage

parent 21af93e5
......@@ -30,6 +30,7 @@ target_link_libraries(kritaresources
KF5::ConfigCore
KF5::CoreAddons
KF5::I18n
KF5::Archive
)
set_target_properties(kritaresources PROPERTIES
......
......@@ -22,6 +22,7 @@
#include <QDebug>
#include <QList>
#include <QDir>
#include <QDirIterator>
#include <QFileInfo>
#include <QMessageBox>
#include <QVersionNumber>
......@@ -34,6 +35,7 @@
#include <KritaVersionWrapper.h>
#include "KoResourcePaths.h"
#include "KisResourceStorage.h"
#include "KisResourceCacheDb.h"
const QString KisResourceLocator::resourceLocationKey {"ResourceDirectory"};
const QStringList KisResourceLocator::resourceTypeFolders = QStringList()
......@@ -109,9 +111,20 @@ KisResourceLocator::LocatorError KisResourceLocator::initialize(const QString &i
if (res != LocatorError::Ok) {
return res;
}
initalizationStatus = InitalizationStatus::Initialized;
}
return LocatorError::Ok;
// Add the folder
d->storages.append(QSharedPointer<KisResourceStorage>::create(d->resourceLocation));
// And add bundles and adobe libraries
QStringList filters = QStringList() << "*.bundle" << "*.abr" << "*.asl";
QDirIterator iter(d->resourceLocation, filters, QDir::Files, QDirIterator::Subdirectories);
while (iter.hasNext()) {
d->storages.append(QSharedPointer<KisResourceStorage>::create(iter.filePath()));
}
return synchronizeDb();
}
QStringList KisResourceLocator::errorMessages() const
......
......@@ -19,18 +19,56 @@
#include "KisResourceStorage.h"
#include <kzip.h>
#include <QFileInfo>
class KisResourceStorage::Private {
public:
QString location;
bool valid {false};
KisResourceStorage::StorageType storageType {KisResourceStorage::StorageType::Unknown};
};
KisResourceStorage::KisResourceStorage()
KisResourceStorage::KisResourceStorage(const QString &location)
: d(new Private())
{
d->location = location;
QFileInfo fi(d->location);
if (fi.isDir()) {
d->storageType = StorageType::Folder;
d->valid = fi.isWritable();
}
else {
if (d->location.endsWith(".bundle")) {
d->storageType = StorageType::Bundle;
// XXX: should we also check whether there's a valid metadata entry? Or is this enough?
d->valid = (fi.isReadable() && KZip(d->location).open(QIODevice::ReadOnly));
}
else if (d->location.endsWith(".abr")) {
d->storageType = StorageType::AdobeBrushLibrary;
d->valid = fi.isReadable();
}
else if (d->location.endsWith(".asl")) {
d->storageType = StorageType::AdobeStyleLibrary;
d->valid = fi.isReadable();
}
}
}
KisResourceStorage::~KisResourceStorage()
{
}
KisResourceStorage::StorageType KisResourceStorage::type() const
{
return d->storageType;
}
bool KisResourceStorage::valid() const
{
return d->valid;
}
......@@ -22,6 +22,7 @@
#include <QSharedPointer>
#include <QScopedPointer>
#include <QString>
#include <kritaresources_export.h>
......@@ -34,13 +35,27 @@
class KRITARESOURCES_EXPORT KisResourceStorage
{
public:
KisResourceStorage();
enum class StorageType {
Unknown,
Folder,
Bundle,
AdobeBrushLibrary,
AdobeStyleLibrary
};
KisResourceStorage(const QString &location);
~KisResourceStorage();
bool valid() const;
StorageType type() const;
private:
class Private;
QScopedPointer<Private> d;
};
typedef QSharedPointer<KisResourceStorage> KisResourceStorageSP;
#endif // KISRESOURCESTORAGE_H
......@@ -22,9 +22,44 @@
#include <KisResourceStorage.h>
#ifndef FILES_DATA_DIR
#error "FILES_DATA_DIR not set. A directory with the data used for testing installing resources"
#endif
void TestResourceStorage ::testStorage()
{
{
KisResourceStorage storage(QString(FILES_DATA_DIR));
QVERIFY(storage.type() == KisResourceStorage::StorageType::Folder);
QVERIFY(storage.valid());
}
{
KisResourceStorage storage(QString(FILES_DATA_DIR) + "/bundles/test1.bundle");
QVERIFY(storage.type() == KisResourceStorage::StorageType::Bundle);
QVERIFY(!storage.valid());
}
{
KisResourceStorage storage(QString(FILES_DATA_DIR) + "/bundles/test2.bundle");
QVERIFY(storage.type() == KisResourceStorage::StorageType::Bundle);
QVERIFY(storage.valid());
}
{
KisResourceStorage storage(QString(FILES_DATA_DIR) + "/brushes/test.abr");
QVERIFY(storage.type() == KisResourceStorage::StorageType::AdobeBrushLibrary);
QVERIFY(storage.valid());
}
{
KisResourceStorage storage(QString(FILES_DATA_DIR) + "/brushes/test.gbr");
QVERIFY(storage.type() == KisResourceStorage::StorageType::Unknown);
QVERIFY(!storage.valid());
}
}
......
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