mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-10-24 10:08:00 -06:00
* Build each crate's integration tests as one binary Every tests/*.rs file is its own executable that links the whole crate graph. Move each crate's test files into tests/it/ as modules of one tests/it/main.rs, for apps/pdfcraft, apps/pdfcraft-cli, automation, cos, crypt, engine, render, sign and ui-egui. ui-egui's ui_group binary and the support modules move into tests/it/ too. Crates with a single test file keep it. The test executables go from 150 to 52, and every crate runs the same number of tests as before. ui-egui perf keeps its own binary (own process): its frame-time budgets would charge each measurement for the other tests running beside it. What the move needs: - include_str!/include_bytes! and #[path] paths gain one "../". - ui-egui: one GPU lock in tests/it/main.rs replaces the five per-file ones (content, document_links, editing, fill_sign, view), so one process creates one wgpu device at a time. The drop-line test in ui.rs and the screenshot blocks behind PDFCRAFT_*_SHOT(S) and CRAFT_UI_DOCKING_DIR, which render without holding it, take it too. - pdfcraft winit_wayland_scroll: the vendored winit source it compiles names crate::event, so that shim lives in main.rs. - parity evidence names the new paths. * Name the one-binary test paths in docs and comments - READMEs, docs, ATTRIBUTION and source comments name tests/it/<file>.rs. - The oracle README's example filters with --test it encryption::qpdf_agrees. - pdfcraft's GPU lock comment points at the UI tests' shared lock in crates/ui-egui/tests/it/main.rs.
55 lines
2.6 KiB
Rust
55 lines
2.6 KiB
Rust
//! `pdfcraft-cli.exe` carries a Windows version resource (`build.rs`), so Explorer, PowerShell's
|
|
//! `VersionInfo` and inventory tools see its version and publisher, as they do for `pdfcraft.exe`.
|
|
|
|
#![cfg(windows)]
|
|
|
|
/// `s` as UTF-16LE, the encoding of every string in a version resource.
|
|
fn utf16(s: &str) -> Vec<u8> {
|
|
s.encode_utf16().flat_map(u16::to_le_bytes).collect()
|
|
}
|
|
|
|
fn find(haystack: &[u8], needle: &[u8]) -> Option<usize> {
|
|
haystack.windows(needle.len()).position(|w| w == needle)
|
|
}
|
|
|
|
/// A little-endian 32-bit DWORD at `at`.
|
|
fn dword(bytes: &[u8], at: usize) -> u32 {
|
|
let b: [u8; 4] = bytes[at..at + 4].try_into().unwrap();
|
|
u32::from_le_bytes(b)
|
|
}
|
|
|
|
/// The value of string-table entry `key`: the key and its terminator, zero padding to the next
|
|
/// 32-bit boundary, then the value and its terminator.
|
|
fn string_value(resource: &[u8], key: &str) -> Option<String> {
|
|
let after_key = find(resource, &utf16(&format!("{key}\0")))? + utf16(key).len() + 2;
|
|
let start = after_key + resource[after_key..].iter().take_while(|&&b| b == 0).count();
|
|
let units: Vec<u16> = resource[start..].as_chunks::<2>().0.iter().map(|&c| u16::from_le_bytes(c)).take_while(|&u| u != 0).collect();
|
|
String::from_utf16(&units).ok()
|
|
}
|
|
|
|
#[test]
|
|
fn the_exe_has_version_info_with_the_package_version() {
|
|
let exe = std::fs::read(env!("CARGO_BIN_EXE_pdfcraft-cli")).unwrap();
|
|
let start = find(&exe, &utf16("VS_VERSION_INFO")).expect("no version resource");
|
|
let resource = &exe[start..];
|
|
for (key, value) in [
|
|
("ProductName", "PdfCraft"),
|
|
("FileDescription", "PdfCraft command-line tool"),
|
|
("LegalCopyright", "Copyright (c) the PdfCraft contributors. MIT OR Apache-2.0."),
|
|
("OriginalFilename", "pdfcraft-cli.exe"),
|
|
("InternalName", "pdfcraft-cli"),
|
|
("FileVersion", env!("CARGO_PKG_VERSION")),
|
|
("ProductVersion", env!("CARGO_PKG_VERSION")),
|
|
] {
|
|
assert_eq!(string_value(resource, key).as_deref(), Some(value), "{key}");
|
|
}
|
|
// VS_FIXEDFILEINFO: signature, struct version, then file and product versions as
|
|
// major << 16 | minor and patch << 16 | build.
|
|
let fixed = start + find(resource, &0xFEEF_04BDu32.to_le_bytes()).expect("no VS_FIXEDFILEINFO");
|
|
let number = |s: &str| -> u32 { s.parse().unwrap() };
|
|
let ms = (number(env!("CARGO_PKG_VERSION_MAJOR")) << 16) | number(env!("CARGO_PKG_VERSION_MINOR"));
|
|
let ls = number(env!("CARGO_PKG_VERSION_PATCH")) << 16;
|
|
assert_eq!([dword(&exe, fixed + 8), dword(&exe, fixed + 12)], [ms, ls], "file version");
|
|
assert_eq!([dword(&exe, fixed + 16), dword(&exe, fixed + 20)], [ms, ls], "product version");
|
|
}
|