From 5507ab47866acb6cd1297a51f036192b9f529ce0 Mon Sep 17 00:00:00 2001 From: favoritas37 Date: Tue, 19 Jan 2016 21:49:23 +0200 Subject: [PATCH] expanded the selection of test folders in test application --- tests/src/QZXingTests/DecodeValidator.cpp | 73 +++++++++++++++++++---- tests/src/QZXingTests/DecodeValidator.h | 8 ++- tests/src/QZXingTests/ValidationStats.cpp | 8 ++- tests/src/QZXingTests/main.cpp | 2 +- 4 files changed, 76 insertions(+), 15 deletions(-) diff --git a/tests/src/QZXingTests/DecodeValidator.cpp b/tests/src/QZXingTests/DecodeValidator.cpp index 6df600a..005c0e5 100644 --- a/tests/src/QZXingTests/DecodeValidator.cpp +++ b/tests/src/QZXingTests/DecodeValidator.cpp @@ -4,8 +4,30 @@ #include #include -DecodeValidator::DecodeValidator() : decoder() +DecodeValidator::DecodeValidator() : decoder(), decoderCorrelationMap(), testResults() { + initializeDecoderCorrelation(); +} + +void DecodeValidator::initializeDecoderCorrelation() +{ + decoderCorrelationMap["aztec"] = QZXing::DecoderFormat_Aztec; + decoderCorrelationMap["codabar"] = QZXing::DecoderFormat_CODABAR; + decoderCorrelationMap["code39"] = QZXing::DecoderFormat_CODE_39; + decoderCorrelationMap["code93"] = QZXing::DecoderFormat_CODE_93; + decoderCorrelationMap["code128"] = QZXing::DecoderFormat_CODE_128; + decoderCorrelationMap["datamatrix"] = QZXing::DecoderFormat_DATA_MATRIX; + decoderCorrelationMap["ean8"] = QZXing::DecoderFormat_EAN_8; + decoderCorrelationMap["ean13"] = QZXing::DecoderFormat_EAN_13; + decoderCorrelationMap["itf"] = QZXing::DecoderFormat_ITF; + decoderCorrelationMap["pdf417"] = QZXing::DecoderFormat_PDF_417; + decoderCorrelationMap["qrcode"] = QZXing::DecoderFormat_QR_CODE; + decoderCorrelationMap["rss14"] = QZXing::DecoderFormat_RSS_14; + decoderCorrelationMap["rssexpanded"] = QZXing::DecoderFormat_RSS_EXPANDED; + decoderCorrelationMap["rssexpandedstacked"] = QZXing::DecoderFormat_RSS_EXPANDED; //??? + decoderCorrelationMap["upca"] = QZXing::DecoderFormat_UPC_A; + decoderCorrelationMap["upce"] = QZXing::DecoderFormat_UPC_E; + decoderCorrelationMap["upcean"] = QZXing::DecoderFormat_UPC_EAN_EXTENSION; } QString DecodeValidator::getDataFromTextFile(const QString &filePath) @@ -32,10 +54,24 @@ std::shared_ptr DecodeValidator::testDecodeWithExpectedOutput(Q return stats_; } +QZXing::DecoderFormat DecodeValidator::getDecoderForFolder(const QString &folderName) +{ + QStringList parts = folderName.split("-"); + + if(!parts.size()) + return QZXing::DecoderFormat_None; + + std::map::iterator it; + it = decoderCorrelationMap.find(parts[0]); + if (it != decoderCorrelationMap.end()) + return decoderCorrelationMap[parts[0]]; + else + return QZXing::DecoderFormat_None; +} + std::shared_ptr DecodeValidator::testDecodeWithExpectedOutput(QZXing::DecoderFormat enabledDecoder, const QString &imageToDecodePath, const QString &expectedOutputFilePath) { - // QUrl imageUrl(imageToDecodePath); - QImage tmpImage = QImage(imageToDecodePath);//imageUrl.toLocalFile()); + QImage tmpImage = QImage(imageToDecodePath); QString expectedOutput = getDataFromTextFile(expectedOutputFilePath); std::shared_ptr stats_ = testDecodeWithExpectedOutput(enabledDecoder, tmpImage, expectedOutput); @@ -46,16 +82,18 @@ std::shared_ptr DecodeValidator::testDecodeWithExpectedOutput(Q qDebug() << "Operation success: " << stats_->getOperationSuccess() << ", Result Match: " << stats_->getResultMatch() << ", Path: " << stats_->getImagePath() - //<< ", Expected Output: " << stats_->getExpectedOutput() + //<< ", Expected Output: " << stats_->getExpectedOutput() ; return stats_; } void DecodeValidator::decodeAllImagesInForderWithValidator(QZXing::DecoderFormat enabledDecoder, const QString &folderPath) { + // auto test = std::vector>(); + QDirIterator dirIt(folderPath, QDirIterator::NoIteratorFlags); - testResults[enabledDecoder] = std::vector>(); + // testResults.insert(enabledDecoder, std::move(test)); while (dirIt.hasNext()) { dirIt.next(); @@ -69,14 +107,25 @@ void DecodeValidator::decodeAllImagesInForderWithValidator(QZXing::DecoderFormat } } -void DecodeValidator::executeTests() +void DecodeValidator::executeTests(const QString &folderPath) { - 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"); + QDirIterator dirIt(folderPath, QDirIterator::NoIteratorFlags); + + while (dirIt.hasNext()) { + dirIt.next(); + QFileInfo fileInfo(dirIt.filePath()); + if (fileInfo.isDir()) { + QString subfolderPath = dirIt.filePath(); + QString subfolderName = dirIt.fileName(); + + QZXing::DecoderFormat decoderFormat = getDecoderForFolder(subfolderName); + + qDebug() << "Decoding folder: " << subfolderPath; + if(decoderFormat != QZXing::DecoderFormat_None) + decodeAllImagesInForderWithValidator(decoderFormat, subfolderPath); + } + } + } diff --git a/tests/src/QZXingTests/DecodeValidator.h b/tests/src/QZXingTests/DecodeValidator.h index d1a26ee..385d117 100644 --- a/tests/src/QZXingTests/DecodeValidator.h +++ b/tests/src/QZXingTests/DecodeValidator.h @@ -6,19 +6,25 @@ #include #include #include +#include class DecodeValidator { private: QZXing decoder; + std::map decoderCorrelationMap; std::map>> testResults; + void initializeDecoderCorrelation(); + QString getDataFromTextFile(const QString &filePath); std::shared_ptr testDecodeWithExpectedOutput(QZXing::DecoderFormat enabledDecoder, const QImage &imageToDecode, const QString &expectedOutput); + QZXing::DecoderFormat getDecoderForFolder(const QString &folderName); + public: DecodeValidator(); @@ -29,7 +35,7 @@ public: void decodeAllImagesInForderWithValidator(QZXing::DecoderFormat enabledDecode, const QString &folderPath); - void executeTests(); + void executeTests(const QString &folderPath); }; #endif // DECODEVALIDATOR_H diff --git a/tests/src/QZXingTests/ValidationStats.cpp b/tests/src/QZXingTests/ValidationStats.cpp index 97e5bd3..a796e6f 100644 --- a/tests/src/QZXingTests/ValidationStats.cpp +++ b/tests/src/QZXingTests/ValidationStats.cpp @@ -60,7 +60,13 @@ void ValidationStats::setImagePath(const QString &value) imagePath = value; } -ValidationStats::ValidationStats() +ValidationStats::ValidationStats(): + imagePath(""), + expectedOutput(""), + operationSuccess(false), + resultMatch(false), + errorMessage(""), + elaspedTime(0) { } diff --git a/tests/src/QZXingTests/main.cpp b/tests/src/QZXingTests/main.cpp index 8ce0ded..6d6914a 100644 --- a/tests/src/QZXingTests/main.cpp +++ b/tests/src/QZXingTests/main.cpp @@ -5,6 +5,6 @@ int main(int argc, char *argv[]) { DecodeValidator decodeValidator; - decodeValidator.executeTests(); + decodeValidator.executeTests("../../resources/"); }