mirror of https://github.com/status-im/qzxing.git
refactoring on the namespaces
Added call to ReedSolomonEncoderTests
This commit is contained in:
parent
55c2e7547d
commit
5b5b851c96
|
@ -20,8 +20,8 @@ public:
|
|||
QImage getOriginalImage();
|
||||
Ref<GreyscaleLuminanceSource> getDelegate() { return delegate; }
|
||||
|
||||
ArrayRef<byte> getRow(int y, ArrayRef<byte> row) const;
|
||||
ArrayRef<byte> getMatrix() const;
|
||||
ArrayRef<zxing::byte> getRow(int y, ArrayRef<zxing::byte> row) const;
|
||||
ArrayRef<zxing::byte> getMatrix() const;
|
||||
|
||||
bool isCropSupported() const;
|
||||
Ref<LuminanceSource> crop(int left, int top, int width, int height) const;
|
||||
|
@ -30,8 +30,8 @@ public:
|
|||
Ref<LuminanceSource> rotateCounterClockwise() const;
|
||||
|
||||
private:
|
||||
ArrayRef<byte> getRowP(int y, ArrayRef<byte> row) const;
|
||||
ArrayRef<byte> getMatrixP() const;
|
||||
ArrayRef<zxing::byte> getRowP(int y, ArrayRef<zxing::byte> row) const;
|
||||
ArrayRef<zxing::byte> getMatrixP() const;
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0))
|
||||
QImage* grayScaleImage(const QImage *origin);
|
||||
#endif
|
||||
|
|
|
@ -341,7 +341,7 @@ QImage QZXing::encodeData(const QString& data)
|
|||
try {
|
||||
Ref<qrcode::QRCode> barcode = qrcode::Encoder::encode(data, qrcode::ErrorCorrectionLevel::L );
|
||||
Ref<qrcode::ByteMatrix> bytesRef = barcode->getMatrix();
|
||||
const std::vector< std::vector <byte> >& bytes = bytesRef->getArray();
|
||||
const std::vector< std::vector <zxing::byte> >& bytes = bytesRef->getArray();
|
||||
image = QImage(bytesRef->getWidth(), bytesRef->getHeight(), QImage::Format_ARGB32);
|
||||
for(int i=0; i<bytesRef->getWidth(); i++)
|
||||
for(int j=0; j<bytesRef->getHeight(); j++)
|
||||
|
|
|
@ -27,6 +27,9 @@ using zxing::BitArray;
|
|||
// VC++
|
||||
using zxing::Ref;
|
||||
|
||||
|
||||
namespace zxing {
|
||||
|
||||
int BitArray::makeArraySize(int size) {
|
||||
return (size + 31) / 32;
|
||||
}
|
||||
|
@ -275,3 +278,5 @@ const std::string BitArray::toString() const
|
|||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,14 +29,17 @@
|
|||
|
||||
using zxing::Ref;
|
||||
using zxing::DecoderResult;
|
||||
using zxing::datamatrix::Decoder;
|
||||
using zxing::datamatrix::DataBlock;
|
||||
using zxing::datamatrix::DecodedBitStreamParser;
|
||||
//using zxing::datamatrix::Decoder;
|
||||
//using zxing::datamatrix::DataBlock;
|
||||
//using zxing::datamatrix::DecodedBitStreamParser;
|
||||
|
||||
// VC++
|
||||
using zxing::ArrayRef;
|
||||
using zxing::BitMatrix;
|
||||
|
||||
namespace zxing {
|
||||
namespace datamatrix {
|
||||
|
||||
Decoder::Decoder() : rsDecoder_(GenericGF::DATA_MATRIX_FIELD_256) {}
|
||||
|
||||
void Decoder::correctErrors(ArrayRef<byte> codewordBytes, int numDataCodewords) {
|
||||
|
@ -93,3 +96,6 @@ Ref<DecoderResult> Decoder::decode(Ref<BitMatrix> bits) {
|
|||
DecodedBitStreamParser decodedBSParser;
|
||||
return Ref<DecoderResult> (decodedBSParser.decode(resultBytes));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -427,10 +427,9 @@ ArrayRef<byte> Encoder::generateECBytes(const std::vector<byte>& dataBytes, int
|
|||
{
|
||||
int numDataBytes = dataBytes.size();
|
||||
std::vector<int> toEncode;
|
||||
toEncode.resize(numDataBytes + numEcBytesInBlock);
|
||||
toEncode.resize(numDataBytes + numEcBytesInBlock);
|
||||
for (int i = 0; i < numDataBytes; i++)
|
||||
//toEncode[i] = dataBytes[i];
|
||||
toEncode[i] = dataBytes[i] & 0xFF;
|
||||
toEncode[i] = dataBytes[i];
|
||||
|
||||
zxing::ReedSolomonEncoder encoder(GenericGF::QR_CODE_FIELD_256);
|
||||
encoder.encode(toEncode, numEcBytesInBlock);
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
#include "zxing/qrcode/encoder/BitArrayTests.h"
|
||||
#include "zxing/qrcode/encoder/QRCodeTests.h"
|
||||
#include "zxing/qrcode/encoder/EncoderTests.h"
|
||||
#include "zxing/common/reedsolomon/ReedSolomonEncoderTests.h"
|
||||
|
||||
namespace zxing {
|
||||
namespace qrcode {
|
||||
namespace tests{
|
||||
|
||||
EncodeValidator::EncodeValidator()
|
||||
|
@ -21,110 +21,28 @@ EncodeValidator::EncodeValidator()
|
|||
void EncodeValidator::execute()
|
||||
{
|
||||
try{
|
||||
MatrixUtilTests t;
|
||||
qrcode::tests::MatrixUtilTests t;
|
||||
t.execute();
|
||||
|
||||
MaskUtilTests t1;
|
||||
qrcode::tests::MaskUtilTests t1;
|
||||
t1.execute();
|
||||
|
||||
BitArrayTests t2;
|
||||
qrcode::tests::BitArrayTests t2;
|
||||
t2.execute();
|
||||
|
||||
QRCodeTests t3;
|
||||
qrcode::tests::QRCodeTests t3;
|
||||
t3.execute();
|
||||
|
||||
EncoderTests t4;
|
||||
ReedSolomonEncoderTests t4;
|
||||
t4.execute();
|
||||
|
||||
qrcode::tests::EncoderTests t5;
|
||||
t5.execute();
|
||||
|
||||
} catch(zxing::Exception &e) {
|
||||
qDebug() << "Exception: " << e.what();
|
||||
}
|
||||
}
|
||||
|
||||
void EncodeValidator::executeQrCodeEncodeTest()
|
||||
{
|
||||
// zxing::qrcode::QRCode qrCode = new zxing::qrcode::QRCode();
|
||||
|
||||
// // First, test simple setters and getters.
|
||||
// // We use numbers of version 7-H.
|
||||
// qrCode.setMode(zxing::qrcode::Mode.BYTE);
|
||||
// qrCode.setECLevel(zxing::qrcode::ErrorCorrectionLevel.H);
|
||||
// qrCode.setVersion(zxing::qrcode::Version.getVersionForNumber(7));
|
||||
// qrCode.setMaskPattern(3);
|
||||
|
||||
// bool modeEquals = Mode.BYTE == qrCode.getMode();
|
||||
// bool errorCodeEquals = zxing::qrcode::ErrorCorrectionLevel.H == qrCode.getECLevel();
|
||||
// bool versionEquals = 7 == qrCode.getVersion().getVersionNumber();
|
||||
// bool maskPatternEquals = 3 = qrCode.getMaskPattern();
|
||||
|
||||
// // Prepare the matrix.
|
||||
// zxing::qrcode::ByteMatrix matrix = new zxing::qrcode::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, (y + x) % 2);
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Set the matrix.
|
||||
// qrCode.setMatrix(matrix);
|
||||
// assertSame(matrix, qrCode.getMatrix());
|
||||
}
|
||||
|
||||
void EncodeValidator::testGetAlphanumericCode() {
|
||||
// The first ten code points are numbers.
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
assertEquals(i, Encoder::getAlphanumericCode('0' + i));
|
||||
}
|
||||
|
||||
// The next 26 code points are capital alphabet letters.
|
||||
for (int i = 10; i < 36; ++i) {
|
||||
assertEquals(i, Encoder::getAlphanumericCode('A' + i - 10));
|
||||
}
|
||||
|
||||
// Others are symbol letters
|
||||
assertEquals(36, Encoder::getAlphanumericCode(' '));
|
||||
assertEquals(37, Encoder::getAlphanumericCode('$'));
|
||||
assertEquals(38, Encoder::getAlphanumericCode('%'));
|
||||
assertEquals(39, Encoder::getAlphanumericCode('*'));
|
||||
assertEquals(40, Encoder::getAlphanumericCode('+'));
|
||||
assertEquals(41, Encoder::getAlphanumericCode('-'));
|
||||
assertEquals(42, Encoder::getAlphanumericCode('.'));
|
||||
assertEquals(43, Encoder::getAlphanumericCode('/'));
|
||||
assertEquals(44, Encoder::getAlphanumericCode(':'));
|
||||
|
||||
// Should return -1 for other letters;
|
||||
assertEquals(-1, Encoder::getAlphanumericCode('a'));
|
||||
assertEquals(-1, Encoder::getAlphanumericCode('#'));
|
||||
assertEquals(-1, Encoder::getAlphanumericCode('\0'));
|
||||
}
|
||||
|
||||
void EncodeValidator::testChooseMode(){
|
||||
// // Numeric mode.
|
||||
// assertSame(Mode::NUMERIC, Mode::chooseMode("0"));
|
||||
// assertSame(Mode::NUMERIC, Mode::chooseMode("0123456789"));
|
||||
// // Alphanumeric mode.
|
||||
// assertSame(Mode::ALPHANUMERIC, Mode::chooseMode("A"));
|
||||
// assertSame(Mode::ALPHANUMERIC,
|
||||
// Encoder.chooseMode("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:"));
|
||||
// // 8-bit byte mode.
|
||||
// assertSame(Mode::BYTE, Mode::chooseMode("a"));
|
||||
// assertSame(Mode::BYTE, Mode::chooseMode("#"));
|
||||
// assertSame(Mode::BYTE, Mode::chooseMode(""));
|
||||
// // Kanji mode. We used to use MODE_KANJI for these, but we stopped
|
||||
// // doing that as we cannot distinguish Shift_JIS from other encodings
|
||||
// // from data bytes alone. See also comments in qrcode_encoder.h.
|
||||
|
||||
// // AIUE in Hiragana in Shift_JIS
|
||||
// assertSame(Mode::BYTE,
|
||||
// Encoder::chooseMode(shiftJISString(new byte[]{0x8, 0xa, 0x8, 0xa, 0x8, 0xa, 0x8, (byte) 0xa6})));
|
||||
|
||||
// // Nihon in Kanji in Shift_JIS.
|
||||
// assertSame(Mode::BYTE, Encoder::chooseMode(shiftJISString(new byte[]{0x9, 0xf, 0x9, 0x7b})));
|
||||
|
||||
// // Sou-Utsu-Byou in Kanji in Shift_JIS.
|
||||
// assertSame(Mode::BYTE, Encoder::chooseMode(shiftJISString(new byte[]{0xe, 0x4, 0x9, 0x5, 0x9, 0x61})));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include <TestCase.h>
|
||||
|
||||
namespace zxing {
|
||||
namespace qrcode {
|
||||
namespace tests{
|
||||
|
||||
class EncodeValidator : public TestCase
|
||||
|
@ -19,15 +18,8 @@ class EncodeValidator : public TestCase
|
|||
public:
|
||||
EncodeValidator();
|
||||
void execute();
|
||||
|
||||
private:
|
||||
void executeQrCodeEncodeTest();
|
||||
void testGetAlphanumericCode();
|
||||
|
||||
void testChooseMode();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@ SOURCES += main.cpp \
|
|||
zxing/qrcode/encoder/MaskUtilTests.cpp \
|
||||
zxing/qrcode/encoder/BitArrayTests.cpp \
|
||||
zxing/qrcode/encoder/QRCodeTests.cpp \
|
||||
zxing/qrcode/encoder/EncoderTests.cpp
|
||||
zxing/qrcode/encoder/EncoderTests.cpp \
|
||||
zxing/common/reedsolomon/ReedSolomonEncoderTests.cpp
|
||||
|
||||
HEADERS += \
|
||||
DecodeValidator.h \
|
||||
|
@ -29,6 +30,7 @@ HEADERS += \
|
|||
zxing/qrcode/encoder/MaskUtilTests.h \
|
||||
zxing/qrcode/encoder/BitArrayTests.h \
|
||||
zxing/qrcode/encoder/QRCodeTests.h \
|
||||
zxing/qrcode/encoder/EncoderTests.h
|
||||
zxing/qrcode/encoder/EncoderTests.h \
|
||||
zxing/common/reedsolomon/ReedSolomonEncoderTests.h
|
||||
|
||||
include(../../../src/QZXing.pri)
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
|
||||
#include "DecodeValidator.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int main(int /*argc*/, char */*argv[]*/)
|
||||
{
|
||||
DecodeValidator decodeValidator;
|
||||
decodeValidator.executeTests("../../resources/");
|
||||
|
||||
zxing::qrcode::tests::EncodeValidator encodeValidator;
|
||||
zxing::tests::EncodeValidator encodeValidator;
|
||||
encodeValidator.execute();
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@ void EncoderTests::execute()
|
|||
testInterleaveWithECBytes();
|
||||
testAppendNumericBytes();
|
||||
testAppendAlphanumericBytes();
|
||||
testAppend8BitBytes();
|
||||
testGenerateECBytes();
|
||||
}
|
||||
|
||||
void EncoderTests::testGetAlphanumericCode()
|
||||
|
@ -138,11 +140,11 @@ void EncoderTests::testAppendBytes()
|
|||
assertEquals(" ..X.X." , bits.toString());
|
||||
// Lower letters such as 'a' cannot be encoded in MODE_ALPHANUMERIC.
|
||||
ASSERT_THROWS(
|
||||
EncoderHack::appendBytes("a", Mode::ALPHANUMERIC, bits, EncoderHack::DEFAULT_BYTE_MODE_ENCODING);
|
||||
)
|
||||
// Should use append8BitBytes.
|
||||
// 0x61, 0x62, 0x63
|
||||
bits = BitArray();
|
||||
EncoderHack::appendBytes("a", Mode::ALPHANUMERIC, bits, EncoderHack::DEFAULT_BYTE_MODE_ENCODING);
|
||||
)
|
||||
// Should use append8BitBytes.
|
||||
// 0x61, 0x62, 0x63
|
||||
bits = BitArray();
|
||||
EncoderHack::appendBytes("abc", Mode::BYTE, bits, EncoderHack::DEFAULT_BYTE_MODE_ENCODING);
|
||||
assertEquals(" .XX....X .XX...X. .XX...XX", bits.toString());
|
||||
// Anything can be encoded in QRCode.MODE_8BIT_BYTE.
|
||||
|
@ -339,6 +341,51 @@ void EncoderTests::testAppendAlphanumericBytes()
|
|||
ASSERT_THROWS( Encoder::appendAlphanumericBytes("abc", bits); )
|
||||
}
|
||||
|
||||
void EncoderTests::testAppend8BitBytes()
|
||||
{
|
||||
BitArray bits;
|
||||
Encoder::append8BitBytes("abc", bits, Encoder::DEFAULT_BYTE_MODE_ENCODING);
|
||||
assertEquals(" .XX....X .XX...X. .XX...XX", bits.toString());
|
||||
// Empty.
|
||||
bits = BitArray();
|
||||
Encoder::append8BitBytes("", bits, Encoder::DEFAULT_BYTE_MODE_ENCODING);
|
||||
assertEquals("", bits.toString());
|
||||
}
|
||||
|
||||
void EncoderTests::testGenerateECBytes()
|
||||
{
|
||||
const byte dataBytes_arr[] = {32, 65, (byte)205, 69, 41, (byte)220, 46, (byte)128, (byte)236};
|
||||
std::vector<byte> dataBytes (dataBytes_arr, dataBytes_arr + getArrayLength(dataBytes_arr));
|
||||
ArrayRef<byte> ecBytes = Encoder::generateECBytes(dataBytes, 17);
|
||||
const int expected[] = {
|
||||
42, 159, 74, 221, 244, 169, 239, 150, 138, 70, 237, 85, 224, 96, 74, 219, 61
|
||||
};
|
||||
assertEquals( getArrayLength(expected), ecBytes.count());
|
||||
for (int x = 0; x < getArrayLength(expected); x++) {
|
||||
assertEquals(expected[x], ecBytes[x] & 0xFF);
|
||||
}
|
||||
// dataBytes = new byte[] {67, 70, 22, 38, 54, 70, 86, 102, 118,
|
||||
// (byte)134, (byte)150, (byte)166, (byte)182, (byte)198, (byte)214};
|
||||
// ecBytes = Encoder.generateECBytes(dataBytes, 18);
|
||||
// expected = new int[] {
|
||||
// 175, 80, 155, 64, 178, 45, 214, 233, 65, 209, 12, 155, 117, 31, 140, 214, 27, 187
|
||||
// };
|
||||
// assertEquals(expected.length, ecBytes.length);
|
||||
// for (int x = 0; x < expected.length; x++) {
|
||||
// assertEquals(expected[x], ecBytes[x] & 0xFF);
|
||||
// }
|
||||
// // High-order zero coefficient case.
|
||||
// dataBytes = new byte[] {32, 49, (byte)205, 69, 42, 20, 0, (byte)236, 17};
|
||||
// ecBytes = Encoder.generateECBytes(dataBytes, 17);
|
||||
// expected = new int[] {
|
||||
// 0, 3, 130, 179, 194, 0, 55, 211, 110, 79, 98, 72, 170, 96, 211, 137, 213
|
||||
// };
|
||||
// assertEquals(expected.length, ecBytes.length);
|
||||
// for (int x = 0; x < expected.length; x++) {
|
||||
// assertEquals(expected[x], ecBytes[x] & 0xFF);
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -34,6 +34,9 @@ private:
|
|||
void testInterleaveWithECBytes();
|
||||
void testAppendNumericBytes();
|
||||
void testAppendAlphanumericBytes();
|
||||
void testAppend8BitBytes();
|
||||
//void testAppendKanjiBytes(); not yet supported
|
||||
void testGenerateECBytes();
|
||||
|
||||
static std::string shiftJISString(byte bytes[]);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue