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,84 @@ + +#include "crypt.h" + +#include +#include + +namespace Crypt +{ + struct data + { + unsigned int d[2]; + }; + struct key + { + unsigned int k[4]; + }; +} + +Q_DECLARE_METATYPE(Crypt::data); +Q_DECLARE_METATYPE(Crypt::key); + +class QQCryptTest : public QObject +{ + Q_OBJECT + +private slots: + void CryptTest(); + void CryptTest_data(); + Crypt::data Crypt_data(char x, char y); + const Crypt::key Crypt_key(char w, char x, char y, char z); +}; + +Crypt::data QQCryptTest::Crypt_data(char x, char y) +{ + Crypt::data a; + a.d[0]=(unsigned int)x; + a.d[1]=(unsigned int)y; + return a; +} + +const Crypt::key QQCryptTest::Crypt_key(char w, char x, char y, char z) +{ + Crypt::key key; + key.k[0]=(unsigned int)w; + key.k[0]=(unsigned int)x; + key.k[0]=(unsigned int)y; + key.k[0]=(unsigned int)z; + return key; +} + +void QQCryptTest::CryptTest_data() +{ + QTest::addColumn("input");/* This character which is going to encrypt */ + QTest::addColumn("encrypted");/* encrypted data && input of the TEA:: decipher function */ + QTest::addColumn("decrypted");/* decrypted data && output of the TEA::decipher function */ + QTest::addColumn("key_value");/* key which is going to used in encryption */ + + QTest::newRow("1") << QQCryptTest::Crypt_data('a','b') << QQCryptTest::Crypt_data('\0','\0') << QQCryptTest::Crypt_data('\0','\0') << QQCryptTest::Crypt_key('a','b','c','d') ; + QTest::newRow("2") << QQCryptTest::Crypt_data('l','m') << QQCryptTest::Crypt_data('\0','\0') << QQCryptTest::Crypt_data('\0','\0') << QQCryptTest::Crypt_key('a','b','c','d') ; + QTest::newRow("3") << QQCryptTest::Crypt_data('x','y') << QQCryptTest::Crypt_data('\0','\0') << QQCryptTest::Crypt_data('\0','\0') << QQCryptTest::Crypt_key('a','b','c','d') ; + QTest::newRow("4") << QQCryptTest::Crypt_data('\0','\0') << QQCryptTest::Crypt_data('\0','\0') << QQCryptTest::Crypt_data('\0','\0') << QQCryptTest::Crypt_key('a','b','c','d') ; +} + +void QQCryptTest::CryptTest() +{ + QFETCH(Crypt::data,input); + QFETCH(Crypt::data,encrypted); + QFETCH(Crypt::data,decrypted); + QFETCH(Crypt::key,key_value); + + /* void TEA::encipher(unsigned int *const v, const unsigned int *const k, unsigned int *const w); */ + TEA::encipher(input.d, key_value.k, encrypted.d); + + /* void TEA::decipher(unsigned int *const v, const unsigned int *const k, unsigned int *const w); */ + TEA::decipher(encrypted.d, key_value.k, decrypted.d); + + QVERIFY(input.d[0] != encrypted.d[0]); + QVERIFY(input.d[1] != encrypted.d[1]); + QCOMPARE(input.d[0],decrypted.d[0]); + QCOMPARE(input.d[1],decrypted.d[1]); +} + +QTEST_MAIN(QQCryptTest) +#include "qqcrypttest.moc"