Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: still creating

...

Below is an annotated TDML file for a very simple example:

Code Block
<?xml version="1.0" encoding="ASCII"?>
<!-- 
Example of a self-contained test described in a TDML file
 -->

 <tdml:testSuite 
  suiteName="Suspected Bugs" 
  description="Illustrates issues found 2013-04-01"
  xmlns:tdml="http://www.ibm.com/xmlns/dfdl/testData" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/" 
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:ex="http://example.com">

  <!--
    Use defineSchema to include a DFDL schema directly inside the TDML file.
    You can alternatively put the DFDL schema in a separate file if you prefer.

    Each defineSchema has a name, so that one TDML file can contain tests which reference
    different DFDL schemas. 

    To embed a schema inside the TDML you don't include the <xs:schema...> element from
    the schema file, nor do you need to wrap the top-level DFDL annotation objects with
    xs:annotation and xs:appinfo.

    In other words, inside a defineSchema you can directly put: 
    dfdl:defineFormat, dfdl:defineEscapeSchema,
    dfdl:format (for the default format), xs:element, xs:simpleType, xs:complexType, xs:group.
   -->

  <tdml:defineSchema name="s1">

    <dfdl:defineFormat name="myDefaults">
      <dfdl:format lengthKind="implicit" representation="text"
        lengthUnits="bytes" encoding="US-ASCII" initiator="" terminator=""
        separator="" ignoreCase="no" textNumberRep="standard" />
    </dfdl:defineFormat>

    <dfdl:format ref="myDefaults" />

    <!-- 
      imagine we are reporting a bug with date/time functionality, and
      this element exercises the feature of concern.
     -->
     
 <xs:element name="dateTimeText" type="xs:dateTime" 
      dfdl:calendarPattern="MM.dd.yyyy 'at' HH:mm:ss ZZZZ" dfdl:calendarPatternKind="explicit"
	  dfdl:lengthKind="explicit" dfdl:length="{ 35 }" />

    <!-- That's it for the schema for this small example -->
  </tdml:defineSchema>

<!-- 
   Here is a test case that exercises the above schema.

   A single TDML file can contain many test cases like the one below. This
   example has only one.

   You must give the name of the model (aka the schema), that can be the name of a
   schema defined immediately in this file like above, or a file name.

   You must also give the name of the root element that the test will use.
 -->

<tdml:parserTestCase name="dateTimeText" root="dateTimeText"
    model="s1" description="date time issue"> <!-- description is optional --> 

<!--
   The data for your test is given by the tdml:document element.

   Notice specifically the use of the CDATA bracketing of the data. This
   insures that no unintended whitespace gets inserted around your data.
  -->
    <tdml:document><![CDATA[04.02.2013 at 14:00:56 GMT-05:00]]></tdml:document>

  <!--
   The infoset element gives the expected infoset, expressed as an XML fragment.
  -->

  <tdml:infoset>
  <!--
     Always need this extra tdml:dfdlInfoset element as well
    -->
       <tdml:dfdlInfoset>

    <!--
      Here is our actual expected result, where the date and time
      is now in XML's cannonical representation for these.
      -->
       <dateTimeText>2013-04-02T14:00:56-05:00</dateTimeText>
      </tdml:dfdlInfoset>
    </tdml:infoset>

<!-- end of the test case -->
 </tdml:parserTestCase>
<!-- end of the whole TDML file --> 
</tdml:testSuite>

Suppose you save the above out as a file "myDateTimeBug.tdml". You can then run it using the Daffodil command line tool:

Code Block
...tbd...

When specifying the test data, there are other ways to do this than using just text.

You can specify the test data in hexadecimal, in individual bits, or you can direct Daffodil to find the data in an external file.

These are illustrated here. You just change the way the tdml:document element is specified to include tdml:documentPart children elements:

