From 664561bcb1abd936f689c6bd52f622b65a6c9a32 Mon Sep 17 00:00:00 2001 From: favoritas37 Date: Tue, 12 Jan 2016 21:28:46 +0200 Subject: [PATCH] First end-to-end version of the automated test. Needs to be further enhanced and add more result analysis. --- tests/src/QZXingTests/DecodeValidator.cpp | 61 +++++++++++++++++++++++ tests/src/QZXingTests/DecodeValidator.h | 18 ++++++- tests/src/QZXingTests/QZXingTests.pro | 2 - tests/src/QZXingTests/ValidationStats.cpp | 24 ++++++++- tests/src/QZXingTests/ValidationStats.h | 6 +++ tests/src/QZXingTests/main.cpp | 7 +-- 6 files changed, 109 insertions(+), 9 deletions(-) diff --git a/tests/src/QZXingTests/DecodeValidator.cpp b/tests/src/QZXingTests/DecodeValidator.cpp index f1402f3..6df600a 100644 --- a/tests/src/QZXingTests/DecodeValidator.cpp +++ b/tests/src/QZXingTests/DecodeValidator.cpp @@ -1,9 +1,22 @@ #include "DecodeValidator.h" +#include +#include +#include + DecodeValidator::DecodeValidator() : decoder() { } +QString DecodeValidator::getDataFromTextFile(const QString &filePath) +{ + QFile f(filePath); + if (!f.open(QFile::ReadOnly | QFile::Text)) + return ""; + QTextStream in(&f); + return in.readAll(); +} + std::shared_ptr DecodeValidator::testDecodeWithExpectedOutput(QZXing::DecoderFormat enabledDecoder, const QImage &imageToDecode, const QString &expectedOutput) { std::shared_ptr stats_ = std::make_shared(); @@ -19,3 +32,51 @@ std::shared_ptr DecodeValidator::testDecodeWithExpectedOutput(Q return stats_; } +std::shared_ptr DecodeValidator::testDecodeWithExpectedOutput(QZXing::DecoderFormat enabledDecoder, const QString &imageToDecodePath, const QString &expectedOutputFilePath) +{ + // QUrl imageUrl(imageToDecodePath); + QImage tmpImage = QImage(imageToDecodePath);//imageUrl.toLocalFile()); + QString expectedOutput = getDataFromTextFile(expectedOutputFilePath); + + std::shared_ptr stats_ = testDecodeWithExpectedOutput(enabledDecoder, tmpImage, expectedOutput); + + stats_->setImagePath(imageToDecodePath); + stats_->setExpectedOutput(expectedOutput); + + qDebug() << "Operation success: " << stats_->getOperationSuccess() + << ", Result Match: " << stats_->getResultMatch() + << ", Path: " << stats_->getImagePath() + //<< ", Expected Output: " << stats_->getExpectedOutput() + ; + return stats_; +} + +void DecodeValidator::decodeAllImagesInForderWithValidator(QZXing::DecoderFormat enabledDecoder, const QString &folderPath) +{ + QDirIterator dirIt(folderPath, QDirIterator::NoIteratorFlags); + + testResults[enabledDecoder] = std::vector>(); + + while (dirIt.hasNext()) { + dirIt.next(); + QFileInfo fileInfo(dirIt.filePath()); + if (fileInfo.isFile() && fileInfo.suffix() != "txt") { + QString imagePath = dirIt.filePath(); + QString expectedOutputTextFile = fileInfo.absoluteDir().absolutePath() + "/" + fileInfo.baseName() + ".txt"; + + testResults[enabledDecoder].push_back(testDecodeWithExpectedOutput(enabledDecoder, imagePath, expectedOutputTextFile)); + } + } +} + +void DecodeValidator::executeTests() +{ + decodeAllImagesInForderWithValidator(QZXing::DecoderFormat_Aztec, "../../resources/aztec-1"); + decodeAllImagesInForderWithValidator(QZXing::DecoderFormat_Aztec, "../../resources/aztec-2"); + decodeAllImagesInForderWithValidator(QZXing::DecoderFormat_QR_CODE, "../../resources/qrcode-1"); + decodeAllImagesInForderWithValidator(QZXing::DecoderFormat_QR_CODE, "../../resources/qrcode-2"); + decodeAllImagesInForderWithValidator(QZXing::DecoderFormat_QR_CODE, "../../resources/qrcode-3"); + decodeAllImagesInForderWithValidator(QZXing::DecoderFormat_QR_CODE, "../../resources/qrcode-4"); +} + + diff --git a/tests/src/QZXingTests/DecodeValidator.h b/tests/src/QZXingTests/DecodeValidator.h index e0d87ed..d1a26ee 100644 --- a/tests/src/QZXingTests/DecodeValidator.h +++ b/tests/src/QZXingTests/DecodeValidator.h @@ -4,18 +4,32 @@ #include "ValidationStats.h" #include #include +#include +#include class DecodeValidator { private: QZXing decoder; + std::map>> testResults; + + QString getDataFromTextFile(const QString &filePath); + + std::shared_ptr testDecodeWithExpectedOutput(QZXing::DecoderFormat enabledDecoder, + const QImage &imageToDecode, + const QString &expectedOutput); public: DecodeValidator(); std::shared_ptr testDecodeWithExpectedOutput(QZXing::DecoderFormat enabledDecoder, - const QImage &imageToDecode, - const QString &expectedOutput); + const QString &imageToDecodePath, + const QString &expectedOutputFilePath); + + void decodeAllImagesInForderWithValidator(QZXing::DecoderFormat enabledDecode, + const QString &folderPath); + + void executeTests(); }; #endif // DECODEVALIDATOR_H diff --git a/tests/src/QZXingTests/QZXingTests.pro b/tests/src/QZXingTests/QZXingTests.pro index 06ed942..1568a03 100644 --- a/tests/src/QZXingTests/QZXingTests.pro +++ b/tests/src/QZXingTests/QZXingTests.pro @@ -17,6 +17,4 @@ HEADERS += \ DecodeValidator.h \ ValidationStats.h - - include(../../../src/QZXing.pri) diff --git a/tests/src/QZXingTests/ValidationStats.cpp b/tests/src/QZXingTests/ValidationStats.cpp index 36fd92a..97e5bd3 100644 --- a/tests/src/QZXingTests/ValidationStats.cpp +++ b/tests/src/QZXingTests/ValidationStats.cpp @@ -40,8 +40,28 @@ void ValidationStats::setElaspedTime(const int64_t &value) elaspedTime = value; } -ValidationStats::ValidationStats() +QString ValidationStats::getExpectedOutput() const { - + return expectedOutput; +} + +void ValidationStats::setExpectedOutput(const QString &value) +{ + expectedOutput = value; +} + +QString ValidationStats::getImagePath() const +{ + return imagePath; +} + +void ValidationStats::setImagePath(const QString &value) +{ + imagePath = value; +} + +ValidationStats::ValidationStats() +{ + } diff --git a/tests/src/QZXingTests/ValidationStats.h b/tests/src/QZXingTests/ValidationStats.h index 0223893..9531997 100644 --- a/tests/src/QZXingTests/ValidationStats.h +++ b/tests/src/QZXingTests/ValidationStats.h @@ -7,6 +7,8 @@ class ValidationStats { private: + QString imagePath; + QString expectedOutput; bool operationSuccess; bool resultMatch; QString errorMessage; @@ -23,6 +25,10 @@ public: void setResultMatch(bool value); void setErrorMessage(const QString &value); void setElaspedTime(const int64_t &value); + QString getExpectedOutput() const; + void setExpectedOutput(const QString &value); + QString getImagePath() const; + void setImagePath(const QString &value); }; #endif // VALIDATIONSTATS_H diff --git a/tests/src/QZXingTests/main.cpp b/tests/src/QZXingTests/main.cpp index d93611d..8ce0ded 100644 --- a/tests/src/QZXingTests/main.cpp +++ b/tests/src/QZXingTests/main.cpp @@ -1,9 +1,10 @@ #include +#include "DecodeValidator.h" + int main(int argc, char *argv[]) { - QCoreApplication a(argc, argv); - - return a.exec(); + DecodeValidator decodeValidator; + decodeValidator.executeTests(); }