13.7.  Format Units

Some tests need width and height. You can use your favourite unit which are predefined constants for the attribute unit="..":

<!-- Predefined constants for units: -->

<xxx unit="CENTIMETER"  />
<xxx unit="DPI72"       />
<xxx unit="INCH"        />
<xxx unit="MILLIMETER"  />
<xxx unit="POINTS"      />

If you omit the attribute unit="..", the default unit MILLIMETER is used.

Example - Field Size

<testcase name="hasField_WidthAndHeight">
  <assertThat testDocument="acrofields/notExportableAcrofield.pdf">
    <hasField withName="Title of 'someField'" 
              width="450" height="30" 
              unit="POINTS" 
    />
  </assertThat>
</testcase>

Example - Sections of a Page

<testcase name="hasTextOnFirstPage_RectangleInInch">
  <assertThat testDocument="content/documentForTextClipping.pdf">
    <hasText on="FIRST_PAGE" >
      <inClippingArea upperLeftX="0.7" upperLeftY="1.8"
                      width="2.4" height="0.4" 
                      unit="INCH" 
      >
        <containing>Content on first page.</containing>
      </inClippingArea>
    </hasText>
  </assertThat>
</testcase>

Example - Page Format

<testcase name="hasFormat_HugeFormat">
  <assertThat testDocument="format/physical-map-of-the-world-1999_1117x863mm.pdf">
    <hasFormat width="2448" height="3168" unit="POINTS" />
  </assertThat>
</testcase>

Example - Error messages

Error messages print both the original units and millimeters. For example, when you expected 111 POINTS for the width in the last example, you see the following error message:

Wrong page format in 'physical-map-of-the-world-1999_1117x863mm.pdf' on page 1. 
Expected: 'height=1117.60, width=39.16 (as 'mm', converted from unit 'points')', 
but was:  'height=1117.60, width=863.60 (as 'mm')'.