Skip to content

Commit

Permalink
Merge pull request #72 from QuasarApp/fixTests
Browse files Browse the repository at this point in the history
fix tests outputs
  • Loading branch information
EndrII authored Mar 25, 2020
2 parents 8326a37 + 3da5c8e commit d8248da
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
8 changes: 3 additions & 5 deletions test.pri
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ contains(QMAKE_HOST.os, Linux):{
!android:deployTest.commands = $$DEPLOYER -bin $$exec clear -qmake $$QMAKE_BIN -targetDir $$PWD/deployTests -libDir $$PWD -recursiveDepth 5

unix:!android:testRSA.commands = $$PWD/deployTests/Qt-SecretTest.sh
win32:testRSA.commands = $$PWD/deployTests/Qt-SecretTest.exe &>> $$PWD/buildLog.log

win32:testRSA.commands = $$PWD/deployTests/Qt-SecretTest.exe
unix:!android:testAES.commands = $$PWD/deployTests/QAESEncryption.sh
win32:testAES.commands = $$PWD/deployTests/QAESEncryption.exe &>> $$PWD/buildLog.log

win32:testAES.commands = $$PWD/deployTests/QAESEncryption.exe
unix:!android:testGMP.commands = $$PWD/deployTests/QtBigIntTests.sh
win32:testGMP.commands =$$PWD/deployTests/QtBigIntTests.exe &>> $$PWD/buildLog.log
win32:testGMP.commands =$$PWD/deployTests/QtBigIntTests.exe

test.depends += deployTest
test.depends += testRSA
Expand Down
35 changes: 19 additions & 16 deletions tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <qdebug.h>
#include <cmath>
#include <time.h>
#include <iostream>

//const int testSize = 20;
static const QHash <int,int > testSize = {
Expand Down Expand Up @@ -39,20 +40,24 @@ QByteArray randomArray(int length = -1) {
return res;
}

void print(const QString& str) {
std::cout << str.toStdString() << std::endl;
}

bool checkKeys(const QByteArray& pubKey, const QByteArray& privKey,
QRSAEncryption::Rsa rsa) {
QRSAEncryption e(rsa);

qInfo() << QString("Private key: %0").arg(QString(pubKey.toHex()));
qInfo() << QString("Public key: %0").arg(QString(privKey.toHex()));
print( QString("Private key: %0").arg(QString(pubKey.toHex())));
print( QString("Public key: %0").arg(QString(privKey.toHex())));

if (pubKey.size() != rsa / 4) {
qCritical() << "pubKey size wrong RSA" << rsa;
print("pubKey size wrong RSA" + QString::number(rsa));
return false;
}

if (privKey.size() != rsa / 4) {
qCritical() << "privKey size wrong RSA" << rsa;
print("privKey size wrong RSA" + QString::number(rsa));
return false;
}

Expand All @@ -63,28 +68,28 @@ bool checkKeys(const QByteArray& pubKey, const QByteArray& privKey,
auto decodeData = e.decode(encodeData, privKey);

if ( base != decodeData) {
qCritical() << "encode/decode data error RSA" << rsa;
print("encode/decode data error RSA" + QString::number(rsa));
return false;
}

encodeData = e.signMessage(base, privKey);

if (!e.checkSignMessage(encodeData, pubKey)) {
qCritical() << "sig message error RSA" << rsa;
print("sig message error RSA" + QString::number(rsa));
return false;
}

encodeData += "work it";

if (e.checkSignMessage(encodeData, pubKey)) {
qCritical() << "sig message error RSA with added value to back" << rsa;
print("sig message error RSA with added value to back" + QString::number(rsa));
return false;
}

encodeData.push_front("not work");

if (e.checkSignMessage(encodeData, pubKey)) {
qCritical() << "sig message error RSA with added value to front" << rsa;
print("sig message error RSA with added value to front" + QString::number(rsa));
return false;
}
}
Expand All @@ -100,10 +105,10 @@ bool testCrypto(QRSAEncryption::Rsa rsa) {

for (int i = 0; i < testSize[rsa]; i++) {

qInfo() << QString("Test RSA-%0 (%1/%2):").arg(rsa).arg(i + 1).arg(testSize[rsa]);
print(QString("Test RSA-%0 (%1/%2):").arg(rsa).arg(i + 1).arg(testSize[rsa]));

if (!e.generatePairKey(pub, priv)) {
qCritical() << "key not generated RSA" << rsa;
print( "key not generated RSA" + QString::number(rsa));
return false;
}

Expand All @@ -125,7 +130,7 @@ bool testExample() {
auto signedMessage = e.signMessage(msg, priv);

if (e.checkSignMessage(signedMessage, pub)) {
qInfo() <<" message signed success";
print(" message signed success");
return true;
}

Expand All @@ -134,8 +139,7 @@ bool testExample() {
}

bool testGetKeyRsaType() {

qInfo() << "Check GetKeyRsaType function";
print("Check GetKeyRsaType function");

QByteArray pub, priv;
QRSAEncryption e(QRSAEncryption::Rsa::RSA_512);
Expand All @@ -160,8 +164,7 @@ bool testGetKeyRsaType() {
if (QRSAEncryption::getKeyRsaType(invalidKey) != QRSAEncryption::Rsa::Invalid) {
return false;
}

qInfo() << "success";
print("success");
return true;
}

Expand Down Expand Up @@ -225,7 +228,7 @@ int main() {
return 1;
}

qInfo() << "Tests passed successfully";
print("Tests passed successfully");

return 0;
}

0 comments on commit d8248da

Please sign in to comment.