1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

test: Replace check on Qtest

This commit is contained in:
Diadlo 2017-06-02 23:33:12 +03:00
parent f616ff36b6
commit b8ae494ef3
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
6 changed files with 103 additions and 201 deletions

View File

@ -10,7 +10,6 @@ enable_testing()
function(auto_test subsystem module)
add_executable(test_${module}
test/common.h
test/${subsystem}/${module}_test.cpp)
target_link_libraries(test_${module}
${PROJECT_NAME}_static
@ -21,9 +20,6 @@ function(auto_test subsystem module)
COMMAND test_${module})
endfunction()
search_dependency(CHECK PACKAGE check OPTIONAL)
if (CHECK_FOUND)
auto_test(core toxpk)
auto_test(core toxid)
auto_test(chatlog textformatter)
endif()
auto_test(core toxpk)
auto_test(core toxid)
auto_test(chatlog textformatter)

View File

@ -18,15 +18,14 @@
*/
#include "src/chatlog/textformatter.h"
#include "test/common.h"
#include <QtTest/QtTest>
#include <QList>
#include <QMap>
#include <QString>
#include <QVector>
#include <QVector>
#include <check.h>
#include <ctime>
using StringToString = QMap<QString, QString>;
@ -129,7 +128,7 @@ static void commonTest(bool showSymbols, const StringToString map, const QString
QString source = key.arg(signs);
TextFormatter tf = TextFormatter(source);
QString result = map[key].arg(showSymbols ? signs : "", signsToTags[signs]);
ck_assert(tf.applyStyling(showSymbols) == result);
QVERIFY(tf.applyStyling(showSymbols) == result);
}
}
@ -141,7 +140,7 @@ static void commonExceptionsTest(const QString signs)
{
for (QString source : commonExceptions) {
TextFormatter tf = TextFormatter(source.arg(signs));
ck_assert(tf.applyStyling(false) == source.arg(signs));
QVERIFY(tf.applyStyling(false) == source.arg(signs));
}
}
@ -153,126 +152,100 @@ static void specialTest(const StringToString map)
{
for (QString key : map.keys()) {
TextFormatter tf = TextFormatter(key);
ck_assert(tf.applyStyling(false) == map[key]);
QVERIFY(tf.applyStyling(false) == map[key]);
}
}
START_TEST(singleSignNoSymbolsTest)
class TestTextFormatter : public QObject
{
Q_OBJECT
private slots:
void singleSignNoSymbolsTest();
void slashNoSymbolsTest();
void doubleSignNoSymbolsTest();
void singleSignWithSymbolsTest();
void slashWithSymbolsTest();
void doubleSignWithSymbolsTest();
void singleSignExceptionsTest();
void slashExceptionsTest();
void doubleSignExceptionsTest();
void slashSpecialTest();
void doubleSignSpecialTest();
void mixedFormattingTest();
void multilineCodeTest();
void urlTest();
};
void TestTextFormatter::singleSignNoSymbolsTest()
{
commonTest(false, commonWorkCases, "*");
}
END_TEST
START_TEST(slashNoSymbolsTest)
void TestTextFormatter::slashNoSymbolsTest()
{
commonTest(false, commonWorkCases, "/");
}
END_TEST
START_TEST(doubleSignNoSymbolsTest)
void TestTextFormatter::doubleSignNoSymbolsTest()
{
commonTest(false, commonWorkCases, "**");
}
END_TEST
START_TEST(singleSignWithSymbolsTest)
void TestTextFormatter::singleSignWithSymbolsTest()
{
commonTest(true, commonWorkCases, "*");
}
END_TEST
START_TEST(slashWithSymbolsTest)
void TestTextFormatter::slashWithSymbolsTest()
{
commonTest(true, commonWorkCases, "/");
}
END_TEST
START_TEST(doubleSignWithSymbolsTest)
void TestTextFormatter::doubleSignWithSymbolsTest()
{
commonTest(true, commonWorkCases, "**");
}
END_TEST
START_TEST(singleSignExceptionsTest)
void TestTextFormatter::singleSignExceptionsTest()
{
commonExceptionsTest("*");
}
END_TEST
START_TEST(slashExceptionsTest)
void TestTextFormatter::slashExceptionsTest()
{
commonExceptionsTest("/");
}
END_TEST
START_TEST(doubleSignExceptionsTest)
void TestTextFormatter::doubleSignExceptionsTest()
{
commonExceptionsTest("**");
}
END_TEST
START_TEST(slashSpecialTest)
void TestTextFormatter::slashSpecialTest()
{
specialTest(singleSlash);
}
END_TEST
START_TEST(doubleSignSpecialTest)
void TestTextFormatter::doubleSignSpecialTest()
{
specialTest(doubleSign);
}
END_TEST
START_TEST(mixedFormattingTest)
void TestTextFormatter::mixedFormattingTest()
{
specialTest(mixedFormatting);
}
END_TEST
START_TEST(multilineCodeTest)
void TestTextFormatter::multilineCodeTest()
{
specialTest(multilineCode);
}
END_TEST
START_TEST(urlTest)
void TestTextFormatter::urlTest()
{
specialTest(urlCases);
}
END_TEST
static Suite* textFormatterSuite(void)
{
Suite* s = suite_create("TextFormatter");
QTEST_GUILESS_MAIN(TestTextFormatter)
#include "textformatter_test.moc"
DEFTESTCASE(singleSignNoSymbols);
DEFTESTCASE(slashNoSymbols);
DEFTESTCASE(doubleSignNoSymbols);
DEFTESTCASE(singleSignWithSymbols);
DEFTESTCASE(slashWithSymbols);
DEFTESTCASE(doubleSignWithSymbols);
DEFTESTCASE(singleSignExceptions);
DEFTESTCASE(slashExceptions);
DEFTESTCASE(doubleSignExceptions);
DEFTESTCASE(slashSpecial);
DEFTESTCASE(doubleSignSpecial);
DEFTESTCASE(mixedFormatting);
DEFTESTCASE(multilineCode);
DEFTESTCASE(url);
return s;
}
int main(int argc, char* argv[])
{
srand((unsigned int)time(NULL));
Suite* tf = textFormatterSuite();
SRunner* runner = srunner_create(tf);
srunner_run_all(runner, CK_NORMAL);
int res = srunner_ntests_failed(runner);
srunner_free(runner);
return res;
}

