mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-28 05:12:34 +00:00
cleaned up many warnings
This commit is contained in:
@@ -30,12 +30,12 @@ fn aztec_black_box1_test_case() {
|
||||
);
|
||||
|
||||
// super("src/test/resources/blackbox/aztec-1", AztecReader::new(), BarcodeFormat::AZTEC);
|
||||
tester.addTest(14, 14, 0.0);
|
||||
tester.addTest(14, 14, 90.0);
|
||||
tester.addTest(14, 14, 180.0);
|
||||
tester.addTest(14, 14, 270.0);
|
||||
tester.add_test(14, 14, 0.0);
|
||||
tester.add_test(14, 14, 90.0);
|
||||
tester.add_test(14, 14, 180.0);
|
||||
tester.add_test(14, 14, 270.0);
|
||||
|
||||
tester.testBlackBox();
|
||||
tester.test_black_box();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,10 +51,10 @@ fn aztec_black_box2_test_case() {
|
||||
BarcodeFormat::AZTEC,
|
||||
);
|
||||
// super(, new AztecReader(), BarcodeFormat.AZTEC);
|
||||
tester.addTest(5, 5, 0.0);
|
||||
tester.addTest(4, 4, 90.0);
|
||||
tester.addTest(6, 6, 180.0);
|
||||
tester.addTest(3, 3, 270.0);
|
||||
tester.add_test(5, 5, 0.0);
|
||||
tester.add_test(4, 4, 90.0);
|
||||
tester.add_test(6, 6, 180.0);
|
||||
tester.add_test(3, 3, 270.0);
|
||||
|
||||
tester.testBlackBox();
|
||||
tester.test_black_box();
|
||||
}
|
||||
|
||||
@@ -43,9 +43,9 @@ pub struct AbstractBlackBoxTestCase<T:Reader> {
|
||||
|
||||
impl<T:Reader> AbstractBlackBoxTestCase<T> {
|
||||
|
||||
pub fn buildTestBase(testBasePathSuffix: &str) -> Box<Path> {
|
||||
pub fn build_test_base(test_base_path_suffix: &str) -> Box<Path> {
|
||||
// A little workaround to prevent aggravation in my IDE
|
||||
let test_base = Path::new(testBasePathSuffix);
|
||||
let test_base = Path::new(test_base_path_suffix);
|
||||
// if !testBase.exists() {
|
||||
// // try starting with 'core' since the test base is often given as the project root
|
||||
// testBase = Paths.get("core").resolve(testBasePathSuffix);
|
||||
@@ -59,7 +59,7 @@ impl<T:Reader> AbstractBlackBoxTestCase<T> {
|
||||
expected_format: BarcodeFormat,
|
||||
) -> Self {
|
||||
Self {
|
||||
test_base: Self::buildTestBase(test_base_path_suffix),
|
||||
test_base: Self::build_test_base(test_base_path_suffix),
|
||||
barcode_reader,
|
||||
expected_format,
|
||||
test_rxing_results: Vec::new(),
|
||||
@@ -67,15 +67,15 @@ impl<T:Reader> AbstractBlackBoxTestCase<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn getTestBase(&self) -> &Box<Path> {
|
||||
pub fn get_test_base(&self) -> &Box<Path> {
|
||||
&self.test_base
|
||||
}
|
||||
|
||||
pub fn addTest(&mut self, must_pass_count: u32, try_harder_count: u32, rotation: f32) {
|
||||
self.addTestComplex(must_pass_count, try_harder_count, 0, 0, rotation);
|
||||
pub fn add_test(&mut self, must_pass_count: u32, try_harder_count: u32, rotation: f32) {
|
||||
self.add_test_complex(must_pass_count, try_harder_count, 0, 0, rotation);
|
||||
}
|
||||
|
||||
pub fn addHint(&mut self, hint: DecodeHintType, value: DecodeHintValue) {
|
||||
pub fn add_hint(&mut self, hint: DecodeHintType, value: DecodeHintValue) {
|
||||
self.hints.insert(hint, value);
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ impl<T:Reader> AbstractBlackBoxTestCase<T> {
|
||||
* reading the wrong contents using the try harder flag
|
||||
* @param rotation The rotation in degrees clockwise to use for this test.
|
||||
*/
|
||||
pub fn addTestComplex(
|
||||
pub fn add_test_complex(
|
||||
&mut self,
|
||||
must_pass_count: u32,
|
||||
try_harder_count: u32,
|
||||
@@ -106,14 +106,14 @@ impl<T:Reader> AbstractBlackBoxTestCase<T> {
|
||||
));
|
||||
}
|
||||
|
||||
pub fn getImageFiles(&self) -> Vec<PathBuf> {
|
||||
pub fn get_image_files(&self) -> Vec<PathBuf> {
|
||||
assert!(
|
||||
self.test_base.exists(),
|
||||
"Please download and install test images, and run from the 'core' directory"
|
||||
);
|
||||
// let paths = Vec::new();
|
||||
let path_search = read_dir(&self.test_base);
|
||||
const possible_extensions: &str = "jpg,jpeg,gif,png,JPG,JPEG,GIF,PNG";
|
||||
const POSSIBLE_EXTENSIONS: &str = "jpg,jpeg,gif,png,JPG,JPEG,GIF,PNG";
|
||||
|
||||
let mut paths = path_search
|
||||
.unwrap()
|
||||
@@ -121,7 +121,7 @@ impl<T:Reader> AbstractBlackBoxTestCase<T> {
|
||||
.filter(|r| r.is_ok()) // Get rid of Err variants for Result<DirEntry>
|
||||
.map(|r| r.unwrap().path()) // This is safe, since we only have the Ok variants
|
||||
.filter(|r| r.is_file()) // Filter out non-folders
|
||||
.filter(|r| possible_extensions.contains(r.extension().unwrap().to_str().unwrap()))
|
||||
.filter(|r| POSSIBLE_EXTENSIONS.contains(r.extension().unwrap().to_str().unwrap()))
|
||||
// .map(|r| r.into_boxed_path())
|
||||
.collect::<Vec<PathBuf>>();
|
||||
|
||||
@@ -130,14 +130,14 @@ impl<T:Reader> AbstractBlackBoxTestCase<T> {
|
||||
paths
|
||||
}
|
||||
|
||||
pub fn getReader(&self) -> &T {
|
||||
pub fn get_reader(&self) -> &T {
|
||||
&self.barcode_reader
|
||||
}
|
||||
|
||||
pub fn testBlackBox(&self) {
|
||||
pub fn test_black_box(&self) {
|
||||
assert!(!self.test_rxing_results.is_empty());
|
||||
|
||||
let image_files = self.getImageFiles();
|
||||
let image_files = self.get_image_files();
|
||||
let test_count = self.test_rxing_results.len();
|
||||
|
||||
let mut passed_counts = vec![0usize; test_count];
|
||||
@@ -145,16 +145,16 @@ impl<T:Reader> AbstractBlackBoxTestCase<T> {
|
||||
let mut try_harder_counts = vec![0usize; test_count];
|
||||
let mut try_harder_misread_counts = vec![0usize; test_count];
|
||||
|
||||
for testImage in &image_files {
|
||||
for test_image in &image_files {
|
||||
// for (Path testImage : imageFiles) {
|
||||
log::info(format!("Starting {}", testImage.to_string_lossy()));
|
||||
log::info(format!("Starting {}", test_image.to_string_lossy()));
|
||||
|
||||
let image = image::open(testImage).unwrap(); //ImageIO.read(testImage.toFile());
|
||||
let image = image::open(test_image).unwrap(); //ImageIO.read(testImage.toFile());
|
||||
|
||||
//let testImageFileName = testImage.getFileName().toString();
|
||||
let file_base_name = testImage.file_stem().unwrap();
|
||||
let file_base_name = test_image.file_stem().unwrap();
|
||||
//let expectedTextFile = self.testBase.resolve(fileBaseName + ".txt");
|
||||
let mut expected_text_file = testImage.clone();
|
||||
let mut expected_text_file = test_image.clone();
|
||||
expected_text_file.set_extension("txt");
|
||||
let expected_text = if expected_text_file.exists() {
|
||||
Self::read_file_as_string(expected_text_file)
|
||||
@@ -171,7 +171,7 @@ impl<T:Reader> AbstractBlackBoxTestCase<T> {
|
||||
let mut expected_metadata_file: PathBuf = self.test_base.clone().to_path_buf();
|
||||
expected_metadata_file.push(format!("{}.metadata", file_base_name.to_str().unwrap()));
|
||||
expected_metadata_file.set_extension("txt");
|
||||
let expectedMetadata_unfinished = if expected_metadata_file.exists() {
|
||||
let expected_metadata_unfinished = if expected_metadata_file.exists() {
|
||||
java_properties::read(
|
||||
std::fs::File::open(expected_metadata_file)
|
||||
.expect("file exists, we already know that"),
|
||||
@@ -184,7 +184,7 @@ impl<T:Reader> AbstractBlackBoxTestCase<T> {
|
||||
HashMap::new()
|
||||
};
|
||||
let expected_metadata = HashMap::new();
|
||||
for (k, v) in expectedMetadata_unfinished {
|
||||
for (k, v) in expected_metadata_unfinished {
|
||||
let new_k = RXingResultMetadataType::from(k);
|
||||
let _new_v = match new_k {
|
||||
RXingResultMetadataType::OTHER => RXingResultMetadataValue::OTHER(v),
|
||||
@@ -230,7 +230,7 @@ impl<T:Reader> AbstractBlackBoxTestCase<T> {
|
||||
|
||||
for x in 0..test_count {
|
||||
// for (int x = 0; x < testCount; x++) {
|
||||
let rotation = self.test_rxing_results.get(x).unwrap().getRotation();
|
||||
let rotation = self.test_rxing_results.get(x).unwrap().get_rotation();
|
||||
let rotated_image = Self::rotate_image(&image, rotation);
|
||||
let source = BufferedImageLuminanceSource::new(rotated_image);
|
||||
let bitmap = BinaryBitmap::new(Box::new(HybridBinarizer::new(Box::new(source))));
|
||||
@@ -296,13 +296,13 @@ impl<T:Reader> AbstractBlackBoxTestCase<T> {
|
||||
let test_rxing_result = self.test_rxing_results.get(x).unwrap();
|
||||
log::info(format!(
|
||||
"Rotation {} degrees:",
|
||||
test_rxing_result.getRotation()
|
||||
test_rxing_result.get_rotation()
|
||||
));
|
||||
log::info(format!(
|
||||
" {} of {} images passed ({} required)",
|
||||
passed_counts[x],
|
||||
image_files.len(),
|
||||
test_rxing_result.getMustPassCount()
|
||||
test_rxing_result.get_must_pass_count()
|
||||
));
|
||||
let mut failed = image_files.len() - passed_counts[x];
|
||||
log::info(format!(
|
||||
@@ -314,7 +314,7 @@ impl<T:Reader> AbstractBlackBoxTestCase<T> {
|
||||
" {} of {} images passed with try harder ({} required)",
|
||||
try_harder_counts[x],
|
||||
image_files.len(),
|
||||
test_rxing_result.getTryHarderCount()
|
||||
test_rxing_result.get_try_harder_count()
|
||||
));
|
||||
failed = image_files.len() - try_harder_counts[x];
|
||||
log::info(format!(
|
||||
@@ -324,18 +324,18 @@ impl<T:Reader> AbstractBlackBoxTestCase<T> {
|
||||
));
|
||||
total_found += passed_counts[x] + try_harder_counts[x];
|
||||
total_must_pass +=
|
||||
test_rxing_result.getMustPassCount() + test_rxing_result.getTryHarderCount();
|
||||
test_rxing_result.get_must_pass_count() + test_rxing_result.get_try_harder_count();
|
||||
total_misread += misread_counts[x] + try_harder_misread_counts[x];
|
||||
total_max_misread +=
|
||||
test_rxing_result.getMaxMisreads() + test_rxing_result.getMaxTryHarderMisreads();
|
||||
test_rxing_result.get_max_misreads() + test_rxing_result.get_max_try_harder_misreads();
|
||||
}
|
||||
|
||||
let totalTests = image_files.len() * test_count * 2;
|
||||
let total_tests = image_files.len() * test_count * 2;
|
||||
log::info(format!(
|
||||
"Decoded {} images out of {} ({}, {} required)",
|
||||
total_found,
|
||||
totalTests,
|
||||
total_found * 100 / totalTests,
|
||||
total_tests,
|
||||
total_found * 100 / total_tests,
|
||||
total_must_pass
|
||||
));
|
||||
if total_found > total_must_pass as usize {
|
||||
@@ -365,32 +365,32 @@ impl<T:Reader> AbstractBlackBoxTestCase<T> {
|
||||
// Then run through again and assert if any failed
|
||||
for x in 0..test_count {
|
||||
// for (int x = 0; x < testCount; x++) {
|
||||
let testRXingResult = self.test_rxing_results.get(x).unwrap();
|
||||
let test_rxing_result = self.test_rxing_results.get(x).unwrap();
|
||||
let label = format!(
|
||||
"Rotation {} degrees: Too many images failed",
|
||||
testRXingResult.getRotation()
|
||||
test_rxing_result.get_rotation()
|
||||
);
|
||||
assert!(
|
||||
passed_counts[x] >= testRXingResult.getMustPassCount() as usize,
|
||||
passed_counts[x] >= test_rxing_result.get_must_pass_count() as usize,
|
||||
"{}",
|
||||
label
|
||||
);
|
||||
assert!(
|
||||
try_harder_counts[x] >= testRXingResult.getTryHarderCount() as usize,
|
||||
try_harder_counts[x] >= test_rxing_result.get_try_harder_count() as usize,
|
||||
"Try harder, {}",
|
||||
label,
|
||||
);
|
||||
let label = format!(
|
||||
"Rotation {} degrees: Too many images misread",
|
||||
testRXingResult.getRotation()
|
||||
test_rxing_result.get_rotation()
|
||||
);
|
||||
assert!(
|
||||
misread_counts[x] <= testRXingResult.getMaxMisreads() as usize,
|
||||
misread_counts[x] <= test_rxing_result.get_max_misreads() as usize,
|
||||
"{}",
|
||||
label
|
||||
);
|
||||
assert!(
|
||||
try_harder_misread_counts[x] <= testRXingResult.getMaxTryHarderMisreads() as usize,
|
||||
try_harder_misread_counts[x] <= test_rxing_result.get_max_try_harder_misreads() as usize,
|
||||
"Try harder, {}",
|
||||
label
|
||||
);
|
||||
@@ -419,13 +419,13 @@ impl<T:Reader> AbstractBlackBoxTestCase<T> {
|
||||
|
||||
// Try in 'pure' mode mostly to exercise PURE_BARCODE code paths for exceptions;
|
||||
// not expected to pass, generally
|
||||
let mut result = None;
|
||||
// let mut result = None;
|
||||
let mut pure_hints = HashMap::new();
|
||||
pure_hints.insert(
|
||||
DecodeHintType::PURE_BARCODE,
|
||||
DecodeHintValue::PureBarcode(true),
|
||||
);
|
||||
result = if let Ok(res) = self.barcode_reader.decode_with_hints(source, &pure_hints) {
|
||||
let mut result = if let Ok(res) = self.barcode_reader.decode_with_hints(source, &pure_hints) {
|
||||
Some(res)
|
||||
} else {
|
||||
None
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
mod TestResult;
|
||||
mod test_result;
|
||||
mod abstract_black_box_test_case;
|
||||
|
||||
pub use TestResult::*;
|
||||
pub use test_result::*;
|
||||
pub use abstract_black_box_test_case::*;
|
||||
@@ -42,23 +42,23 @@ impl TestRXingResult {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn getMustPassCount(&self) -> u32 {
|
||||
pub fn get_must_pass_count(&self) -> u32 {
|
||||
self.must_pass_count
|
||||
}
|
||||
|
||||
pub fn getTryHarderCount(&self) -> u32 {
|
||||
pub fn get_try_harder_count(&self) -> u32 {
|
||||
self.try_harder_count
|
||||
}
|
||||
|
||||
pub fn getMaxMisreads(&self) -> u32 {
|
||||
pub fn get_max_misreads(&self) -> u32 {
|
||||
self.max_misreads
|
||||
}
|
||||
|
||||
pub fn getMaxTryHarderMisreads(&self) -> u32 {
|
||||
pub fn get_max_try_harder_misreads(&self) -> u32 {
|
||||
self.max_try_harder_misreads
|
||||
}
|
||||
|
||||
pub fn getRotation(&self) -> f32 {
|
||||
pub fn get_rotation(&self) -> f32 {
|
||||
self.rotation
|
||||
}
|
||||
}
|
||||
@@ -29,9 +29,9 @@ fn maxicode1_test_case() {
|
||||
BarcodeFormat::MAXICODE,
|
||||
);
|
||||
// super("src/test/resources/blackbox/maxicode-1", new MultiFormatReader(), BarcodeFormat.MAXICODE);
|
||||
tester.addTest(6, 6, 0.0);
|
||||
tester.add_test(6, 6, 0.0);
|
||||
|
||||
tester.testBlackBox();
|
||||
tester.test_black_box();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,12 +48,12 @@ fn maxi_code_black_box1_test_case() {
|
||||
BarcodeFormat::MAXICODE,
|
||||
);
|
||||
// super("src/test/resources/blackbox/maxicode-1", new MultiFormatReader(), BarcodeFormat.MAXICODE);
|
||||
tester.addHint(
|
||||
tester.add_hint(
|
||||
DecodeHintType::PURE_BARCODE,
|
||||
rxing::DecodeHintValue::PureBarcode(true),
|
||||
);
|
||||
|
||||
tester.addTest(1, 1, 0.0);
|
||||
tester.add_test(1, 1, 0.0);
|
||||
|
||||
tester.testBlackBox();
|
||||
tester.test_black_box();
|
||||
}
|
||||
|
||||
@@ -30,12 +30,12 @@ fn qrcode_black_box1_test_case() {
|
||||
rxing::BarcodeFormat::QR_CODE,
|
||||
);
|
||||
// super("src/test/resources/blackbox/qrcode-1", new MultiFormatReader(), BarcodeFormat.QR_CODE);
|
||||
tester.addTest(17, 17, 0.0);
|
||||
tester.addTest(14, 14, 90.0);
|
||||
tester.addTest(17, 17, 180.0);
|
||||
tester.addTest(14, 14, 270.0);
|
||||
tester.add_test(17, 17, 0.0);
|
||||
tester.add_test(14, 14, 90.0);
|
||||
tester.add_test(17, 17, 180.0);
|
||||
tester.add_test(14, 14, 270.0);
|
||||
|
||||
tester.testBlackBox();
|
||||
tester.test_black_box();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,12 +49,12 @@ fn qrcode_black_box2_test_case() {
|
||||
QRCodeReader {},
|
||||
BarcodeFormat::QR_CODE,
|
||||
);
|
||||
tester.addTest(31, 31, 0.0);
|
||||
tester.addTest(30, 30, 90.0);
|
||||
tester.addTest(30, 30, 180.0);
|
||||
tester.addTest(30, 30, 270.0);
|
||||
tester.add_test(31, 31, 0.0);
|
||||
tester.add_test(30, 30, 90.0);
|
||||
tester.add_test(30, 30, 180.0);
|
||||
tester.add_test(30, 30, 270.0);
|
||||
|
||||
tester.testBlackBox();
|
||||
tester.test_black_box();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,12 +68,12 @@ fn qrcode_black_box3_test_case() {
|
||||
QRCodeReader {},
|
||||
BarcodeFormat::QR_CODE,
|
||||
);
|
||||
tester.addTest(38, 38, 0.0);
|
||||
tester.addTest(39, 39, 90.0);
|
||||
tester.addTest(36, 36, 180.0);
|
||||
tester.addTest(39, 39, 270.0);
|
||||
tester.add_test(38, 38, 0.0);
|
||||
tester.add_test(39, 39, 90.0);
|
||||
tester.add_test(36, 36, 180.0);
|
||||
tester.add_test(39, 39, 270.0);
|
||||
|
||||
tester.testBlackBox();
|
||||
tester.test_black_box();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,12 +89,12 @@ fn qrcode_black_box4_test_case() {
|
||||
QRCodeReader {},
|
||||
BarcodeFormat::QR_CODE,
|
||||
);
|
||||
tester.addTest(36, 36, 0.0);
|
||||
tester.addTest(35, 35, 90.0);
|
||||
tester.addTest(35, 35, 180.0);
|
||||
tester.addTest(35, 35, 270.0);
|
||||
tester.add_test(36, 36, 0.0);
|
||||
tester.add_test(35, 35, 90.0);
|
||||
tester.add_test(35, 35, 180.0);
|
||||
tester.add_test(35, 35, 270.0);
|
||||
|
||||
tester.testBlackBox();
|
||||
tester.test_black_box();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,12 +112,12 @@ fn qrcode_black_box5_test_case() {
|
||||
QRCodeReader {},
|
||||
BarcodeFormat::QR_CODE,
|
||||
);
|
||||
tester.addTest(19, 19, 0.0);
|
||||
tester.addTest(19, 19, 90.0);
|
||||
tester.addTest(19, 19, 180.0);
|
||||
tester.addTest(19, 19, 270.0);
|
||||
tester.add_test(19, 19, 0.0);
|
||||
tester.add_test(19, 19, 90.0);
|
||||
tester.add_test(19, 19, 180.0);
|
||||
tester.add_test(19, 19, 270.0);
|
||||
|
||||
tester.testBlackBox();
|
||||
tester.test_black_box();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,10 +132,10 @@ fn qrcode_black_box6_test_case() {
|
||||
QRCodeReader {},
|
||||
BarcodeFormat::QR_CODE,
|
||||
);
|
||||
tester.addTest(15, 15, 0.0);
|
||||
tester.addTest(14, 14, 90.0);
|
||||
tester.addTest(13, 13, 180.0);
|
||||
tester.addTest(14, 14, 270.0);
|
||||
tester.add_test(15, 15, 0.0);
|
||||
tester.add_test(14, 14, 90.0);
|
||||
tester.add_test(13, 13, 180.0);
|
||||
tester.add_test(14, 14, 270.0);
|
||||
|
||||
tester.testBlackBox();
|
||||
tester.test_black_box();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user