diff options
author | Siddharth Mathur <siddharth.mathur@nokia.com> | 2010-03-05 21:52:51 (GMT) |
---|---|---|
committer | Peter Hartmann <peter.hartmann@nokia.com> | 2011-04-01 14:02:04 (GMT) |
commit | bbc4cf1bad3c40fce3c42cf74409cdc163b04c01 (patch) | |
tree | 74e3b2265d1bb162167aa1bd745a3a695d596bd9 /tests/auto/qnetworkdiskcache | |
parent | db9a81e5cc0f18e4b6dae5edf2309c6fc90b9eb3 (diff) | |
download | Qt-bbc4cf1bad3c40fce3c42cf74409cdc163b04c01.zip Qt-bbc4cf1bad3c40fce3c42cf74409cdc163b04c01.tar.gz Qt-bbc4cf1bad3c40fce3c42cf74409cdc163b04c01.tar.bz2 |
QNetworkDiskCache: change file organization
Faster disk cache for mobile devices. Reduce file-system touching
operations and work around FAT performance issues. Features new
on-disk layout. Cached objects are now saved in multiple
subdirectories and filenames are shorter in length.
Merge-Request: 2505
Reviewed-by: Peter Hartmann
Diffstat (limited to 'tests/auto/qnetworkdiskcache')
-rw-r--r-- | tests/auto/qnetworkdiskcache/tst_qnetworkdiskcache.cpp | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/tests/auto/qnetworkdiskcache/tst_qnetworkdiskcache.cpp b/tests/auto/qnetworkdiskcache/tst_qnetworkdiskcache.cpp index e974fcc..91b0164 100644 --- a/tests/auto/qnetworkdiskcache/tst_qnetworkdiskcache.cpp +++ b/tests/auto/qnetworkdiskcache/tst_qnetworkdiskcache.cpp @@ -46,6 +46,8 @@ #include "../../shared/util.h" #define EXAMPLE_URL "http://user:pass@www.example.com/#foo" +//cached objects are organized into these many subdirs +#define NUM_SUBDIRECTORIES 16 class tst_QNetworkDiskCache : public QObject { @@ -176,8 +178,7 @@ void tst_QNetworkDiskCache::initTestCase() cache.clear(); QString s = QDir::tempPath() + "/diskCache/"; QDir dir; - dir.rmdir(s + "http"); - dir.rmdir(s + "https"); + dir.rmdir(s + "data7"); // the number is the internal cache version dir.rmdir(s + "prepared"); dir.rmdir(s); } @@ -277,16 +278,16 @@ void tst_QNetworkDiskCache::clear() QVERIFY(cache.cacheSize() > qint64(0)); QString cacheDirectory = cache.cacheDirectory(); - QCOMPARE(countFiles(cacheDirectory).count(), 3); + QCOMPARE(countFiles(cacheDirectory).count(), NUM_SUBDIRECTORIES + 3); cache.clear(); - QCOMPARE(countFiles(cacheDirectory).count(), 2); + QCOMPARE(countFiles(cacheDirectory).count(), NUM_SUBDIRECTORIES + 2); // don't delete files that it didn't create - QTemporaryFile file(cacheDirectory + "/cache_XXXXXX"); + QTemporaryFile file(cacheDirectory + "/XXXXXX"); if (file.open()) { - QCOMPARE(countFiles(cacheDirectory).count(), 3); + QCOMPARE(countFiles(cacheDirectory).count(), NUM_SUBDIRECTORIES + 3); cache.clear(); - QCOMPARE(countFiles(cacheDirectory).count(), 3); + QCOMPARE(countFiles(cacheDirectory).count(), NUM_SUBDIRECTORIES + 3); } } @@ -317,12 +318,6 @@ void tst_QNetworkDiskCache::data() QUrl url(EXAMPLE_URL); cache.setupWithOne(url, data); - // flush the cache - QTemporaryFile file(cache.cacheDirectory() + "/cache_XXXXXX.cache"); - if (file.open()) { - cache.call_fileMetaData(file.fileName()); - } - for (int i = 0; i < 3; ++i) { QIODevice *d = cache.data(url); QVERIFY(d); @@ -362,9 +357,9 @@ void tst_QNetworkDiskCache::remove() QUrl url(EXAMPLE_URL); cache.setupWithOne(url); QString cacheDirectory = cache.cacheDirectory(); - QCOMPARE(countFiles(cacheDirectory).count(), 3); + QCOMPARE(countFiles(cacheDirectory).count(), NUM_SUBDIRECTORIES + 3); cache.remove(url); - QCOMPARE(countFiles(cacheDirectory).count(), 2); + QCOMPARE(countFiles(cacheDirectory).count(), NUM_SUBDIRECTORIES + 2); } void tst_QNetworkDiskCache::setCacheDirectory_data() @@ -414,7 +409,7 @@ void tst_QNetworkDiskCache::fileMetaData() QString cacheDirectory = cache.cacheDirectory(); QStringList list = countFiles(cacheDirectory); - QCOMPARE(list.count(), 3); + QCOMPARE(list.count(), NUM_SUBDIRECTORIES + 3); foreach(QString fileName, list) { QFileInfo info(fileName); if (info.isFile()) { @@ -491,7 +486,7 @@ void tst_QNetworkDiskCache::oldCacheVersionFile() if (pass == 0) { QString name; { - QTemporaryFile file(cache.cacheDirectory() + "/cache_XXXXXX.cache"); + QTemporaryFile file(cache.cacheDirectory() + "/XXXXXX.d"); file.setAutoRemove(false); QVERIFY(file.open()); QDataStream out(&file); @@ -507,7 +502,7 @@ void tst_QNetworkDiskCache::oldCacheVersionFile() QVERIFY(!QFile::exists(name)); } else { QStringList files = countFiles(cache.cacheDirectory()); - QCOMPARE(files.count(), 3); + QCOMPARE(files.count(), NUM_SUBDIRECTORIES + 3); // find the file QString cacheFile; foreach (QString file, files) { |