mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-27 04:42:35 +00:00
rename bitmatrix test cases mod
This commit is contained in:
@@ -109,7 +109,12 @@ impl Display for BarcodeFormat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Defaults to QRCode if no proper formatting available
|
impl From<String> for BarcodeFormat {
|
||||||
|
fn from(value: String) -> Self {
|
||||||
|
value.as_str().into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<&str> for BarcodeFormat {
|
impl From<&str> for BarcodeFormat {
|
||||||
fn from(value: &str) -> Self {
|
fn from(value: &str) -> Self {
|
||||||
match value.to_lowercase().as_str() {
|
match value.to_lowercase().as_str() {
|
||||||
|
|||||||
@@ -690,3 +690,19 @@ impl From<&BitMatrix> for image::DynamicImage {
|
|||||||
pixels.into()
|
pixels.into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// impl From<BitMatrix> for Vec<u8> {
|
||||||
|
// fn from(value: BitMatrix) -> Self {
|
||||||
|
// let mut output_vector = Vec::new();
|
||||||
|
// for y in 0..value.getHeight() {
|
||||||
|
// for col in (0..value.getWidth()).step_by(8) {
|
||||||
|
// let mut byte = 0_u8;
|
||||||
|
// for x in 0..8 {
|
||||||
|
// byte |= u8::from(value.get(col+x, y)) << x
|
||||||
|
// }
|
||||||
|
// output_vector.push(byte);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// output_vector
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|||||||
@@ -396,5 +396,3 @@ fn get_input(width: u32, height: u32) -> BitMatrix {
|
|||||||
}
|
}
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
// }
|
|
||||||
@@ -10,7 +10,7 @@ mod StringUtilsTestCase;
|
|||||||
mod BitArrayTestCase;
|
mod BitArrayTestCase;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) mod BitMatrixTestCase;
|
pub(crate) mod bit_matrix_test_case;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod BitSourceTestCase;
|
mod BitSourceTestCase;
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ impl OneDimensionalCodeWriter for CodaBarWriter {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod CodaBarWriterTestCase {
|
mod CodaBarWriterTestCase {
|
||||||
use crate::{
|
use crate::{
|
||||||
common::{BitMatrix, BitMatrixTestCase},
|
common::{bit_matrix_test_case, BitMatrix},
|
||||||
BarcodeFormat, Writer,
|
BarcodeFormat, Writer,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -210,7 +210,7 @@ mod CodaBarWriterTestCase {
|
|||||||
|
|
||||||
fn doTest(input: &str, expected: &str) {
|
fn doTest(input: &str, expected: &str) {
|
||||||
let result = encode(input);
|
let result = encode(input);
|
||||||
assert_eq!(expected, BitMatrixTestCase::matrix_to_string(&result));
|
assert_eq!(expected, bit_matrix_test_case::matrix_to_string(&result));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode(input: &str) -> BitMatrix {
|
fn encode(input: &str) -> BitMatrix {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ use std::collections::HashMap;
|
|||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
common::{BitMatrix, BitMatrixTestCase},
|
common::{bit_matrix_test_case, BitMatrix},
|
||||||
oned::{Code128Reader, OneDReader},
|
oned::{Code128Reader, OneDReader},
|
||||||
BarcodeFormat, EncodeHintType, EncodeHintValue, EncodingHintDictionary, Exceptions, Writer,
|
BarcodeFormat, EncodeHintType, EncodeHintValue, EncodingHintDictionary, Exceptions, Writer,
|
||||||
};
|
};
|
||||||
@@ -65,7 +65,7 @@ fn testEncodeWithFunc3() {
|
|||||||
|
|
||||||
let result = encode(toEncode, false, "123").expect("encode");
|
let result = encode(toEncode, false, "123").expect("encode");
|
||||||
|
|
||||||
let actual = BitMatrixTestCase::matrix_to_string(&result);
|
let actual = bit_matrix_test_case::matrix_to_string(&result);
|
||||||
assert_eq!(expected, actual);
|
assert_eq!(expected, actual);
|
||||||
|
|
||||||
let width = result.getWidth();
|
let width = result.getWidth();
|
||||||
@@ -93,7 +93,7 @@ fn testEncodeWithFunc2() {
|
|||||||
|
|
||||||
let result = encode(toEncode, false, "123").expect("encode");
|
let result = encode(toEncode, false, "123").expect("encode");
|
||||||
|
|
||||||
let actual = BitMatrixTestCase::matrix_to_string(&result);
|
let actual = bit_matrix_test_case::matrix_to_string(&result);
|
||||||
assert_eq!(expected, actual);
|
assert_eq!(expected, actual);
|
||||||
|
|
||||||
let width = result.getWidth();
|
let width = result.getWidth();
|
||||||
@@ -121,7 +121,7 @@ fn testEncodeWithFunc1() {
|
|||||||
|
|
||||||
let result = encode(toEncode, false, "123").expect("encode");
|
let result = encode(toEncode, false, "123").expect("encode");
|
||||||
|
|
||||||
let actual = BitMatrixTestCase::matrix_to_string(&result);
|
let actual = bit_matrix_test_case::matrix_to_string(&result);
|
||||||
assert_eq!(expected, actual);
|
assert_eq!(expected, actual);
|
||||||
|
|
||||||
let width = result.getWidth();
|
let width = result.getWidth();
|
||||||
@@ -222,7 +222,7 @@ fn testEncodeWithFunc4() {
|
|||||||
|
|
||||||
let result = encode(toEncode, false, "").expect("encode");
|
let result = encode(toEncode, false, "").expect("encode");
|
||||||
|
|
||||||
let actual = BitMatrixTestCase::matrix_to_string(&result);
|
let actual = bit_matrix_test_case::matrix_to_string(&result);
|
||||||
assert_eq!(expected, actual);
|
assert_eq!(expected, actual);
|
||||||
|
|
||||||
let width = result.getWidth();
|
let width = result.getWidth();
|
||||||
@@ -250,7 +250,7 @@ fn testEncodeWithFncsAndNumberInCodesetA() {
|
|||||||
|
|
||||||
let result = encode(toEncode, false, "").expect("encode");
|
let result = encode(toEncode, false, "").expect("encode");
|
||||||
|
|
||||||
let actual = BitMatrixTestCase::matrix_to_string(&result);
|
let actual = bit_matrix_test_case::matrix_to_string(&result);
|
||||||
|
|
||||||
assert_eq!(expected, actual);
|
assert_eq!(expected, actual);
|
||||||
|
|
||||||
@@ -310,7 +310,7 @@ fn testEncodeSwitchBetweenCodesetsAAndB() {
|
|||||||
|
|
||||||
fn testEncode(toEncode: &str, expected: &str) {
|
fn testEncode(toEncode: &str, expected: &str) {
|
||||||
let result = encode(toEncode, false, toEncode).expect("encode");
|
let result = encode(toEncode, false, toEncode).expect("encode");
|
||||||
let actual = BitMatrixTestCase::matrix_to_string(&result);
|
let actual = bit_matrix_test_case::matrix_to_string(&result);
|
||||||
assert_eq!(expected, actual, "{}", toEncode);
|
assert_eq!(expected, actual, "{}", toEncode);
|
||||||
|
|
||||||
let width = result.getWidth();
|
let width = result.getWidth();
|
||||||
@@ -432,7 +432,7 @@ fn testEncodeWithForcedCodeSetFailureCodeSetA() {
|
|||||||
.encode_with_hints(toEncode, &BarcodeFormat::CODE_128, 0, 0, &hints)
|
.encode_with_hints(toEncode, &BarcodeFormat::CODE_128, 0, 0, &hints)
|
||||||
.expect("encode");
|
.expect("encode");
|
||||||
|
|
||||||
let actual = BitMatrixTestCase::matrix_to_string(&result);
|
let actual = bit_matrix_test_case::matrix_to_string(&result);
|
||||||
assert_eq!(expected, actual);
|
assert_eq!(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -465,7 +465,7 @@ fn testEncodeWithForcedCodeSetFailureCodeSetB() {
|
|||||||
.encode_with_hints(toEncode, &BarcodeFormat::CODE_128, 0, 0, &hints)
|
.encode_with_hints(toEncode, &BarcodeFormat::CODE_128, 0, 0, &hints)
|
||||||
.expect("encode");
|
.expect("encode");
|
||||||
|
|
||||||
let actual = BitMatrixTestCase::matrix_to_string(&result);
|
let actual = bit_matrix_test_case::matrix_to_string(&result);
|
||||||
assert_eq!(expected, actual);
|
assert_eq!(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ impl Code39Writer {
|
|||||||
* Tests {@link Code39Writer}.
|
* Tests {@link Code39Writer}.
|
||||||
*/
|
*/
|
||||||
mod Code39WriterTestCase {
|
mod Code39WriterTestCase {
|
||||||
use crate::{common::BitMatrixTestCase, oned::Code39Writer, BarcodeFormat, Writer};
|
use crate::{common::bit_matrix_test_case, oned::Code39Writer, BarcodeFormat, Writer};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn testEncode() {
|
fn testEncode() {
|
||||||
@@ -248,7 +248,7 @@ mod Code39WriterTestCase {
|
|||||||
.expect("must encode");
|
.expect("must encode");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
expected,
|
expected,
|
||||||
BitMatrixTestCase::matrix_to_string(&result),
|
bit_matrix_test_case::matrix_to_string(&result),
|
||||||
"{}",
|
"{}",
|
||||||
input
|
input
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ impl Code93Writer {
|
|||||||
*/
|
*/
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod Code93WriterTestCase {
|
mod Code93WriterTestCase {
|
||||||
use crate::{common::BitMatrixTestCase, oned::Code93Writer, BarcodeFormat, Writer};
|
use crate::{common::bit_matrix_test_case, oned::Code93Writer, BarcodeFormat, Writer};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn testEncode() {
|
fn testEncode() {
|
||||||
@@ -247,7 +247,7 @@ mod Code93WriterTestCase {
|
|||||||
let result = Code93Writer::default()
|
let result = Code93Writer::default()
|
||||||
.encode(input, &BarcodeFormat::CODE_93, 0, 0)
|
.encode(input, &BarcodeFormat::CODE_93, 0, 0)
|
||||||
.expect("encode");
|
.expect("encode");
|
||||||
assert_eq!(expected, BitMatrixTestCase::matrix_to_string(&result));
|
assert_eq!(expected, bit_matrix_test_case::matrix_to_string(&result));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ const CODE_WIDTH: usize = 3 + // start guard
|
|||||||
*/
|
*/
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod EAN13WriterTestCase {
|
mod EAN13WriterTestCase {
|
||||||
use crate::{common::BitMatrixTestCase, BarcodeFormat, Writer};
|
use crate::{common::bit_matrix_test_case, BarcodeFormat, Writer};
|
||||||
|
|
||||||
use super::EAN13Writer;
|
use super::EAN13Writer;
|
||||||
|
|
||||||
@@ -151,7 +151,7 @@ mod EAN13WriterTestCase {
|
|||||||
0,
|
0,
|
||||||
)
|
)
|
||||||
.expect("exist");
|
.expect("exist");
|
||||||
assert_eq!(testStr, BitMatrixTestCase::matrix_to_string(&result));
|
assert_eq!(testStr, bit_matrix_test_case::matrix_to_string(&result));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -166,7 +166,7 @@ mod EAN13WriterTestCase {
|
|||||||
0,
|
0,
|
||||||
)
|
)
|
||||||
.expect("exist");
|
.expect("exist");
|
||||||
assert_eq!(testStr, BitMatrixTestCase::matrix_to_string(&result));
|
assert_eq!(testStr, bit_matrix_test_case::matrix_to_string(&result));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ impl OneDimensionalCodeWriter for EAN8Writer {
|
|||||||
*/
|
*/
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod EAN8WriterTestCase {
|
mod EAN8WriterTestCase {
|
||||||
use crate::{common::BitMatrixTestCase, BarcodeFormat, Writer};
|
use crate::{common::bit_matrix_test_case, BarcodeFormat, Writer};
|
||||||
|
|
||||||
use super::EAN8Writer;
|
use super::EAN8Writer;
|
||||||
|
|
||||||
@@ -136,7 +136,7 @@ mod EAN8WriterTestCase {
|
|||||||
0,
|
0,
|
||||||
)
|
)
|
||||||
.expect("ok");
|
.expect("ok");
|
||||||
assert_eq!(testStr, BitMatrixTestCase::matrix_to_string(&result));
|
assert_eq!(testStr, bit_matrix_test_case::matrix_to_string(&result));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -151,7 +151,7 @@ mod EAN8WriterTestCase {
|
|||||||
0,
|
0,
|
||||||
)
|
)
|
||||||
.expect("ok");
|
.expect("ok");
|
||||||
assert_eq!(testStr, BitMatrixTestCase::matrix_to_string(&result));
|
assert_eq!(testStr, bit_matrix_test_case::matrix_to_string(&result));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ const PATTERNS: [[usize; 5]; 10] = [
|
|||||||
*/
|
*/
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod ITFWriterTestCase {
|
mod ITFWriterTestCase {
|
||||||
use crate::{common::BitMatrixTestCase, BarcodeFormat, Writer};
|
use crate::{common::bit_matrix_test_case, BarcodeFormat, Writer};
|
||||||
|
|
||||||
use super::ITFWriter;
|
use super::ITFWriter;
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@ mod ITFWriterTestCase {
|
|||||||
let result = ITFWriter::default()
|
let result = ITFWriter::default()
|
||||||
.encode(input, &BarcodeFormat::ITF, 0, 0)
|
.encode(input, &BarcodeFormat::ITF, 0, 0)
|
||||||
.expect("encode");
|
.expect("encode");
|
||||||
assert_eq!(expected, BitMatrixTestCase::matrix_to_string(&result));
|
assert_eq!(expected, bit_matrix_test_case::matrix_to_string(&result));
|
||||||
}
|
}
|
||||||
|
|
||||||
//@Test(expected = IllegalArgumentException.class)
|
//@Test(expected = IllegalArgumentException.class)
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ impl Writer for UPCAWriter {
|
|||||||
*/
|
*/
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod UPCAWriterTestCase {
|
mod UPCAWriterTestCase {
|
||||||
use crate::{common::BitMatrixTestCase, BarcodeFormat, Writer};
|
use crate::{common::bit_matrix_test_case, BarcodeFormat, Writer};
|
||||||
|
|
||||||
use super::UPCAWriter;
|
use super::UPCAWriter;
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ mod UPCAWriterTestCase {
|
|||||||
0,
|
0,
|
||||||
)
|
)
|
||||||
.expect("ok");
|
.expect("ok");
|
||||||
assert_eq!(testStr, BitMatrixTestCase::matrix_to_string(&result));
|
assert_eq!(testStr, bit_matrix_test_case::matrix_to_string(&result));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -102,6 +102,6 @@ mod UPCAWriterTestCase {
|
|||||||
0,
|
0,
|
||||||
)
|
)
|
||||||
.expect("ok");
|
.expect("ok");
|
||||||
assert_eq!(testStr, BitMatrixTestCase::matrix_to_string(&result));
|
assert_eq!(testStr, bit_matrix_test_case::matrix_to_string(&result));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ impl OneDimensionalCodeWriter for UPCEWriter {
|
|||||||
*/
|
*/
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod UPCEWriterTestCase {
|
mod UPCEWriterTestCase {
|
||||||
use crate::{common::BitMatrixTestCase, BarcodeFormat, Writer};
|
use crate::{common::bit_matrix_test_case, BarcodeFormat, Writer};
|
||||||
|
|
||||||
use super::UPCEWriter;
|
use super::UPCEWriter;
|
||||||
|
|
||||||
@@ -160,7 +160,7 @@ mod UPCEWriterTestCase {
|
|||||||
0,
|
0,
|
||||||
)
|
)
|
||||||
.expect("ok");
|
.expect("ok");
|
||||||
assert_eq!(encoding, BitMatrixTestCase::matrix_to_string(&result));
|
assert_eq!(encoding, bit_matrix_test_case::matrix_to_string(&result));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user