You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by ja...@apache.org on 2019/12/30 18:00:18 UTC
[incubator-daffodil] branch master updated: Fixed issue unparsing
optional unordered elements
This is an automated email from the ASF dual-hosted git repository.
jadams pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-daffodil.git
The following commit(s) were added to refs/heads/master by this push:
new 26742cc Fixed issue unparsing optional unordered elements
26742cc is described below
commit 26742ccffed2c9c3d83ff792c3978d8a168fc310
Author: Josh Adams <ja...@tresys.com>
AuthorDate: Mon Dec 30 10:05:48 2019 -0500
Fixed issue unparsing optional unordered elements
A user discovered an issue when the first element of an unordered
sequence is optinal and does not have a maxOccurs > 1. There was a logic
error that was resulting in the element being treated as a scalar
element when it should have been treated as an array, due to it being
optional.
DAFFODIL-2261
---
.../daffodil/grammar/SequenceGrammarMixin.scala | 4 +-
.../section14/unordered_sequences/BE.dfdl.xsd | 63 ++++++++++
.../daffodil/section14/unordered_sequences/BE.tdml | 131 +++++++++++++++++++++
.../TestUnorderedSequencesNew.scala | 8 ++
4 files changed, 204 insertions(+), 2 deletions(-)
diff --git a/daffodil-core/src/main/scala/org/apache/daffodil/grammar/SequenceGrammarMixin.scala b/daffodil-core/src/main/scala/org/apache/daffodil/grammar/SequenceGrammarMixin.scala
index 74227e5..699c6c8 100644
--- a/daffodil-core/src/main/scala/org/apache/daffodil/grammar/SequenceGrammarMixin.scala
+++ b/daffodil-core/src/main/scala/org/apache/daffodil/grammar/SequenceGrammarMixin.scala
@@ -145,8 +145,8 @@ trait SequenceGrammarMixin
case (e: EB, Ordered__, TrailingStr, Implicit__, ___, UNB) => new RepOrderedWithMinMaxSequenceChild(this, e, groupIndex)
case (e: EB, Ordered__, TrailingStr, Implicit__, ___, max) => new RepOrderedWithMinMaxSequenceChild(this, e, groupIndex)
case (e: EB, Ordered__, Always_____, Implicit__, ___, max) => new RepOrderedWithMinMaxSequenceChild(this, e, groupIndex)
- case (e: EB, Unordered, ___________, __________, ___, ONE) => new ScalarOrderedSequenceChild(this, e, groupIndex)
- case (e: EB, Unordered, ___________, Parsed____, ___, max) => new RepOrderedWithMinMaxSequenceChild(this, e, groupIndex)
+ case (e: EB, Unordered, ___________, __________, ONE, ONE) => new ScalarOrderedSequenceChild(this, e, groupIndex)
+ case (e: EB, Unordered, ___________, Parsed____, ___, __2) => new RepOrderedWithMinMaxSequenceChild(this, e, groupIndex)
case (e: EB, Unordered, ___________, __________, ___, __2) => e.SDE("When sequenceKind='unordered', occursCountKind must be 'parsed'")
case (m: MG, Unordered, ___________, __________, ___, __2) => child.SDE("All memebers of an unordered sequence must be Element or ElemenntRef")
case (m: MG, _________, ___________, __________, ___, __2) => new ScalarOrderedSequenceChild(this, m, groupIndex)
diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/section14/unordered_sequences/BE.dfdl.xsd b/daffodil-test/src/test/resources/org/apache/daffodil/section14/unordered_sequences/BE.dfdl.xsd
new file mode 100644
index 0000000..8c13038
--- /dev/null
+++ b/daffodil-test/src/test/resources/org/apache/daffodil/section14/unordered_sequences/BE.dfdl.xsd
@@ -0,0 +1,63 @@
+<?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.
+-->
+
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://example.com" xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://example.com">
+
+
+ <include schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
+
+<annotation>
+ <appinfo source="http://www.ogf.org/dfdl/">
+ <dfdl:format ref="tns:GeneralFormat" lengthKind="delimited" separator=""
+ leadingSkip='0' encoding="US-ASCII" ignoreCase='no' initiator=""
+ terminator="" initiatedContent="no" textNumberRep="standard"
+ separatorSuppressionPolicy="anyEmpty" separatorPosition="infix"
+ documentFinalTerminatorCanBeMissing='yes'
+ byteOrder="bigEndian" binaryNumberRep='binary'
+ representation="text"
+ occursCountKind='parsed'/>
+ </appinfo>
+ </annotation>
+
+ <!-- unordered sequences -->
+ <element name="seq">
+ <complexType>
+ <sequence dfdl:sequenceKind="unordered">
+ <element name="x" type="xsd:string" maxOccurs="4"
+ dfdl:initiator="X:" dfdl:terminator="%NL;" />
+ <element name="y" type="xsd:string" maxOccurs="4"
+ dfdl:initiator="Y:" dfdl:terminator="%NL;" />
+ <element name="z" type="xsd:string" minOccurs="2"
+ maxOccurs="4" dfdl:initiator="Z:" dfdl:terminator="%NL;" />
+ </sequence>
+ </complexType>
+ </element>
+
+ <element name="seq2">
+ <complexType>
+ <sequence dfdl:sequenceKind="unordered">
+ <element name="x" type="xsd:string" dfdl:initiator="X:" dfdl:terminator="%NL;" minOccurs="0" />
+ <element name="y" type="xsd:string" dfdl:initiator="Y:" dfdl:terminator="%NL;" minOccurs="0" />
+ </sequence>
+ </complexType>
+ </element>
+
+</schema>
diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/section14/unordered_sequences/BE.tdml b/daffodil-test/src/test/resources/org/apache/daffodil/section14/unordered_sequences/BE.tdml
new file mode 100644
index 0000000..0b9adba
--- /dev/null
+++ b/daffodil-test/src/test/resources/org/apache/daffodil/section14/unordered_sequences/BE.tdml
@@ -0,0 +1,131 @@
+<?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.
+-->
+
+<testSuite suiteName="BE" xmlns="http://www.ibm.com/xmlns/dfdl/testData"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:ex="http://example.com"
+ xmlns:tdml="http://www.ibm.com/xmlns/dfdl/testData"
+ defaultImplementations="ibm daffodil"
+ defaultRoundTrip="onePass">
+
+ <parserTestCase name="BE000" root="seq" model="BE.dfdl.xsd" roundTrip="twoPass"
+ description="Unordered sequences">
+ <document>
+ <tdml:documentPart type="text" replaceDFDLEntities="true"><![CDATA[Z:z0%LF;X:x0%LF;X:x1%LF;X:x2%LF;Y:y0%LF;Z:z1%LF;Y:y1%LF;Y:y2%LF;]]></tdml:documentPart>
+ </document>
+ <infoset>
+ <dfdlInfoset>
+ <ex:seq>
+ <x>x0</x>
+ <x>x1</x>
+ <x>x2</x>
+ <y>y0</y>
+ <y>y1</y>
+ <y>y2</y>
+ <z>z0</z>
+ <z>z1</z>
+ </ex:seq>
+ </dfdlInfoset>
+ </infoset>
+ </parserTestCase>
+
+ <parserTestCase name="BE001" root="seq" model="BE.dfdl.xsd" roundTrip="twoPass"
+ description="Unordered sequences">
+ <document>
+ <tdml:documentPart type="text" replaceDFDLEntities="true"><![CDATA[Z:z0%LF;X:x0%LF;X:x1%LF;X:x2%LF;Y:y0%LF;Z:z1%LF;Y:y1%LF;Y:y2%LF;Z:z2%LF;Z:z3%LF;Y:y3%LF;X:x3%LF;]]></tdml:documentPart>
+ </document>
+ <infoset>
+ <dfdlInfoset>
+ <ex:seq>
+ <x>x0</x>
+ <x>x1</x>
+ <x>x2</x>
+ <x>x3</x>
+ <y>y0</y>
+ <y>y1</y>
+ <y>y2</y>
+ <y>y3</y>
+ <z>z0</z>
+ <z>z1</z>
+ <z>z2</z>
+ <z>z3</z>
+ </ex:seq>
+ </dfdlInfoset>
+ </infoset>
+ </parserTestCase>
+
+ <parserTestCase name="BE002" root="seq2" model="BE.dfdl.xsd"
+ description="Unordered sequences">
+ <document>
+ <tdml:documentPart type="text" replaceDFDLEntities="true"><![CDATA[X:x0%LF;Y:y0%LF;]]></tdml:documentPart>
+ </document>
+ <infoset>
+ <dfdlInfoset>
+ <ex:seq2>
+ <x>x0</x>
+ <y>y0</y>
+ </ex:seq2>
+ </dfdlInfoset>
+ </infoset>
+ </parserTestCase>
+
+ <parserTestCase name="BE003" root="seq2" model="BE.dfdl.xsd" roundTrip="twoPass"
+ description="Unordered sequences">
+ <document>
+ <tdml:documentPart type="text" replaceDFDLEntities="true"><![CDATA[Y:y0%LF;X:x0%LF;]]></tdml:documentPart>
+ </document>
+ <infoset>
+ <dfdlInfoset>
+ <ex:seq2>
+ <x>x0</x>
+ <y>y0</y>
+ </ex:seq2>
+ </dfdlInfoset>
+ </infoset>
+ </parserTestCase>
+
+ <parserTestCase name="BE004" root="seq2" model="BE.dfdl.xsd"
+ description="Unordered sequences">
+ <document>
+ <tdml:documentPart type="text" replaceDFDLEntities="true"><![CDATA[Y:y0%LF;]]></tdml:documentPart>
+ </document>
+ <infoset>
+ <dfdlInfoset>
+ <ex:seq2>
+ <y>y0</y>
+ </ex:seq2>
+ </dfdlInfoset>
+ </infoset>
+ </parserTestCase>
+
+ <parserTestCase name="BE004-A" root="seq2" model="BE.dfdl.xsd"
+ description="Unordered sequences">
+ <document>
+ <tdml:documentPart type="text" replaceDFDLEntities="true"><![CDATA[Y:y0%LF;]]></tdml:documentPart>
+ </document>
+ <infoset>
+ <dfdlInfoset>
+ <ex:seq2>
+ <y>y0</y>
+ </ex:seq2>
+ </dfdlInfoset>
+ </infoset>
+ </parserTestCase>
+
+
+</testSuite>
diff --git a/daffodil-test/src/test/scala/org/apache/daffodil/section14/unordered_sequences/TestUnorderedSequencesNew.scala b/daffodil-test/src/test/scala/org/apache/daffodil/section14/unordered_sequences/TestUnorderedSequencesNew.scala
index 9a71570..cece073 100644
--- a/daffodil-test/src/test/scala/org/apache/daffodil/section14/unordered_sequences/TestUnorderedSequencesNew.scala
+++ b/daffodil-test/src/test/scala/org/apache/daffodil/section14/unordered_sequences/TestUnorderedSequencesNew.scala
@@ -24,6 +24,7 @@ import org.apache.daffodil.tdml.Runner
object TestUnorderedSequencesNew {
val testDir = "/org/apache/daffodil/section14/unordered_sequences/"
val runner = Runner(testDir, "UnorderedSequences.tdml")
+ val runnerBE = Runner(testDir, "BE.tdml")
@AfterClass def shutDown {
runner.reset
@@ -59,4 +60,11 @@ class TestUnorderedSequencesNew {
// DAFFODIL-1034
@Test def test_initiated_unordered1 = { runner.runOneTest("test_initiated_unordered1") }
+
+ @Test def test_BE000 = { runnerBE.runOneTest("BE000") }
+ @Test def test_BE001 = { runnerBE.runOneTest("BE001") }
+ @Test def test_BE002 = { runnerBE.runOneTest("BE002") }
+ @Test def test_BE003 = { runnerBE.runOneTest("BE003") }
+ @Test def test_BE004 = { runnerBE.runOneTest("BE004") }
+ @Test def test_BE004_A = { runnerBE.runOneTest("BE004-A") }
}