You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by "mbeckerle (via GitHub)" <gi...@apache.org> on 2024/11/18 17:21:32 UTC

[PR] Added tests of decimalSigned to show that it fails in a few cases. [daffodil]

mbeckerle opened a new pull request, #1376:
URL: https://github.com/apache/daffodil/pull/1376

   Note: This PR has 2 commits. The first one is for a separate feature (with separate PR) that I'm depending on in this PR. Please ignore that first commit and review the 2 files of changes in the 2nd commit. 
   
   ----
   
   Tests show that parse of negative representations (from packed decimal reps) does not detect the error when decimalSigned="no".
   
   Test also show that unparse of negative values into binary, packed, and bcd all are broken.
   
   This doesn't fix the issue. Just adds tests to illustrate the failing cases.
   
   DAFFODIL-2957


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added tests of decimalSigned to show that it fails in a few cases. [daffodil]

Posted by "olabusayoT (via GitHub)" <gi...@apache.org>.
olabusayoT commented on code in PR #1376:
URL: https://github.com/apache/daffodil/pull/1376#discussion_r1847005151


##########
daffodil-test/src/test/resources/org/apache/daffodil/section13/decimal/TestDecimalSigned.tdml:
##########
@@ -0,0 +1,157 @@
+<?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
+  description="For type xs:decimal this tests interactions of decimalSigned='no'
+  with negative values being unparsed and parsed."
+  xmlns="http://www.ibm.com/xmlns/dfdl/testData"
+  xmlns:tdml="http://www.ibm.com/xmlns/dfdl/testData"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
+  xmlns:xs="http://www.w3.org/2001/XMLSchema"
+  xmlns:ex="http://example.com"
+  defaultRoundTrip="none">
+
+  <tdml:defineSchema name="s" xmlns="http://www.w3.org/2001/XMLSchema"
+                     elementFormDefault="unqualified" useDefaultNamespace="false">
+    <include schemaLocation="/org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
+
+    <dfdl:format ref="ex:GeneralFormat"
+                 representation="binary"
+                 lengthKind="explicit"
+                 binaryDecimalVirtualPoint="2"
+                 binaryPackedSignCodes="C D F C"/>
+
+    <element name="r1" type="xs:decimal" dfdl:decimalSigned="no" dfdl:length="2" dfdl:binaryNumberRep="binary"/>
+
+    <!-- BCD is never signed, so cannot represent a negative value -->
+    <element name="r2" type="xs:decimal" dfdl:decimalSigned="yes" dfdl:length="2" dfdl:binaryNumberRep="bcd"/>
+
+    <element name="r3" type="xs:decimal" dfdl:decimalSigned="no" dfdl:length="2" dfdl:binaryNumberRep="packed"/>
+
+    <element name="r4" type="xs:decimal" dfdl:decimalSigned="no" dfdl:length="2" dfdl:binaryNumberRep="ibm4690Packed"/>
+
+
+  </tdml:defineSchema>
+
+  <parserTestCase name="parseTestDecimalSigned_no_binary" root="r1" model="s"
+    description="decimalSigned='no' works for parsing with binaryNumberRep='binary'" >
+    <document>
+      <!-- same bytes as -123 as big-endian twos complement 2-bytes -->

Review Comment:
   -1.23*



##########
daffodil-test/src/test/resources/org/apache/daffodil/section13/decimal/TestDecimalSigned.tdml:
##########
@@ -0,0 +1,157 @@
+<?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
+  description="For type xs:decimal this tests interactions of decimalSigned='no'
+  with negative values being unparsed and parsed."
+  xmlns="http://www.ibm.com/xmlns/dfdl/testData"
+  xmlns:tdml="http://www.ibm.com/xmlns/dfdl/testData"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
+  xmlns:xs="http://www.w3.org/2001/XMLSchema"
+  xmlns:ex="http://example.com"
+  defaultRoundTrip="none">
+
+  <tdml:defineSchema name="s" xmlns="http://www.w3.org/2001/XMLSchema"
+                     elementFormDefault="unqualified" useDefaultNamespace="false">
+    <include schemaLocation="/org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
+
+    <dfdl:format ref="ex:GeneralFormat"
+                 representation="binary"
+                 lengthKind="explicit"
+                 binaryDecimalVirtualPoint="2"
+                 binaryPackedSignCodes="C D F C"/>
+
+    <element name="r1" type="xs:decimal" dfdl:decimalSigned="no" dfdl:length="2" dfdl:binaryNumberRep="binary"/>
+
+    <!-- BCD is never signed, so cannot represent a negative value -->
+    <element name="r2" type="xs:decimal" dfdl:decimalSigned="yes" dfdl:length="2" dfdl:binaryNumberRep="bcd"/>
+
+    <element name="r3" type="xs:decimal" dfdl:decimalSigned="no" dfdl:length="2" dfdl:binaryNumberRep="packed"/>
+
+    <element name="r4" type="xs:decimal" dfdl:decimalSigned="no" dfdl:length="2" dfdl:binaryNumberRep="ibm4690Packed"/>
+
+
+  </tdml:defineSchema>
+
+  <parserTestCase name="parseTestDecimalSigned_no_binary" root="r1" model="s"
+    description="decimalSigned='no' works for parsing with binaryNumberRep='binary'" >
+    <document>
+      <!-- same bytes as -123 as big-endian twos complement 2-bytes -->
+      <documentPart type="byte">FF85</documentPart>
+    </document>
+    <infoset>
+      <dfdlInfoset>
+        <ex:r1>654.13</ex:r1>
+      </dfdlInfoset>

