2017-02-19 22:48:44 +08:00
|
|
|
/*
|
2019-06-24 22:01:18 +08:00
|
|
|
Copyright © 2017-2019 by The qTox Project Contributors
|
2017-02-19 22:48:44 +08:00
|
|
|
|
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
|
|
|
qTox is libre software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
qTox is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2022-03-07 20:18:16 +08:00
|
|
|
#include "src/core/chatid.h"
|
2019-04-12 04:38:37 +08:00
|
|
|
#include "src/core/toxpk.h"
|
2017-01-31 05:06:42 +08:00
|
|
|
#include "src/core/toxid.h"
|
2019-04-12 04:38:37 +08:00
|
|
|
#include "src/core/groupid.h"
|
|
|
|
|
2017-06-03 04:33:12 +08:00
|
|
|
#include <QtTest/QtTest>
|
2017-01-31 05:06:42 +08:00
|
|
|
#include <QByteArray>
|
2017-02-26 19:52:45 +08:00
|
|
|
#include <QString>
|
2017-01-31 05:06:42 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
const uint8_t testPkArray[32] = {0xC7, 0x71, 0x9C, 0x68, 0x08, 0xC1, 0x4B, 0x77, 0x34, 0x80, 0x04,
|
|
|
|
0x95, 0x6D, 0x1D, 0x98, 0x04, 0x6C, 0xE0, 0x9A, 0x34, 0x37, 0x0E,
|
|
|
|
0x76, 0x08, 0x15, 0x0E, 0xAD, 0x74, 0xC3, 0x81, 0x5D, 0x30};
|
2017-01-31 05:06:42 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
const QString testStr =
|
|
|
|
QStringLiteral("C7719C6808C14B77348004956D1D98046CE09A34370E7608150EAD74C3815D30");
|
2017-01-31 05:06:42 +08:00
|
|
|
const QByteArray testPk = QByteArray::fromHex(testStr.toLatin1());
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
const QString echoStr =
|
|
|
|
QStringLiteral("76518406F6A9F2217E8DC487CC783C25CC16A15EB36FF32E335A235342C48A39");
|
2017-01-31 05:06:42 +08:00
|
|
|
const QByteArray echoPk = QByteArray::fromHex(echoStr.toLatin1());
|
|
|
|
|
2022-03-07 20:18:16 +08:00
|
|
|
class TestChatId : public QObject
|
2017-06-03 04:33:12 +08:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private slots:
|
|
|
|
void toStringTest();
|
|
|
|
void equalTest();
|
|
|
|
void clearTest();
|
|
|
|
void copyTest();
|
2019-04-12 04:38:37 +08:00
|
|
|
void dataTest();
|
|
|
|
void sizeTest();
|
2020-05-04 06:58:45 +08:00
|
|
|
void hashableTest();
|
2017-06-03 04:33:12 +08:00
|
|
|
};
|
|
|
|
|
2022-03-07 20:18:16 +08:00
|
|
|
void TestChatId::toStringTest()
|
2017-01-31 05:06:42 +08:00
|
|
|
{
|
|
|
|
ToxPk pk(testPk);
|
2017-06-03 04:33:12 +08:00
|
|
|
QVERIFY(testStr == pk.toString());
|
2017-01-31 05:06:42 +08:00
|
|
|
}
|
|
|
|
|
2022-03-07 20:18:16 +08:00
|
|
|
void TestChatId::equalTest()
|
2017-01-31 05:06:42 +08:00
|
|
|
{
|
|
|
|
ToxPk pk1(testPk);
|
|
|
|
ToxPk pk2(testPk);
|
|
|
|
ToxPk pk3(echoPk);
|
2017-06-03 04:33:12 +08:00
|
|
|
QVERIFY(pk1 == pk2);
|
|
|
|
QVERIFY(pk1 != pk3);
|
|
|
|
QVERIFY(!(pk1 != pk2));
|
2017-01-31 05:06:42 +08:00
|
|
|
}
|
|
|
|
|
2022-03-07 20:18:16 +08:00
|
|
|
void TestChatId::clearTest()
|
2017-01-31 05:06:42 +08:00
|
|
|
{
|
|
|
|
ToxPk empty;
|
|
|
|
ToxPk pk(testPk);
|
2017-06-03 04:33:12 +08:00
|
|
|
QVERIFY(empty.isEmpty());
|
|
|
|
QVERIFY(!pk.isEmpty());
|
2017-01-31 05:06:42 +08:00
|
|
|
}
|
|
|
|
|
2022-03-07 20:18:16 +08:00
|
|
|
void TestChatId::copyTest()
|
2017-01-31 05:06:42 +08:00
|
|
|
{
|
|
|
|
ToxPk src(testPk);
|
|
|
|
ToxPk copy = src;
|
2017-06-03 04:33:12 +08:00
|
|
|
QVERIFY(copy == src);
|
2017-01-31 05:06:42 +08:00
|
|
|
}
|
|
|
|
|
2022-03-07 20:18:16 +08:00
|
|
|
void TestChatId::dataTest()
|
2017-01-31 05:06:42 +08:00
|
|
|
{
|
|
|
|
ToxPk pk(testPk);
|
2019-04-12 04:38:37 +08:00
|
|
|
QVERIFY(testPk == pk.getByteArray());
|
|
|
|
for (int i = 0; i < pk.getSize(); i++) {
|
|
|
|
QVERIFY(testPkArray[i] == pk.getData()[i]);
|
2017-01-31 05:06:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-07 20:18:16 +08:00
|
|
|
void TestChatId::sizeTest()
|
2019-04-12 04:38:37 +08:00
|
|
|
{
|
|
|
|
ToxPk pk;
|
|
|
|
GroupId id;
|
2022-03-13 19:59:40 +08:00
|
|
|
QVERIFY(pk.getSize() == ToxPk::size);
|
|
|
|
QVERIFY(id.getSize() == GroupId::size);
|
2019-04-12 04:38:37 +08:00
|
|
|
}
|
2017-01-31 05:06:42 +08:00
|
|
|
|
2022-03-07 20:18:16 +08:00
|
|
|
void TestChatId::hashableTest()
|
2020-05-04 06:58:45 +08:00
|
|
|
{
|
|
|
|
ToxPk pk1{testPkArray};
|
|
|
|
ToxPk pk2{testPk};
|
|
|
|
QVERIFY(qHash(pk1) == qHash(pk2));
|
|
|
|
ToxPk pk3{echoPk};
|
|
|
|
QVERIFY(qHash(pk1) != qHash(pk3));
|
|
|
|
}
|
|
|
|
|
2022-03-07 20:18:16 +08:00
|
|
|
QTEST_GUILESS_MAIN(TestChatId)
|
|
|
|
#include "chatid_test.moc"
|