summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@nokia.com>2011-05-20 12:12:57 (GMT)
committerLiang Qi <liang.qi@nokia.com>2011-05-20 12:12:57 (GMT)
commit4e9286880fd2686e61de2c4be3c317e01f0d9989 (patch)
tree3644c5f147547090ea12d327b3b17e6506e0d59f /tests
parent0ccf01368adcabbb25958a55976083f72116a2d5 (diff)
downloadQt-4e9286880fd2686e61de2c4be3c317e01f0d9989.zip
Qt-4e9286880fd2686e61de2c4be3c317e01f0d9989.tar.gz
Qt-4e9286880fd2686e61de2c4be3c317e01f0d9989.tar.bz2
Add some autotests and benchmarks for QUuid
Missing those functions for optimization. Reviewed-by: joao
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quuid/tst_quuid.cpp65
-rw-r--r--tests/benchmarks/corelib/plugin/quuid/tst_quuid.cpp89
2 files changed, 152 insertions, 2 deletions
diff --git a/tests/auto/quuid/tst_quuid.cpp b/tests/auto/quuid/tst_quuid.cpp
index 50e48c9..f24c893 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 9e885ee..47a3d3f 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"