diff --git a/Cargo.lock b/Cargo.lock index ed948433c..362c82ac7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2738,6 +2738,7 @@ dependencies = [ name = "craft-pst" version = "0.1.0" dependencies = [ + "craft-pst", "proptest", ] diff --git a/crates/pst/Cargo.toml b/crates/pst/Cargo.toml index 25a1a08bd..60ead7d8f 100644 --- a/crates/pst/Cargo.toml +++ b/crates/pst/Cargo.toml @@ -10,7 +10,9 @@ repository.workspace = true [features] # The test writer (`test_writer`): synthetic .pst files for the tests of code that reads them. # A dev-dependency feature only. -test-writer = [] +test-support = [] +# The earlier name of `test-support`, kept as an alias that turns it on. +test-writer = ["test-support"] [lints] workspace = true @@ -18,4 +20,5 @@ workspace = true [dependencies] [dev-dependencies] +craft-pst = { path = ".", features = ["test-support"] } proptest = { workspace = true } diff --git a/crates/pst/README.md b/crates/pst/README.md index 68b57c7a4..d6c8583d8 100644 --- a/crates/pst/README.md +++ b/crates/pst/README.md @@ -53,7 +53,8 @@ is left out and named (`Error::Cap`). ## What is not here -- Writing. The `test-writer` feature has a writer of small synthetic files, for tests only. +- Writing. The `test-support` feature has a writer of small synthetic files, for tests only. + `test-writer` is an alias of `test-support`. - Offline folders files with 4 KB pages (version 36) and files protected by Windows Information Protection (version 37): `Error::UnsupportedVersion`. - Text in a code page: `PropValue::String8` carries the bytes, and the caller decodes them in diff --git a/crates/pst/src/crypt.rs b/crates/pst/src/crypt.rs index 984bacc34..e5a9f94ab 100644 --- a/crates/pst/src/crypt.rs +++ b/crates/pst/src/crypt.rs @@ -24,7 +24,7 @@ pub(crate) fn decode(method: Encryption, data: &mut [u8], bid: u64) { } /// Encodes `data` in place (the test writer's side). -#[cfg(any(test, feature = "test-writer"))] +#[cfg(any(test, feature = "test-support"))] pub(crate) fn encode(method: Encryption, data: &mut [u8], bid: u64) { match method { Encryption::None => {} diff --git a/crates/pst/src/lib.rs b/crates/pst/src/lib.rs index b532fbeaa..c1f86236e 100644 --- a/crates/pst/src/lib.rs +++ b/crates/pst/src/lib.rs @@ -36,9 +36,9 @@ mod pst; pub mod recur; mod source; /// The test writer: synthetic .pst files from invented folders and messages, for this crate's -/// tests and, through the `test-writer` feature (a dev-dependency only, never in a build that -/// ships), for the tests of the import that reads them. -#[cfg(any(test, feature = "test-writer"))] +/// tests and, through the `test-support` feature (a dev-dependency only, never in a build that +/// ships; `test-writer` is an alias of it), for the tests of the import that reads them. +#[cfg(any(test, feature = "test-support"))] #[doc(hidden)] #[path = "tests/writer.rs"] #[allow( diff --git a/crates/pst/tests/test_support.rs b/crates/pst/tests/test_support.rs new file mode 100644 index 000000000..e5b5a6e02 --- /dev/null +++ b/crates/pst/tests/test_support.rs @@ -0,0 +1,36 @@ +//! The test writer used the way a dependent crate's tests use it: through the `test-support` +//! feature (or `test-writer`, its alias), from outside the crate. + +use std::io::Cursor; + +use craft_pst::test_writer::{FileSpec, FolderSpec, Layout, MessageSpec, build}; +use craft_pst::{Encryption, Format, Pst}; + +#[test] +fn a_file_from_the_test_writer_opens() { + let spec = FileSpec { + layout: Layout::new(Format::Unicode, Encryption::Permute), + password: None, + password_ansi: false, + name: "Personal Folders".into(), + folders: vec![FolderSpec { + name: "Inbox".into(), + class: Some("IPF.Note".into()), + messages: vec![MessageSpec { class: "IPM.Note".into(), subject: "Lunch on Friday?".into(), ..Default::default() }], + children: Vec::new(), + }], + named: Vec::new(), + named_strings: Vec::new(), + }; + let bytes = build(&spec); + let mut pst = Pst::open(Cursor::new(bytes.as_slice())).unwrap(); + assert_eq!(pst.format(), Format::Unicode); + assert_eq!(pst.encryption(), Encryption::Permute); + assert_eq!(pst.store().unwrap().display_name.as_deref(), Some("Personal Folders")); + + let tree = pst.walk_folders().unwrap(); + let inbox = tree.folders.iter().find(|f| f.folder.name == "Inbox").unwrap(); + let items = pst.items(inbox.folder.id).unwrap(); + let subjects: Vec> = items.items.iter().map(|i| i.properties.text(0x0037)).collect(); + assert_eq!(subjects, vec![Some("Lunch on Friday?".to_string())]); +}