-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Telepen support #39
Telepen support #39
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went through and did a basic review over the PR.
I added a few comments for fixes before we can merge.
In addition: I found that the test-suite fails with:
INFO :: Starting test_resources/blackbox/cpp/qrcode-2/12.png
FINE :: could not read at rotation 0: NotFoundException("")
thread 'cpp_qrcode_black_box2_test_case' panicked at src/oned/telepen_reader.rs:217:33:
slice index starts at 1 but ends at 0
Just glancing at it, I believe that the new Telepen reader is faulting when being fed an image with a qr-code in it. Possibly a check there to make sure the out-of-bounds issue does not cause a panic.
Great PR, I'm excited to get this merged, thank you!
src/oned/mod.rs
Outdated
@@ -85,3 +91,6 @@ pub use ean_8_writer::*; | |||
|
|||
mod upc_e_writer; | |||
pub use upc_e_writer::*; | |||
|
|||
mod telepen_common; | |||
pub use telepen_common::*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does telepen_common need to be public here or can it be internal to the crate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure whether the raw conversion functions might be of use outside the library, but happy to internalise them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with it being public in that case, I'm going to move to v0.5 with this PR (and a couple other small fixes I'm rolling up with it), so some changes to the API are totally fine.
src/oned/telepen_reader.rs
Outdated
|
||
pub fn arrayContains(array: &[char], key: char) -> bool { | ||
array.contains(&key) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason why you wrap this in a helper function? I have no objection to it, just curious if I missed something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My starting point was to copy the Codabar reader; it's retained from that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weird, I wonder why I did that, totally lost to me at this point. probably I copied it from the java codebase for reasons unknown. you can leave it as is and I'll go through and clean them all up at some point in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now removed.
src/oned/telepen_writer.rs
Outdated
hints.get(&EncodeHintType::TELEPEN_AS_NUMERIC), | ||
Some(EncodeHintValue::TelepenAsNumeric(true)) | ||
) { | ||
decodedContents = TelepenCommon::numeric_to_ascii(&contents).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please just pass this conversion error up with the Result rather than calling .unwrap()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one should never have been an unwrap; my mistake!
numeric = "11058474"; | ||
result = TelepenCommon::numeric_to_ascii(numeric).unwrap(); | ||
assert_eq!("& oe", result); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please move these tests to the src/oned/telepen_common.rs
file, the goal here is to keep the unit tests close to the code they test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't select the text correctly, the tests that should be moved are:
#[test]
fn telepen_checksum_test1() {
let contents = "Hello world!";
let checksum = TelepenCommon::calculate_checksum(contents);
assert_eq!('\u{1a}', checksum);
}
#[test]
fn telepen_checksum_test2() {
let contents = "ABC123456";
let checksum = TelepenCommon::calculate_checksum(contents);
assert_eq!('\u{1}', checksum);
}
#[test]
fn telepen_alpha_to_numeric_test() {
let mut ascii = "'=Siu";
let mut result = TelepenCommon::ascii_to_numeric(ascii);
assert_eq!("1234567890", result);
ascii = "& oe";
result = TelepenCommon::ascii_to_numeric(ascii);
assert_eq!("11058474", result);
}
#[test]
fn telepen_numeric_to_ascii_test() {
let mut numeric = "1234567890";
let mut result = TelepenCommon::numeric_to_ascii(numeric).unwrap();
assert_eq!("'=Siu", result);
numeric = "11058474";
result = TelepenCommon::numeric_to_ascii(numeric).unwrap();
assert_eq!("& oe", result);
}
@cpwood I went through and did a review. Only a few fixes to be handled. The panic when attempting to read a qr-code is the main breaking issue so far. |
No problem. As I mentioned, I'm a rookie Rust developer, so the feedback is gratefully received! Will work on the above and come back to you. |
Sounds good! A word of warning, even on high-power machines the test suite takes a long time to run if it isn't built in "release" mode, so I always suggest that if you want to run the entire test suite you do so with |
I poked at it, the out of bounds is fixed with a change to
but that's probably not the best fix. |
Haha, I've done this: // Any Telepen barcode will be longer than two bytes.
if byteLength < 3 {
return Err(Exceptions::NOT_FOUND);
} The start and end of the barcode are two bytes even before you get to the main content, so it should be 3 bytes at the very least. This should mean we never can go out of bounds anymore. |
Perfect! once you push all your changes let me know and I'll re-auth all the automated tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All tests pass, code review looks good, all outstanding concerns fully addressed.
Fully resolves #39
Oh, thinking about rust style in general, I didn't think about it while I was doing the review but It's not required, just a general rust style guide that I try to follow. When I did the final prep for the release I noticed that it warned a few times on your functions, and that was really the only thing it complained about. Great PR, thanks again for your hard work. |
Addresses #38 .