mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-25 20:02:34 +00:00
port QRBitMatrixParserTest
This commit is contained in:
@@ -1,73 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2017 Huy Cuong Nguyen
|
|
||||||
* Copyright 2008 ZXing authors
|
|
||||||
*/
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
#include "BitMatrix.h"
|
|
||||||
#include "BitMatrixIO.h"
|
|
||||||
#include "ByteArray.h"
|
|
||||||
#include "qrcode/QRBitMatrixParser.h"
|
|
||||||
#include "qrcode/QRFormatInformation.h"
|
|
||||||
#include "qrcode/QRVersion.h"
|
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
|
||||||
|
|
||||||
using namespace ZXing;
|
|
||||||
using namespace ZXing::QRCode;
|
|
||||||
|
|
||||||
TEST(QRBitMatrixParserTest, MQRCodeM3L)
|
|
||||||
{
|
|
||||||
const auto bitMatrix = ParseBitMatrix("XXXXXXX X X X X\n"
|
|
||||||
"X X X X \n"
|
|
||||||
"X XXX X XXXXXXX\n"
|
|
||||||
"X XXX X X X XX\n"
|
|
||||||
"X XXX X X XX\n"
|
|
||||||
"X X X X X X\n"
|
|
||||||
"XXXXXXX X XX \n"
|
|
||||||
" X X X\n"
|
|
||||||
"XXXXXX X X X\n"
|
|
||||||
" X XX XXX\n"
|
|
||||||
"XXX XX XXXX XXX\n"
|
|
||||||
" X X XXX X \n"
|
|
||||||
"X XXXXX XXX X X\n"
|
|
||||||
" X X X XXX \n"
|
|
||||||
"XXX XX X X XXXX\n",
|
|
||||||
88, false);
|
|
||||||
|
|
||||||
const auto version = ReadVersion(bitMatrix);
|
|
||||||
EXPECT_EQ(3, version->versionNumber());
|
|
||||||
const auto format = ReadFormatInformation(bitMatrix, true);
|
|
||||||
const auto codewords = ReadCodewords(bitMatrix, *version, format);
|
|
||||||
EXPECT_EQ(17, codewords.size());
|
|
||||||
EXPECT_EQ(0x0, codewords[10]);
|
|
||||||
EXPECT_EQ(0xd1, codewords[11]);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(QRBitMatrixParserTest, MQRCodeM3M)
|
|
||||||
{
|
|
||||||
const auto bitMatrix = ParseBitMatrix("XXXXXXX X X X X\n"
|
|
||||||
"X X XX\n"
|
|
||||||
"X XXX X X XX XX\n"
|
|
||||||
"X XXX X X X \n"
|
|
||||||
"X XXX X XX XXXX\n"
|
|
||||||
"X X XX \n"
|
|
||||||
"XXXXXXX X XXXX\n"
|
|
||||||
" X XXX \n"
|
|
||||||
"X XX XX X X\n"
|
|
||||||
" X X XX \n"
|
|
||||||
"XX XX XXXXXXX\n"
|
|
||||||
" X X X\n"
|
|
||||||
"XX X X X \n"
|
|
||||||
" X X X \n"
|
|
||||||
"X X XXXX XXX\n",
|
|
||||||
88, false);
|
|
||||||
|
|
||||||
const auto version = ReadVersion(bitMatrix);
|
|
||||||
EXPECT_EQ(3, version->versionNumber());
|
|
||||||
const auto format = ReadFormatInformation(bitMatrix, true);
|
|
||||||
const auto codewords = ReadCodewords(bitMatrix, *version, format);
|
|
||||||
EXPECT_EQ(17, codewords.size());
|
|
||||||
EXPECT_EQ(0x0, codewords[8]);
|
|
||||||
EXPECT_EQ(0x89, codewords[9]);
|
|
||||||
}
|
|
||||||
69
src/qrcode/cpp_port/test/QRBitMatrixParserTest.rs
Normal file
69
src/qrcode/cpp_port/test/QRBitMatrixParserTest.rs
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017 Huy Cuong Nguyen
|
||||||
|
* Copyright 2008 ZXing authors
|
||||||
|
*/
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
use crate::{qrcode::cpp_port::{ bitmatrix_parser::{ReadFormatInformation, ReadCodewords, ReadVersion}}, common::BitMatrix};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn MQRCodeM3L()
|
||||||
|
{
|
||||||
|
let bitMatrix =
|
||||||
|
BitMatrix::parse_strings(
|
||||||
|
r"XXXXXXX X X X X
|
||||||
|
X X X X
|
||||||
|
X XXX X XXXXXXX
|
||||||
|
X XXX X X X XX
|
||||||
|
X XXX X X XX
|
||||||
|
X X X X X X
|
||||||
|
XXXXXXX X XX
|
||||||
|
X X X
|
||||||
|
XXXXXX X X X
|
||||||
|
X XX XXX
|
||||||
|
XXX XX XXXX XXX
|
||||||
|
X X XXX X
|
||||||
|
X XXXXX XXX X X
|
||||||
|
X X X XXX
|
||||||
|
XXX XX X X XXXX
|
||||||
|
", "X", " ").expect("parse must parse");
|
||||||
|
|
||||||
|
let version = ReadVersion(&bitMatrix).unwrap();
|
||||||
|
assert_eq!(3, version.getVersionNumber());
|
||||||
|
let format = ReadFormatInformation(&bitMatrix, true).expect("could not read format information");
|
||||||
|
let codewords = ReadCodewords(&bitMatrix, version, &format).expect("could not read codewords");
|
||||||
|
assert_eq!(17, codewords.len());
|
||||||
|
assert_eq!(0x0, codewords[10]);
|
||||||
|
assert_eq!(0xd1, codewords[11]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn MQRCodeM3M()
|
||||||
|
{
|
||||||
|
let bitMatrix = BitMatrix::parse_strings(
|
||||||
|
r"XXXXXXX X X X X
|
||||||
|
X X XX
|
||||||
|
X XXX X X XX XX
|
||||||
|
X XXX X X X
|
||||||
|
X XXX X XX XXXX
|
||||||
|
X X XX
|
||||||
|
XXXXXXX X XXXX
|
||||||
|
X XXX
|
||||||
|
X XX XX X X
|
||||||
|
X X XX
|
||||||
|
XX XX XXXXXXX
|
||||||
|
X X X
|
||||||
|
XX X X X
|
||||||
|
X X X
|
||||||
|
X X XXXX XXX
|
||||||
|
"
|
||||||
|
,"X", " ").unwrap();
|
||||||
|
|
||||||
|
let version = ReadVersion(&bitMatrix).unwrap();
|
||||||
|
assert_eq!(3, version.getVersionNumber());
|
||||||
|
let format = ReadFormatInformation(&bitMatrix, true).expect("could not read format information");
|
||||||
|
let codewords = ReadCodewords(&bitMatrix, version, &format).expect("could not read codewords");
|
||||||
|
assert_eq!(17, codewords.len());
|
||||||
|
assert_eq!(0x0, codewords[8]);
|
||||||
|
assert_eq!(0x89, codewords[9]);
|
||||||
|
}
|
||||||
@@ -8,3 +8,5 @@ mod QRErrorCorrectionLevelTest;
|
|||||||
mod QRDecodedBitStreamParserTest;
|
mod QRDecodedBitStreamParserTest;
|
||||||
|
|
||||||
mod QRDataMaskTest;
|
mod QRDataMaskTest;
|
||||||
|
|
||||||
|
mod QRBitMatrixParserTest;
|
||||||
Reference in New Issue
Block a user