You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by ja...@apache.org on 2019/04/24 13:59:53 UTC

[incubator-daffodil] branch master updated: Enable facet range checking for xs:decimal

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

jadams 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 ebd2863  Enable facet range checking for xs:decimal
ebd2863 is described below

commit ebd28636d915dba407c268f112fb5058974c0d45
Author: Josh Adams <ja...@tresys.com>
AuthorDate: Wed Apr 17 16:35:07 2019 -0400

    Enable facet range checking for xs:decimal
    
    Also changed the SDE to for unknown types to an Assert.usageError
    
    DAFFODIL-2108
---
 .../scala/org/apache/daffodil/dsom/Facets.scala    |   3 +-
 .../apache/daffodil/section05/facets/Facets.tdml   | 152 ++++++++++++++++++++-
 .../daffodil/section05/facets/TestFacets.scala     |  10 ++
 3 files changed, 163 insertions(+), 2 deletions(-)

diff --git a/daffodil-core/src/main/scala/org/apache/daffodil/dsom/Facets.scala b/daffodil-core/src/main/scala/org/apache/daffodil/dsom/Facets.scala
index db2e94e..85e60ed 100644
--- a/daffodil-core/src/main/scala/org/apache/daffodil/dsom/Facets.scala
+++ b/daffodil-core/src/main/scala/org/apache/daffodil/dsom/Facets.scala
@@ -384,13 +384,14 @@ trait Facets { self: Restriction =>
                 facetType, localFacet)
             }
           }
+          case PrimType.Decimal => { /* Nothing to do here */ }
           case PrimType.DateTime => { /* Nothing to do here */ }
           case PrimType.Date => { /* Nothing to do here */ }
           case PrimType.Time => { /* Nothing to do here */ }
           case PrimType.Boolean => notYetImplemented("checkValueSpaceFacetRange - Boolean")
           case PrimType.HexBinary => { /* Nothing to do here */ }
           case PrimType.String => { /* Nothing to do here */ }
-          case _ => schemaDefinitionError("checkValueSpaceFacetRange - Unrecognized primitive type: %s", primType.name)
+          case _ => Assert.usageError("checkValueSpaceFacetRange - Unrecognized primitive type: " + primType.name)
         }
       }
       case _ => { /* Nothing to do */ }
diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/section05/facets/Facets.tdml b/daffodil-test/src/test/resources/org/apache/daffodil/section05/facets/Facets.tdml
index 5b9a1d2..ecf53eb 100644
--- a/daffodil-test/src/test/resources/org/apache/daffodil/section05/facets/Facets.tdml
+++ b/daffodil-test/src/test/resources/org/apache/daffodil/section05/facets/Facets.tdml
@@ -4095,6 +4095,20 @@
         </xs:restriction>
       </xs:simpleType>
     </xs:element>
+    <xs:element name="e4_3_4" dfdl:lengthKind="delimited">
+      <xs:annotation>
+        <xs:appinfo source="http://www.ogf.org/dfdl/">
+          <dfdl:assert test="{ dfdl:checkConstraints(.) }"
+            message="Assertion failed for dfdl:checkConstraints(.)" />
+        </xs:appinfo>
+      </xs:annotation>
+      <xs:simpleType>
+        <xs:restriction base="xs:decimal">
+          <xs:minInclusive value="-5" />
+          <xs:maxInclusive value="5" />
+        </xs:restriction>
+      </xs:simpleType>
+    </xs:element>
     <xs:element name="e4_4_1" dfdl:lengthKind="delimited">
       <xs:annotation>
         <xs:appinfo source="http://www.ogf.org/dfdl/">
@@ -4109,6 +4123,20 @@
         </xs:restriction>
       </xs:simpleType>
     </xs:element>
+    <xs:element name="e4_4_2" dfdl:lengthKind="delimited">
+      <xs:annotation>
+        <xs:appinfo source="http://www.ogf.org/dfdl/">
+          <dfdl:assert test="{ dfdl:checkConstraints(.) }"
+            message="Assertion failed for dfdl:checkConstraints(.)" />
+        </xs:appinfo>
+      </xs:annotation>
+      <xs:simpleType>
+        <xs:restriction base="xs:decimal">
+          <xs:minExclusive value="-5" />
+          <xs:maxExclusive value="5" />
+        </xs:restriction>
+      </xs:simpleType>
+    </xs:element>
     <xs:element name="e4_5_1" dfdl:lengthKind="delimited">
       <xs:annotation>
         <xs:appinfo source="http://www.ogf.org/dfdl/">
@@ -4701,7 +4729,129 @@
       </tdml:dfdlInfoset>
     </tdml:infoset>
   </tdml:parserTestCase>
