Index: tests/protocols/CMakeLists.txt =================================================================== --- tests/protocols/CMakeLists.txt +++ tests/protocols/CMakeLists.txt @@ -1 +1,2 @@ add_subdirectory(oscar) +add_subdirectory(qq) Index: tests/protocols/qq/CMakeLists.txt =================================================================== --- /dev/null +++ tests/protocols/qq/CMakeLists.txt @@ -0,0 +1,21 @@ +find_package(Qt5 REQUIRED COMPONENTS Test) +include_directories( + ${CMAKE_SOURCE_DIR}/protocols/qq + ${CMAKE_SOURCE_DIR}/protocols/qq/icons + ${CMAKE_SOURCE_DIR}/protocols/qq/ui + ${KOPETE_SOURCE_DIR} +) + +set( + QQ_TEST_LIBRARIES + KF5::KDELibs4Support + Qt5::Test + ${CMAKE_SOURCE_DIR}/protocols/qq/crypt.cpp +) + +# Test for crypt(TEA) +set(qqcrypttest_SRCS qqcrypttest.cpp) +ecm_add_test( + ${qqcrypttest_SRCS} + LINK_LIBRARIES ${QQ_TEST_LIBRARIES} +) Index: tests/protocols/qq/qqcrypttest.cpp =================================================================== --- /dev/null +++ tests/protocols/qq/qqcrypttest.cpp @@ -0,0 +1,65 @@ +#include "crypt.h" + +#include +#include + +Q_DECLARE_METATYPE(unsigned int*); + +class QQCryptTest : public QObject +{ + Q_OBJECT +private slots: + void CryptTest(); + void CryptTest_data(); + unsigned int* Crypt_Data(char*); + unsigned int* Crypt_Key(char*); +}; + +/* The data is going to decrypted */ +unsigned int* QQCryptTest::Crypt_Data(char* x) +{ + static unsigned int d[2]; + d[0] = x[0]; + d[1] = x[1]; + return d; +} + +/* Key which is used for encryption and decryption */ +unsigned int* QQCryptTest::Crypt_Key(char* x) +{ + static unsigned int k[4]; + k[0] = x[0]; + k[1] = x[1]; + k[2] = x[2]; + k[3] = x[3]; + return k; +} + +void QQCryptTest::CryptTest_data() +{ + QTest::addColumn("data"); + QTest::addColumn("key"); + + QTest::newRow("1") << QQCryptTest::Crypt_Data("ad") << QQCryptTest::Crypt_Key("abcd"); + QTest::newRow("2") << QQCryptTest::Crypt_Data("xy") << QQCryptTest::Crypt_Key("wxyz"); +} + +void QQCryptTest::CryptTest() +{ + QFETCH(unsigned int*, data); + QFETCH(unsigned int*, key); + + unsigned int encrypted[2]={0,0};/* encrypted data && input of the TEA::decipher function */ + unsigned int decrypted[2]={0,0};/* decrypted data */ + + TEA::encipher(data, key, encrypted); + TEA::decipher(encrypted, key, decrypted); + + QVERIFY(data[0] != encrypted[0]); + QVERIFY(data[1] != encrypted[1]); + QCOMPARE(data[0], decrypted[0]); + QCOMPARE(data[1], decrypted[1]); +} + +QTEST_MAIN(QQCryptTest) +#include "qqcrypttest.moc"