This commit is contained in:
Henry Schimke
2022-10-16 11:54:49 -05:00
parent 07348168ad
commit c63dd67e4d

View File

@@ -16,8 +16,7 @@
use std::{ use std::{
collections::HashMap, collections::HashMap,
fs::{read_dir, read_to_string, File}, fs::{read_dir, read_to_string},
io::Write,
path::{Path, PathBuf}, path::{Path, PathBuf},
}; };
@@ -28,7 +27,7 @@ use rxing::{
use super::TestRXingResult; use super::TestRXingResult;
use image;
/** /**
* @author Sean Owen * @author Sean Owen
@@ -154,7 +153,7 @@ impl AbstractBlackBoxTestCase {
//let testImageFileName = testImage.getFileName().toString(); //let testImageFileName = testImage.getFileName().toString();
let file_base_name = testImage.file_stem().unwrap(); let file_base_name = testImage.file_stem().unwrap();
//let expectedTextFile = self.testBase.resolve(fileBaseName + ".txt"); //let expectedTextFile = self.testBase.resolve(fileBaseName + ".txt");
let mut expected_text_file = PathBuf::from(testImage.clone()); let mut expected_text_file = testImage.clone();
expected_text_file.set_extension("txt"); expected_text_file.set_extension("txt");
let expected_text = if expected_text_file.exists() { let expected_text = if expected_text_file.exists() {
Self::read_file_as_string(expected_text_file) Self::read_file_as_string(expected_text_file)
@@ -186,7 +185,7 @@ impl AbstractBlackBoxTestCase {
let expected_metadata = HashMap::new(); let expected_metadata = HashMap::new();
for (k, v) in expectedMetadata_unfinished { for (k, v) in expectedMetadata_unfinished {
let new_k = RXingResultMetadataType::from(k); let new_k = RXingResultMetadataType::from(k);
let new_v = match new_k { let _new_v = match new_k {
RXingResultMetadataType::OTHER => RXingResultMetadataValue::OTHER(v), RXingResultMetadataType::OTHER => RXingResultMetadataValue::OTHER(v),
RXingResultMetadataType::ORIENTATION => { RXingResultMetadataType::ORIENTATION => {
RXingResultMetadataValue::Orientation(v.parse().unwrap_or_default()) RXingResultMetadataValue::Orientation(v.parse().unwrap_or_default())
@@ -448,7 +447,7 @@ impl AbstractBlackBoxTestCase {
} }
let result_text = result.getText(); let result_text = result.getText();
if !(expected_text == result_text) { if expected_text != result_text {
log::info(format!( log::info(format!(
"Content mismatch: expected '{}' but got '{}'{}", "Content mismatch: expected '{}' but got '{}'{}",
expected_text, result_text, suffix expected_text, result_text, suffix
@@ -470,12 +469,12 @@ impl AbstractBlackBoxTestCase {
} }
} }
return Ok(true); Ok(true)
} }
fn read_file_as_string(file: PathBuf) -> Result<String, std::io::Error> { fn read_file_as_string(file: PathBuf) -> Result<String, std::io::Error> {
let string_contents = read_to_string(&file)?; //new String(Files.readAllBytes(file), charset); let string_contents = read_to_string(&file)?; //new String(Files.readAllBytes(file), charset);
if string_contents.ends_with("\n") { if string_contents.ends_with('\n') {
log::info(format!("String contents of file {} end with a newline. This may not be intended and cause a test failure",file.to_string_lossy())); log::info(format!("String contents of file {} end with a newline. This may not be intended and cause a test failure",file.to_string_lossy()));
} }
Ok(string_contents) Ok(string_contents)