| <?xml version="1.0" encoding="UTF-8"?> |
| <tdml:testSuite suiteName="runtime-properties" |
| description="properties that can have expressions to compute their values from data" |
| 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" |
| xmlns:daf="urn:ogf:dfdl:2013:imp:opensource.ncsa.illinois.edu:2012:ext" |
| xmlns:fn="http://www.w3.org/2005/xpath-functions"> |
| |
| <tdml:defineSchema name="s1"> |
| <dfdl:format ref="ex:daffodilTest1" representation="binary" |
| byteOrder="bigEndian" binaryNumberRep="binary" lengthKind="implicit" /> |
| |
| |
| |
| <xs:element name="e1" type="xs:int" dfdl:byteOrder="{ 'bigEndian' }" /> |
| <xs:element name="e1b" type="xs:int" dfdl:byteOrder="{ 'middleEndian' }" /> |
| |
| <xs:element name="e2"> |
| <xs:complexType> |
| <xs:sequence> |
| <xs:element name="bom" type="xs:unsignedByte" /> |
| <xs:element name="num" type="xs:int"> |
| <xs:annotation> |
| <xs:appinfo source="http://www.ogf.org/dfdl/"> |
| <dfdl:element> |
| <dfdl:property name="byteOrder"><![CDATA[{ |
| if (daf:trace(daf:trace(xs:unsignedByte(../ex:bom), 'bom') eq 10, 'pred1')) then 'bigEndian' |
| else ( |
| if (daf:trace(xs:unsignedByte(../ex:bom) eq 20, 'pred2')) then 'littleEndian' |
| else daf:error() |
| ) |
| }]]></dfdl:property> |
| </dfdl:element> |
| </xs:appinfo> |
| </xs:annotation> |
| </xs:element> |
| </xs:sequence> |
| </xs:complexType> |
| </xs:element> |
| |
| <xs:element name="e2b"> |
| <xs:complexType> |
| <xs:sequence> |
| <xs:element name="bom" type="xs:unsignedByte" /> |
| <xs:element name="num" type="xs:int"> |
| <xs:annotation> |
| <xs:appinfo source="http://www.ogf.org/dfdl/"> |
| <dfdl:element> |
| <dfdl:property name="byteOrder"><![CDATA[{ |
| if (fn:trace(fn:trace(xs:unsignedByte(../ex:bom), 'bom') eq 10, 'pred1')) then 'bigEndian' |
| else ( |
| if (fn:trace(xs:unsignedByte(../ex:bom) eq 20, 'pred2')) then 'littleEndian' |
| else daf:error() |
| ) |
| }]]></dfdl:property> |
| </dfdl:element> |
| </xs:appinfo> |
| </xs:annotation> |
| </xs:element> |
| </xs:sequence> |
| </xs:complexType> |
| </xs:element> |
| |
| <xs:element name="e3"> |
| <xs:complexType> |
| <xs:sequence> |
| <xs:element name="bom" type="xs:unsignedShort" /> |
| <xs:element name="num" type="xs:int"> |
| <xs:annotation> |
| <xs:appinfo source="http://www.ogf.org/dfdl/"> |
| <dfdl:element> |
| <dfdl:property name="byteOrder"><![CDATA[{ |
| if (daf:trace(daf:trace(xs:unsignedShort(../ex:bom), 'bom') eq 65279, 'pred1')) then 'bigEndian' |
| else if (daf:trace(xs:unsignedShort(../ex:bom) eq 65534, 'pred2')) then 'littleEndian' |
| else daf:error() |
| }]]></dfdl:property> |
| </dfdl:element> |
| </xs:appinfo> |
| </xs:annotation> |
| </xs:element> |
| </xs:sequence> |
| </xs:complexType> |
| </xs:element> |
| |
| <dfdl:defineVariable name="bom" type="xs:string" /> |
| |
| <xs:element name="e4"> |
| <xs:complexType> |
| <xs:sequence> |
| <xs:element name="bom" type="xs:unsignedShort"> |
| <xs:annotation> |
| <xs:appinfo source="http://www.ogf.org/dfdl/"> |
| <!-- hoist calculation so we do it only once --> |
| <dfdl:setVariable ref="ex:bom"><![CDATA[{ |
| if (daf:trace(daf:trace(xs:unsignedShort(.), 'bom') eq 65279, 'pred1')) then 'bigEndian' |
| else if (daf:trace(xs:unsignedShort(.) eq 65534, 'pred2')) then 'littleEndian' |
| else daf:error() |
| }]]></dfdl:setVariable> |
| </xs:appinfo> |
| </xs:annotation> |
| </xs:element> |
| <xs:element name="num" type="xs:int" |
| dfdl:byteOrder="{ $ex:bom }" /> |
| </xs:sequence> |
| </xs:complexType> |
| </xs:element> |
| |
| <xs:element name="e5"> |
| <xs:complexType> |
| <xs:sequence> |
| <xs:element name="bOm" type="xs:string" dfdl:lengthKind="delimited" dfdl:terminator="."/> |
| <xs:element name="num" type="xs:int" dfdl:byteOrder="{ xs:string(../ex:bOm) }"/> |
| </xs:sequence> |
| </xs:complexType> |
| </xs:element> |
| |
| <xs:element name="e5b"> |
| <xs:complexType> |
| <xs:sequence> |
| <xs:element name="bOm" dfdl:terminator="."> |
| <xs:simpleType> |
| <xs:restriction base="xs:string"> |
| <xs:minLength value="12"/> |
| <xs:maxLength value="12"/> |
| </xs:restriction> |
| </xs:simpleType> |
| </xs:element> |
| <xs:element name="num" type="xs:int" dfdl:byteOrder="{ xs:string(../ex:bOm) }"/> |
| </xs:sequence> |
| </xs:complexType> |
| </xs:element> |
| |
| <xs:element name="e5c"> |
| <xs:complexType> |
| <xs:sequence> |
| <xs:element name="bOm" dfdl:terminator="."> |
| <xs:simpleType> |
| <xs:restriction base="xs:string"> |
| <xs:minLength value="12"/> |
| <xs:maxLength value="12"/> |
| </xs:restriction> |
| </xs:simpleType> |
| </xs:element> |
| <xs:element name="num" type="xs:int" dfdl:byteOrder="{ xs:string(../ex:bOm) }"/> |
| </xs:sequence> |
| </xs:complexType> |
| </xs:element> |
| |
| <dfdl:defineVariable name="myVar" type="xs:string"/> |
| |
| <xs:element name="e_err"> |
| <xs:complexType> |
| <xs:sequence> |
| <xs:element name="bom" type="xs:unsignedShort"> |
| <xs:annotation> |
| <xs:appinfo source="http://www.ogf.org/dfdl/"> |
| |
| <!-- don't set it --> |
| </xs:appinfo> |
| </xs:annotation> |
| </xs:element> |
| <xs:element name="num" type="xs:int" |
| dfdl:byteOrder="{ $ex:myVar }" /> |
| </xs:sequence> |
| </xs:complexType> |
| </xs:element> |
| |
| |
| </tdml:defineSchema> |
| |
| <!-- |
| Test Name: byteOrderExpr1 |
| Schema: s1 |
| Root: e1 |
| Purpose: This test demonstrates the ability to use an expression to determine the data's byte order. |
| This is the simplest case and just uses the string "bigEndian" within the expression. |
| --> |
| |
| <tdml:parserTestCase name="byteOrderExpr1" root="e1" |
| model="s1" description="simplest byte order"> |
| |
| <tdml:document> |
| <tdml:documentPart type="byte">01000100 |
| </tdml:documentPart> |
| </tdml:document> |
| |
| <tdml:infoset> |
| <tdml:dfdlInfoset> |
| <ex:e1>16777472</ex:e1> |
| </tdml:dfdlInfoset> |
| </tdml:infoset> |
| |
| </tdml:parserTestCase> |
| |
| <!-- |
| Test Name: byteOrderExpr1b |
| Schema: s1 |
| Root: e1b |
| Purpose: This test demonstrates the ability to use an expression to determine the data's byte order. |
| This is the simplest case and uses the invalid "middleEndian" within the expression. |
| --> |
| |
| <tdml:parserTestCase name="byteOrderExpr1b" root="e1b" |
| model="s1" description="simplest byte order"> |
| |
| <tdml:document> |
| <tdml:documentPart type="byte">01000100</tdml:documentPart> |
| </tdml:document> |
| <tdml:errors> |
| <tdml:error>Schema Definition Error</tdml:error> |
| <tdml:error>Unknown Property Value</tdml:error> |
| </tdml:errors> |
| </tdml:parserTestCase> |
| |
| <!-- |
| Test Name: byteOrderExpr2b |
| Schema: s1 |
| Root: e2b |
| Purpose: This test demonstrates that fn:trace is no longer acceptable - the replacement is the trace function that is in |
| the daffodil extension namespace |
| --> |
| |
| <tdml:parserTestCase name="byteOrderExpr2b" root="e2b" |
| model="s1" description="fn:trace no longer available"> |
| |
| <tdml:document> |
| <tdml:documentPart type="byte">0A01000100</tdml:documentPart> |
| </tdml:document> |
| <tdml:errors> |
| <tdml:error>Schema Definition Error</tdml:error> |
| <tdml:error>Unsupported function: fn:trace</tdml:error> |
| </tdml:errors> |
| </tdml:parserTestCase> |
| |
| <!-- |
| Test Name: byteOrderExpr2 |
| Schema: s1 |
| Root: e2 |
| Purpose: This test demonstrates the ability to use an expression to determine the data's byte order. |
| In this case the first element is a flag that determines the byteOrder. Since the first byte is |
| hex for 10, the rest of the data is bigEndian |
| --> |
| |
| <tdml:parserTestCase name="byteOrderExpr2" root="e2" |
| model="s1" description="byte order based on flag byte before the data"> |
| |
| <tdml:document> |
| <tdml:documentPart type="byte">0A01000100 |
| </tdml:documentPart> |
| </tdml:document> |
| |
| <tdml:infoset> |
| <tdml:dfdlInfoset> |
| <ex:e2> |
| <ex:bom>10</ex:bom> |
| <ex:num>16777472</ex:num> |
| </ex:e2> |
| </tdml:dfdlInfoset> |
| </tdml:infoset> |
| |
| </tdml:parserTestCase> |
| |
| <!-- |
| Test Name: byteOrderExpr3 |
| Schema: s1 |
| Root: e2 |
| Purpose: This test demonstrates the ability to use an expression to determine the data's byte order. |
| In this case the first element is a flag that determines the byteOrder. Since the first byte is |
| hex for 20, the rest of the data is littleEndian |
| --> |
| |
| <tdml:parserTestCase name="byteOrderExpr3" root="e2" |
| model="s1" description="byte order based on flag byte before the data"> |
| |
| <tdml:document> |
| <tdml:documentPart type="byte">14 00 01 00 01 |
| </tdml:documentPart> |
| </tdml:document> |
| |
| <tdml:infoset> |
| <tdml:dfdlInfoset> |
| <ex:e2> |
| <ex:bom>20</ex:bom> |
| <ex:num>16777472</ex:num> |
| </ex:e2> |
| </tdml:dfdlInfoset> |
| </tdml:infoset> |
| |
| </tdml:parserTestCase> |
| |
| <!-- |
| Test Name: byteOrderExpr4 |
| Schema: s1 |
| Root: e3 |
| Purpose: This test demonstrates the ability to use an expression to determine the data's byte order. |
| In this case the first element is a flag that determines the byteOrder. Since the first two bytes |
| translate to 65279, the remaining data is in bigEndian |
| --> |
| |
| <tdml:parserTestCase name="byteOrderExpr4" root="e3" |
| model="s1" |
| description="byte order based on two bytes of a utf-16 byte order mark before the data"> |
| |
| <tdml:document> |
| <tdml:documentPart type="byte">FE FF 01 00 01 00 |
| </tdml:documentPart> |
| </tdml:document> |
| |
| <tdml:infoset> |
| <tdml:dfdlInfoset> |
| <ex:e3> |
| <ex:bom>65279</ex:bom> |
| <ex:num>16777472</ex:num> |
| </ex:e3> |
| </tdml:dfdlInfoset> |
| </tdml:infoset> |
| |
| </tdml:parserTestCase> |
| |
| <!-- |
| Test Name: byteOrderExpr5 |
| Schema: s1 |
| Root: e3 |
| Purpose: This test demonstrates the ability to use an expression to determine the data's byte order. |
| In this case the first element is a flag that determines the byteOrder. Since the first two bytes |
| translate to 65534, the remaining data is in littleEndian |
| --> |
| |
| <tdml:parserTestCase name="byteOrderExpr5" root="e3" |
| model="s1" |
| description="byte order based on two bytes of a utf-16 byte order mark before the data"> |
| |
| <tdml:document> |
| <tdml:documentPart type="byte">FF FE 00 01 00 01 |
| </tdml:documentPart> |
| </tdml:document> |
| |
| <tdml:infoset> |
| <tdml:dfdlInfoset> |
| <ex:e3> |
| <ex:bom>65534</ex:bom> |
| <ex:num>16777472</ex:num> |
| </ex:e3> |
| </tdml:dfdlInfoset> |
| </tdml:infoset> |
| |
| </tdml:parserTestCase> |
| |
| <!-- |
| Test Name: byteOrderExpr6 |
| Schema: s1 |
| Root: e4 |
| Purpose: This test demonstrates the ability to use an expression to determine the data's byte order. |
| The difference in this test is that it stores the byteOrder in a variable to be used later. |
| --> |
| |
| <tdml:parserTestCase name="byteOrderExpr6" root="e4" |
| model="s1" |
| description="byte order based on two bytes of a utf-16 byte order mark before the data"> |
| |
| <tdml:document> |
| <tdml:documentPart type="byte">FF FE 00 01 00 01 |
| </tdml:documentPart> |
| </tdml:document> |
| |
| <tdml:infoset> |
| <tdml:dfdlInfoset> |
| <ex:e4> |
| <ex:bom>65534</ex:bom> |
| <ex:num>16777472</ex:num> |
| </ex:e4> |
| </tdml:dfdlInfoset> |
| </tdml:infoset> |
| |
| </tdml:parserTestCase> |
| |
| <!-- |
| Test Name: byteOrderExpr7 |
| Schema: s1 |
| Root: e5 |
| Purpose: This test demonstrates the ability to use an expression to determine the data's byte order. |
| In this case the byte order for the second element is set to whatever is specified in the first element. |
| --> |
| |
| <tdml:parserTestCase name="byteOrderExpr7" root="e5" |
| model="s1" |
| description="byte order based on string"> |
| |
| <tdml:document> |
| <tdml:documentPart type="byte">6C 69 74 74 6C 65 45 6E 64 69 61 6E 2E</tdml:documentPart> <!-- littleEndian. --> |
| <tdml:documentPart type="byte">00 01 00 01</tdml:documentPart> |
| </tdml:document> |
| |
| <tdml:infoset> |
| <tdml:dfdlInfoset> |
| <e5> |
| <bOm>littleEndian</bOm> |
| <num>16777472</num> |
| </e5> |
| </tdml:dfdlInfoset> |
| </tdml:infoset> |
| |
| </tdml:parserTestCase> |
| |
| <!-- |
| Test Name: byteOrderExpr7b |
| Schema: s1 |
| Root: e5b |
| Purpose: This test demonstrates the ability to use an expression to determine the data's byte order. |
| --> |
| |
| <tdml:parserTestCase name="byteOrderExpr7b" root="e5b" |
| model="s1" |
| description="byte order based on string"> |
| |
| <tdml:document> |
| <tdml:documentPart type="byte">6C 69 74 74 6C 65 45 6E 64 69 61 6E 2E</tdml:documentPart> <!-- littleEndian. --> |
| <tdml:documentPart type="byte">00 01 00 01</tdml:documentPart> |
| </tdml:document> |
| |
| <tdml:infoset> |
| <tdml:dfdlInfoset> |
| <e5b> |
| <bOm>littleEndian</bOm> |
| <num>16777472</num> |
| </e5b> |
| </tdml:dfdlInfoset> |
| </tdml:infoset> |
| |
| </tdml:parserTestCase> |
| |
| <!-- |
| Test Name: byteOrderExpr7c |
| Schema: s1 |
| Root: e5c |
| Purpose: This test demonstrates the ability to use an expression to determine the data's byte order. |
| --> |
| |
| <tdml:parserTestCase name="byteOrderExpr7c" root="e5c" |
| model="s1" |
| description="byte order based on string"> |
| |
| <tdml:document> |
| <tdml:documentPart type="byte">6c 69 74 74 6c 65 45 6e 64 69 61 6e 2e</tdml:documentPart> <!-- littleEndian. --> |
| <tdml:documentPart type="byte">00 01 00 01</tdml:documentPart> |
| </tdml:document> |
| |
| <tdml:infoset> |
| <tdml:dfdlInfoset> |
| <e5c> |
| <bOm>littleEndian</bOm> |
| <num>16777472</num> |
| </e5c> |
| </tdml:dfdlInfoset> |
| </tdml:infoset> |
| |
| </tdml:parserTestCase> |
| |
| <!-- |
| Test Name: byteOrderExpr8 |
| Schema: s1 |
| Root: e5 |
| Purpose: This test demonstrates the ability to use an expression to determine the data's byte order. |
| In this case the byte order for the second element is set to whatever is specified in the first element. |
| --> |
| |
| <tdml:parserTestCase name="byteOrderExpr8" root="e5" |
| model="s1" |
| description="byte order based on string"> |
| |
| <tdml:document> |
| <tdml:documentPart type="byte">62 69 67 45 6E 64 69 61 6E 2E</tdml:documentPart> <!-- bigEndian. --> |
| <tdml:documentPart type="byte">00 01 00 01</tdml:documentPart> |
| </tdml:document> |
| |
| <tdml:infoset> |
| <tdml:dfdlInfoset> |
| <ex:e5> |
| <ex:bOm>bigEndian</ex:bOm> |
| <ex:num>65537</ex:num> |
| </ex:e5> |
| </tdml:dfdlInfoset> |
| </tdml:infoset> |
| |
| </tdml:parserTestCase> |
| |
| <!-- |
| Test Name: byteOrderExpr9 |
| Schema: s1 |
| Root: e5 |
| Purpose: This test demonstrates the ability to use an expression to determine the data's byte order. |
| In this case the byte order for the second element is set to whatever is specified in the first element. |
| --> |
| |
| <tdml:parserTestCase name="byteOrderExpr9" root="e5" |
| model="s1" |
| description="byte order based on string"> |
| |
| <tdml:document> |
| <tdml:documentPart type="byte">66 61 74 45 6E 64 69 61 6E 2E</tdml:documentPart> <!-- fatEndian. --> |
| <tdml:documentPart type="byte">00 01 00 01</tdml:documentPart> |
| </tdml:document> |
| <tdml:errors> |
| <tdml:error>Schema Definition Error</tdml:error> |
| <tdml:error>Unknown property value</tdml:error> |
| </tdml:errors> |
| |
| </tdml:parserTestCase> |
| |
| <tdml:parserTestCase name="variableRefError" root="e_err" |
| model="s1" |
| description="erroneous setVariable ref attribute should provide good error message."> |
| |
| <tdml:document> |
| <tdml:documentPart type="byte">FF FE 0 0 0 1 0 0 0 1 |
| </tdml:documentPart> |
| </tdml:document> |
| |
| <tdml:errors> |
| <tdml:error>Schema Definition Error</tdml:error> |
| <tdml:error>myVar</tdml:error> |
| <tdml:error>no value</tdml:error> |
| <tdml:error>variable</tdml:error> |
| </tdml:errors> |
| |
| </tdml:parserTestCase> |
| |
| </tdml:testSuite> |