View File

@ -1,13 +0,0 @@
#ifndef _TEST_COMMON_H_
#define _TEST_COMMON_H_
#define DEFTESTCASE(NAME) \
TCase* tc_##NAME = tcase_create(#NAME); \
tcase_add_test(tc_##NAME, NAME##Test); \
suite_add_tcase(s, tc_##NAME);
#define DEFTESTCASE_SLOW(NAME, TIMEOUT) \
DEFTESTCASE(NAME) \
tcase_set_timeout(tc_##NAME, TIMEOUT);
#endif // _TEST_COMMON_H_

View File

@ -19,10 +19,8 @@
#include "src/core/toxid.h"
#include "test/common.h"
#include <QtTest/QtTest>
#include <QString>
#include <check.h>
#include <ctime>
const QString corrupted =
@ -34,82 +32,63 @@ const QString publicKey =
const QString echoToxId =
QStringLiteral("76518406F6A9F2217E8DC487CC783C25CC16A15EB36FF32E335A235342C48A39218F515C39A6");
START_TEST(toStringTest)
class TestToxId : public QObject
{
Q_OBJECT
private slots:
void toStringTest();
void equalTest();
void notEqualTest();
void clearTest();
void copyTest();
void validationTest();
};
void TestToxId::toStringTest()
{
ToxId toxId(testToxId);
ck_assert(testToxId == toxId.toString());
QVERIFY(testToxId == toxId.toString());
}
END_TEST
START_TEST(equalTest)
void TestToxId::equalTest()
{
ToxId toxId1(testToxId);
ToxId toxId2(publicKey);
ck_assert(toxId1 == toxId2);
ck_assert(!(toxId1 != toxId2));
QVERIFY(toxId1 == toxId2);
QVERIFY(!(toxId1 != toxId2));
}
END_TEST
START_TEST(notEqualTest)
void TestToxId::notEqualTest()
{
ToxId toxId1(testToxId);
ToxId toxId2(echoToxId);
ck_assert(toxId1 != toxId2);
QVERIFY(toxId1 != toxId2);
}
END_TEST
START_TEST(clearTest)
void TestToxId::clearTest()
{
ToxId empty;
ToxId test(testToxId);
ck_assert(empty != test);
QVERIFY(empty != test);
test.clear();
ck_assert(empty == test);
QVERIFY(empty == test);
}
END_TEST
START_TEST(copyTest)
void TestToxId::copyTest()
{
ToxId src(testToxId);
ToxId copy = src;
ck_assert(copy == src);
QVERIFY(copy == src);
}
END_TEST
START_TEST(validationTest)
void TestToxId::validationTest()
{
ck_assert(ToxId(testToxId).isValid());
ck_assert(!ToxId(publicKey).isValid());
ck_assert(!ToxId(corrupted).isValid());
QVERIFY(ToxId(testToxId).isValid());
QVERIFY(!ToxId(publicKey).isValid());
QVERIFY(!ToxId(corrupted).isValid());
QString deadbeef = "DEADBEEF";
ck_assert(!ToxId(deadbeef).isValid());
}
END_TEST
static Suite* toxIdSuite(void)
{
Suite* s = suite_create("ToxId");
DEFTESTCASE(toString);
DEFTESTCASE(equal);
DEFTESTCASE(notEqual);
DEFTESTCASE(clear);
DEFTESTCASE(copy);
DEFTESTCASE(validation);
return s;
QVERIFY(!ToxId(deadbeef).isValid());
}
int main(int argc, char* argv[])
{
srand((unsigned int)time(NULL));
Suite* toxId = toxIdSuite();
SRunner* runner = srunner_create(toxId);
srunner_run_all(runner, CK_NORMAL);
int res = srunner_ntests_failed(runner);
srunner_free(runner);
return res;
}
QTEST_GUILESS_MAIN(TestToxId)
#include "toxid_test.moc"

View File

@ -19,13 +19,10 @@
#include "src/core/toxid.h"
#include "test/common.h"
#include <QtTest/QtTest>
#include <QByteArray>
#include <QString>
#include <check.h>
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};
@ -38,74 +35,57 @@ const QString echoStr =
QStringLiteral("76518406F6A9F2217E8DC487CC783C25CC16A15EB36FF32E335A235342C48A39");
const QByteArray echoPk = QByteArray::fromHex(echoStr.toLatin1());
START_TEST(toStringTest)
class TestToxPk : public QObject
{
Q_OBJECT
private slots:
void toStringTest();
void equalTest();
void clearTest();
void copyTest();
void publicKeyTest();
};
void TestToxPk::toStringTest()
{
ToxPk pk(testPk);
ck_assert(testStr == pk.toString());
QVERIFY(testStr == pk.toString());
}
END_TEST
START_TEST(equalTest)
void TestToxPk::equalTest()
{
ToxPk pk1(testPk);
ToxPk pk2(testPk);
ToxPk pk3(echoPk);
ck_assert(pk1 == pk2);
ck_assert(pk1 != pk3);
ck_assert(!(pk1 != pk2));
QVERIFY(pk1 == pk2);
QVERIFY(pk1 != pk3);
QVERIFY(!(pk1 != pk2));
}
END_TEST
START_TEST(clearTest)
void TestToxPk::clearTest()
{
ToxPk empty;
ToxPk pk(testPk);
ck_assert(empty.isEmpty());
ck_assert(!pk.isEmpty());
QVERIFY(empty.isEmpty());
QVERIFY(!pk.isEmpty());
}
END_TEST
START_TEST(copyTest)
void TestToxPk::copyTest()
{
ToxPk src(testPk);
ToxPk copy = src;
ck_assert(copy == src);
QVERIFY(copy == src);
}
END_TEST
START_TEST(publicKeyTest)
void TestToxPk::publicKeyTest()
{
ToxPk pk(testPk);
ck_assert(testPk == pk.getKey());
QVERIFY(testPk == pk.getKey());
for (int i = 0; i < ToxPk::getPkSize(); i++) {
ck_assert(testPkArray[i] == pk.getBytes()[i]);
QVERIFY(testPkArray[i] == pk.getBytes()[i]);
}
}
END_TEST
static Suite* toxPkSuite(void)
{
Suite* s = suite_create("ToxPk");
QTEST_GUILESS_MAIN(TestToxPk)
#include "toxpk_test.moc"
DEFTESTCASE(toString);
DEFTESTCASE(equal);
DEFTESTCASE(clear);
DEFTESTCASE(publicKey);
DEFTESTCASE(copy);
return s;
}
int main(int argc, char* argv[])
{
srand((unsigned int)time(NULL));
Suite* toxPk = toxPkSuite();
SRunner* runner = srunner_create(toxPk);
srunner_run_all(runner, CK_NORMAL);
int res = srunner_ntests_failed(runner);
srunner_free(runner);
return res;
}

View File

@ -1,13 +0,0 @@
#ifndef _TEST_UTILS_H_
#define _TEST_UTILS_H_
#define DEFTESTCASE(NAME) \
TCase* tc_##NAME = tcase_create(#NAME); \
tcase_add_test(tc_##NAME, NAME##Test); \
suite_add_tcase(s, tc_##NAME);
#define DEFTESTCASE_SLOW(NAME, TIMEOUT) \
DEFTESTCASE(NAME) \
tcase_set_timeout(tc_##NAME, TIMEOUT);
#endif // _TEST_UTILS_H_