Add some autotests and benchmarks for QUuid

Missing those functions for optimization.

Reviewed-by: joao
(cherry picked from commit 4e9286880fd2686e61de2c4be3c317e01f0d9989)

Change-Id: I147e028f10cec7abc545dcbcca911d39a89d830e
Reviewed-on: http://codereview.qt.nokia.com/165
Reviewed-by: Liang Qi <liang.qi@nokia.com>
This commit is contained in:
Liang Qi 2011-05-20 14:12:57 +02:00 committed by Qt Continuous Integration System
parent 750f995fb2
commit d6c9916fd1
2 changed files with 152 additions and 2 deletions

View File

@ -60,7 +60,10 @@ public:
tst_QUuid();
private slots:
void fromChar();
void toString();
void fromString();
void check_QDataStream();
void isNull();
void equal();
void notEqual();
@ -83,16 +86,74 @@ public:
tst_QUuid::tst_QUuid()
{
uuidA = "{fc69b59e-cc34-4436-a43c-ee95d128b8c5}";
uuidB = "{1ab6e93a-b1cb-4a87-ba47-ec7e99039a7b}";
//"{fc69b59e-cc34-4436-a43c-ee95d128b8c5}";
uuidA = QUuid(0xfc69b59e, 0xcc34 ,0x4436 ,0xa4 ,0x3c ,0xee ,0x95 ,0xd1 ,0x28 ,0xb8 ,0xc5);
//"{1ab6e93a-b1cb-4a87-ba47-ec7e99039a7b}";
uuidB = QUuid(0x1ab6e93a ,0xb1cb ,0x4a87 ,0xba ,0x47 ,0xec ,0x7e ,0x99 ,0x03 ,0x9a ,0x7b);
}
void tst_QUuid::fromChar()
{
QCOMPARE(uuidA, QUuid("{fc69b59e-cc34-4436-a43c-ee95d128b8c5}"));
QCOMPARE(uuidA, QUuid("fc69b59e-cc34-4436-a43c-ee95d128b8c5}"));
QCOMPARE(uuidA, QUuid("{fc69b59e-cc34-4436-a43c-ee95d128b8c5"));
QCOMPARE(uuidA, QUuid("fc69b59e-cc34-4436-a43c-ee95d128b8c5"));
QCOMPARE(QUuid(), QUuid("{fc69b59e-cc34-4436-a43c-ee95d128b8c"));
QCOMPARE(QUuid(), QUuid("{fc69b59e-cc34"));
QCOMPARE(QUuid(), QUuid("fc69b59e-cc34-"));
QCOMPARE(QUuid(), QUuid("fc69b59e-cc34"));
QCOMPARE(QUuid(), QUuid("cc34"));
QCOMPARE(QUuid(), QUuid(NULL));
QCOMPARE(uuidB, QUuid(QString("{1ab6e93a-b1cb-4a87-ba47-ec7e99039a7b}")));
}
void tst_QUuid::toString()
{
QCOMPARE(uuidA.toString(), QString("{fc69b59e-cc34-4436-a43c-ee95d128b8c5}"));
QCOMPARE(uuidB.toString(), QString("{1ab6e93a-b1cb-4a87-ba47-ec7e99039a7b}"));
}
void tst_QUuid::fromString()
{
QCOMPARE(uuidA, QUuid(QString("{fc69b59e-cc34-4436-a43c-ee95d128b8c5}")));
QCOMPARE(uuidA, QUuid(QString("fc69b59e-cc34-4436-a43c-ee95d128b8c5}")));
QCOMPARE(uuidA, QUuid(QString("{fc69b59e-cc34-4436-a43c-ee95d128b8c5")));
QCOMPARE(uuidA, QUuid(QString("fc69b59e-cc34-4436-a43c-ee95d128b8c5")));
QCOMPARE(QUuid(), QUuid(QString("{fc69b59e-cc34-4436-a43c-ee95d128b8c")));
QCOMPARE(uuidB, QUuid(QString("{1ab6e93a-b1cb-4a87-ba47-ec7e99039a7b}")));
}
void tst_QUuid::check_QDataStream()
{
QUuid tmp;
QByteArray ar;
{
QDataStream out(&ar,QIODevice::WriteOnly);
out.setByteOrder(QDataStream::BigEndian);
out << uuidA;
}
{
QDataStream in(&ar,QIODevice::ReadOnly);
in.setByteOrder(QDataStream::BigEndian);
in >> tmp;
QCOMPARE(uuidA, tmp);
}
{
QDataStream out(&ar,QIODevice::WriteOnly);
out.setByteOrder(QDataStream::LittleEndian);
out << uuidA;
}
{
QDataStream in(&ar,QIODevice::ReadOnly);
in.setByteOrder(QDataStream::LittleEndian);
in >> tmp;
QCOMPARE(uuidA, tmp);
}
}
void tst_QUuid::isNull()
{

View File

@ -53,6 +53,14 @@ public:
private slots:
void createUuid();
void fromChar();
void toString();
void fromString();
void toDataStream();
void fromDataStream();
void isNull();
void operatorLess();
void operatorMore();
};
void tst_bench_QUuid::createUuid()
@ -62,5 +70,86 @@ void tst_bench_QUuid::createUuid()
}
}
void tst_bench_QUuid::fromChar()
{
QBENCHMARK {
QUuid uuid("{67C8770B-44F1-410A-AB9A-F9B5446F13EE}");
}
}
void tst_bench_QUuid::toString()
{
QUuid uuid = QUuid::createUuid();
QBENCHMARK {
uuid.toString();
}
}
void tst_bench_QUuid::fromString()
{
QString string = "{67C8770B-44F1-410A-AB9A-F9B5446F13EE}";
QBENCHMARK {
QUuid uuid(string);
}
}
void tst_bench_QUuid::toDataStream()
{
QUuid uuid1, uuid2;
uuid1 = QUuid::createUuid();
QByteArray ar;
{
QDataStream out(&ar,QIODevice::WriteOnly);
QBENCHMARK {
out << uuid1;
}
}
}
void tst_bench_QUuid::fromDataStream()
{
QUuid uuid1, uuid2;
uuid1 = QUuid::createUuid();
QByteArray ar;
{
QDataStream out(&ar,QIODevice::WriteOnly);
out << uuid1;
}
{
QDataStream in(&ar,QIODevice::ReadOnly);
QBENCHMARK {
in >> uuid2;
}
}
}
void tst_bench_QUuid::isNull()
{
QUuid uuid = QUuid();
QBENCHMARK {
uuid.isNull();
}
}
void tst_bench_QUuid::operatorLess()
{
QUuid uuid1, uuid2;
uuid1 = QUuid::createUuid();
uuid2 = QUuid::createUuid();
QBENCHMARK {
uuid1 < uuid2;
}
}
void tst_bench_QUuid::operatorMore()
{
QUuid uuid1, uuid2;
uuid1 = QUuid::createUuid();
uuid2 = QUuid::createUuid();
QBENCHMARK {
uuid1 > uuid2;
}
}
QTEST_MAIN(tst_bench_QUuid);
#include "tst_quuid.moc"