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 2019/09/27 15:10:15 UTC
[incubator-daffodil] branch master updated: Added tests that
illustrate nested choice technique.
This is an automated email from the ASF dual-hosted git repository.
mbeckerle 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 9c5a6b1 Added tests that illustrate nested choice technique.
9c5a6b1 is described below
commit 9c5a6b1d352939aeb6cd0e4ff09b7f2d1f53dea3
Author: Michael Beckerle <mb...@tresys.com>
AuthorDate: Wed Sep 25 21:32:27 2019 -0400
Added tests that illustrate nested choice technique.
DAFFODIL-2207
---
.../section15/choice_groups/choiceNests.tdml | 155 +++++++++++++++++++++
.../section15/choice_groups/TestChoiceNest.scala | 45 ++++++
2 files changed, 200 insertions(+)
diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/choiceNests.tdml b/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/choiceNests.tdml
new file mode 100644
index 0000000..80eea34
--- /dev/null
+++ b/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/choiceNests.tdml
@@ -0,0 +1,155 @@
+<?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
+ xmlns:tdml="http://www.ibm.com/xmlns/dfdl/testData"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
+ xmlns:dfdlx="http://www.ogf.org/dfdl/dfdl-1.0/extensions"
+ xmlns:ex="http://example.com"
+ xmlns:daf="urn:ogf:dfdl:2013:imp:daffodil.apache.org:2018:ext"
+ xmlns:fn="http://www.w3.org/2005/xpath-functions"
+ defaultRoundTrip="true">
+
+ <tdml:defineSchema name="choiceNest" xmlns:ex="http://example.com"
+ elementFormDefault="unqualified">
+
+ <xs:include schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd" />
+ <dfdl:format ref="ex:GeneralFormat" lengthKind="delimited" />
+
+ <dfdl:defineVariable name="captureUnknown" type="xs:boolean" external="true"
+ defaultValue="false" />
+
+ <xs:element name="messages">
+ <xs:complexType>
+ <xs:sequence dfdl:separator="%NL;">
+ <xs:element name="message" maxOccurs="10" dfdl:occursCountKind="implicit">
+ <xs:complexType>
+ <xs:sequence dfdl:separator="|">
+ <xs:element name="ID" type="xs:string" />
+ <xs:choice>
+ <!--
+ This double-nested choice, as work around for the
+ lack of a default choice branch selection, works, but it's
+ ugly because while you do get the diganostic from the assert,
+ you ALSO get the diagnostic that the choice branches of the
+ inner choice failed.
+ -->
+ <xs:choice dfdl:choiceDispatchKey="{ xs:string(xs:int(ID)) }">
+ <xs:element name="Type1" type="xs:string" dfdl:choiceBranchKey="1" />
+ <xs:element name="Type2" type="xs:string" dfdl:choiceBranchKey="2" />
+ </xs:choice>
+
+ <xs:element name="unknownType" type="xs:string">
+ <xs:annotation>
+ <xs:appinfo source="http://www.ogf.org/dfdl/">
+ <dfdl:assert message="{fn:concat('Unsupported Message Format: ', ../ID ) }"
+ test="{ $ex:captureUnknown }" />
+ </xs:appinfo>
+ </xs:annotation>
+ </xs:element>
+ </xs:choice>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
+ </tdml:defineSchema>
+
+ <tdml:defineConfig name="capture">
+ <daf:externalVariableBindings>
+ <daf:bind name="ex:captureUnknown">true</daf:bind>
+ </daf:externalVariableBindings>
+ </tdml:defineConfig>
+
+ <tdml:parserTestCase name="choiceNest1" root="messages" model="choiceNest"
+ roundTrip="onePass">
+ <tdml:document><![CDATA[1|This is Type 1
+2|This is Type 2
+1|This is Type 1]]></tdml:document>
+
+ <tdml:infoset>
+ <tdml:dfdlInfoset>
+ <ex:messages>
+ <message><ID>1</ID><Type1>This is Type 1</Type1></message>
+ <message><ID>2</ID><Type2>This is Type 2</Type2></message>
+ <message><ID>1</ID><Type1>This is Type 1</Type1></message>
+ </ex:messages>
+ </tdml:dfdlInfoset>
+ </tdml:infoset>
+
+ </tdml:parserTestCase>
+
+ <tdml:parserTestCase name="choiceNest2" root="messages" model="choiceNest"
+ roundTrip="onePass">
+ <tdml:document>3|This is Type 3</tdml:document>
+
+ <tdml:errors>
+ <tdml:error>Assertion failed</tdml:error>
+ <tdml:error>Unsupported Message Format: 3</tdml:error>
+ </tdml:errors>
+
+ </tdml:parserTestCase>
+
+ <tdml:parserTestCase name="choiceNest2a" root="messages" model="choiceNest"
+ roundTrip="onePass"
+ config="capture">
+ <tdml:document>3|This is Type 3</tdml:document>
+
+ <tdml:infoset>
+ <tdml:dfdlInfoset>
+ <ex:messages><message><ID>3</ID><unknownType>This is Type 3</unknownType></message></ex:messages>
+ </tdml:dfdlInfoset>
+ </tdml:infoset>
+
+ </tdml:parserTestCase>
+
+
+
+ <tdml:parserTestCase name="choiceNest3" root="messages" model="choiceNest"
+ roundTrip="onePass"
+ config="capture">
+ <tdml:document>notAnInt|This is bad data</tdml:document>
+
+ <tdml:infoset>
+ <tdml:dfdlInfoset>
+ <ex:messages>
+ <message><ID>notAnInt</ID><unknownType>This is bad data</unknownType></message>
+ </ex:messages>
+ </tdml:dfdlInfoset>
+ </tdml:infoset>
+
+ </tdml:parserTestCase>
+
+ <tdml:parserTestCase name="choiceNest4" root="messages" model="choiceNest"
+ roundTrip="onePass">
+ <tdml:document>notAnInt|This is bad data</tdml:document>
+
+ <tdml:errors>
+ <tdml:error>All choice alternatives failed</tdml:error>
+ <tdml:error>Parse Error</tdml:error>
+ <tdml:error>Cannot convert</tdml:error>
+ <tdml:error>Assertion failed</tdml:error>
+ <tdml:error>Unsupported Message Format: notAnInt</tdml:error>
+ </tdml:errors>
+
+ </tdml:parserTestCase>
+</tdml:testSuite>
\ No newline at end of file
diff --git a/daffodil-test/src/test/scala/org/apache/daffodil/section15/choice_groups/TestChoiceNest.scala b/daffodil-test/src/test/scala/org/apache/daffodil/section15/choice_groups/TestChoiceNest.scala
new file mode 100644
index 0000000..a57eec8
--- /dev/null
+++ b/daffodil-test/src/test/scala/org/apache/daffodil/section15/choice_groups/TestChoiceNest.scala
@@ -0,0 +1,45 @@
+/*
+ * 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.junit.Test
+import org.apache.daffodil.tdml.Runner
+import org.junit.AfterClass
+
+object TestChoiceNest {
+ val testDir = "/org/apache/daffodil/section15/choice_groups/"
+
+ val runner = Runner(testDir, "choiceNests.tdml")
+
+ @AfterClass def shutDown {
+ runner.reset
+ }
+
+}
+
+class TestChoiceNest {
+
+ import TestChoiceNest._
+
+ @Test def test_choiceNest1() { runner.runOneTest("choiceNest1") }
+ @Test def test_choiceNest2() { runner.runOneTest("choiceNest2") }
+ @Test def test_choiceNest2a() { runner.runOneTest("choiceNest2a") }
+ @Test def test_choiceNest3() { runner.runOneTest("choiceNest3") }
+ @Test def test_choiceNest4() { runner.runOneTest("choiceNest4") }
+
+}