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/>.
|
|
|
|
*/
|
|
|
|
|
2017-01-31 05:06:42 +08:00
|
|
|
#include "src/core/toxid.h"
|
|
|
|
|
2017-06-03 04:33:12 +08:00
|
|
|
#include <QtTest/QtTest>
|
2017-01-31 05:06:42 +08:00
|
|
|
#include <QString>
|
2017-04-11 05:39:11 +08:00
|
|
|
#include <ctime>
|
2017-01-31 05:06:42 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
const QString corrupted =
|
2022-02-16 21:19:24 +08:00
|
|
|
QStringLiteral("A369865720756105C324F27C20093F26BEEB2655F803977D5C2EB6B408B8E404AFC201CC15D2");
|
2017-02-26 19:52:45 +08:00
|
|
|
const QString testToxId =
|
2022-02-16 21:19:24 +08:00
|
|
|
QStringLiteral("A369865720756105C324F27C20093F26BEEB2655F803977D5C2EB6B408B8E404AFC201CC15D1");
|
|
|
|
const QString newNoSpam =
|
|
|
|
QStringLiteral("A369865720756105C324F27C20093F26BEEB2655F803977D5C2EB6B408B8E40476ECD68C1BBF");
|
2017-02-26 19:52:45 +08:00
|
|
|
const QString echoToxId =
|
|
|
|
QStringLiteral("76518406F6A9F2217E8DC487CC783C25CC16A15EB36FF32E335A235342C48A39218F515C39A6");
|
2017-01-31 05:06:42 +08:00
|
|
|
|
2017-06-03 04:33:12 +08:00
|
|
|
class TestToxId : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private slots:
|
|
|
|
void toStringTest();
|
|
|
|
void equalTest();
|
|
|
|
void notEqualTest();
|
|
|
|
void clearTest();
|
|
|
|
void copyTest();
|
|
|
|
void validationTest();
|
|
|
|
};
|
|
|
|
|
|
|
|
void TestToxId::toStringTest()
|
2017-01-31 05:06:42 +08:00
|
|
|
{
|
|
|
|
ToxId toxId(testToxId);
|
2017-06-03 04:33:12 +08:00
|
|
|
QVERIFY(testToxId == toxId.toString());
|
2017-01-31 05:06:42 +08:00
|
|
|
}
|
|
|
|
|
2017-06-03 04:33:12 +08:00
|
|
|
void TestToxId::equalTest()
|
2017-01-31 05:06:42 +08:00
|
|
|
{
|
|
|
|
ToxId toxId1(testToxId);
|
2022-02-16 21:19:24 +08:00
|
|
|
ToxId toxId2(newNoSpam);
|
2017-06-03 04:33:12 +08:00
|
|
|
QVERIFY(toxId1 == toxId2);
|
|
|
|
QVERIFY(!(toxId1 != toxId2));
|
2017-01-31 05:06:42 +08:00
|
|
|
}
|
|
|
|
|
2017-06-03 04:33:12 +08:00
|
|
|
void TestToxId::notEqualTest()
|
2017-01-31 05:06:42 +08:00
|
|
|
{
|
|
|
|
ToxId toxId1(testToxId);
|
|
|
|
ToxId toxId2(echoToxId);
|
2017-06-03 04:33:12 +08:00
|
|
|
QVERIFY(toxId1 != toxId2);
|
2017-01-31 05:06:42 +08:00
|
|
|
}
|
|
|
|
|
2017-06-03 04:33:12 +08:00
|
|
|
void TestToxId::clearTest()
|
2017-01-31 05:06:42 +08:00
|
|
|
{
|
|
|
|
ToxId empty;
|
|
|
|
ToxId test(testToxId);
|
2017-06-03 04:33:12 +08:00
|
|
|
QVERIFY(empty != test);
|
2017-01-31 05:06:42 +08:00
|
|
|
test.clear();
|
2017-06-03 04:33:12 +08:00
|
|
|
QVERIFY(empty == test);
|
2017-01-31 05:06:42 +08:00
|
|
|
}
|
|
|
|
|
2017-06-03 04:33:12 +08:00
|
|
|
void TestToxId::copyTest()
|
2017-01-31 05:06:42 +08:00
|
|
|
{
|
|
|
|
ToxId src(testToxId);
|
|
|
|
ToxId copy = src;
|
2017-06-03 04:33:12 +08:00
|
|
|
QVERIFY(copy == src);
|
2017-01-31 05:06:42 +08:00
|
|
|
}
|
|
|
|
|
2017-06-03 04:33:12 +08:00
|
|
|
void TestToxId::validationTest()
|
2017-01-31 05:06:42 +08:00
|
|
|
{
|
2017-06-03 04:33:12 +08:00
|
|
|
QVERIFY(ToxId(testToxId).isValid());
|
2022-02-16 21:19:24 +08:00
|
|
|
QVERIFY(ToxId(newNoSpam).isValid());
|
2017-06-03 04:33:12 +08:00
|
|
|
QVERIFY(!ToxId(corrupted).isValid());
|
2017-01-31 05:06:42 +08:00
|
|
|
}
|
|
|
|
|
2017-06-03 04:33:12 +08:00
|
|
|
QTEST_GUILESS_MAIN(TestToxId)
|
|
|
|
#include "toxid_test.moc"
|