You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by mb...@apache.org on 2022/03/15 17:57:21 UTC

[daffodil] branch main updated: Fix invariant broken masking of unparse error.

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

mbeckerle pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil.git


The following commit(s) were added to refs/heads/main by this push:
     new 613c2b0  Fix invariant broken masking of unparse error.
613c2b0 is described below

commit 613c2b0c077f56dbb425e7ebab1a2d154cbdbd06
Author: Michael Beckerle <mb...@apache.org>
AuthorDate: Mon Mar 14 19:16:39 2022 -0400

    Fix invariant broken masking of unparse error.
    
    Add test files focused on enums using repType/repValues
    in the simplest possible way.
    
    DAFFODIL-2673
---
 .../unparsers/SequenceChildUnparsers.scala         |   6 +-
 .../org/apache/daffodil/extensions/enum/enums.tdml | 112 +++++++++++++++++++++
 .../org/apache/daffodil/extensions/TestEnums.scala |  41 ++++++++
 3 files changed, 156 insertions(+), 3 deletions(-)

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 b0b32c3..cbee0ff 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
@@ -16,12 +16,12 @@
  */
 package org.apache.daffodil.processors.unparsers
 
-import org.apache.daffodil.processors.Success
 import org.apache.daffodil.processors.SequenceRuntimeData
 import org.apache.daffodil.processors.ElementRuntimeData
 import org.apache.daffodil.processors.TermRuntimeData
 import org.apache.daffodil.exceptions.Assert
-import org.apache.daffodil.processors.parsers.{EndArrayChecksMixin, MinMaxRepeatsMixin}
+import org.apache.daffodil.processors.parsers.EndArrayChecksMixin
+import org.apache.daffodil.processors.parsers.MinMaxRepeatsMixin
 import org.apache.daffodil.schema.annotation.props.gen.OccursCountKind
 
 /**
@@ -107,7 +107,7 @@ abstract class RepeatingChildUnparser(
 
     val actualOccurs = state.arrayPos
 
-    Assert.invariant(state.processorStatus eq Success)
+    // State could be Success or Failure here.
 
     endArray(state, actualOccurs)
   }
diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/extensions/enum/enums.tdml b/daffodil-test/src/test/resources/org/apache/daffodil/extensions/enum/enums.tdml
new file mode 100644
index 0000000..d1ea6ab
--- /dev/null
+++ b/daffodil-test/src/test/resources/org/apache/daffodil/extensions/enum/enums.tdml
@@ -0,0 +1,112 @@
+<?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
+  xmlns:ex="http://example.com"
+  xmlns:tdml="http://www.ibm.com/xmlns/dfdl/testData"
+  xmlns="http://www.ibm.com/xmlns/dfdl/testData"
+  xmlns:xs="http://www.w3.org/2001/XMLSchema"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
+  xmlns:dfdlx="http://www.ogf.org/dfdl/dfdl-1.0/extensions"
+  xmlns:fn="http://www.w3.org/2005/xpath-functions"
+  xmlns:tns="http://example.com"
+  defaultRoundTrip="onePass"
+  defaultValidation="on">
+
+  <tdml:defineSchema
+    name="s1"
+    useDefaultNamespace="false"
+    elementFormDefault="unqualified"
+    xmlns="http://www.w3.org/2001/XMLSchema">
+
+    <include schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
+    <dfdl:format ref="ex:GeneralFormat" representation="binary"/>
+
+    <element name="r1">
+      <complexType>
+        <sequence>
+          <element name="e1" type="ex:enum1" minOccurs="0"/>
+        </sequence>
+      </complexType>
+    </element>
+
+    <simpleType name="myByte" dfdl:lengthKind="explicit" dfdl:length="1">
+      <restriction base="xs:byte"/>
+    </simpleType>
+
+    <simpleType name="enum1" dfdlx:repType="ex:myByte">
+      <restriction base="xs:string">
+        <enumeration value="validA" dfdlx:repValues="0"/>
+        <enumeration value="validB" dfdlx:repValues="1"/>
+        <enumeration value="invalidC" dfdlx:repValues="2"/>
+        <!--
+        pattern insures that while all enums are well-formed,
+        only ones beginning with "valid" prefix are XSD valid.
+        -->
+        <pattern value="valid.*"/>
+      </restriction>
+    </simpleType>
+
+  </tdml:defineSchema>
+
+  <parserTestCase name="enumValid1" model="s1" root="r1">
+    <document>
+      <documentPart type="byte">01</documentPart>
+    </document>
+    <infoset>
+      <tdml:dfdlInfoset xmlns="">
+        <ex:r1>
+          <e1>validB</e1>
+        </ex:r1>
+      </tdml:dfdlInfoset>
+    </infoset>
+  </parserTestCase>
+
+  <parserTestCase name="enumInvalid1" model="s1" root="r1">
+    <document>
+      <documentPart type="byte">02</documentPart>
+    </document>
+    <infoset>
+      <tdml:dfdlInfoset xmlns="">
+        <ex:r1>
+          <e1>invalidC</e1><!-- well formed, but invalid -->
+        </ex:r1>
+      </tdml:dfdlInfoset>
+    </infoset>
+    <validationErrors>
+      <error>invalidC</error>
+    </validationErrors>
+  </parserTestCase>
+
+
+
+  <unparserTestCase name="enumMiss1" model="s1" root="r1">
+    <infoset>
+      <tdml:dfdlInfoset xmlns="">
+        <ex:r1>
+          <e1>notOneOfTheEnumStrings</e1>
+        </ex:r1>
+      </tdml:dfdlInfoset>
+    </infoset>
+    <errors>
+      <error>notOneOfTheEnumStrings</error>
+    </errors>
+  </unparserTestCase>
+
+</testSuite>
diff --git a/daffodil-test/src/test/scala/org/apache/daffodil/extensions/TestEnums.scala b/daffodil-test/src/test/scala/org/apache/daffodil/extensions/TestEnums.scala
new file mode 100644
index 0000000..faa5bc0
--- /dev/null
+++ b/daffodil-test/src/test/scala/org/apache/daffodil/extensions/TestEnums.scala
@@ -0,0 +1,41 @@
+/*
+ * 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.extensions
+
+import org.junit.Test
+import org.apache.daffodil.tdml.Runner
+import org.junit.AfterClass
+
+object TestEnums {
+  val testDir = "/org/apache/daffodil/extensions/enum/"
+
+  val runner = Runner(testDir, "enums.tdml")
+
+  @AfterClass def shutDown(): Unit = {
+    runner.reset
+  }
+
+}
+
+class TestEnums {
+  import TestEnums._
+  @Test def test_enumValid1(): Unit = { runner.runOneTest("enumValid1") }
+  @Test def test_enumInvalid1(): Unit = { runner.runOneTest("enumInvalid1") }
+  @Test def test_enumMiss1(): Unit = { runner.runOneTest("enumMiss1") }
+
+}