ported test SimpleSJIS and fixed regression pdf417

This commit is contained in:
Henry Schimke
2023-04-14 11:03:04 -05:00
parent 1900e1ca57
commit 23951ac87c
6 changed files with 109 additions and 53 deletions

View File

@@ -125,7 +125,7 @@ pub fn DecodeByteSegment(
result.switch_encoding(CharacterSet::Unknown);
result.reserve(count as usize);
for i in 0..count {
for _i in 0..count {
// for (int i = 0; i < count; i++)
*result += (bits.readBits(8)?) as u8;
}
@@ -297,7 +297,7 @@ pub fn DecodeBitStream(
let mut structuredAppend = StructuredAppendInfo::default();
let modeBitLength = Mode::get_codec_mode_bits_length(version);
let res = (|| {
let _res = (|| {
while (!IsEndOfStream(&mut bits, version)?) {
let mode: Mode;
if (modeBitLength == 0) {
@@ -361,26 +361,26 @@ pub fn DecodeBitStream(
// throw FormatError("Unsupported HANZI subset");
}
let count = bits.readBits(mode.CharacterCountBits(version) as usize)?;
DecodeHanziSegment(&mut bits, count, &mut result);
DecodeHanziSegment(&mut bits, count, &mut result)?;
}
_ => {
// "Normal" QR code modes:
// How many characters will follow, encoded in this mode?
let count = bits.readBits(mode.CharacterCountBits(version) as usize)?;
match (mode) {
Mode::NUMERIC => DecodeNumericSegment(&mut bits, count, &mut result),
Mode::NUMERIC => DecodeNumericSegment(&mut bits, count, &mut result)?,
Mode::ALPHANUMERIC => {
DecodeAlphanumericSegment(&mut bits, count, &mut result)
DecodeAlphanumericSegment(&mut bits, count, &mut result)?
}
Mode::BYTE => DecodeByteSegment(&mut bits, count, &mut result),
Mode::KANJI => DecodeKanjiSegment(&mut bits, count, &mut result),
Mode::BYTE => DecodeByteSegment(&mut bits, count, &mut result)?,
Mode::KANJI => DecodeKanjiSegment(&mut bits, count, &mut result)?,
_ => return Err(Exceptions::format_with("Invalid CodecMode")), //throw FormatError("Invalid CodecMode");
};
}
}
}
Ok(())
})();
})()?;
// } catch (std::out_of_range& e) { // see BitSource::readBits
// error = FormatError("Truncated bit stream");
// } catch (Error e) {

View File

@@ -36,11 +36,11 @@ use crate::{
#[test]
fn SimpleByteMode() {
let mut ba = BitArray::new();
ba.appendBits(0x04, 4); // Byte mode
ba.appendBits(0x03, 8); // 3 bytes
ba.appendBits(0xF1, 8);
ba.appendBits(0xF2, 8);
ba.appendBits(0xF3, 8);
ba.appendBits(0x04, 4).unwrap(); // Byte mode
ba.appendBits(0x03, 8).unwrap(); // 3 bytes
ba.appendBits(0xF1, 8).unwrap();
ba.appendBits(0xF2, 8).unwrap();
ba.appendBits(0xF3, 8).unwrap();
let bytes: Vec<u8> = ba.into();
let result = DecodeBitStream(
&bytes,
@@ -57,12 +57,12 @@ fn SimpleByteMode() {
#[test]
fn SimpleSJIS() {
let mut ba = BitArray::new();
ba.appendBits(0x04, 4); // Byte mode
ba.appendBits(0x04, 8); // 4 bytes
ba.appendBits(0xA1, 8);
ba.appendBits(0xA2, 8);
ba.appendBits(0xA3, 8);
ba.appendBits(0xD0, 8);
ba.appendBits(0x04, 4).expect("append"); // Byte mode
ba.appendBits(0x04, 8).expect("append"); // 4 bytes
ba.appendBits(0xA1, 8).expect("append");
ba.appendBits(0xA2, 8).expect("append");
ba.appendBits(0xA3, 8).expect("append");
ba.appendBits(0xD0, 8).expect("append");
let bytes: Vec<u8> = ba.into();
let result = DecodeBitStream(
&bytes,
@@ -78,13 +78,13 @@ fn SimpleSJIS() {
#[test]
fn ECI() {
let mut ba = BitArray::new();
ba.appendBits(0x07, 4); // ECI mode
ba.appendBits(0x02, 8); // ECI 2 = CP437 encoding
ba.appendBits(0x04, 4); // Byte mode
ba.appendBits(0x03, 8); // 3 bytes
ba.appendBits(0xA1, 8);
ba.appendBits(0xA2, 8);
ba.appendBits(0xA3, 8);
ba.appendBits(0x07, 4).expect("append"); // ECI mode
ba.appendBits(0x02, 8).expect("append"); // ECI 2 = CP437 encoding
ba.appendBits(0x04, 4).expect("append"); // Byte mode
ba.appendBits(0x03, 8).expect("append"); // 3 bytes
ba.appendBits(0xA1, 8).expect("append");
ba.appendBits(0xA2, 8).expect("append");
ba.appendBits(0xA3, 8).expect("append");
let bytes: Vec<u8> = ba.into();
let result = DecodeBitStream(
&bytes,
@@ -100,10 +100,10 @@ fn ECI() {
#[test]
fn Hanzi() {
let mut ba = BitArray::new();
ba.appendBits(0x0D, 4); // Hanzi mode
ba.appendBits(0x01, 4); // Subset 1 = GB2312 encoding
ba.appendBits(0x01, 8); // 1 characters
ba.appendBits(0x03C1, 13);
ba.appendBits(0x0D, 4).expect("append"); // Hanzi mode
ba.appendBits(0x01, 4).expect("append"); // Subset 1 = GB2312 encoding
ba.appendBits(0x01, 8).expect("append"); // 1 characters
ba.appendBits(0x03C1, 13).expect("append");
let bytes: Vec<u8> = ba.into();
let result = DecodeBitStream(
&bytes,
@@ -119,11 +119,11 @@ fn Hanzi() {
#[test]
fn HanziLevel1() {
let mut ba = BitArray::new();
ba.appendBits(0x0D, 4); // Hanzi mode
ba.appendBits(0x01, 4); // Subset 1 = GB2312 encoding
ba.appendBits(0x01, 8); // 1 characters
// A5A2 (U+30A2) => A5A2 - A1A1 = 401, 4*60 + 01 = 0181
ba.appendBits(0x0181, 13);
ba.appendBits(0x0D, 4).expect("append"); // Hanzi mode
ba.appendBits(0x01, 4).expect("append"); // Subset 1 = GB2312 encoding
ba.appendBits(0x01, 8).expect("append"); // 1 characters
// A5A2 (U+30A2) => A5A2 - A1A1 = 401, 4*60 + 01 = 0181
ba.appendBits(0x0181, 13).expect("append");
let bytes: Vec<u8> = ba.into();