Review Comment:
   Is this the incorrect result? Shouldn't we have the correct result and comment out the test in junit?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added tests of decimalSigned to show that it fails in a few cases. [daffodil]

Posted by "mbeckerle (via GitHub)" <gi...@apache.org>.
mbeckerle merged PR #1376:
URL: https://github.com/apache/daffodil/pull/1376


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added tests of decimalSigned to show that it fails in a few cases. [daffodil]

Posted by "mbeckerle (via GitHub)" <gi...@apache.org>.
mbeckerle commented on code in PR #1376:
URL: https://github.com/apache/daffodil/pull/1376#discussion_r1847378475


##########
daffodil-test/src/test/resources/org/apache/daffodil/section13/decimal/TestDecimalSigned.tdml:
##########
@@ -0,0 +1,157 @@
+<?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
+  description="For type xs:decimal this tests interactions of decimalSigned='no'
+  with negative values being unparsed and parsed."
+  xmlns="http://www.ibm.com/xmlns/dfdl/testData"
+  xmlns:tdml="http://www.ibm.com/xmlns/dfdl/testData"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
+  xmlns:xs="http://www.w3.org/2001/XMLSchema"
+  xmlns:ex="http://example.com"
+  defaultRoundTrip="none">
+
+  <tdml:defineSchema name="s" xmlns="http://www.w3.org/2001/XMLSchema"
+                     elementFormDefault="unqualified" useDefaultNamespace="false">
+    <include schemaLocation="/org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
+
+    <dfdl:format ref="ex:GeneralFormat"
+                 representation="binary"
+                 lengthKind="explicit"
+                 binaryDecimalVirtualPoint="2"
+                 binaryPackedSignCodes="C D F C"/>
+
+    <element name="r1" type="xs:decimal" dfdl:decimalSigned="no" dfdl:length="2" dfdl:binaryNumberRep="binary"/>
+
+    <!-- BCD is never signed, so cannot represent a negative value -->
+    <element name="r2" type="xs:decimal" dfdl:decimalSigned="yes" dfdl:length="2" dfdl:binaryNumberRep="bcd"/>
+
+    <element name="r3" type="xs:decimal" dfdl:decimalSigned="no" dfdl:length="2" dfdl:binaryNumberRep="packed"/>
+
+    <element name="r4" type="xs:decimal" dfdl:decimalSigned="no" dfdl:length="2" dfdl:binaryNumberRep="ibm4690Packed"/>
+
+
+  </tdml:defineSchema>
+
+  <parserTestCase name="parseTestDecimalSigned_no_binary" root="r1" model="s"
+    description="decimalSigned='no' works for parsing with binaryNumberRep='binary'" >
+    <document>
+      <!-- same bytes as -123 as big-endian twos complement 2-bytes -->

Review Comment:
   The integer that is stored is actually -123. It becomes -1.23 in the infoset due to binaryDecimalVirtualPoint="2". 
   Since this is talking about the bytes of representation I think -123 is correct. 



##########
daffodil-test/src/test/resources/org/apache/daffodil/section13/decimal/TestDecimalSigned.tdml:
##########
@@ -0,0 +1,157 @@
+<?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
+  description="For type xs:decimal this tests interactions of decimalSigned='no'
+  with negative values being unparsed and parsed."
+  xmlns="http://www.ibm.com/xmlns/dfdl/testData"
+  xmlns:tdml="http://www.ibm.com/xmlns/dfdl/testData"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
+  xmlns:xs="http://www.w3.org/2001/XMLSchema"
+  xmlns:ex="http://example.com"
+  defaultRoundTrip="none">
+
+  <tdml:defineSchema name="s" xmlns="http://www.w3.org/2001/XMLSchema"
+                     elementFormDefault="unqualified" useDefaultNamespace="false">
+    <include schemaLocation="/org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
+
+    <dfdl:format ref="ex:GeneralFormat"
+                 representation="binary"
+                 lengthKind="explicit"
+                 binaryDecimalVirtualPoint="2"
+                 binaryPackedSignCodes="C D F C"/>
+
+    <element name="r1" type="xs:decimal" dfdl:decimalSigned="no" dfdl:length="2" dfdl:binaryNumberRep="binary"/>
+
+    <!-- BCD is never signed, so cannot represent a negative value -->
+    <element name="r2" type="xs:decimal" dfdl:decimalSigned="yes" dfdl:length="2" dfdl:binaryNumberRep="bcd"/>
+
+    <element name="r3" type="xs:decimal" dfdl:decimalSigned="no" dfdl:length="2" dfdl:binaryNumberRep="packed"/>
+
+    <element name="r4" type="xs:decimal" dfdl:decimalSigned="no" dfdl:length="2" dfdl:binaryNumberRep="ibm4690Packed"/>
+
+
+  </tdml:defineSchema>
+
+  <parserTestCase name="parseTestDecimalSigned_no_binary" root="r1" model="s"
+    description="decimalSigned='no' works for parsing with binaryNumberRep='binary'" >
+    <document>
+      <!-- same bytes as -123 as big-endian twos complement 2-bytes -->
+      <documentPart type="byte">FF85</documentPart>
+    </document>
+    <infoset>
+      <dfdlInfoset>
+        <ex:r1>654.13</ex:r1>
+      </dfdlInfoset>

Review Comment:
   This is the correct result. The bits are FF85 which is the representation of this value as well as -123. This test shows that when decimalSigned="no" it interprets it as a positive integer with range up to 65535. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org