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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
