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/01/04 17:04:56 UTC

[daffodil] branch main updated: Added test to reproduce shared group bug.

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 090cd85  Added test to reproduce shared group bug.
090cd85 is described below

commit 090cd854de9387afd977c8ee40ca0ec5a420e010
Author: Michael Beckerle <mb...@apache.org>
AuthorDate: Fri Dec 31 15:31:14 2021 -0500

    Added test to reproduce shared group bug.
    
    Commented out currently so it won't break the build.
    
    DAFFODIL-2615
---
 .../choice_groups/SharedGroupTestSchema.dfdl.xsd   | 94 ++++++++++++++++++++++
 .../section15/choice_groups/testSharedGroups.tdml  | 59 ++++++++++++++
 .../section15/choice_groups/TestSharedGroups.scala | 40 +++++++++
 3 files changed, 193 insertions(+)

diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/SharedGroupTestSchema.dfdl.xsd b/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/SharedGroupTestSchema.dfdl.xsd
new file mode 100644
index 0000000..c487088
--- /dev/null
+++ b/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/SharedGroupTestSchema.dfdl.xsd
@@ -0,0 +1,94 @@
+<?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:xs="http://www.w3.org/2001/XMLSchema"
+           xmlns="http://www.w3.org/2001/XMLSchema"
+           xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
+           xmlns:ex="http://example.com"
+           targetNamespace="http://example.com"
+           elementFormDefault="unqualified">
+
+  <include schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
+
+  <annotation>
+    <appinfo source="http://www.ogf.org/dfdl/">
+      <dfdl:format ref="ex:GeneralFormat"/>
+    </appinfo>
+  </annotation>
+
+  <simpleType name="str" dfdl:lengthKind="explicit" dfdl:length="1">
+    <restriction base="xs:string"/>
+  </simpleType>
+
+  <simpleType name="str0" dfdl:lengthKind="explicit" dfdl:length="0">
+    <restriction base="xs:string"/>
+  </simpleType>
+
+  <element name="msg">
+    <complexType>
+      <sequence>
+        <element name="messageID" type="ex:str"/>
+        <choice dfdl:choiceDispatchKey="{ messageID }">
+          <sequence dfdl:choiceBranchKey="1">
+            <element name="ack" type="ex:str"/>
+            <group ref="ex:check"/>
+            <element name="ackInfo" type="ex:str"/>
+          </sequence>
+          <sequence dfdl:choiceBranchKey="2">
+            <!--
+            DAFFODIL-2615
+            Ack test works, but Nack test fails
+            because the group ref below shares the group "ex:check" with the above choice branch.
+
+            The error is an Unparse Error:
+            Expected element start event for {}nackInfo, but received element start event for (invalid) {}nackInfo.
+
+            To make the Nack test work, add suffix _b so you are referencing "ex:check_b".
+            This group is a clone of the ex:check group. But doing this there is no longer
+            a group being shared.
+            -->
+            <element name="nack" type="ex:str"/>
+            <group ref="ex:check"/>
+            <element name="nackInfo" type="ex:str"/>
+          </sequence>
+        </choice>
+      </sequence>
+    </complexType>
+  </element>
+
+
+  <group name="check">
+    <choice dfdl:choiceDispatchKey="{ 'V' }">
+      <sequence dfdl:choiceBranchKey="V"/>
+      <element dfdl:choiceBranchKey="I" name="invalid" type="ex:str0"/>
+    </choice>
+  </group>
+
+  <!--
+  DAFFODIL-2615
+
+  To workaround the bug, we cloned check, and added "_b" suffix.
+  This allows users to invoke the same check, but without sharing the group.
+  -->
+  <group name="check_b">
+    <choice dfdl:choiceDispatchKey="{ 'V' }">
+      <sequence dfdl:choiceBranchKey="V"/>
+      <element dfdl:choiceBranchKey="I" name="invalid" type="ex:str0"/>
+    </choice>
+  </group>
+
+</schema>
\ No newline at end of file
diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/testSharedGroups.tdml b/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/testSharedGroups.tdml
new file mode 100644
index 0000000..4e3f02b
--- /dev/null
+++ b/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/testSharedGroups.tdml
@@ -0,0 +1,59 @@
+<?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:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
+  xmlns:tdml="http://www.ibm.com/xmlns/dfdl/testData"
+  xmlns="http://www.ibm.com/xmlns/dfdl/testData"
+  xmlns:ex="http://example.com"
+  xmlns:xs="http://www.w3.org/2001/XMLSchema"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  defaultRoundTrip="none"
+  defaultValidation="off">
+
+  <unparserTestCase name="Ack"
+                    model="org/apache/daffodil/section15/choice_groups/SharedGroupTestSchema.dfdl.xsd"
+                    root="msg">
+    <document>1ZA</document>
+    <infoset>
+      <dfdlInfoset>
+        <ex:msg xmlns:ex="http://example.com" xmlns="">
+          <messageID>1</messageID>
+          <ack>Z</ack>
+          <ackInfo>A</ackInfo>
+        </ex:msg>
+      </dfdlInfoset>
+    </infoset>
+  </unparserTestCase>
+
+  <unparserTestCase name="Nack"
+                    model="org/apache/daffodil/section15/choice_groups/SharedGroupTestSchema.dfdl.xsd"
+                    root="msg">
+    <document>2XA</document>
+    <infoset>
+      <dfdlInfoset>
+        <ex:msg xmlns:ex="http://example.com" xmlns="">
+          <messageID>2</messageID>
+          <nack>X</nack>
+          <nackInfo>A</nackInfo>
+        </ex:msg>
+      </dfdlInfoset>
+    </infoset>
+  </unparserTestCase>
+
+
+</testSuite>
diff --git a/daffodil-test/src/test/scala/org/apache/daffodil/section15/choice_groups/TestSharedGroups.scala b/daffodil-test/src/test/scala/org/apache/daffodil/section15/choice_groups/TestSharedGroups.scala
new file mode 100644
index 0000000..91b8683
--- /dev/null
+++ b/daffodil-test/src/test/scala/org/apache/daffodil/section15/choice_groups/TestSharedGroups.scala
@@ -0,0 +1,40 @@
+/*
+ * 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.section15.choice_groups
+
+import org.apache.daffodil.tdml.Runner
+import org.junit.AfterClass
+import org.junit.Test
+
+object TestSharedGroups {
+  val testDir = "/org/apache/daffodil/section15/choice_groups/"
+  lazy val runner = Runner(testDir, "testSharedGroups.tdml")
+
+  @AfterClass def shutDown() = {
+    runner.reset
+  }
+}
+
+class TestSharedGroups {
+
+  import TestSharedGroups._
+
+  @Test def testShowsSharedGroupOkFirstUse() = { runner.runOneTest("Ack") }
+  // DAFFODIL-2615 - shared groups problem
+  //@Test def testShowsSharedGroupFailsSecondUse() = { runner.runOneTest("Nack") }
+
+}