mod app;
mod core;
mod img;
mod pdf;
pub use crate::core::Core;
pub use app::*;
pub use img::*;
pub use pdf::*;
#[cfg(test)]
mod tests {
use std::collections::HashMap;
use crate::{ImgApp, ImgFormat, PdfApp, WkhtmlInput};
#[test]
#[ignore = "requires wkhtmltopdf installed and network access"]
fn test_pdf() {
let _ = env_logger::try_init();
let mut pdf_app = PdfApp::new().expect("Failed to init PDF Application");
let args = HashMap::from([("enable-smart-shrinking", "true")]);
pdf_app.set_args(args).unwrap();
let html_code = r#"<html><body><div>DEMO</div></body></html>"#;
let res = pdf_app.run(WkhtmlInput::Html(html_code), "demo");
assert!(res.is_ok(), "{}", res.unwrap_err());
assert!(res.unwrap().extension().unwrap() == "pdf");
let res = pdf_app.run(WkhtmlInput::File("examples/index.html"), "demo");
assert!(res.is_ok(), "{}", res.unwrap_err());
let res = pdf_app.run(WkhtmlInput::Url("https://wkhtmltopdf.org/"), "demo");
assert!(res.is_ok(), "{}", res.unwrap_err());
}
#[test]
#[ignore = "requires wkhtmltoimage installed and network access"]
fn test_img() {
let _ = env_logger::try_init();
let mut image_app = ImgApp::new().expect("Failed to init image Application");
let args = HashMap::from([("height", "100"), ("width", "100")]);
let res = image_app
.set_format(ImgFormat::Png)
.unwrap()
.set_args(args)
.unwrap()
.run(WkhtmlInput::File("examples/index.html"), "demo");
assert!(res.is_ok(), "{}", res.unwrap_err());
let res = image_app.run(WkhtmlInput::Url("https://wkhtmltopdf.org/"), "demo");
assert!(res.is_ok(), "{}", res.unwrap_err());
}
#[test]
#[ignore = "requires wkhtmltopdf installed"]
fn test_rejects_path_traversal_names() {
let pdf_app = PdfApp::new().expect("Failed to init PDF Application");
let res = pdf_app.run(WkhtmlInput::Html("<p>x</p>"), "../escape");
assert!(res.is_err());
}
}