<?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: keep-together_overflow-recovery_bug49835.xml 1079013 2011-03-07 23:04:03Z adelmelle $ -->
<testcase>
  <info>
    <p>This test checks for an issue with overflow recovery if there is no 
    previous break. See also Bugzilla 49835. The test checks behavior both
    in single- and multi-column layout. 
    Expected behavior: in case the next page does not have more space available, 
    content should just overflow on the first page. Otherwise, the entire block 
    should be deferred to the next page, but only if it can be kept together there.
    </p>
  </info>
  <fo>
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <fo:layout-master-set>
        <fo:simple-page-master master-name="master-short-single" page-width="10cm" page-height="2cm">
          <fo:region-body />
        </fo:simple-page-master>
        <fo:simple-page-master master-name="master-longer-single" page-width="10cm" page-height="2.5cm">
          <fo:region-body />
        </fo:simple-page-master>
        <fo:simple-page-master master-name="master-long-single" page-width="10cm" page-height="5cm">
          <fo:region-body />
        </fo:simple-page-master>
        <fo:simple-page-master master-name="master-short-multi" page-width="10cm" page-height="2cm">
          <fo:region-body column-count="3"/>
        </fo:simple-page-master>
        <fo:simple-page-master master-name="master-longer-multi" page-width="10cm" page-height="2.5cm">
          <fo:region-body column-count="3"/>
        </fo:simple-page-master>
        <fo:simple-page-master master-name="master-long-multi" page-width="10cm" page-height="5cm">
          <fo:region-body column-count="3"/>
        </fo:simple-page-master>
        <fo:page-sequence-master master-name="master-one">
          <fo:single-page-master-reference master-reference="master-short-single"/>
        </fo:page-sequence-master>
        <fo:page-sequence-master master-name="master-two">
          <fo:single-page-master-reference master-reference="master-short-single"/>
          <fo:single-page-master-reference master-reference="master-long-single"/>
        </fo:page-sequence-master>
        <fo:page-sequence-master master-name="master-three">
          <fo:single-page-master-reference master-reference="master-short-multi"/>
        </fo:page-sequence-master>
        <fo:page-sequence-master master-name="master-four">
          <fo:single-page-master-reference master-reference="master-short-multi"/>
          <fo:single-page-master-reference master-reference="master-long-multi"/>
        </fo:page-sequence-master>
        <fo:page-sequence-master master-name="master-five">
          <fo:single-page-master-reference master-reference="master-short-single"/>
          <fo:single-page-master-reference master-reference="master-longer-single"/>
        </fo:page-sequence-master>
        <fo:page-sequence-master master-name="master-six">
          <fo:single-page-master-reference master-reference="master-short-multi"/>
          <fo:single-page-master-reference master-reference="master-longer-multi"/>
        </fo:page-sequence-master>
      </fo:layout-master-set>
      <fo:page-sequence master-reference="master-one">
        <fo:flow flow-name="xsl-region-body">
          <fo:block id="block-1" keep-together.within-column="always">
            <fo:block>Line 1</fo:block>
            <fo:block>Line 2</fo:block>
            <fo:block>Line 3</fo:block>
            <fo:block>Line 4</fo:block>
            <fo:block>Line 5</fo:block>
          </fo:block>
        </fo:flow>
      </fo:page-sequence>
      <fo:page-sequence master-reference="master-two">
        <fo:flow flow-name="xsl-region-body">
          <fo:block id="block-2" keep-together.within-column="always">
            <fo:block>Line 1</fo:block>
            <fo:block>Line 2</fo:block>
            <fo:block>Line 3</fo:block>
            <fo:block>Line 4</fo:block>
            <fo:block>Line 5</fo:block>
          </fo:block>
        </fo:flow>
      </fo:page-sequence>
      <fo:page-sequence master-reference="master-three">
        <fo:flow flow-name="xsl-region-body">
          <fo:block id="block-3" keep-together.within-column="always">
            <fo:block>Line 1</fo:block>
            <fo:block>Line 2</fo:block>
            <fo:block>Line 3</fo:block>
            <fo:block>Line 4</fo:block>
            <fo:block>Line 5</fo:block>
          </fo:block>
        </fo:flow>
      </fo:page-sequence>
      <fo:page-sequence master-reference="master-four">
        <fo:flow flow-name="xsl-region-body">
          <fo:block id="block-4" keep-together.within-column="always">
            <fo:block>Line 1</fo:block>
            <fo:block>Line 2</fo:block>
            <fo:block>Line 3</fo:block>
            <fo:block>Line 4</fo:block>
            <fo:block>Line 5</fo:block>
          </fo:block>
        </fo:flow>
      </fo:page-sequence>
      <fo:page-sequence master-reference="master-five">
        <fo:flow flow-name="xsl-region-body">
          <fo:block id="block-5" keep-together.within-column="always">
            <fo:block>Line 1</fo:block>
            <fo:block>Line 2</fo:block>
            <fo:block>Line 3</fo:block>
            <fo:block>Line 4</fo:block>
            <fo:block>Line 5</fo:block>
          </fo:block>
        </fo:flow>
      </fo:page-sequence>
      <fo:page-sequence master-reference="master-six">
        <fo:flow flow-name="xsl-region-body">
          <fo:block id="block-6" keep-together.within-column="always">
            <fo:block>Line 1</fo:block>
            <fo:block>Line 2</fo:block>
            <fo:block>Line 3</fo:block>
            <fo:block>Line 4</fo:block>
            <fo:block>Line 5</fo:block>
          </fo:block>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
  </fo>
  <checks>
    <!-- overflow on first page -->
    <eval expected="1" xpath="count(//pageSequence[1]/pageViewport)" />
    <eval expected="1" xpath="count(//pageSequence[1]//span[.//block[@prod-id='block-1']])" />
    <!-- deferral to second page -->
    <eval expected="2" xpath="count(//pageSequence[2]/pageViewport)" />
    <eval expected="1" xpath="count(//pageSequence[2]//span[.//block[@prod-id='block-2']])" />
    <!-- overflow on first page, first column -->
    <eval expected="1" xpath="count(//pageSequence[3]/pageViewport)" />
    <eval expected="1" xpath="count(//pageSequence[3]//span[.//block[@prod-id='block-3']])" />
    <!-- deferral to second page, first column -->
    <eval expected="2" xpath="count(//pageSequence[4]/pageViewport)" />
    <eval expected="1" xpath="count(//pageSequence[4]//span[.//block[@prod-id='block-4']])" />
    <!-- overflow on first page -->
    <eval expected="1" xpath="count(//pageSequence[5]/pageViewport)" />
    <eval expected="1" xpath="count(//pageSequence[5]//span[.//block[@prod-id='block-5']])" />
    <!-- overflow on first page, first column -->
    <eval expected="1" xpath="count(//pageSequence[6]/pageViewport)" />
    <eval expected="1" xpath="count(//pageSequence[6]//span[.//block[@prod-id='block-6']])" />
  </checks>
</testcase>
