{
Q_OBJECT
+public:
+ tst_QNetworkDiskCache();
+
public slots:
void initTestCase();
void cleanupTestCase();
void sync();
void crashWhenParentingCache();
+
+private:
+ QTemporaryDir tempDir;
};
// FIXME same as in tst_qnetworkreply.cpp .. could be unified
qint64 call_expire()
{ return SubQNetworkDiskCache::expire(); }
- void setupWithOne(const QUrl &url, const QNetworkCacheMetaData &metaData = QNetworkCacheMetaData())
+ void setupWithOne(const QString &path, const QUrl &url, const QNetworkCacheMetaData &metaData = QNetworkCacheMetaData())
{
- setCacheDirectory(QDir::tempPath() + "/diskCache");
+ setCacheDirectory(path);
QIODevice *d = 0;
if (metaData.isValid()) {
}
};
+tst_QNetworkDiskCache::tst_QNetworkDiskCache()
+ : tempDir(QDir::tempPath() + "/tst_qnetworkdiskcache.XXXXXX")
+{
+}
+
// This will be called before the first test function is executed.
// It is only called once.
void tst_QNetworkDiskCache::initTestCase()
{
+ QVERIFY(tempDir.isValid());
+
SubQNetworkDiskCache cache;
- cache.setCacheDirectory(QDir::tempPath() + "/diskCache");
- cache.clear();
- QString s = QDir::tempPath() + "/diskCache/";
- QDir dir;
- dir.rmdir(s + "data7"); // the number is the internal cache version
- dir.rmdir(s + "prepared");
- dir.rmdir(s);
- dir.rmdir(s + "http"); // delete directory used by 4.7 and earlier (would make the tests fail)
+ cache.setCacheDirectory(tempDir.path());
}
// This will be called after the last test function is executed.
QNetworkCacheMetaData metaData;
metaData.setUrl(url);
badCache.prepare(metaData);
- badCache.setCacheDirectory(QDir::tempPath() + "/diskCache");
+ badCache.setCacheDirectory(tempDir.path());
badCache.prepare(metaData);
}
void tst_QNetworkDiskCache::prepare()
{
SubQNetworkDiskCache cache;
- cache.setCacheDirectory(QDir::tempPath() + "/diskCache");
+ cache.setCacheDirectory(tempDir.path());
QUrl url(EXAMPLE_URL);
QNetworkCacheMetaData metaData;
void tst_QNetworkDiskCache::cacheSize()
{
SubQNetworkDiskCache cache;
- cache.setCacheDirectory(QDir::tempPath() + "/diskCache");
+ cache.setCacheDirectory(tempDir.path());
QCOMPARE(cache.cacheSize(), qint64(0));
QUrl url(EXAMPLE_URL);
{
SubQNetworkDiskCache cache;
QUrl url(EXAMPLE_URL);
- cache.setupWithOne(url);
+ cache.setupWithOne(tempDir.path(), url);
QVERIFY(cache.cacheSize() > qint64(0));
QString cacheDirectory = cache.cacheDirectory();
QFETCH(QNetworkCacheMetaData, data);
SubQNetworkDiskCache cache;
QUrl url(EXAMPLE_URL);
- cache.setupWithOne(url, data);
+ cache.setupWithOne(tempDir.path(), url, data);
for (int i = 0; i < 3; ++i) {
QIODevice *d = cache.data(url);
metaData.setExpirationDate(QDateTime::currentDateTime());
metaData.setSaveToDisk(true);
- cache.setupWithOne(url, metaData);
+ cache.setupWithOne(tempDir.path(), url, metaData);
for (int i = 0; i < 3; ++i) {
QNetworkCacheMetaData cacheMetaData = cache.metaData(url);
{
SubQNetworkDiskCache cache;
QUrl url(EXAMPLE_URL);
- cache.setupWithOne(url);
+ cache.setupWithOne(tempDir.path(), url);
QString cacheDirectory = cache.cacheDirectory();
QCOMPARE(countFiles(cacheDirectory).count(), NUM_SUBDIRECTORIES + 3);
cache.remove(url);
{
QUrl url(EXAMPLE_URL);
SubQNetworkDiskCache cache;
- cache.setupWithOne(url);
+ cache.setupWithOne(tempDir.path(), url);
QNetworkCacheMetaData metaData = cache.metaData(url);
metaData.setLastModified(QDateTime::currentDateTime());
{
SubQNetworkDiskCache cache;
QUrl url(EXAMPLE_URL);
- cache.setupWithOne(url);
+ cache.setupWithOne(tempDir.path(), url);
url.setPassword(QString());
url.setFragment(QString());
void tst_QNetworkDiskCache::expire()
{
SubQNetworkDiskCache cache;
- cache.setCacheDirectory(QDir::tempPath() + "/diskCache");
+ cache.setCacheDirectory(tempDir.path());
QCOMPARE(cache.call_expire(), (qint64)0);
QUrl url(EXAMPLE_URL);
- cache.setupWithOne(url);
+ cache.setupWithOne(tempDir.path(), url);
QVERIFY(cache.call_expire() > (qint64)0);
qint64 limit = (1024 * 1024 / 4) * 5;
cache.setMaximumCacheSize(limit);
QFETCH(int, pass);
SubQNetworkDiskCache cache;
QUrl url(EXAMPLE_URL);
- cache.setupWithOne(url);
+ cache.setupWithOne(tempDir.path(), url);
if (pass == 0) {
QString name;
{
public:
- Runner()
+ Runner(const QString& cachePath)
: QThread()
, other(0)
+ , cachePath(cachePath)
{}
void run()
metaData2.setExpirationDate(dt);
QNetworkDiskCache cache;
- cache.setCacheDirectory(QDir::tempPath() + "/diskCache");
+ cache.setCacheDirectory(cachePath);
int read = 0;
QDateTime dt;
bool write;
Runner *other;
+ QString cachePath;
};
void tst_QNetworkDiskCache::crashWhenParentingCache()
QTime midnight(0, 0, 0);
qsrand(midnight.secsTo(QTime::currentTime()));
- Runner reader;
+ Runner reader(tempDir.path());
reader.dt = QDateTime::currentDateTime();
reader.write = false;
- Runner writer;
+ Runner writer(tempDir.path());
writer.dt = reader.dt;
writer.write = true;