This file is part of the KDE libraries
SPDX-FileCopyrightText: 2012 David Faure <faure@kde.org>
SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include <kshareddatacache.h>
#include <QStandardPaths>
#include <QTest>
#include <QObject>
#include <QStandardPaths>
#include <QString>
#include <string.h>
class KSharedDataCacheTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void simpleInsert();
};
void KSharedDataCacheTest::initTestCase()
{
}
void KSharedDataCacheTest::simpleInsert()
{
const QLatin1String cacheName("myTestCache");
const QLatin1String key("mypic");
QString cacheFile = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QLatin1String("/") + cacheName + QLatin1String(".kcache");
QFile file(cacheFile);
if (file.exists()) {
QVERIFY(file.remove());
}
KSharedDataCache cache(cacheName, 5 * 1024 * 1024);
#ifndef Q_OS_WIN
QVERIFY(file.exists());
#endif
QByteArray data;
data.resize(9228);
strcpy(data.data(), "Hello world");
QVERIFY(cache.insert(key, data));
QByteArray result;
QVERIFY(cache.find(key, &result));
QCOMPARE(result, data);
strcpy(data.data(), "Hello KDE");
QVERIFY(cache.insert(key, data));
QVERIFY(cache.find(key, &result));
QCOMPARE(result, data);
}
QTEST_MAIN(KSharedDataCacheTest)
#include "kshareddatacachetest.moc"