Skip to main content

ppt_rs/core/
powerpoint_compat.rs

1//! Structural compatibility checks aligned with PowerPoint package expectations.
2//!
3//! This module is a thin wrapper around [`crate::core::package_validation`] for
4//! backward compatibility. Prefer [`validate_package_bytes`] for new code.
5
6use std::io::{Read, Seek};
7
8use zip::ZipArchive;
9
10pub use crate::core::package_validation::{validate_package, PackageValidationReport};
11
12/// Result of a PowerPoint structural compatibility scan (legacy).
13#[derive(Debug, Default)]
14pub struct CompatReport {
15    pub issues: Vec<String>,
16}
17
18impl CompatReport {
19    pub fn is_ok(&self) -> bool {
20        self.issues.is_empty()
21    }
22
23    pub fn push(&mut self, issue: impl Into<String>) {
24        self.issues.push(issue.into());
25    }
26}
27
28impl From<PackageValidationReport> for CompatReport {
29    fn from(report: PackageValidationReport) -> Self {
30        Self {
31            issues: report.error_messages(),
32        }
33    }
34}
35
36/// Validate structural compatibility of a PPTX ZIP archive.
37pub fn validate_powerpoint_structure<R: Read + Seek>(
38    archive: &mut ZipArchive<R>,
39) -> CompatReport {
40    validate_package(archive).into()
41}
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46    use crate::generator::create_pptx;
47
48    #[test]
49    fn minimal_deck_passes_compat_gate() {
50        let bytes = create_pptx("Compat", 1).unwrap();
51        let cursor = std::io::Cursor::new(bytes);
52        let mut archive = ZipArchive::new(cursor).unwrap();
53        let report = validate_powerpoint_structure(&mut archive);
54        assert!(report.is_ok(), "issues: {:?}", report.issues);
55    }
56
57    #[test]
58    fn compat_report_matches_package_validation() {
59        use crate::validate_package_bytes;
60        let bytes = create_pptx("Compat", 3).unwrap();
61        let package_report = validate_package_bytes(&bytes);
62        let compat: CompatReport = package_report.clone().into();
63        assert_eq!(compat.issues, package_report.error_messages());
64    }
65}