PageRenderTime 27ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/contrib-imola/cics-bc/jbi4cics/src/test/java/it/imolinfo/jbi4cics/test/mapping/coboltypes/CobolZonedTypeMappingTest.java

https://bitbucket.org/pymma/openesb-components
Java | 533 lines | 374 code | 55 blank | 104 comment | 0 complexity | 0bb7e400548bdd88057f5b25ede15f3c MD5 | raw file
  1. /*******************************************************************************
  2. * Copyright (c) 2005, 2006 Imola Informatica.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the LGPL License v2.1
  5. * which accompanies this distribution, and is available at
  6. * http://www.gnu.org/licenses/lgpl.html
  7. *******************************************************************************/
  8. package it.imolinfo.jbi4cics.test.mapping.coboltypes;
  9. import it.imolinfo.jbi4cics.typemapping.cobol.CobolFieldFormatter;
  10. import it.imolinfo.jbi4cics.typemapping.cobol.CobolType;
  11. import it.imolinfo.jbi4cics.typemapping.cobol.CobolTypeDescriptor;
  12. import it.imolinfo.jbi4cics.typemapping.cobol.HexDump;
  13. import java.math.BigDecimal;
  14. import java.math.BigInteger;
  15. import java.math.MathContext;
  16. import java.util.Arrays;
  17. import junit.framework.TestCase;
  18. import org.apache.commons.logging.Log;
  19. import org.apache.commons.logging.LogFactory;
  20. public class CobolZonedTypeMappingTest extends TestCase {
  21. private static Log log=LogFactory.getLog(CobolZonedTypeMappingTest.class);
  22. public static final String DeafultHostCodePage="CP1144";
  23. public CobolZonedTypeMappingTest(String arg0){
  24. super(arg0);
  25. }
  26. /**
  27. * testo un zoned
  28. * PIC 9(10)
  29. * con valore 10
  30. *
  31. */
  32. public void testZoned9_10(){
  33. try{
  34. CobolTypeDescriptor cobolTypeDescriptor=new CobolTypeDescriptor();
  35. cobolTypeDescriptor.setType(CobolType.ZONED);
  36. cobolTypeDescriptor.setIntegerPartLength(10);
  37. cobolTypeDescriptor.setCodePage(DeafultHostCodePage);
  38. cobolTypeDescriptor.setZonedSignFormat(CobolTypeDescriptor.SIGN_FORMAT_TRAILING);
  39. cobolTypeDescriptor.setPadCharacter(" ");
  40. BigInteger value=BigInteger.valueOf(10);
  41. byte[] buffer=new byte[10];
  42. byte[] expectedBuffer=new byte[] {(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf1,(byte)0xf0};
  43. // '0' '0' '0' '0' '0' '0' '0' '0' '1' '0'
  44. long millis1=System.currentTimeMillis();
  45. CobolFieldFormatter.format(value,buffer,cobolTypeDescriptor,0);
  46. long millis2=System.currentTimeMillis();
  47. log.debug("buffer dopo il format in string: ["+new String(buffer,DeafultHostCodePage)+"]");
  48. log.debug("buffer dopo il format in esadecimale: ["+HexDump.toHex(buffer)+"]");
  49. log.debug("buffer expected in esadecimale: ["+HexDump.toHex(expectedBuffer)+"]");
  50. log.debug("conversion time="+(millis2-millis1)+" millis");
  51. assertTrue("conversione non corretta",Arrays.equals(expectedBuffer,buffer));
  52. }
  53. catch(Exception e){
  54. e.printStackTrace();
  55. fail(e.getMessage());
  56. }
  57. }
  58. /**
  59. * testo un zoned
  60. * PIC s9(10)
  61. * con valore 10
  62. *
  63. */
  64. public void testZonedsp9_10(){
  65. try{
  66. CobolTypeDescriptor cobolTypeDescriptor=new CobolTypeDescriptor();
  67. cobolTypeDescriptor.setType(CobolType.ZONED);
  68. cobolTypeDescriptor.setIntegerPartLength(10);
  69. cobolTypeDescriptor.setCodePage(DeafultHostCodePage);
  70. cobolTypeDescriptor.setPadCharacter(" ");
  71. cobolTypeDescriptor.setZonedSignFormat(CobolTypeDescriptor.SIGN_FORMAT_TRAILING);
  72. cobolTypeDescriptor.setSigned(true);
  73. BigInteger value=BigInteger.valueOf(10);
  74. byte[] buffer=new byte[10];
  75. byte[] expectedBuffer=new byte[] {(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf1,(byte)0xc0};
  76. // '0' '0' '0' '0' '0' '0' '0' '0' '1' '0'
  77. long millis1=System.currentTimeMillis();
  78. CobolFieldFormatter.format(value,buffer,cobolTypeDescriptor,0);
  79. long millis2=System.currentTimeMillis();
  80. log.debug("buffer dopo il format in string: ["+new String(buffer,DeafultHostCodePage)+"]");
  81. log.debug("buffer dopo il format in esadecimale: ["+HexDump.toHex(buffer)+"]");
  82. log.debug("buffer expected in esadecimale: ["+HexDump.toHex(expectedBuffer)+"]");
  83. log.debug("conversion time="+(millis2-millis1)+" millis");
  84. assertTrue("conversione non corretta",Arrays.equals(expectedBuffer,buffer));
  85. }
  86. catch(Exception e){
  87. e.printStackTrace();
  88. fail(e.getMessage());
  89. }
  90. }
  91. /**
  92. * testo un zoned
  93. * PIC s9(10)
  94. * con valore 10
  95. *
  96. */
  97. public void testZonedsm9_10(){
  98. try{
  99. CobolTypeDescriptor cobolTypeDescriptor=new CobolTypeDescriptor();
  100. cobolTypeDescriptor.setType(CobolType.ZONED);
  101. cobolTypeDescriptor.setIntegerPartLength(10);
  102. cobolTypeDescriptor.setCodePage(DeafultHostCodePage);
  103. cobolTypeDescriptor.setZonedSignFormat(CobolTypeDescriptor.SIGN_FORMAT_TRAILING);
  104. cobolTypeDescriptor.setPadCharacter(" ");
  105. cobolTypeDescriptor.setSigned(true);
  106. BigInteger value=BigInteger.valueOf(-10);
  107. byte[] buffer=new byte[10];
  108. byte[] expectedBuffer=new byte[] {(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf1,(byte)0xd0};
  109. // '0' '0' '0' '0' '0' '0' '0' '0' '1' '0'
  110. long millis1=System.currentTimeMillis();
  111. CobolFieldFormatter.format(value,buffer,cobolTypeDescriptor,0);
  112. long millis2=System.currentTimeMillis();
  113. log.debug("buffer dopo il format in string: ["+new String(buffer,DeafultHostCodePage)+"]");
  114. log.debug("buffer dopo il format in esadecimale: ["+HexDump.toHex(buffer)+"]");
  115. log.debug("buffer expected in esadecimale: ["+HexDump.toHex(expectedBuffer)+"]");
  116. log.debug("conversion time="+(millis2-millis1)+" millis");
  117. assertTrue("conversione non corretta",Arrays.equals(expectedBuffer,buffer));
  118. }
  119. catch(Exception e){
  120. e.printStackTrace();
  121. fail(e.getMessage());
  122. }
  123. }
  124. /**
  125. * testo un zoned
  126. * PIC 9(10)v9(2)
  127. * con valore 10.10
  128. *
  129. */
  130. public void testZoned9_10_9_2(){
  131. try{
  132. CobolTypeDescriptor cobolTypeDescriptor=new CobolTypeDescriptor();
  133. cobolTypeDescriptor.setType(CobolType.ZONED);
  134. cobolTypeDescriptor.setIntegerPartLength(10);
  135. cobolTypeDescriptor.setDecimalPartLength(2);
  136. cobolTypeDescriptor.setCodePage(DeafultHostCodePage);
  137. cobolTypeDescriptor.setZonedSignFormat(CobolTypeDescriptor.SIGN_FORMAT_TRAILING);
  138. cobolTypeDescriptor.setPadCharacter(" ");
  139. BigDecimal value=BigDecimal.valueOf(10.10);
  140. byte[] buffer=new byte[12];
  141. byte[] expectedBuffer=new byte[] {(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf1,(byte)0xf0,(byte)0xf1,(byte)0xf0};
  142. // '0' '0' '0' '0' '0' '0' '0' '0' '1' '0' '1' '0'
  143. long millis1=System.currentTimeMillis();
  144. CobolFieldFormatter.format(value,buffer,cobolTypeDescriptor,0);
  145. long millis2=System.currentTimeMillis();
  146. log.debug("buffer dopo il format in string: ["+new String(buffer,DeafultHostCodePage)+"]");
  147. log.debug("buffer dopo il format in esadecimale: ["+HexDump.toHex(buffer)+"]");
  148. log.debug("buffer expected in esadecimale: ["+HexDump.toHex(expectedBuffer)+"]");
  149. log.debug("conversion time="+(millis2-millis1)+" millis");
  150. assertTrue("conversione non corretta",Arrays.equals(expectedBuffer,buffer));
  151. }
  152. catch(Exception e){
  153. e.printStackTrace();
  154. fail(e.getMessage());
  155. }
  156. }
  157. /**
  158. * testo un zoned
  159. * PIC s9(10)v9(2)
  160. * con valore 10.10
  161. *
  162. */
  163. public void testZonedsp9_10_9_2(){
  164. try{
  165. CobolTypeDescriptor cobolTypeDescriptor=new CobolTypeDescriptor();
  166. cobolTypeDescriptor.setType(CobolType.ZONED);
  167. cobolTypeDescriptor.setIntegerPartLength(10);
  168. cobolTypeDescriptor.setDecimalPartLength(2);
  169. cobolTypeDescriptor.setCodePage(DeafultHostCodePage);
  170. cobolTypeDescriptor.setZonedSignFormat(CobolTypeDescriptor.SIGN_FORMAT_TRAILING);
  171. cobolTypeDescriptor.setPadCharacter(" ");
  172. cobolTypeDescriptor.setSigned(true);
  173. BigDecimal value=BigDecimal.valueOf(10.10);
  174. byte[] buffer=new byte[12];
  175. byte[] expectedBuffer=new byte[] {(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf1,(byte)0xf0,(byte)0xf1,(byte)0xc0};
  176. // '0' '0' '0' '0' '0' '0' '0' '0' '1' '0' '1' '0'
  177. long millis1=System.currentTimeMillis();
  178. CobolFieldFormatter.format(value,buffer,cobolTypeDescriptor,0);
  179. long millis2=System.currentTimeMillis();
  180. log.debug("buffer dopo il format in string: ["+new String(buffer,DeafultHostCodePage)+"]");
  181. log.debug("buffer dopo il format in esadecimale: ["+HexDump.toHex(buffer)+"]");
  182. log.debug("buffer expected in esadecimale: ["+HexDump.toHex(expectedBuffer)+"]");
  183. log.debug("conversion time="+(millis2-millis1)+" millis");
  184. assertTrue("conversione non corretta",Arrays.equals(expectedBuffer,buffer));
  185. }
  186. catch(Exception e){
  187. e.printStackTrace();
  188. fail(e.getMessage());
  189. }
  190. }
  191. /**
  192. * testo un zoned
  193. * PIC s9(10)v9(2)
  194. * con valore 10.10
  195. *
  196. */
  197. public void testZonedsm9_10_9_2(){
  198. try{
  199. CobolTypeDescriptor cobolTypeDescriptor=new CobolTypeDescriptor();
  200. cobolTypeDescriptor.setType(CobolType.ZONED);
  201. cobolTypeDescriptor.setIntegerPartLength(10);
  202. cobolTypeDescriptor.setDecimalPartLength(2);
  203. cobolTypeDescriptor.setCodePage(DeafultHostCodePage);
  204. cobolTypeDescriptor.setZonedSignFormat(CobolTypeDescriptor.SIGN_FORMAT_TRAILING);
  205. cobolTypeDescriptor.setPadCharacter(" ");
  206. cobolTypeDescriptor.setSigned(true);
  207. BigDecimal value=BigDecimal.valueOf(-10.10);
  208. byte[] buffer=new byte[12];
  209. byte[] expectedBuffer=new byte[] {(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf1,(byte)0xf0,(byte)0xf1,(byte)0xd0};
  210. // '0' '0' '0' '0' '0' '0' '0' '0' '1' '0' '1' '0'
  211. long millis1=System.currentTimeMillis();
  212. CobolFieldFormatter.format(value,buffer,cobolTypeDescriptor,0);
  213. long millis2=System.currentTimeMillis();
  214. log.debug("buffer dopo il format in string: ["+new String(buffer,DeafultHostCodePage)+"]");
  215. log.debug("buffer dopo il format in esadecimale: ["+HexDump.toHex(buffer)+"]");
  216. log.debug("buffer expected in esadecimale: ["+HexDump.toHex(expectedBuffer)+"]");
  217. log.debug("conversion time="+(millis2-millis1)+" millis");
  218. assertTrue("conversione non corretta",Arrays.equals(expectedBuffer,buffer));
  219. }
  220. catch(Exception e){
  221. e.printStackTrace();
  222. fail(e.getMessage());
  223. }
  224. }
  225. /**
  226. * testo un zoned
  227. * PIC 9(10)
  228. * con valore 10
  229. *
  230. */
  231. public void testUnformatZoned9_10(){
  232. try{
  233. CobolTypeDescriptor cobolTypeDescriptor=new CobolTypeDescriptor();
  234. cobolTypeDescriptor.setType(CobolType.ZONED);
  235. cobolTypeDescriptor.setIntegerPartLength(10);
  236. cobolTypeDescriptor.setCodePage(DeafultHostCodePage);
  237. cobolTypeDescriptor.setZonedSignFormat(CobolTypeDescriptor.SIGN_FORMAT_TRAILING);
  238. cobolTypeDescriptor.setPadCharacter(" ");
  239. BigDecimal value=BigDecimal.valueOf(10);
  240. byte[] buffer=new byte[] {(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf1,(byte)0xf0};
  241. // '0' '0' '0' '0' '0' '0' '0' '0' '1' '0'
  242. long millis1=System.currentTimeMillis();
  243. Object result=CobolFieldFormatter.unformat(buffer,cobolTypeDescriptor,0);
  244. long millis2=System.currentTimeMillis();
  245. log.debug("value ottenuto: ["+result.toString()+"]");
  246. log.debug("buffer esadecimale: ["+HexDump.toHex(buffer)+"]");
  247. log.debug("conversion time="+(millis2-millis1)+" millis");
  248. assertEquals("conversione non corretta",value,result);
  249. }
  250. catch(Exception e){
  251. e.printStackTrace();
  252. fail(e.getMessage());
  253. }
  254. }
  255. /**
  256. * testo un zoned
  257. * PIC s9(10)
  258. * con valore 10
  259. *
  260. */
  261. public void testUnformatZonedsp9_10(){
  262. try{
  263. CobolTypeDescriptor cobolTypeDescriptor=new CobolTypeDescriptor();
  264. cobolTypeDescriptor.setType(CobolType.ZONED);
  265. cobolTypeDescriptor.setIntegerPartLength(10);
  266. cobolTypeDescriptor.setCodePage(DeafultHostCodePage);
  267. cobolTypeDescriptor.setPadCharacter(" ");
  268. cobolTypeDescriptor.setZonedSignFormat(CobolTypeDescriptor.SIGN_FORMAT_TRAILING);
  269. cobolTypeDescriptor.setSigned(true);
  270. BigDecimal value=BigDecimal.valueOf(10);
  271. byte[] buffer=new byte[] {(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf1,(byte)0xc0};
  272. // '0' '0' '0' '0' '0' '0' '0' '0' '1' '0'
  273. long millis1=System.currentTimeMillis();
  274. Object result=CobolFieldFormatter.unformat(buffer,cobolTypeDescriptor,0);
  275. long millis2=System.currentTimeMillis();
  276. log.debug("value ottenuto: ["+result.toString()+"]");
  277. log.debug("buffer esadecimale: ["+HexDump.toHex(buffer)+"]");
  278. log.debug("conversion time="+(millis2-millis1)+" millis");
  279. assertEquals("conversione non corretta",value,result);
  280. }
  281. catch(Exception e){
  282. e.printStackTrace();
  283. fail(e.getMessage());
  284. }
  285. }
  286. /**
  287. * testo un zoned
  288. * PIC s9(10)
  289. * con valore 10
  290. *
  291. */
  292. public void testUnformatZonedsm9_10(){
  293. try{
  294. CobolTypeDescriptor cobolTypeDescriptor=new CobolTypeDescriptor();
  295. cobolTypeDescriptor.setType(CobolType.ZONED);
  296. cobolTypeDescriptor.setIntegerPartLength(10);
  297. cobolTypeDescriptor.setCodePage(DeafultHostCodePage);
  298. cobolTypeDescriptor.setZonedSignFormat(CobolTypeDescriptor.SIGN_FORMAT_TRAILING);
  299. cobolTypeDescriptor.setPadCharacter(" ");
  300. cobolTypeDescriptor.setSigned(true);
  301. BigDecimal value=BigDecimal.valueOf(-10);
  302. byte[] buffer=new byte[] {(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf1,(byte)0xd0};
  303. // '0' '0' '0' '0' '0' '0' '0' '0' '1' '0'
  304. long millis1=System.currentTimeMillis();
  305. Object result=CobolFieldFormatter.unformat(buffer,cobolTypeDescriptor,0);
  306. long millis2=System.currentTimeMillis();
  307. log.debug("value ottenuto: ["+result.toString()+"]");
  308. log.debug("buffer esadecimale: ["+HexDump.toHex(buffer)+"]");
  309. log.debug("conversion time="+(millis2-millis1)+" millis");
  310. assertEquals("conversione non corretta",value,result);
  311. }
  312. catch(Exception e){
  313. e.printStackTrace();
  314. fail(e.getMessage());
  315. }
  316. }
  317. /**
  318. * testo un zoned
  319. * PIC 9(10)v9(2)
  320. * con valore 10.10
  321. *
  322. */
  323. public void testUnformatZoned9_10_9_2(){
  324. try{
  325. CobolTypeDescriptor cobolTypeDescriptor=new CobolTypeDescriptor();
  326. cobolTypeDescriptor.setType(CobolType.ZONED);
  327. cobolTypeDescriptor.setIntegerPartLength(10);
  328. cobolTypeDescriptor.setDecimalPartLength(2);
  329. cobolTypeDescriptor.setCodePage(DeafultHostCodePage);
  330. cobolTypeDescriptor.setZonedSignFormat(CobolTypeDescriptor.SIGN_FORMAT_TRAILING);
  331. cobolTypeDescriptor.setPadCharacter(" ");
  332. BigDecimal value=new BigDecimal(10.10,new MathContext(4));
  333. byte[] buffer=new byte[] {(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf1,(byte)0xf0,(byte)0xf1,(byte)0xf0};
  334. // '0' '0' '0' '0' '0' '0' '0' '0' '1' '0' '1' '0'
  335. long millis1=System.currentTimeMillis();
  336. Object result=CobolFieldFormatter.unformat(buffer,cobolTypeDescriptor,0);
  337. long millis2=System.currentTimeMillis();
  338. log.debug("value ottenuto: ["+result.toString()+"]");
  339. log.debug("buffer esadecimale: ["+HexDump.toHex(buffer)+"]");
  340. log.debug("conversion time="+(millis2-millis1)+" millis");
  341. assertEquals("conversione non corretta",value,result);
  342. }
  343. catch(Exception e){
  344. e.printStackTrace();
  345. fail(e.getMessage());
  346. }
  347. }
  348. /**
  349. * testo un zoned
  350. * PIC s9(10)v9(2)
  351. * con valore 10.10
  352. *
  353. */
  354. public void testUnformatZonedsp9_10_9_2(){
  355. try{
  356. CobolTypeDescriptor cobolTypeDescriptor=new CobolTypeDescriptor();
  357. cobolTypeDescriptor.setType(CobolType.ZONED);
  358. cobolTypeDescriptor.setIntegerPartLength(10);
  359. cobolTypeDescriptor.setDecimalPartLength(2);
  360. cobolTypeDescriptor.setCodePage(DeafultHostCodePage);
  361. cobolTypeDescriptor.setZonedSignFormat(CobolTypeDescriptor.SIGN_FORMAT_TRAILING);
  362. cobolTypeDescriptor.setPadCharacter(" ");
  363. cobolTypeDescriptor.setSigned(true);
  364. BigDecimal value=new BigDecimal(10.10,new MathContext(4));
  365. byte[] buffer=new byte[] {(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf1,(byte)0xf0,(byte)0xf1,(byte)0xc0};
  366. // '0' '0' '0' '0' '0' '0' '0' '0' '1' '0' '1' '0'
  367. long millis1=System.currentTimeMillis();
  368. Object result=CobolFieldFormatter.unformat(buffer,cobolTypeDescriptor,0);
  369. long millis2=System.currentTimeMillis();
  370. log.debug("value ottenuto: ["+result.toString()+"]");
  371. log.debug("buffer esadecimale: ["+HexDump.toHex(buffer)+"]");
  372. log.debug("conversion time="+(millis2-millis1)+" millis");
  373. assertEquals("conversione non corretta",value,result);
  374. }
  375. catch(Exception e){
  376. e.printStackTrace();
  377. fail(e.getMessage());
  378. }
  379. }
  380. /**
  381. * testo un zoned
  382. * PIC s9(10)v9(2)
  383. * con valore 10.10
  384. *
  385. */
  386. public void testUnformatZonedsm9_10_9_2(){
  387. try{
  388. CobolTypeDescriptor cobolTypeDescriptor=new CobolTypeDescriptor();
  389. cobolTypeDescriptor.setType(CobolType.ZONED);
  390. cobolTypeDescriptor.setIntegerPartLength(10);
  391. cobolTypeDescriptor.setDecimalPartLength(2);
  392. cobolTypeDescriptor.setCodePage(DeafultHostCodePage);
  393. cobolTypeDescriptor.setZonedSignFormat(CobolTypeDescriptor.SIGN_FORMAT_TRAILING);
  394. cobolTypeDescriptor.setPadCharacter(" ");
  395. cobolTypeDescriptor.setSigned(true);
  396. // a causa del fatto che equals funziona se il valore e la precisione sono
  397. // gli stessi e che da host ritorna una precisione 4 mentre in java a causa dello 0 la precisione va a 3, gliela forzo a 4.
  398. // non ho indagato se in futuro questo possa essere un baco.
  399. BigDecimal value=new BigDecimal(-10.10,new MathContext(4));
  400. byte[] buffer=new byte[] {(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf1,(byte)0xf0,(byte)0xf1,(byte)0xd0};
  401. // '0' '0' '0' '0' '0' '0' '0' '0' '1' '0' '1' '0'
  402. long millis1=System.currentTimeMillis();
  403. Object result=CobolFieldFormatter.unformat(buffer,cobolTypeDescriptor,0);
  404. long millis2=System.currentTimeMillis();
  405. log.debug("result ottenuto: ["+result.toString()+"]");
  406. log.debug("value originale: ["+value.toString()+"]");
  407. log.debug("buffer esadecimale: ["+HexDump.toHex(buffer)+"]");
  408. log.debug("conversion time="+(millis2-millis1)+" millis");
  409. assertEquals("conversione non corretta",value,result);
  410. }
  411. catch(Exception e){
  412. e.printStackTrace();
  413. fail(e.getMessage());
  414. }
  415. }
  416. /**
  417. * testo un zoned
  418. * PIC +9(10)
  419. * con valore 10
  420. *
  421. */
  422. public void testZonedpp9_10(){
  423. try{
  424. CobolTypeDescriptor cobolTypeDescriptor=new CobolTypeDescriptor();
  425. cobolTypeDescriptor.setType(CobolType.ZONED);
  426. cobolTypeDescriptor.setIntegerPartLength(10);
  427. cobolTypeDescriptor.setCodePage(DeafultHostCodePage);
  428. cobolTypeDescriptor.setPadCharacter(" ");
  429. //cobolTypeDescriptor.setZonedDecimalSign(CobolTypeDescriptor.EXTERNAL_DECIMAL_SIGN_ASCII);
  430. cobolTypeDescriptor.setZonedSignFormat(CobolTypeDescriptor.SIGN_FORMAT_LEADING_SEPARATE);
  431. cobolTypeDescriptor.setSigned(true);
  432. BigInteger value=BigInteger.valueOf(10);
  433. byte[] buffer=new byte[11];
  434. byte[] expectedBuffer=new byte[] {(byte)0x4e,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf1,(byte)0xf0};
  435. // '+' '0' '0' '0' '0' '0' '0' '0' '0' '1' '0'
  436. long millis1=System.currentTimeMillis();
  437. CobolFieldFormatter.format(value,buffer,cobolTypeDescriptor,0);
  438. long millis2=System.currentTimeMillis();
  439. log.debug("buffer dopo il format in string: ["+new String(buffer,DeafultHostCodePage)+"]");
  440. log.debug("buffer dopo il format in esadecimale: ["+HexDump.toHex(buffer)+"]");
  441. log.debug("buffer expected in esadecimale: ["+HexDump.toHex(expectedBuffer)+"]");
  442. log.debug("conversion time="+(millis2-millis1)+" millis");
  443. assertTrue("conversione non corretta",Arrays.equals(expectedBuffer,buffer));
  444. }
  445. catch(Exception e){
  446. e.printStackTrace();
  447. fail(e.getMessage());
  448. }
  449. }
  450. public void testZonedmm9_10(){
  451. try{
  452. CobolTypeDescriptor cobolTypeDescriptor=new CobolTypeDescriptor();
  453. cobolTypeDescriptor.setType(CobolType.ZONED);
  454. cobolTypeDescriptor.setIntegerPartLength(10);
  455. cobolTypeDescriptor.setCodePage(DeafultHostCodePage);
  456. cobolTypeDescriptor.setPadCharacter(" ");
  457. //cobolTypeDescriptor.setZonedDecimalSign(CobolTypeDescriptor.EXTERNAL_DECIMAL_SIGN_ASCII);
  458. cobolTypeDescriptor.setZonedSignFormat(CobolTypeDescriptor.SIGN_FORMAT_LEADING_SEPARATE);
  459. cobolTypeDescriptor.setSigned(true);
  460. BigInteger value=BigInteger.valueOf(-10);
  461. byte[] buffer=new byte[11];
  462. byte[] expectedBuffer=new byte[] {(byte)0x60,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf0,(byte)0xf1,(byte)0xf0};
  463. // '-' '0' '0' '0' '0' '0' '0' '0' '0' '1' '0'
  464. long millis1=System.currentTimeMillis();
  465. CobolFieldFormatter.format(value,buffer,cobolTypeDescriptor,0);
  466. long millis2=System.currentTimeMillis();
  467. log.debug("buffer dopo il format in string: ["+new String(buffer,DeafultHostCodePage)+"]");
  468. log.debug("buffer dopo il format in esadecimale: ["+HexDump.toHex(buffer)+"]");
  469. log.debug("buffer expected in esadecimale: ["+HexDump.toHex(expectedBuffer)+"]");
  470. log.debug("conversion time="+(millis2-millis1)+" millis");
  471. assertTrue("conversione non corretta",Arrays.equals(expectedBuffer,buffer));
  472. }
  473. catch(Exception e){
  474. e.printStackTrace();
  475. fail(e.getMessage());
  476. }
  477. }
  478. }