Move data generation to initTestCase() method and store the results.
Per the comments on Ie4100a1ca4dbe7bf1cd73de883a9854377ac2f5e, having Q_ASSERT was not a good idea, and data functions can't really handle QVERIFY/QCOMPARE/etc, so do this in initTestCase instead. Change-Id: I19e61dec7fe415bb1fa0f53a2920d99b8c7c8ea7 Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
This commit is contained in:
parent
0f3d9b1d84
commit
57004b7fda
@ -54,6 +54,7 @@ class tst_QHash : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void qhash_qt4_data() { data(); }
|
||||
void qhash_qt4();
|
||||
void qhash_faster_data() { data(); }
|
||||
@ -63,90 +64,75 @@ private slots:
|
||||
|
||||
private:
|
||||
void data();
|
||||
|
||||
QStringList smallFilePaths;
|
||||
QStringList uuids;
|
||||
QStringList dict;
|
||||
QStringList numbers;
|
||||
};
|
||||
|
||||
///////////////////// QHash /////////////////////
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
void tst_QHash::initTestCase()
|
||||
{
|
||||
// small list of file paths
|
||||
QFile smallPathsData("paths_small_data.txt");
|
||||
QVERIFY(smallPathsData.open(QIODevice::ReadOnly));
|
||||
smallFilePaths = QString::fromLatin1(smallPathsData.readAll()).split(QLatin1Char('\n'));
|
||||
QVERIFY(!smallFilePaths.isEmpty());
|
||||
|
||||
// list of UUIDs
|
||||
// guaranteed to be completely random, generated by http://xkcd.com/221/
|
||||
QUuid ns = QUuid("{f43d2ef3-2fe9-4563-a6f5-5a0100c2d699}");
|
||||
uuids.reserve(smallFilePaths.size());
|
||||
|
||||
foreach (const QString &path, smallFilePaths)
|
||||
uuids.append(QUuid::createUuidV5(ns, path).toString());
|
||||
|
||||
|
||||
// lots of strings with alphabetical characters, vaguely reminiscent of
|
||||
// a dictionary.
|
||||
//
|
||||
// this programatically generates a series like:
|
||||
// AAAAAA
|
||||
// AAAAAB
|
||||
// AAAAAC
|
||||
// ...
|
||||
// AAAAAZ
|
||||
// AAAABZ
|
||||
// ...
|
||||
// AAAAZZ
|
||||
// AAABZZ
|
||||
QByteArray id("AAAAAAA");
|
||||
|
||||
if (dict.isEmpty()) {
|
||||
for (int i = id.length() - 1; i > 0;) {
|
||||
dict.append(id);
|
||||
char c = id.at(i);
|
||||
id[i] = ++c;
|
||||
|
||||
if (c == 'Z') {
|
||||
// wrap to next digit
|
||||
i--;
|
||||
id[i] = 'A';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// string versions of numbers.
|
||||
for (int i = 5000000; i < 5005001; ++i)
|
||||
numbers.append(QString::number(i));
|
||||
}
|
||||
|
||||
void tst_QHash::data()
|
||||
{
|
||||
QTest::addColumn<QStringList>("items");
|
||||
static QStringList smallFilePaths;
|
||||
|
||||
{
|
||||
// small list of file paths
|
||||
if (smallFilePaths.isEmpty()) {
|
||||
QFile smallPathsData("paths_small_data.txt");
|
||||
QVERIFY(smallPathsData.open(QIODevice::ReadOnly));
|
||||
smallFilePaths = QString::fromLatin1(smallPathsData.readAll()).split(QLatin1Char('\n'));
|
||||
Q_ASSERT(!smallFilePaths.isEmpty());
|
||||
}
|
||||
|
||||
QTest::newRow("paths-small") << smallFilePaths;
|
||||
}
|
||||
|
||||
{
|
||||
// list of UUIDs
|
||||
static QStringList uuids;
|
||||
if (uuids.isEmpty()) {
|
||||
// guaranteed to be completely random, generated by http://xkcd.com/221/
|
||||
QUuid ns = QUuid("{f43d2ef3-2fe9-4563-a6f5-5a0100c2d699}");
|
||||
uuids.reserve(smallFilePaths.size());
|
||||
|
||||
foreach (const QString &path, smallFilePaths)
|
||||
uuids.append(QUuid::createUuidV5(ns, path).toString());
|
||||
}
|
||||
|
||||
QTest::newRow("uuids-list") << uuids;
|
||||
}
|
||||
|
||||
{
|
||||
// lots of strings with alphabetical characters, vaguely reminiscent of
|
||||
// a dictionary.
|
||||
//
|
||||
// this programatically generates a series like:
|
||||
// AAAAAA
|
||||
// AAAAAB
|
||||
// AAAAAC
|
||||
// ...
|
||||
// AAAAAZ
|
||||
// AAAABZ
|
||||
// ...
|
||||
// AAAAZZ
|
||||
// AAABZZ
|
||||
QByteArray id("AAAAAAA");
|
||||
static QStringList dict;
|
||||
|
||||
if (dict.isEmpty()) {
|
||||
for (int i = id.length() - 1; i > 0;) {
|
||||
dict.append(id);
|
||||
char c = id.at(i);
|
||||
id[i] = ++c;
|
||||
|
||||
if (c == 'Z') {
|
||||
// wrap to next digit
|
||||
i--;
|
||||
id[i] = 'A';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QTest::newRow("dictionary") << dict;
|
||||
}
|
||||
|
||||
{
|
||||
// string versions of numbers.
|
||||
static QStringList numbers;
|
||||
|
||||
if (numbers.isEmpty()) {
|
||||
for (int i = 5000000; i < 5005001; ++i)
|
||||
numbers.append(QString::number(i));
|
||||
}
|
||||
|
||||
QTest::newRow("numbers") << numbers;
|
||||
}
|
||||
|
||||
QTest::newRow("paths-small") << smallFilePaths;
|
||||
QTest::newRow("uuids-list") << uuids;
|
||||
QTest::newRow("dictionary") << dict;
|
||||
QTest::newRow("numbers") << numbers;
|
||||
}
|
||||
|
||||
void tst_QHash::qhash_qt4()
|
||||
|
Loading…
Reference in New Issue
Block a user