From f583f1a71459f413f9f869b8f1616722054dbea8 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Mon, 10 Feb 2020 22:16:12 +0100 Subject: utils: Generate UUIDs for stanza hashes by default The QXmppUtils::generateStanzaHash() generates UUIDs by default now. UUIDs are not generated, if the default parameter is changed to a different value (!= 36). The behaviour is not changed for other values than 36. This way all users of QXmpp will automatically start to use UUIDs, if they use the generateStanzaHash() method. --- tests/qxmpputils/tst_qxmpputils.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'tests/qxmpputils/tst_qxmpputils.cpp') diff --git a/tests/qxmpputils/tst_qxmpputils.cpp b/tests/qxmpputils/tst_qxmpputils.cpp index 27424e1a..f879ba3a 100644 --- a/tests/qxmpputils/tst_qxmpputils.cpp +++ b/tests/qxmpputils/tst_qxmpputils.cpp @@ -37,6 +37,7 @@ private slots: void testJid(); void testMime(); void testTimezoneOffset(); + void testStanzaHash(); }; void tst_QXmppUtils::testCrc32() @@ -127,5 +128,21 @@ void tst_QXmppUtils::testTimezoneOffset() QCOMPARE(QXmppUtils::timezoneOffsetToString(-5400), QLatin1String("-01:30")); } +void tst_QXmppUtils::testStanzaHash() +{ + for (int i = 0; i < 100; i++) { + const QString hash = QXmppUtils::generateStanzaHash(i); + QCOMPARE(hash.size(), i); + + if (i == 36) { + QCOMPARE(hash.count('-'), 4); + } + } + + const QString hash = QXmppUtils::generateStanzaUuid(); + QCOMPARE(hash.size(), 36); + QCOMPARE(hash.count('-'), 4); +} + QTEST_MAIN(tst_QXmppUtils) #include "tst_qxmpputils.moc" -- cgit v1.2.3