-  
+
+  <!--
+    Test name: checkMinInclusiveDecimal_Pass
+       Schema: checkConstraints
+      Purpose: This test demonstrates the use of validation for the maxInclusive facet with xs:decimal.
+  -->
+  <tdml:parserTestCase name="checkMinInclusiveDecimal_Pass"
+    root="e4_3_4" model="TestFacets">
+
+    <tdml:document>-5</tdml:document>
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <e4_3_4>-5</e4_3_4>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+  </tdml:parserTestCase>
+
+    <!--
+    Test name: checkMaxInclusiveDecimal_Pass
+       Schema: checkConstraints
+      Purpose: This test demonstrates the use of validation for the maxInclusive facet with xs:decimal.
+  -->
+  <tdml:parserTestCase name="checkMaxInclusiveDecimal_Pass"
+    root="e4_3_4" model="TestFacets">
+
+    <tdml:document>5</tdml:document>
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <e4_3_4>5</e4_3_4>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+  </tdml:parserTestCase>
+
+    <!--
+    Test name: checkMinInclusiveDecimal_Fail
+       Schema: checkConstraints
+      Purpose: This test demonstrates the use of validation for the maxInclusive facet with xs:decimal.
+               Specifically will fial because -6 is more negative than -5
+  -->
+  <tdml:parserTestCase name="checkMinInclusiveDecimal_Fail"
+    root="e4_3_4" model="TestFacets">
+
+    <tdml:document>-6</tdml:document>
+    <tdml:errors>
+      <tdml:error>Assertion failed: Assertion failed for dfdl:checkConstraints(.)</tdml:error>
+    </tdml:errors>
+  </tdml:parserTestCase>
+
+    <!--
+    Test name: checkMaxInclusiveDecimal_Fail
+       Schema: checkConstraints
+      Purpose: This test demonstrates the use of validation for the maxInclusive facet with xs:decimal.
+               Specifically will fail because 6 is greater than 5.
+  -->
+  <tdml:parserTestCase name="checkMaxInclusiveDecimal_Fail"
+    root="e4_3_4" model="TestFacets">
+
+    <tdml:document>6</tdml:document>
+    <tdml:errors>
+      <tdml:error>Assertion failed: Assertion failed for dfdl:checkConstraints(.)</tdml:error>
+    </tdml:errors>
+  </tdml:parserTestCase>
+
+  <!--
+    Test name: checkMinExclusiveDecimal_Fail
+       Schema: checkConstraints
+      Purpose: This test demonstrates the use of validation for the maxInclusive facet with xs:decimal.
+  -->
+  <tdml:parserTestCase name="checkMinExclusiveDecimal_Fail"
+    root="e4_4_2" model="TestFacets">
+
+    <tdml:document>-5</tdml:document>
+    <tdml:errors>
+      <tdml:error></tdml:error>
+    </tdml:errors>
+  </tdml:parserTestCase>
+
+    <!--
+    Test name: checkMaxExclusiveDecimal_Fail
+       Schema: checkConstraints
+      Purpose: This test demonstrates the use of validation for the maxInclusive facet with xs:decimal.
+  -->
+  <tdml:parserTestCase name="checkMaxExclusiveDecimal_Fail"
+    root="e4_4_2" model="TestFacets">
+
+    <tdml:document>5</tdml:document>
+    <tdml:errors>
+      <tdml:error></tdml:error>
+    </tdml:errors>
+  </tdml:parserTestCase>
+
+      <!--
+    Test name: checkMinExclusiveDecimal_Pass
+       Schema: checkConstraints
+      Purpose: This test demonstrates the use of validation for the maxExclusive facet with xs:decimal.
+  -->
+  <tdml:parserTestCase name="checkMinExclusiveDecimal_Pass"
+    root="e4_4_2" model="TestFacets">
+
+    <tdml:document>-4</tdml:document>
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <e4_4_2>-4</e4_4_2>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+  </tdml:parserTestCase>
+
+    <!--
+    Test name: checkMaxExclusiveDecimal_Pass
+       Schema: checkConstraints
+      Purpose: This test demonstrates the use of validation for the maxExclusive facet with xs:decimal.
+  -->
+  <tdml:parserTestCase name="checkMaxExclusiveDecimal_Pass"
+    root="e4_4_2" model="TestFacets">
+
+    <tdml:document>4</tdml:document>
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <e4_4_2>4</e4_4_2>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+  </tdml:parserTestCase>
+
   <!--
     Test name: checkCombining_Pass
        Schema: checkConstraints
diff --git a/daffodil-test/src/test/scala/org/apache/daffodil/section05/facets/TestFacets.scala b/daffodil-test/src/test/scala/org/apache/daffodil/section05/facets/TestFacets.scala
index 03d74dd..39dedce 100644
--- a/daffodil-test/src/test/scala/org/apache/daffodil/section05/facets/TestFacets.scala
+++ b/daffodil-test/src/test/scala/org/apache/daffodil/section05/facets/TestFacets.scala
@@ -127,6 +127,16 @@ class TestFacets {
   @Test def test_checkMaxInclusive_Fail_MaxInt { runner.runOneTest("checkMaxInclusive_Fail_MaxInt") }
   @Test def test_checkMinInclusive_Fail_MinInt { runner.runOneTest("checkMinInclusive_Fail_MinInt") }
 
+  @Test def test_checkMinInclusiveDecimal_Pass { runner.runOneTest("checkMinInclusiveDecimal_Pass") }
+  @Test def test_checkMaxInclusiveDecimal_Pass { runner.runOneTest("checkMaxInclusiveDecimal_Pass") }
+  @Test def test_checkMinInclusiveDecimal_Fail { runner.runOneTest("checkMinInclusiveDecimal_Fail") }
+  @Test def test_checkMaxInclusiveDecimal_Fail { runner.runOneTest("checkMaxInclusiveDecimal_Fail") }
+
+  @Test def test_checkMinExclusiveDecimal_Pass { runner.runOneTest("checkMinExclusiveDecimal_Pass") }
+  @Test def test_checkMaxExclusiveDecimal_Pass { runner.runOneTest("checkMaxExclusiveDecimal_Pass") }
+  @Test def test_checkMinExclusiveDecimal_Fail { runner.runOneTest("checkMinExclusiveDecimal_Fail") }
+  @Test def test_checkMaxExclusiveDecimal_Fail { runner.runOneTest("checkMaxExclusiveDecimal_Fail") }
+
   @Test def test_checkMinExclusive_Fail { runner.runOneTest("checkMinExclusive_Fail") }
   @Test def test_checkMaxExclusive_Fail { runner.runOneTest("checkMaxExclusive_Fail") }
   @Test def test_checkMinExclusive_Pass { runner.runOneTest("checkMinExclusive_Pass") }