You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by sl...@apache.org on 2020/09/14 12:37:58 UTC

[incubator-daffodil] branch master updated (fc3269c -> d3c5850)

This is an automated email from the ASF dual-hosted git repository.

slawrence pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-daffodil.git.


 discard fc3269c  Removed old test
 discard 8eae1c2  Update per Steve's comments
 discard 055f5b4  Throw SDE in the case of a choice with no branches
     new d3c5850  Throw SDE in the case of a choice with no branches

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (fc3269c)
            \
             N -- N -- N   refs/heads/master (d3c5850)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:


[incubator-daffodil] 01/01: Throw SDE in the case of a choice with no branches

Posted by sl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

slawrence pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-daffodil.git

commit d3c5850d0394fff75ebf3680a5015cbd207cc331
Author: Steinberger <rs...@tresys.com>
AuthorDate: Fri Sep 11 10:10:40 2020 -0400

    Throw SDE in the case of a choice with no branches
    
    Section 15 of the spec satates that a choice that declares no branches
    in the DFDL schema is a schema definition error.
    
    Daffodil-1032
---
 .../org/apache/daffodil/dsom/ChoiceGroup.scala     |  7 ++++
 .../daffodil/section15/choice_groups/choice.tdml   | 49 ++++++++++++++--------
 .../section15/choice_groups/noBranches.dfdl.xsd    | 43 -------------------
 .../section15/choice_groups/TestChoice.scala       |  5 +--
 4 files changed, 40 insertions(+), 64 deletions(-)

