Browse Source

Remove tests from pdf.rs file

pull/6/head
gilardh 4 years ago
parent
commit
d85c5f0a8b
  1. 86
      lib/src/pdf.rs

86
lib/src/pdf.rs

@ -258,88 +258,4 @@ fn split_to_max(s: &str, max: usize, blocksize: usize) -> Vec<String> {
// Add spaces
return ans;
}
#[cfg(test)]
mod tests {
#[test]
fn test_qrcode_scale() {
use array2d::Array2D;
use qrcode::QrCode;
use crate::pdf::qrcode_scaled;
let testdata = "This is some testdata";
let code = QrCode::new(testdata.as_bytes()).unwrap();
let width = code.width();
let factor = 10;
let padding = 10;
let (scaled, size) = qrcode_scaled(testdata, factor);
let scaled_size = (width * factor)+(2*padding);
assert_eq!(size, scaled_size);
// 3 bytes per pixel
let scaled_qrcode = Array2D::from_row_major(&scaled, scaled_size, scaled_size*3);
for i in 0..scaled_size {
for j in 0..scaled_size {
// The padding should be white
if i < padding || i >= (width*factor) + padding ||
j < padding || j >= (width*factor) + padding {
for px in 0..3 {
assert_eq!(scaled_qrcode[(i, j*3+px)], 255u8);
}
} else {
// Should match the QR code module
let module_i = (i-padding)/factor;
let module_j = (j-padding)/factor;
// This should really be (i,j), but I think there's a bug in the qrcode
// module that is returning it the other way.
let color = if code[(module_j, module_i)] == qrcode::Color::Light {
// Light color is white
255u8
} else {
// Dark color is black
0u8
};
for px in 0..3 {
assert_eq!(scaled_qrcode[(i, j*3+px)], color);
}
}
}
}
}
#[test]
fn test_split() {
use crate::pdf::split_to_max;
assert_eq!(split_to_max("a", 1, 1).join("\n"), "a\n");
// Test the address splitting using max/blocksize we'll know we use
let addr = "ztestsapling1w00pdjthkzmzgut4c3y7hu6q6c8ferjczyvc03xwu0rvdgtre8a25em5w3w6jxghvcar5jzehnn";
assert_eq!(split_to_max(addr, 44, 8).join("\n"), "ztestsap ling1w00 pdjthkzm zgut4c3y 7hu6q6c8 ferj\nczyvc03x wu0rvdgt re8a25em 5w3w6jxg hvcar5jz ehnn\n");
assert_eq!(split_to_max(addr, 44, 8).join(" ").replace(" ", ""), addr);
assert_eq!(split_to_max(addr, 42, 8).join(" ").replace(" ", ""), addr);
assert_eq!(split_to_max(addr, 39, 39).join(" ").replace(" ", ""), addr);
// Test the PK splitting using max/blocksize we'll know we use
let pk = "secret-extended-key-test1qj7vst8eqqqqqqpu2w6r0p2ykewm95h3d28k7r7y87e9p4v5zhzd4hj2y57clsprjveg997vqk7ak9tr2pnyyxmfzyzs6dhtuflt3aea9srp08teskpqfy2dtm07n08z3dyra407xumf3fk9ds4x06rzur7mgfyu39krj2g28lsxsxtv7swzu0j9vw4qf8rn5z72ztgeqj6u5zehylqm75c7d3um9ds9zvek4tdyta7qhln5fkc0dks6qwmkvr48fvgucpc3542kmdc97uqzt";
assert_eq!(split_to_max(pk, 44, 8).join(" ").replace(" ", ""), pk);
assert_eq!(split_to_max(pk, 45, 10).join(" ").replace(" ", ""), pk);
assert_eq!(split_to_max(pk, 45, 45).join(" ").replace(" ", ""), pk);
// Test random combinations of block size and spaces to ensure that
// the string is always preserved
for m in 1..100 {
for b in 1..40 {
assert_eq!(split_to_max(addr, m, b).join(" ").replace(" ", ""), addr);
assert_eq!(split_to_max(pk, m, b).join(" ").replace(" ", ""), pk);
}
}
}
}
}
Loading…
Cancel
Save