<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- $Id$ -->
<testcase>
  <info>
    <p>
      This test checks for fo:instream-foreign-object in fo:markers.
    </p>
  </info>
  <fo>
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <fo:layout-master-set>
        <fo:simple-page-master master-name="first"
              margin-right="1.5cm"
              margin-left="1.5cm"
              margin-bottom="2cm"
              margin-top="1cm"
              page-width="21cm"
              page-height="29.7cm">
          <fo:region-body margin-top="1cm"/>
          <fo:region-before extent="1cm"/>
          <fo:region-after extent="1.5cm"/>
        </fo:simple-page-master>
      </fo:layout-master-set>
      <fo:page-sequence master-reference="first" initial-page-number="1">
        <fo:static-content flow-name="xsl-region-before">
          <fo:block-container height="1cm" width="15cm" top="0cm" left="0cm" position="absolute">
            <fo:block font-size="0pt">
              <fo:retrieve-marker retrieve-class-name="mark"
                                  retrieve-boundary="page"
                                  retrieve-position="last-ending-within-page"/>
            </fo:block>
          </fo:block-container>
        </fo:static-content>
        <fo:static-content flow-name="xsl-region-after">
          <fo:block text-align="start" font-size="10pt" font-family="serif" line-height="1em + 2pt">
            Page (<fo:page-number/> / <fo:page-number-citation ref-id="end-of-document"/>)
          </fo:block>
        </fo:static-content>
        <fo:flow flow-name="xsl-region-body">
          <fo:block text-align="start" font-size="12pt" font-family="sans-serif">
            Some text.
          </fo:block>
          <fo:block id="end-of-document">
            <fo:marker marker-class-name="mark">
              <fo:instream-foreign-object width="15cm" height="1cm" id="ifo1">
                <svg xmlns="http://www.w3.org/2000/svg" width="15cm" height="1cm" xml:space="preserve">
                  <rect style="fill:red;stroke:red" x="0" y="0" width="15cm" height="1cm"/>
                </svg>
              </fo:instream-foreign-object>
            </fo:marker>
          </fo:block>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
  </fo>
  <checks>
    <!-- check whether the i-f-o viewport exists -->
    <true xpath="boolean(//viewport[@prod-id='ifo1'])" fail-msg="foreign object viewport not found" />
    <!-- check whether the i-f-o viewport has any content -->
    <true xpath="boolean(//viewport[@prod-id='ifo1']/*)" fail-msg="foreign object not rendered" />
    <!-- check whether the foreign object itself survives marker-cloning -->
    <eval expected="1" xpath="count(//foreignObject[@prod-id='ifo1'][1]/*)" />
    <eval expected="svg" xpath="local-name(//foreignObject[@prod-id='ifo1'][1]/*[1])" />
    <eval expected="1" xpath="count(//foreignObject[@prod-id='ifo1'][1]/*/*)" />
    <eval expected="rect" xpath="local-name(//foreignObject[@prod-id='ifo1'][1]/*[1]/*[1])" />
  </checks>
</testcase>
