mykovalenko / legstar-cob2xsd

Automatically exported from code.google.com/p/legstar-cob2xsd
Other
0 stars 0 forks source link

Incorrect byte length in binding generated type #52

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Prepare an input file with the following copybook:

       05 SAMPLE-INPUT.
           10 SAMPLE-TYPE PICTURE IS Z(2)9(2)
                          USAGE IS DISPLAY.

2. Execute CobolStructureToXsdTask:

<cob2xsd target="${xsdpath}/Sample.xsd" codeFormat="FIXED_FORMAT" 
xsdEncoding="UTF-8" targetNamespace="http://sample" 
addLegStarAnnotations="true">
    <fileset file="${projectpath}/cobol/SAMPLE.cobol" />
</cob2xsd>

3. Execute CobolJAXBGenerator on the Sample.xsd file generated:
<jaxbgen xsdFile="${xsdpath}/Sample.xsd" targetDir="${generatedpath}" 
jaxbPackageName="${basepackage}" generateIsSetMethod="true" serializableUid="1" 
/>

4. Compile classes and execute CoxbBindingGenerator:
<coxbgen targetDir="${generatedpath}" jaxbPackageName="${basepackage}" 
coxbPackageName="${basepackage}.bind">
    <jaxbRootClass name="SampleInput" />
</coxbgen>

What is the expected output? What do you see instead?

A type SampleInputBinding is created in ${basepackage} package. Field 
BYTE_LENGTH has value 94 (see next line) but should be 4 (2 + 2)
    /** Maximum host bytes size for this complex object. */
    private static final int BYTE_LENGTH = 94;

But should be:
    /** Maximum host bytes size for this complex object. */
    private static final int BYTE_LENGTH = 4;

What version of the product are you using? On what operating system?

Legstar: 1.4.3 
cob2xsd: 0.3.2
Windows XP

Please provide any additional information below.

Problem seems to be in com.legstar.coxb.util.PictureUtil.getSymbolsNumber(final 
char[] symbols, final String input) processing inputs with a numeric + 
parentheses.
In the sample, while processing Z(2)9(2) the method processes the string in 2 
steps:
1) Z(2) returns length = 2
2) 9(2) returns length = 92 (wrong)

I have attached a patch modifying PictureUtil and adding a couple of tests to 
com.legstar.coxb.impl.CalcByteLengthTest and 
com.legstar.coxb.util.PictureUtilTest

Original issue reported on code.google.com by jose.dil...@gmail.com on 9 Feb 2011 at 7:11

Attachments:

GoogleCodeExporter commented 9 years ago
This is great stuff Jose!

Your patch is in:http://code.google.com/p/legstar/source/detail?r=1532.

Let me know if you need me to create a SNAPSHOT release or if you can wait for 
the next official release.

Thanks very much for your contribution.

Original comment by fady.mou...@gmail.com on 10 Feb 2011 at 9:54

GoogleCodeExporter commented 9 years ago

Original comment by fady.mou...@gmail.com on 11 Feb 2011 at 7:36

GoogleCodeExporter commented 9 years ago

Original comment by fady.mou...@gmail.com on 11 Feb 2011 at 7:38

GoogleCodeExporter commented 9 years ago

Original comment by fady.mou...@gmail.com on 11 Feb 2011 at 8:49

GoogleCodeExporter commented 9 years ago
I have found another error in byte length calculation, with a type like this:
10 SAMPLE-TYPE PICTURE IS Z(3)DB

Length should be 5 (3 for Z(3) plus 2 for DB) but the B in DB is counted twice, 
and method returns 6.

I have prepared a quick fix for this. Maybe you prefer some more elegant fix, 
so feel free to apply the fix or modify it.

The fix is attached as a path, with 2 more test cases.

A release with these fixes would be great.

Original comment by jose.dil...@gmail.com on 11 Feb 2011 at 2:20

Attachments:

GoogleCodeExporter commented 9 years ago
Re opened as http://code.google.com/p/legstar/issues/detail?id=124.

Your code is perfectly fine. Edited numerics got much better thanks to you.

I will try to push release 1.4.4 early next week.

Thanks again for your efforts.

Original comment by fady.mou...@gmail.com on 11 Feb 2011 at 5:22