<?xml version="1.0" encoding="utf-8"?>
<t:test xmlns:t="http://xproc.org/ns/testsuite/3.0"
        xml:base="/pdf-decrypt-001.xml"
        name="pdf-decrypt-001.xml"
        expected="pass">
   <t:info>
      <t:title>pdf-decrypt-001</t:title>
      <t:revision-history>
         <t:revision>
            <t:date>2026-06-11</t:date>
            <t:author>
               <t:name>Norm Tovey-Walsh</t:name>
            </t:author>
            <t:description xmlns="http://www.w3.org/1999/xhtml">
               <p>Created test.</p>
            </t:description>
         </t:revision>
      </t:revision-history>
   </t:info>
   <t:description xmlns="http://www.w3.org/1999/xhtml">
      <p>Tests that pdf-decrypt works.</p>
   </t:description>
   <t:pipeline>
      <p:declare-step xmlns:cx="http://xmlcalabash.com/ns/extensions"
                      xmlns:p="http://www.w3.org/ns/xproc"
                      name="main"
                      version="3.0">
         <p:import href="https://xmlcalabash.com/ext/library/pdf-steps.xpl"/>
         <p:output port="result"/>
         <p:try name="nopass">
            <cx:pdf-info>
               <p:with-input href="../documents/encrypted.pdf"/>
            </cx:pdf-info>
            <p:catch>
               <p:identity>
                  <p:with-input>
                     <result>Failed to load without password</result>
                  </p:with-input>
               </p:identity>
            </p:catch>
         </p:try>
         <cx:pdf-info name="info" password="sekrit">
            <p:with-input href="../documents/encrypted.pdf"/>
         </cx:pdf-info>
         <p:wrap-sequence wrapper="wrapper">
            <p:with-input pipe="@nopass @info"/>
         </p:wrap-sequence>
      </p:declare-step>
   </t:pipeline>
   <t:schematron>
      <s:schema xmlns:s="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
         <s:ns prefix="cx" uri="http://xmlcalabash.com/ns/extensions"/>
         <s:ns prefix="f" uri="http://xmlcalabash.com/ns/acro-form"/>
         <s:pattern>
            <s:rule context="/">
               <s:assert test="wrapper">Wrong document element&gt;</s:assert>
            </s:rule>
         </s:pattern>
         <s:pattern>
            <s:rule context="/wrapper">
               <s:assert test="count(result) = 1">Wrong number of result outputs</s:assert>
               <s:assert test="count(cx:pdf-info) = 1">Wrong number of PDF outputs</s:assert>
            </s:rule>
         </s:pattern>
         <s:pattern>
            <s:rule context="/wrapper/result">
               <s:assert test="contains(., 'Failed to load without password')">Wrong message</s:assert>
            </s:rule>
         </s:pattern>
         <s:pattern>
            <s:rule context="/wrapper/cx:pdf-info">
               <s:assert test="cx:encrypted = 'true'">Encrypted value incorrect</s:assert>
            </s:rule>
         </s:pattern>
      </s:schema>
   </t:schematron>
   <t:result name="pdf-decrypt-001.xml">
      <wrapper>
         <result xmlns:cx="http://xmlcalabash.com/ns/extensions">Failed to load without password</result>
         <cx:pdf-info xmlns:cx="http://xmlcalabash.com/ns/extensions"
                      href="file:/woodpecker/src/codeberg.org/xmlcalabash/xmlcalabash3/tests/extra-suite/test-suite/documents/encrypted.pdf">
            <cx:version>1.6</cx:version>
            <cx:form>none</cx:form>
            <cx:pages>1</cx:pages>
            <cx:encrypted>true</cx:encrypted>
            <cx:permissions assemble="true"
                            extract="true"
                            extract-for-accessibility="true"
                            fill-in-form="true"
                            modify="true"
                            modify-annotations="true"
                            print="true"
                            print-faithful="true"
                            readonly="false"/>
            <cx:page-size width="595" height="842" units="px">A4</cx:page-size>
            <cx:title>Example Encrypted PDF Document</cx:title>
            <cx:creator>Bear</cx:creator>
            <cx:producer>macOS Version 26.5 (Build 25F71) Quartz PDFContext</cx:producer>
            <cx:author>Norm Tovey-Walsh</cx:author>
            <cx:creation-date>2026-06-10T14:28:22Z</cx:creation-date>
            <cx:modification-date>2026-06-10T14:28:22Z</cx:modification-date>
            <cx:subject>Sample documents</cx:subject>
            <cx:keyword>xmlcalabash</cx:keyword>
            <cx:keyword>testsuite</cx:keyword>
            <cx:file-size>117130</cx:file-size>
         </cx:pdf-info>
      </wrapper>
   </t:result>
</t:test>
