added implementation of zxing/qrcode/encoder/QRCodeTests

This commit is contained in:
favoritas37 2016-07-22 02:05:30 +03:00
parent 7ca98d0365
commit 711d9537b9
2 changed files with 147 additions and 0 deletions

View File

@ -0,0 +1,120 @@
#include "QRCodeTests.h"
#include <zxing/qrcode/encoder/QRCode.h>
namespace zxing{
namespace qrcode{
namespace tests{
QRCodeTests::QRCodeTests()
{
}
void QRCodeTests::execute()
{
test();
testToString1();
testToString2();
testIsValidMaskPattern();
}
void QRCodeTests::test()
{
QRCode qrCode;
// First, test simple setters and getters.
// We use numbers of version 7-H.
qrCode.setMode(Mode::BYTE);
qrCode.setECLevel(Ref<ErrorCorrectionLevel>(new ErrorCorrectionLevel(ErrorCorrectionLevel::H)));
qrCode.setVersion(Version::getVersionForNumber(7));
qrCode.setMaskPattern(3);
assertEquals(7, qrCode.getVersion()->getVersionNumber());
assertEquals(3, qrCode.getMaskPattern());
// Prepare the matrix.
Ref<ByteMatrix> matrix(new ByteMatrix(45, 45));
// Just set bogus zero/one values.
for (int y = 0; y < 45; ++y) {
for (int x = 0; x < 45; ++x) {
matrix->set(x, y, (byte)((y + x) % 2));
}
}
// Set the matrix.
qrCode.setMatrix(matrix);
assertSame(matrix, qrCode.getMatrix());
}
void QRCodeTests::testToString1() {
QRCode qrCode;
std::string expected =
"<<\n"
// " mode: null\n"
" ecLevel: {unimpl}\n"
" version: {unimpl}\n"
" maskPattern: -1\n"
" matrix: null\n"
"\n>>";
assertEquals(expected, qrCode.toString());
}
void QRCodeTests::testToString2()
{
QRCode qrCode;
qrCode.setMode(Mode::BYTE);
qrCode.setECLevel(Ref<ErrorCorrectionLevel>(new ErrorCorrectionLevel(ErrorCorrectionLevel::H)));
qrCode.setVersion(Version::getVersionForNumber(1));
qrCode.setMaskPattern(3);
Ref<ByteMatrix> matrix(new ByteMatrix(21, 21));
for (int y = 0; y < 21; ++y) {
for (int x = 0; x < 21; ++x) {
matrix->set(x, y, (byte)((y + x) % 2));
}
}
qrCode.setMatrix(matrix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0 1 0 1 0 1 0 1\n"
" 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n"
"\n>>";
assertEquals(expected, qrCode.toString());
}
void QRCodeTests::testIsValidMaskPattern()
{
assertFalse(QRCode::isValidMaskPattern(-1));
assertTrue(QRCode::isValidMaskPattern(0));
assertTrue(QRCode::isValidMaskPattern(7));
assertFalse(QRCode::isValidMaskPattern(8));
}
}
}
}

View File

@ -0,0 +1,27 @@
#ifndef QRCODETESTS_H
#define QRCODETESTS_H
#include "TestCase.h"
namespace zxing{
namespace qrcode{
namespace tests{
class QRCodeTests : public TestCase
{
public:
QRCodeTests();
void execute();
private:
void test();
void testToString1();
void testToString2();
void testIsValidMaskPattern();
};
}
}
}
#endif // QRCODETESTS_H