diff --git a/daffodil-core/src/main/scala/org/apache/daffodil/dsom/ChoiceGroup.scala b/daffodil-core/src/main/scala/org/apache/daffodil/dsom/ChoiceGroup.scala
index 35a90fd..410d235 100644
--- a/daffodil-core/src/main/scala/org/apache/daffodil/dsom/ChoiceGroup.scala
+++ b/daffodil-core/src/main/scala/org/apache/daffodil/dsom/ChoiceGroup.scala
@@ -100,6 +100,7 @@ abstract class ChoiceTermBase(
   with ChoiceAGMixin
   with HasOptRepTypeMixinImpl {
 
+  requiredEvaluationsIfActivated(noBranchesFound)
   requiredEvaluationsIfActivated(branchesAreNonOptional)
   requiredEvaluationsIfActivated(branchesAreNotIVCElements)
   requiredEvaluationsIfActivated(modelGroupRuntimeData.preSerialization)
@@ -201,6 +202,12 @@ abstract class ChoiceTermBase(
     }
   }.value
 
+  final lazy val noBranchesFound = LV('noBranchesFound) {
+    if (groupMembers.size == 0) {
+      SDE("choice element must contain one or more branches")
+    }
+  }.value
+
   /**
    * The DFDL Spec as of this writing 2015-06-02 says that branches cannot be optional, but then
    * specifies that what it means is that if a choice branch root is an element/element-ref, it
diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/choice.tdml b/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/choice.tdml
index d549e03..b9a8f5d 100644
--- a/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/choice.tdml
+++ b/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/choice.tdml
@@ -52,6 +52,18 @@
       </xs:complexType>
     </xs:element>
 
+    <xs:element name="ch2">
+      <xs:complexType>
+        <xs:sequence>
+          <xs:element name="redOrBlue" minOccurs="0" dfdl:occursCountKind="implicit">
+            <xs:complexType>
+              <xs:choice>
+              </xs:choice>
+            </xs:complexType>
+          </xs:element>
+        </xs:sequence>
+      </xs:complexType>
+    </xs:element>
 
   </tdml:defineSchema>
 
@@ -71,6 +83,20 @@
 
   </tdml:parserTestCase>
 
+  <!--
+   Test Name: choice_noBranch
+   Schema: basic
+   Purpose: This test demonstrates the SDE where you have a choice with no branches.
+  -->
+
+  <tdml:parserTestCase name="choice_noBranch" root="ch2"
+                       model="basic">
+    <tdml:document>red</tdml:document>
+    <tdml:errors>
+      <tdml:error>Schema Definition Error</tdml:error>
+      <tdml:error>choice element must contain one or more branches</tdml:error>
+    </tdml:errors>
+  </tdml:parserTestCase>
 
   <tdml:defineSchema name="choice2">
     <xs:include schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
@@ -1320,19 +1346,6 @@
 
   </tdml:parserTestCase>
 
-  <tdml:parserTestCase name="choice_noBranch" root="choice_noBranches"
-    model="noBranches.dfdl.xsd"
-    description="Section 15 - Choice Groups - A choice that declares no branches in the DFDL schema is a schema definition error..">
-
-    <tdml:document><![CDATA[test]]></tdml:document>
-
-    <tdml:errors>
-      <tdml:error>Schema Definition Error</tdml:error>
-      <tdml:error>Placeholder</tdml:error>
-    </tdml:errors>
-
-  </tdml:parserTestCase>
-  
   <tdml:defineSchema name="optionalChoices">
     <xs:include schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
     <dfdl:format ref="ex:GeneralFormat" lengthKind="delimited" />
@@ -1399,11 +1412,11 @@
 
   </tdml:defineSchema>
 
-<!--
-     Test Name: optionalChoice01
-     Schema: optionalChoices
-     Purpose: This test demonstrates the scenario where you have a choice of two initiated elements in an optional choice. In this case the first element should be selected.
--->
+  <!--
+       Test Name: optionalChoice01
+       Schema: optionalChoices
+       Purpose: This test demonstrates the scenario where you have a choice of two initiated elements in an optional choice. In this case the first element should be selected.
+  -->
   
   <tdml:parserTestCase name="optionalChoice01" root="e1"
     model="optionalChoices">
diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/noBranches.dfdl.xsd b/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/noBranches.dfdl.xsd
deleted file mode 100644
index d35efc8..0000000
--- a/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/noBranches.dfdl.xsd
+++ /dev/null
@@ -1,43 +0,0 @@
-<?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://www.example.org/example1/" xmlns:ex="http://www.example.org/example1/"
-  xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/" xmlns:xs="http://www.w3.org/2001/XMLSchema"
-  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-
-  <include schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
-
-  <annotation>
-    <appinfo source="http://www.ogf.org/dfdl/">
-      <dfdl:format ref="ex:GeneralFormat" initiator=""
-        leadingSkip="0" trailingSkip="0" separator=""
-        encoding="utf-8" occursCountKind="parsed" separatorSuppressionPolicy="anyEmpty"
-        textNumberRep="standard" ignoreCase="no" representation="text"
-        lengthUnits="characters" lengthKind="delimited" initiatedContent="no" />
-    </appinfo>
-  </annotation>
-  
-  <xs:element name="choice_noBranches">
-    <xs:complexType>
-      <xs:choice>
-      </xs:choice>
-    </xs:complexType>
-  </xs:element>
-
-</schema>
diff --git a/daffodil-test/src/test/scala/org/apache/daffodil/section15/choice_groups/TestChoice.scala b/daffodil-test/src/test/scala/org/apache/daffodil/section15/choice_groups/TestChoice.scala
index 6cb5687..9fc7df1 100644
--- a/daffodil-test/src/test/scala/org/apache/daffodil/section15/choice_groups/TestChoice.scala
+++ b/daffodil-test/src/test/scala/org/apache/daffodil/section15/choice_groups/TestChoice.scala
@@ -38,6 +38,8 @@ class TestChoice {
 
   import TestChoice._
 
+  @Test def test_choice_noBranch (): Unit = { runnerCH.runOneTest("choice_noBranch") }
+
   @Test def test_optionalChoice01(): Unit = { runnerCH.runOneTest("optionalChoice01") }
   @Test def test_optionalChoice02(): Unit = { runnerCH.runOneTest("optionalChoice02") }
   @Test def test_optionalChoice03(): Unit = { runnerCH.runOneTest("optionalChoice03") }
@@ -123,9 +125,6 @@ class TestChoice {
   @Test def test_direct_dispatch_16(): Unit = { runnerCH.runOneTest("direct_dispatch_16") }
   @Test def test_direct_dispatch_17(): Unit = { runnerCH.runOneTest("direct_dispatch_17") }
 
-  //@Test def test_choice_noBranch() { runnerCH.runOneTest("choice_noBranch") } - Test consumes no data, which causes a TDMLError
-
-
   @Test def test_explicit_01(): Unit = { runnerCE.runOneTest("explicit_01") }
   @Test def test_explicit_02(): Unit = { runnerCE.runOneTest("explicit_02") }
   @Test def test_explicit_03(): Unit = { runnerCE.runOneTest("explicit_03") }