expanded the selection of test folders in test application

This commit is contained in:
favoritas37 2016-01-19 21:49:23 +02:00
parent 664561bcb1
commit 5507ab4786
4 changed files with 76 additions and 15 deletions

View File

@ -4,8 +4,30 @@
#include <QDirIterator>
#include <QFileInfo>
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<ValidationStats> 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<QString,QZXing::DecoderFormat>::iterator it;
it = decoderCorrelationMap.find(parts[0]);
if (it != decoderCorrelationMap.end())
return decoderCorrelationMap[parts[0]];
else
return QZXing::DecoderFormat_None;
}
std::shared_ptr<ValidationStats> 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<ValidationStats> stats_ = testDecodeWithExpectedOutput(enabledDecoder, tmpImage, expectedOutput);
@ -46,16 +82,18 @@ std::shared_ptr<ValidationStats> 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<std::shared_ptr<ValidationStats>>();
QDirIterator dirIt(folderPath, QDirIterator::NoIteratorFlags);
testResults[enabledDecoder] = std::vector<std::shared_ptr<ValidationStats>>();
// 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);
}
}
}

View File

@ -6,19 +6,25 @@
#include <memory>
#include <vector>
#include <map>
#include <QMap>
class DecodeValidator
{
private:
QZXing decoder;
std::map<QString,QZXing::DecoderFormat> decoderCorrelationMap;
std::map<QZXing::DecoderFormat, std::vector<std::shared_ptr<ValidationStats>>> testResults;
void initializeDecoderCorrelation();
QString getDataFromTextFile(const QString &filePath);
std::shared_ptr<ValidationStats> 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

View File

@ -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)
{
}

View File

@ -5,6 +5,6 @@
int main(int argc, char *argv[])
{
DecodeValidator decodeValidator;
decodeValidator.executeTests();
decodeValidator.executeTests("../../resources/");
}