mirror of https://github.com/status-im/qzxing.git
First end-to-end version of the automated test. Needs to be further enhanced and add more result analysis.
This commit is contained in:
parent
a4c8f03d7b
commit
664561bcb1
|
@ -1,9 +1,22 @@
|
||||||
#include "DecodeValidator.h"
|
#include "DecodeValidator.h"
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
|
#include <QDirIterator>
|
||||||
|
#include <QFileInfo>
|
||||||
|
|
||||||
DecodeValidator::DecodeValidator() : decoder()
|
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<ValidationStats> DecodeValidator::testDecodeWithExpectedOutput(QZXing::DecoderFormat enabledDecoder, const QImage &imageToDecode, const QString &expectedOutput)
|
std::shared_ptr<ValidationStats> DecodeValidator::testDecodeWithExpectedOutput(QZXing::DecoderFormat enabledDecoder, const QImage &imageToDecode, const QString &expectedOutput)
|
||||||
{
|
{
|
||||||
std::shared_ptr<ValidationStats> stats_ = std::make_shared<ValidationStats>();
|
std::shared_ptr<ValidationStats> stats_ = std::make_shared<ValidationStats>();
|
||||||
|
@ -19,3 +32,51 @@ std::shared_ptr<ValidationStats> DecodeValidator::testDecodeWithExpectedOutput(Q
|
||||||
return stats_;
|
return stats_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<ValidationStats> 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<ValidationStats> 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<std::shared_ptr<ValidationStats>>();
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,18 +4,32 @@
|
||||||
#include "ValidationStats.h"
|
#include "ValidationStats.h"
|
||||||
#include <QZXing.h>
|
#include <QZXing.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
class DecodeValidator
|
class DecodeValidator
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
QZXing decoder;
|
QZXing decoder;
|
||||||
|
std::map<QZXing::DecoderFormat, std::vector<std::shared_ptr<ValidationStats>>> testResults;
|
||||||
|
|
||||||
|
QString getDataFromTextFile(const QString &filePath);
|
||||||
|
|
||||||
|
std::shared_ptr<ValidationStats> testDecodeWithExpectedOutput(QZXing::DecoderFormat enabledDecoder,
|
||||||
|
const QImage &imageToDecode,
|
||||||
|
const QString &expectedOutput);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DecodeValidator();
|
DecodeValidator();
|
||||||
|
|
||||||
std::shared_ptr<ValidationStats> testDecodeWithExpectedOutput(QZXing::DecoderFormat enabledDecoder,
|
std::shared_ptr<ValidationStats> testDecodeWithExpectedOutput(QZXing::DecoderFormat enabledDecoder,
|
||||||
const QImage &imageToDecode,
|
const QString &imageToDecodePath,
|
||||||
const QString &expectedOutput);
|
const QString &expectedOutputFilePath);
|
||||||
|
|
||||||
|
void decodeAllImagesInForderWithValidator(QZXing::DecoderFormat enabledDecode,
|
||||||
|
const QString &folderPath);
|
||||||
|
|
||||||
|
void executeTests();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DECODEVALIDATOR_H
|
#endif // DECODEVALIDATOR_H
|
||||||
|
|
|
@ -17,6 +17,4 @@ HEADERS += \
|
||||||
DecodeValidator.h \
|
DecodeValidator.h \
|
||||||
ValidationStats.h
|
ValidationStats.h
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
include(../../../src/QZXing.pri)
|
include(../../../src/QZXing.pri)
|
||||||
|
|
|
@ -40,8 +40,28 @@ void ValidationStats::setElaspedTime(const int64_t &value)
|
||||||
elaspedTime = 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()
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
class ValidationStats
|
class ValidationStats
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
QString imagePath;
|
||||||
|
QString expectedOutput;
|
||||||
bool operationSuccess;
|
bool operationSuccess;
|
||||||
bool resultMatch;
|
bool resultMatch;
|
||||||
QString errorMessage;
|
QString errorMessage;
|
||||||
|
@ -23,6 +25,10 @@ public:
|
||||||
void setResultMatch(bool value);
|
void setResultMatch(bool value);
|
||||||
void setErrorMessage(const QString &value);
|
void setErrorMessage(const QString &value);
|
||||||
void setElaspedTime(const int64_t &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
|
#endif // VALIDATIONSTATS_H
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
|
||||||
|
#include "DecodeValidator.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QCoreApplication a(argc, argv);
|
DecodeValidator decodeValidator;
|
||||||
|
decodeValidator.executeTests();
|
||||||
return a.exec();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue