mbeckerle closed pull request #99: Fix missing checks for minOccurs after zero 
occurrences.
URL: https://github.com/apache/incubator-daffodil/pull/99
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/daffodil-runtime1-unparser/src/main/scala/org/apache/daffodil/processors/unparsers/SeparatedSequenceUnparsers.scala
 
b/daffodil-runtime1-unparser/src/main/scala/org/apache/daffodil/processors/unparsers/SeparatedSequenceUnparsers.scala
index f4e7a65f6..a4645edb6 100644
--- 
a/daffodil-runtime1-unparser/src/main/scala/org/apache/daffodil/processors/unparsers/SeparatedSequenceUnparsers.scala
+++ 
b/daffodil-runtime1-unparser/src/main/scala/org/apache/daffodil/processors/unparsers/SeparatedSequenceUnparsers.scala
@@ -364,7 +364,7 @@ class OrderedSeparatedSequenceUnparser(
                 }
                 // System.err.println("Finished unparse of array/opt %s. Array 
Index Stack is: %s, maxReps %s, numOccurrences %s".format(
                 //   erd.namedQName, state.arrayIndexStack, maxReps, 
numOccurrences))
-                unparser.checkFinalOccursCountBetweenMinAndMaxOccurs(state, 
unparser, numOccurrences, maxReps)
+                unparser.checkFinalOccursCountBetweenMinAndMaxOccurs(state, 
unparser, numOccurrences, maxReps, state.arrayPos - 1)
                 unparser.endArrayOrOptional(erd, state)
               } else {
                 //
@@ -384,9 +384,8 @@ class OrderedSeparatedSequenceUnparser(
               val eventNQN = ev.node.namedQName
               Assert.invariant(eventNQN != erd.namedQName)
             } else {
-              //              if (!(ev.isEnd && ev.isComplex))
-              //                Assert.invariantFailed("Expected end of 
complex. Was " + ev)
-              // System.err.println("End event: " + ev)
+              Assert.invariant(ev.isEnd && ev.isComplex)
+              unparser.checkFinalOccursCountBetweenMinAndMaxOccurs(state, 
unparser, numOccurrences, maxReps, 0)
             }
           } else {
             // no event (state.inspect returned false)
diff --git 
a/daffodil-runtime1-unparser/src/main/scala/org/apache/daffodil/processors/unparsers/SequenceChildUnparsers.scala
 
b/daffodil-runtime1-unparser/src/main/scala/org/apache/daffodil/processors/unparsers/SequenceChildUnparsers.scala
index 516d3ee4d..0583a9685 100644
--- 
a/daffodil-runtime1-unparser/src/main/scala/org/apache/daffodil/processors/unparsers/SequenceChildUnparsers.scala
+++ 
b/daffodil-runtime1-unparser/src/main/scala/org/apache/daffodil/processors/unparsers/SequenceChildUnparsers.scala
@@ -232,7 +232,7 @@ abstract class RepeatingChildUnparser(
   def checkFinalOccursCountBetweenMinAndMaxOccurs(
     state: UState,
     unparser: RepeatingChildUnparser,
-    numOccurrences: Int, maxReps: Long): Unit = {
+    numOccurrences: Int, maxReps: Long, arrPos: Long): Unit = {
     import OccursCountKind._
 
     val minReps = unparser.minRepeats(state)
@@ -254,7 +254,6 @@ abstract class RepeatingChildUnparser(
     //
     val ock = erd.maybeOccursCountKind.get
     // System.err.println("Checking for events consistent with Array index:\n 
==> Array Index Stack is:" + state.arrayIndexStack)
-    val arrPos = state.arrayPos - 1 // because we advance after each unparse 
so this is the position of the next (non-existing) occurrence
 
     Assert.invariant(arrPos <= maxReps || !(ock eq Implicit))
 
diff --git 
a/daffodil-runtime1-unparser/src/main/scala/org/apache/daffodil/processors/unparsers/UnseparatedSequenceUnparsers.scala
 
b/daffodil-runtime1-unparser/src/main/scala/org/apache/daffodil/processors/unparsers/UnseparatedSequenceUnparsers.scala
index 7fbd25f82..ae44f980d 100644
--- 
a/daffodil-runtime1-unparser/src/main/scala/org/apache/daffodil/processors/unparsers/UnseparatedSequenceUnparsers.scala
+++ 
b/daffodil-runtime1-unparser/src/main/scala/org/apache/daffodil/processors/unparsers/UnseparatedSequenceUnparsers.scala
@@ -128,7 +128,7 @@ class OrderedUnseparatedSequenceUnparser(rd: 
SequenceRuntimeData, childUnparsers
                   if (isArr) if (state.dataProc.isDefined) 
state.dataProc.get.afterRepetition(state, this)
                 }
 
-                unparser.checkFinalOccursCountBetweenMinAndMaxOccurs(state, 
unparser, numOccurrences, maxReps)
+                unparser.checkFinalOccursCountBetweenMinAndMaxOccurs(state, 
unparser, numOccurrences, maxReps, state.arrayPos - 1)
                 unparser.endArrayOrOptional(erd, state)
               } else {
                 //
@@ -153,6 +153,7 @@ class OrderedUnseparatedSequenceUnparser(rd: 
SequenceRuntimeData, childUnparsers
               Assert.invariant(eventNQN != erd.namedQName)
             } else {
               Assert.invariant(ev.isEnd && ev.isComplex)
+              unparser.checkFinalOccursCountBetweenMinAndMaxOccurs(state, 
unparser, numOccurrences, maxReps, 0)
             }
           } else {
             // no event (state.inspect returned false)
diff --git 
a/daffodil-test/src/test/resources/org/apache/daffodil/section16/array_optional_elem/ArrayComb.tdml
 
b/daffodil-test/src/test/resources/org/apache/daffodil/section16/array_optional_elem/ArrayComb.tdml
new file mode 100644
index 000000000..cf42a346b
--- /dev/null
+++ 
b/daffodil-test/src/test/resources/org/apache/daffodil/section16/array_optional_elem/ArrayComb.tdml
@@ -0,0 +1,104 @@
+<?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.
+-->
+
+<tdml:testSuite suiteName="ArrayCombTest"
+  description="Section 16 - Arrays and Optional Elements" 
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:ct="http://w3.ibm.com/xmlns/dfdl/ctInfoset";
+  xmlns:ex="http://example.com";
+  xmlns:daf="urn:ogf:dfdl:2013:imp:daffodil.apache.org:2018:ext"
+  defaultRoundTrip="true">
+
+  <tdml:defineSchema name="s1" elementFormDefault="unqualified">
+
+    <dfdl:format lengthKind="delimited" lengthUnits="bytes"
+      ref="ex:GeneralFormat" encoding="UTF-8" separator="" initiator="" 
terminator=""
+      occursCountKind="implicit" ignoreCase="no" textNumberRep="standard"
+      representation="text" />
+
+  <xs:element name="root1">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element name="foo" type="xs:int" />
+        <xs:element name="bar" minOccurs="1" maxOccurs="2" 
dfdl:occursCountKind="implicit">
+          <xs:complexType>
+            <xs:sequence>
+              <xs:annotation>
+                <xs:appinfo source="http://www.ogf.org/dfdl/";>
+                  <dfdl:discriminator>{ ../foo gt 0 }</dfdl:discriminator>
+                </xs:appinfo>
+              </xs:annotation>
+              <xs:sequence dfdl:hiddenGroupRef="ex:hiddenGroup" />
+              <xs:group ref="someGroupWithRequiredElement" />
+            </xs:sequence>
+          </xs:complexType>
+        </xs:element>
+      </xs:sequence>
+    </xs:complexType>
+  </xs:element>
+    
+    <xs:group name="hiddenGroup">
+      <xs:sequence>
+        <xs:element name="hiddenThing" type="xs:int" dfdl:outputValueCalc="{ 0 
}"/>
+      </xs:sequence>
+    </xs:group>
+    
+    <xs:group name="someGroupWithRequiredElement">
+      <xs:sequence>
+        <xs:element name="quux" type="xs:int"/>
+      </xs:sequence>
+    </xs:group>
+
+  </tdml:defineSchema>
+
+
+  <tdml:parserTestCase name="arrayComb1" root="root1" model="s1"
+    description="Test for user-reported bug - Assertion failure.">
+
+    <tdml:document><![CDATA[0]]></tdml:document>
+    
+    <tdml:errors>
+      <tdml:error>Parse Error</tdml:error>
+      <tdml:error>Assertion Failed</tdml:error>
+      <tdml:error>../foo gt 0</tdml:error>
+    </tdml:errors>
+  </tdml:parserTestCase>
+  
+  <tdml:unparserTestCase name="arrayComb2" root="root1" model="s1"
+    description="Test for user-reported bug - Assertion failure."
+    roundTrip="none">
+
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <ex:root1>
+          <foo>1</foo>
+        </ex:root1>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+    
+    <tdml:errors>
+      <tdml:error>Unparse Error</tdml:error>
+      <tdml:error>Expected 1 additional</tdml:error>
+      <tdml:error>bar</tdml:error>
+      <tdml:error>received element end event</tdml:error>
+      <tdml:error>ex:root1</tdml:error>
+    </tdml:errors>        
+  </tdml:unparserTestCase>
+  
+
+  </tdml:testSuite>
diff --git 
a/daffodil-test/src/test/scala/org/apache/daffodil/section16/array_optional_elem/TestArrayOptionalElem.scala
 
b/daffodil-test/src/test/scala/org/apache/daffodil/section16/array_optional_elem/TestArrayOptionalElem.scala
index b965dbd2c..de4a50f24 100644
--- 
a/daffodil-test/src/test/scala/org/apache/daffodil/section16/array_optional_elem/TestArrayOptionalElem.scala
+++ 
b/daffodil-test/src/test/scala/org/apache/daffodil/section16/array_optional_elem/TestArrayOptionalElem.scala
@@ -30,12 +30,14 @@ object TestArrayOptionalElem {
   val runner01 = Runner(testDir01, "Facets.tdml", validateTDMLFile = false)
   val runner1 = Runner(testDir1, "dpaext2.tdml")
   val rBack = Runner(testDir, "backtracking.tdml")
+  val runnerAC = Runner(testDir, "ArrayComb.tdml")
 
   @AfterClass def shutDown {
     runner.reset
     runner01.reset
     runner1.reset
     rBack.reset
+    runnerAC.reset
   }
 
 }
@@ -44,6 +46,10 @@ class TestArrayOptionalElem {
 
   import TestArrayOptionalElem._
 
+  // DAFFODIL-1964
+  @Test def test_arrayComb1() = { runnerAC.runOneTest("arrayComb1") }
+  @Test def test_arrayComb2() = { runnerAC.runOneTest("arrayComb2") }
+
   @Test def test_arrayExpressions01() { 
runner.runOneTest("arrayExpressions01") }
   @Test def test_arrayExpressions02() { 
runner.runOneTest("arrayExpressions02") }
   @Test def test_arrayExpressions02b() { 
runner.runOneTest("arrayExpressions02b") }
diff --git 
a/daffodil-test/src/test/scala/org/apache/daffodil/section16/array_optional_elem/TestArrayOptionalElemNew.scala
 
b/daffodil-test/src/test/scala/org/apache/daffodil/section16/array_optional_elem/TestArrayOptionalElemNew.scala
deleted file mode 100644
index 125064741..000000000
--- 
a/daffodil-test/src/test/scala/org/apache/daffodil/section16/array_optional_elem/TestArrayOptionalElemNew.scala
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.daffodil.section16.array_optional_elem
-
-import org.apache.daffodil.util._
-import org.apache.daffodil.tdml.DFDLTestSuite
-import org.junit.AfterClass
-
-object TestArrayOptionalElemNew {
-
-  val testDir = "/org/apache/daffodil/section16/array_optional_elem/"
-  //  val aa_fixed = testDir + "UnparseArrayFixedOptionalElem.tdml"
-  //  var runner_fixed = new DFDLTestSuite(Misc.getRequiredResource(aa_fixed))
-  //
-  //  val aa_imp = testDir + "UnparseArrayImplicitOptionalElem.tdml"
-  //  var runner_imp = new DFDLTestSuite(Misc.getRequiredResource(aa_imp))
-  //
-  //  val aa_parsed = testDir + "UnparseArrayParsedOptionalElem.tdml"
-  //  var runner_parsed = new 
DFDLTestSuite(Misc.getRequiredResource(aa_parsed))
-  //
-  //  val aa_expr = testDir + "UnparseArrayExpressionConstant.tdml"
-  //  var runner_expr = new DFDLTestSuite(Misc.getRequiredResource(aa_expr))
-
-  val aa_delim = testDir + "UnparseArrayDelimitedOptionalElem.tdml"
-  var runner_delim = new DFDLTestSuite(Misc.getRequiredResource(aa_delim))
-
-  /**
-   * Avoid memory leak of adding more and more test suites to static objects 
as we run more and more test suites.
-   */
-  @AfterClass def tearDown() {
-    //    runner_fixed = null
-    //    runner_imp = null
-    //    runner_parsed = null
-    //    runner_expr = null
-    runner_delim = null
-  }
-
-}
-
-class TestArrayOptionalElemNew {
-
-}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to