add additional tests from c++
@@ -45,7 +45,7 @@ impl ECIStringBuilder {
|
||||
Self {
|
||||
current_bytes: Vec::new(),
|
||||
result: String::new(),
|
||||
current_charset: encoding::all::UTF_8,
|
||||
current_charset: encoding::all::ISO_8859_1,
|
||||
}
|
||||
}
|
||||
pub fn with_capacity(initial_capacity: usize) -> Self {
|
||||
|
||||
@@ -195,6 +195,9 @@ fn decodeAsciiSegment(
|
||||
fnc1positions: &mut Vec<usize>,
|
||||
) -> Result<Mode, Exceptions> {
|
||||
let mut upperShift = false;
|
||||
let mut firstFNC1Position = 1;
|
||||
let mut firstCodeword = true;
|
||||
let mut sai = StructuredAppendInfo::default();
|
||||
loop {
|
||||
let mut oneByte = bits.readBits(8)?;
|
||||
if oneByte == 0 {
|
||||
@@ -226,14 +229,24 @@ fn decodeAsciiSegment(
|
||||
231=> // Latch to Base 256 encodation
|
||||
return Ok(Mode::BASE256_ENCODE),
|
||||
232=> {// FNC1
|
||||
fnc1positions.push(result.len());
|
||||
result.append_char( 29 as char); // translate as ASCII 29
|
||||
if (bits.getByteOffset() == firstFNC1Position)
|
||||
{/*result.symbology.modifier = '2';*/} // GS1
|
||||
else if (bits.getByteOffset() == firstFNC1Position + 1)
|
||||
{/*result.symbology.modifier = '3';*/} // AIM, note no AIM Application Indicator format defined, ISO 16022:2006 11.2
|
||||
else
|
||||
{fnc1positions.push(result.len());
|
||||
result.append_char( 29 as char); }// translate as ASCII 29
|
||||
},
|
||||
233| // Structured Append
|
||||
234=> // Reader Programming
|
||||
// Ignore these symbols for now
|
||||
//throw ReaderException.getInstance();
|
||||
{},
|
||||
{
|
||||
if (!firstCodeword) // Must be first ISO 16022:2006 5.6.1
|
||||
{return Err(Exceptions::FormatException(Some("structured append tag must be first code word".to_owned())));}
|
||||
parse_structured_append(bits, &mut sai)?;
|
||||
firstFNC1Position = 5;
|
||||
},
|
||||
235=> // Upper Shift (shift to Extended ASCII)
|
||||
upperShift = true,
|
||||
236=> {// 05 Macro
|
||||
@@ -265,6 +278,7 @@ fn decodeAsciiSegment(
|
||||
if bits.available() == 0 {
|
||||
break;
|
||||
}
|
||||
firstCodeword = false;
|
||||
} //while (bits.available() > 0);
|
||||
Ok(Mode::ASCII_ENCODE)
|
||||
}
|
||||
@@ -412,7 +426,7 @@ fn decodeTextSegment(
|
||||
} else if cValue < TEXT_BASIC_SET_CHARS.len() as u32 {
|
||||
let textChar = TEXT_BASIC_SET_CHARS[cValue as usize];
|
||||
if upperShift {
|
||||
result.append_char(char::from_u32(textChar as u32 + 128_u32).unwrap());
|
||||
result.append_char(char::from_u32(textChar as u32 + 128).unwrap());
|
||||
upperShift = false;
|
||||
} else {
|
||||
result.append_char(textChar);
|
||||
@@ -667,15 +681,30 @@ fn decodeBase256Segment(
|
||||
* See ISO 16022:2007, 5.4.1
|
||||
*/
|
||||
fn decodeECISegment(bits: &mut BitSource, result: &mut ECIStringBuilder) -> Result<(), Exceptions> {
|
||||
if bits.available() < 8 {
|
||||
return Err(Exceptions::FormatException(None));
|
||||
}
|
||||
let c1 = bits.readBits(8)?;
|
||||
if c1 <= 127 {
|
||||
result.appendECI(c1 - 1)?;
|
||||
let firstByte = bits.readBits(8)?;
|
||||
if (firstByte <= 127) {
|
||||
return result.appendECI(firstByte - 1);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
let secondByte = bits.readBits(8)?;
|
||||
if (firstByte <= 191) {
|
||||
return result.appendECI(firstByte - 1);
|
||||
}
|
||||
|
||||
let thirdByte = bits.readBits(8)?;
|
||||
|
||||
return result
|
||||
.appendECI((firstByte - 192) * 64516 + 16383 + (secondByte - 1) * 254 + thirdByte - 1);
|
||||
|
||||
// if bits.available() < 8 {
|
||||
// return Err(Exceptions::FormatException(None));
|
||||
// }
|
||||
// let c1 = bits.readBits(8)?;
|
||||
// if c1 <= 127 {
|
||||
// result.appendECI(c1 - 1)?;
|
||||
// }
|
||||
|
||||
// Ok(())
|
||||
//currently we only support character set ECIs
|
||||
/*} else {
|
||||
if (bits.available() < 8) {
|
||||
@@ -692,6 +721,48 @@ fn decodeECISegment(bits: &mut BitSource, result: &mut ECIStringBuilder) -> Resu
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
* See ISO 16022:2006, 5.6
|
||||
*/
|
||||
fn parse_structured_append(
|
||||
bits: &mut BitSource,
|
||||
sai: &mut StructuredAppendInfo,
|
||||
) -> Result<(), Exceptions> {
|
||||
// 5.6.2 Table 8
|
||||
let symbolSequenceIndicator = bits.readBits(8)?;
|
||||
sai.index = (symbolSequenceIndicator >> 4) as i32;
|
||||
sai.count = (17 - (symbolSequenceIndicator & 0x0F)) as i32; // 2-16 permitted, 17 invalid
|
||||
|
||||
if (sai.count == 17 || sai.count <= sai.index)
|
||||
// If info doesn't make sense
|
||||
{
|
||||
sai.count = 0; // Choose to mark count as unknown
|
||||
}
|
||||
|
||||
let fileId1 = bits.readBits(8)?; // File identification 1
|
||||
let fileId2 = bits.readBits(8)?; // File identification 2
|
||||
|
||||
// There's no conversion method or meaning given to the 2 file id codewords in Section 5.6.3, apart from
|
||||
// saying that each value should be 1-254. Choosing here to represent them as base 256.
|
||||
sai.id = ((fileId1 << 8) | fileId2).to_string();
|
||||
Ok(())
|
||||
}
|
||||
struct StructuredAppendInfo {
|
||||
index: i32, //= -1;
|
||||
count: i32, // = -1;
|
||||
id: String,
|
||||
}
|
||||
|
||||
impl Default for StructuredAppendInfo {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
index: -1,
|
||||
count: -1,
|
||||
id: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* See ISO 16022:2006, Annex B, B.2
|
||||
*/
|
||||
|
||||
BIN
test_resources/blackbox/datamatrix-1/#378.png
Normal file
|
After Width: | Height: | Size: 417 B |
1
test_resources/blackbox/datamatrix-1/#378.txt
Normal file
@@ -0,0 +1 @@
|
||||
Data Matrix Code
|
||||
@@ -0,0 +1,2 @@
|
||||
symbologyIdentifier=]d1
|
||||
isMirrored=false
|
||||
BIN
test_resources/blackbox/datamatrix-1/144x144_wrong.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
5
test_resources/blackbox/datamatrix-1/144x144_wrong.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
|
||||
|
||||
Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
|
||||
|
||||
Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse - there is still some space, so I'm filling it with letters. And I don't speak latin.... - there is still some space, so I'm filling it with letters. And I don't speak latin.... - there is still some space, so I'm filling it with letters. And I don't speak latin.... - there is still some space, so I'm filling it with letters. And I don't speak latin....
|
||||
BIN
test_resources/blackbox/datamatrix-1/abcd-36x12-mirrored.png
Normal file
|
After Width: | Height: | Size: 330 B |
@@ -0,0 +1 @@
|
||||
isMirrored=true
|
||||
@@ -0,0 +1 @@
|
||||
abcdefghijklmnopq
|
||||
1
test_resources/blackbox/datamatrix-1/eci-mixed.bin
Normal file
@@ -0,0 +1 @@
|
||||
帷 ⊥别悓禓@@@@@@@@@_
|
||||
@@ -0,0 +1,2 @@
|
||||
symbologyIdentifier=]d1
|
||||
contentType=UnknownECI
|
||||
BIN
test_resources/blackbox/datamatrix-1/eci-mixed.png
Normal file
|
After Width: | Height: | Size: 253 B |
BIN
test_resources/blackbox/datamatrix-1/eci.png
Normal file
|
After Width: | Height: | Size: 158 B |
1
test_resources/blackbox/datamatrix-1/eci.txt
Normal file
@@ -0,0 +1 @@
|
||||
¶Ж
|
||||
@@ -0,0 +1,2 @@
|
||||
symbologyIdentifier=]d2
|
||||
contentType=GS1
|
||||
|
After Width: | Height: | Size: 321 B |
@@ -0,0 +1 @@
|
||||
01095040000591012112345678p901101234567p171411208200http://www.gs1.org/demo/
|
||||
BIN
test_resources/blackbox/datamatrix-1/mod-size-1.png
Normal file
|
After Width: | Height: | Size: 119 B |
1
test_resources/blackbox/datamatrix-1/mod-size-1.txt
Normal file
@@ -0,0 +1 @@
|
||||
c++
|
||||
BIN
test_resources/blackbox/datamatrix-1/readerinit.png
Normal file
|
After Width: | Height: | Size: 132 B |
@@ -0,0 +1,2 @@
|
||||
symbologyIdentifier=]d1
|
||||
readerInit=true
|
||||
1
test_resources/blackbox/datamatrix-1/readerinit.txt
Normal file
@@ -0,0 +1 @@
|
||||
$I
|
||||
@@ -466,7 +466,9 @@ impl<T: Reader> AbstractBlackBoxTestCase<T> {
|
||||
let result_text = result.getText();
|
||||
if expected_text != result_text {
|
||||
log::info(format!(
|
||||
"Content mismatch: expected '{expected_text}' but got '{result_text}'{suffix}"
|
||||
"Content mismatch: expected '{}' but got '{}'{suffix}",
|
||||
expected_text.escape_default(),
|
||||
result_text.escape_default()
|
||||
));
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||