From d6c9916fd157f0d3de5dbe17609177ee32e93488 Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Fri, 20 May 2011 14:12:57 +0200 Subject: [PATCH] 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 --- tests/auto/quuid/tst_quuid.cpp | 65 +++++++++++++++- .../benchmarks/corelib/plugin/quuid/tst_quuid.cpp | 89 ++++++++++++++++++++++ 2 files changed, 152 insertions(+), 2 deletions(-) diff --git a/tests/auto/quuid/tst_quuid.cpp b/tests/auto/quuid/tst_quuid.cpp index 6333e83..6e067b7 100644 --- a/tests/auto/quuid/tst_quuid.cpp +++ b/tests/auto/quuid/tst_quuid.cpp @@ -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() { diff --git a/tests/benchmarks/corelib/plugin/quuid/tst_quuid.cpp b/tests/benchmarks/corelib/plugin/quuid/tst_quuid.cpp index dbec65c..61876e5 100644 --- a/tests/benchmarks/corelib/plugin/quuid/tst_quuid.cpp +++ b/tests/benchmarks/corelib/plugin/quuid/tst_quuid.cpp @@ -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" -- 2.7.4