mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-02 23:35:40 +08:00
refs #695 Allow to set a mock root directory for caches, for unit tests.
This commit is contained in:
@@ -99,10 +99,7 @@ namespace BlackMisc
|
|||||||
|
|
||||||
const QString &CDataCache::persistentStore()
|
const QString &CDataCache::persistentStore()
|
||||||
{
|
{
|
||||||
static const QString dir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) +
|
static const QString dir = getCacheRootDirectory() + "/data/cache/core";
|
||||||
"/org.swift-project/" +
|
|
||||||
CDirectoryUtils::normalizedApplicationDirectory() +
|
|
||||||
"/data/cache/core";
|
|
||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,10 +26,7 @@ namespace BlackMisc
|
|||||||
|
|
||||||
const QString &CSettingsCache::persistentStore()
|
const QString &CSettingsCache::persistentStore()
|
||||||
{
|
{
|
||||||
static const QString dir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) +
|
static const QString dir = getCacheRootDirectory() + "/settings/core";
|
||||||
"/org.swift-project/" +
|
|
||||||
CDirectoryUtils::normalizedApplicationDirectory() +
|
|
||||||
"/settings/core";
|
|
||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include "blackmisc/valuecache.h"
|
#include "blackmisc/valuecache.h"
|
||||||
#include "blackmisc/atomicfile.h"
|
#include "blackmisc/atomicfile.h"
|
||||||
|
#include "blackmisc/directoryutils.h"
|
||||||
#include "blackmisc/identifier.h"
|
#include "blackmisc/identifier.h"
|
||||||
#include "blackmisc/lockfree.h"
|
#include "blackmisc/lockfree.h"
|
||||||
#include "blackmisc/logcategory.h"
|
#include "blackmisc/logcategory.h"
|
||||||
@@ -28,6 +29,7 @@
|
|||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QMetaMethod>
|
#include <QMetaMethod>
|
||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
|
#include <QStandardPaths>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <Qt>
|
#include <Qt>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@@ -46,6 +48,28 @@ namespace BlackMisc
|
|||||||
bool isSafeToIncrement(const T &value) { return value < std::numeric_limits<T>::max(); }
|
bool isSafeToIncrement(const T &value) { return value < std::numeric_limits<T>::max(); }
|
||||||
|
|
||||||
|
|
||||||
|
//! \private
|
||||||
|
std::pair<QString &, std::atomic<bool> &> getCacheRootDirectoryMutable()
|
||||||
|
{
|
||||||
|
static QString dir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) +
|
||||||
|
"/org.swift-project/" + CDirectoryUtils::normalizedApplicationDirectory();
|
||||||
|
static std::atomic<bool> frozen { false };
|
||||||
|
return { dir, frozen };
|
||||||
|
}
|
||||||
|
|
||||||
|
void setMockCacheRootDirectory(const QString &dir)
|
||||||
|
{
|
||||||
|
Q_ASSERT_X(! getCacheRootDirectoryMutable().second, Q_FUNC_INFO, "Too late to call this function");
|
||||||
|
getCacheRootDirectoryMutable().first = dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &CValueCache::getCacheRootDirectory()
|
||||||
|
{
|
||||||
|
getCacheRootDirectoryMutable().second = true;
|
||||||
|
return getCacheRootDirectoryMutable().first;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
// CValueCachePacket
|
// CValueCachePacket
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|||||||
@@ -48,6 +48,13 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
class CLogCategoryList;
|
class CLogCategoryList;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Overwrite the default root directory for cache and settings, for testing purposes.
|
||||||
|
*
|
||||||
|
* May not be called after any cache or settings objects have been constructed.
|
||||||
|
*/
|
||||||
|
BLACKMISC_EXPORT void setMockCacheRootDirectory(const QString &path);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Value class used for signalling changed values in the cache.
|
* Value class used for signalling changed values in the cache.
|
||||||
*/
|
*/
|
||||||
@@ -280,6 +287,9 @@ namespace BlackMisc
|
|||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
qint64 getTimestampSync(const QString &key) { return std::get<1>(getValue(key)); }
|
qint64 getTimestampSync(const QString &key) { return std::get<1>(getValue(key)); }
|
||||||
|
|
||||||
|
//! \private
|
||||||
|
static const QString &getCacheRootDirectory();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class Private::CValuePage;
|
friend class Private::CValuePage;
|
||||||
struct Element;
|
struct Element;
|
||||||
|
|||||||
Reference in New Issue
Block a user