Code Block
    <tdml:document>

      <!--
          A document part with type="text" is text. Use CDATA to avoid whitespace changes.

          So in the example below, the line ending after '250;' and after '967;' are intentional
          parts of the data.
        -->

      <tdml:documentPart type="text"><![CDATA[quantity:250;
hardnessRating:967;
]]></tdml:documentPart>

      <!-- 
          In 'text' both XML character entities, and DFDL's own character entities are interpreted.

          So here is a NUL terminated string that contains a date with some Japanese Kanji characters.
          The Japanese characters are expressed using XML numeric character entities. The NUL termination
          is expressed using a DFDL character entity.

          In this example one has no choice but to use a DFDL character entity. The NUL character (which has character
          code zero), is not allowed in XML documents, not even using an XML character entity. So you 
          have to write '%NUL;' or '%#x00;' to express it using DFDL character entities.
        -->

      <tdml:documentPart type="text"><![CDATA[1987&#x5E74;10&#x6708;&#x65e5; BCE%NUL;]]></tdml:documentPart>

      <!--
          Type 'byte' means use hexadecimal to specify the data. Freeform whitespace is allowed. 
          Actually, any character that is not a-zA-Z0-9 is ignored. So you can use "." or "-" to separate
          groups of hex digits if you like.
       -->
 
      <tdml:documentPart type="byte">
            9Abf e4c3
            A5-E9-FF-00
      </tdml:documentPart>
      
       <!--
          Type 'bits' allows you to specify individual 0 and 1. Any character other than 0 or 1 is ignored.
        -->

       <tdml:documentPart type="bits">
            1.110 0.011 1101 First 5 bit fields.
       </tdml:documentPart>

       <!--
          Type 'file' means the content is a file name where to get the data
         -->
  
       <tdml:documentPart type="file">/some/directory/testData.in</tdml:documentPart>

    </tdml:document>

 

 

Finally, here's an example that uses Unicode characters :

Code Block
<?xml version="1.0" encoding="ASCII="UTF-8"?>
<!-- 
Example of a self-contained test described in a TDML file

Note that in the XML slug line above, we're using UTF-8.

That will allow you to put any unicode character into your test
data or expected result.
 -->

 <tdml:testSuite 
  suiteName="Suspected Bugs" 
  description="Illustrates issues found 2013-04-01"
  xmlns:tdml="http://www.ibm.com/xmlns/dfdl/testData" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/" 
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:ex="http://example.com">

  <!--
    Use defineSchema to include a DFDL schema directly inside the TDML file.
    You can alternatively put the DFDL schema in a separate file if you prefer.

    Each defineSchema has a name, so that one TDML file can contain tests which reference
    different DFDL schemas. 

    To embed a schema inside the TDML you don't include the <xs:schema...> element from
    the schema file, nor do you need to wrap the top-level DFDL annotation objects with
    xs:annotation and xs:appinfo.

    In other words, inside a defineSchema you can directly put: 
    dfdl:defineFormat, dfdl:defineEscapeSchema,
    dfdl:format (for the default format), xs:element, xs:simpleType, xs:complexType, xs:group.
   -->

  <tdml:defineSchema name="s1">

    <dfdl:defineFormat name="myDefaults">
      <dfdl:format lengthKind="implicit" representation="text"
        lengthUnits="bytes" encoding="US-ASCII" initiator="" terminator=""
        separator="" ignoreCase="no" textNumberRep="standard" />
    </dfdl:defineFormat>

    <dfdl:format ref="myDefaults" />

    <!-- 
      imagine we are reporting a bug with date/time functionality.

      Note that since the whole file is utf-8, we can freely put unicode 
      characters in here. These are Japanese.

      If you cannot see the Japanese characters in the calendarPattern property
      but instead are seeing things like 'å ¹ ´ ' below, then either your web 
      browser or your system are not setup properly 
      for Unicode. Search this wiki for Unicode and you'll find some hints on 
      how to set up for Unicode.
     -->
     
 <xs:element name="dateTimeText" type="xs:dateTime" 
      dfdl:calendarPattern="yyyy年MM月dd日のHH:mm:ss ZZZZ" dfdl:calendarPatternKind="explicit"
	  dfdl:lengthKind="explicit" dfdl:length="{ 35 }" />

  </tdml:defineSchema>

<!-- 
   Here is a test case that exercises the above schema

   You must give the name of the model (aka the schema), that can be the name of a
   schema defined immediately in this file like above, or a file name.

   You must also give the name of the root element that the test will use.
 -->

<tdml:parserTestCase name="dateTimeText" root="dateTimeText"
    model="s1" description="date time issue"> <!-- description is optional --> 

<!--
   The data for your test is given by the tdml:document element.

   Notice specifically the use of the CDATA bracketing of the data. This
   insures that no unintended whitespace gets inserted around your data.

   This specific example is using text data. We'll see examples of hexadecimal,
   bits, and use of data from an external file as well.

   Our test is expecting some Japanese Unicode characters in here. 
  -->
    <tdml:document><![CDATA[2013年04月02日の14:00:56 GMT-05:00]]></tdml:document>

  <!--
   The infoset element gives the expected infoset, expressed as an XML fragment.
  -->

  <tdml:infoset>
      <tdml:dfdlInfoset>
        <dateTimeText>2013-04-02T14:00:56-05:00</dateTimeText>
      </tdml:dfdlInfoset>
    </tdml:infoset>

<!-- end of the test case -->
 </tdml:parserTestCase>
<!-- end of the whole TDML file --> 
</tdml:testSuite>
 

...