/src/test/java/io/proleap/cobol/asg/procedure/close/CloseStatementTest.java

https://github.com/uwol/proleap-cobol-parser · Java · 317 lines · 256 code · 61 blank · 0 comment · 0 complexity · d9930f8ac901fdd151243a8cb7559144 MD5 · raw file

  1. package io.proleap.cobol.asg.procedure.close;
  2. import static org.junit.Assert.assertEquals;
  3. import static org.junit.Assert.assertFalse;
  4. import static org.junit.Assert.assertNotNull;
  5. import static org.junit.Assert.assertTrue;
  6. import java.io.File;
  7. import java.math.BigDecimal;
  8. import java.util.List;
  9. import org.junit.Test;
  10. import io.proleap.cobol.CobolTestBase;
  11. import io.proleap.cobol.asg.metamodel.CompilationUnit;
  12. import io.proleap.cobol.asg.metamodel.IntegerLiteral;
  13. import io.proleap.cobol.asg.metamodel.Program;
  14. import io.proleap.cobol.asg.metamodel.ProgramUnit;
  15. import io.proleap.cobol.asg.metamodel.call.Call;
  16. import io.proleap.cobol.asg.metamodel.call.Call.CallType;
  17. import io.proleap.cobol.asg.metamodel.call.FileControlEntryCall;
  18. import io.proleap.cobol.asg.metamodel.environment.EnvironmentDivision;
  19. import io.proleap.cobol.asg.metamodel.environment.inputoutput.InputOutputSection;
  20. import io.proleap.cobol.asg.metamodel.environment.inputoutput.filecontrol.FileControlEntry;
  21. import io.proleap.cobol.asg.metamodel.environment.inputoutput.filecontrol.FileControlParagraph;
  22. import io.proleap.cobol.asg.metamodel.procedure.ProcedureDivision;
  23. import io.proleap.cobol.asg.metamodel.procedure.StatementTypeEnum;
  24. import io.proleap.cobol.asg.metamodel.procedure.close.AssociatedDataLengthPhrase;
  25. import io.proleap.cobol.asg.metamodel.procedure.close.AssociatedDataPhrase;
  26. import io.proleap.cobol.asg.metamodel.procedure.close.CloseDispositionPhrase;
  27. import io.proleap.cobol.asg.metamodel.procedure.close.CloseFile;
  28. import io.proleap.cobol.asg.metamodel.procedure.close.ClosePortFileIoStatement;
  29. import io.proleap.cobol.asg.metamodel.procedure.close.CloseReelUnitStatement;
  30. import io.proleap.cobol.asg.metamodel.procedure.close.CloseRelativeStatement;
  31. import io.proleap.cobol.asg.metamodel.procedure.close.CloseStatement;
  32. import io.proleap.cobol.asg.metamodel.procedure.close.Using;
  33. import io.proleap.cobol.asg.metamodel.valuestmt.CallValueStmt;
  34. import io.proleap.cobol.asg.metamodel.valuestmt.IntegerLiteralValueStmt;
  35. import io.proleap.cobol.asg.runner.impl.CobolParserRunnerImpl;
  36. import io.proleap.cobol.preprocessor.CobolPreprocessor.CobolSourceFormatEnum;
  37. public class CloseStatementTest extends CobolTestBase {
  38. @Test
  39. public void test() throws Exception {
  40. final File inputFile = new File("src/test/resources/io/proleap/cobol/asg/procedure/close/CloseStatement.cbl");
  41. final Program program = new CobolParserRunnerImpl().analyzeFile(inputFile, CobolSourceFormatEnum.TANDEM);
  42. final CompilationUnit compilationUnit = program.getCompilationUnit("CloseStatement");
  43. final ProgramUnit programUnit = compilationUnit.getProgramUnit();
  44. final FileControlEntry fileControlEntry1a;
  45. final FileControlEntry fileControlEntry1b;
  46. final FileControlEntry fileControlEntry2;
  47. final FileControlEntry fileControlEntry3;
  48. final FileControlEntry fileControlEntry4;
  49. final FileControlEntry fileControlEntry5;
  50. {
  51. final EnvironmentDivision environmentDivision = programUnit.getEnvironmentDivision();
  52. {
  53. final InputOutputSection inputOutputSection = environmentDivision.getInputOutputSection();
  54. {
  55. final FileControlParagraph fileControlParagraph = inputOutputSection.getFileControlParagraph();
  56. {
  57. fileControlEntry1a = fileControlParagraph.getFileControlEntry("SOMEFILE1A");
  58. assertNotNull(fileControlEntry1a);
  59. assertEquals(3, fileControlEntry1a.getCalls().size());
  60. }
  61. {
  62. fileControlEntry1b = fileControlParagraph.getFileControlEntry("SOMEFILE1B");
  63. assertNotNull(fileControlEntry1b);
  64. assertEquals(3, fileControlEntry1b.getCalls().size());
  65. }
  66. {
  67. fileControlEntry2 = fileControlParagraph.getFileControlEntry("SOMEFILE2");
  68. assertNotNull(fileControlEntry2);
  69. assertEquals(3, fileControlEntry2.getCalls().size());
  70. }
  71. {
  72. fileControlEntry3 = fileControlParagraph.getFileControlEntry("SOMEFILE3");
  73. assertNotNull(fileControlEntry3);
  74. assertEquals(3, fileControlEntry3.getCalls().size());
  75. }
  76. {
  77. fileControlEntry4 = fileControlParagraph.getFileControlEntry("SOMEFILE4");
  78. assertNotNull(fileControlEntry4);
  79. assertEquals(3, fileControlEntry4.getCalls().size());
  80. }
  81. {
  82. fileControlEntry5 = fileControlParagraph.getFileControlEntry("SOMEFILE5");
  83. assertNotNull(fileControlEntry5);
  84. assertEquals(3, fileControlEntry5.getCalls().size());
  85. }
  86. }
  87. }
  88. }
  89. final ProcedureDivision procedureDivision = programUnit.getProcedureDivision();
  90. assertEquals(0, procedureDivision.getParagraphs().size());
  91. assertEquals(5, procedureDivision.getStatements().size());
  92. {
  93. final CloseStatement closeStatement = (CloseStatement) procedureDivision.getStatements().get(0);
  94. assertEquals(StatementTypeEnum.CLOSE, closeStatement.getStatementType());
  95. {
  96. final CloseFile closeFile = closeStatement.getCloseFiles().get(0);
  97. {
  98. final Call call = closeFile.getFileCall();
  99. assertNotNull(call);
  100. assertEquals(CallType.FILE_CONTROL_ENTRY_CALL, call.getCallType());
  101. {
  102. final FileControlEntryCall fileControlEntryCall = (FileControlEntryCall) call;
  103. assertEquals(fileControlEntry1a, fileControlEntryCall.getFileControlEntry());
  104. }
  105. }
  106. assertEquals(CloseFile.CloseFileType.REEL_UNIT, closeFile.getCloseFileType());
  107. {
  108. final CloseReelUnitStatement closeReelUnitStatement = closeFile.getCloseReelUnitStatement();
  109. assertEquals(CloseReelUnitStatement.CloseReelUnitType.UNIT,
  110. closeReelUnitStatement.getCloseReelUnitType());
  111. assertTrue(closeReelUnitStatement.isForRemovel());
  112. assertEquals(CloseReelUnitStatement.WithType.LOCK, closeReelUnitStatement.getWithType());
  113. }
  114. }
  115. {
  116. final CloseFile closeFile = closeStatement.getCloseFiles().get(1);
  117. {
  118. final Call call = closeFile.getFileCall();
  119. assertNotNull(call);
  120. assertEquals(CallType.FILE_CONTROL_ENTRY_CALL, call.getCallType());
  121. {
  122. final FileControlEntryCall fileControlEntryCall = (FileControlEntryCall) call;
  123. assertEquals(fileControlEntry1b, fileControlEntryCall.getFileControlEntry());
  124. }
  125. }
  126. assertEquals(CloseFile.CloseFileType.REEL_UNIT, closeFile.getCloseFileType());
  127. {
  128. final CloseReelUnitStatement closeReelUnitStatement = closeFile.getCloseReelUnitStatement();
  129. assertEquals(CloseReelUnitStatement.CloseReelUnitType.REEL,
  130. closeReelUnitStatement.getCloseReelUnitType());
  131. assertFalse(closeReelUnitStatement.isForRemovel());
  132. }
  133. }
  134. }
  135. {
  136. final CloseStatement closeStatement = (CloseStatement) procedureDivision.getStatements().get(1);
  137. assertEquals(StatementTypeEnum.CLOSE, closeStatement.getStatementType());
  138. {
  139. final CloseFile closeFile = closeStatement.getCloseFiles().get(0);
  140. {
  141. final Call call = closeFile.getFileCall();
  142. assertNotNull(call);
  143. assertEquals(CallType.FILE_CONTROL_ENTRY_CALL, call.getCallType());
  144. {
  145. final FileControlEntryCall fileControlEntryCall = (FileControlEntryCall) call;
  146. assertEquals(fileControlEntry2, fileControlEntryCall.getFileControlEntry());
  147. }
  148. }
  149. assertEquals(CloseFile.CloseFileType.RELATIVE, closeFile.getCloseFileType());
  150. {
  151. final CloseRelativeStatement closeRelativeStatement = closeFile.getCloseRelativeStatement();
  152. assertEquals(CloseRelativeStatement.WithType.LOCK, closeRelativeStatement.getWithType());
  153. }
  154. }
  155. }
  156. {
  157. final CloseStatement closeStatement = (CloseStatement) procedureDivision.getStatements().get(2);
  158. assertEquals(StatementTypeEnum.CLOSE, closeStatement.getStatementType());
  159. {
  160. final CloseFile closeFile = closeStatement.getCloseFiles().get(0);
  161. {
  162. final Call call = closeFile.getFileCall();
  163. assertNotNull(call);
  164. assertEquals(CallType.FILE_CONTROL_ENTRY_CALL, call.getCallType());
  165. {
  166. final FileControlEntryCall fileControlEntryCall = (FileControlEntryCall) call;
  167. assertEquals(fileControlEntry3, fileControlEntryCall.getFileControlEntry());
  168. }
  169. }
  170. assertEquals(CloseFile.CloseFileType.PORT_FILE_IO, closeFile.getCloseFileType());
  171. {
  172. final ClosePortFileIoStatement closePortFileIOStatement = closeFile.getClosePortFileIOStatement();
  173. assertEquals(ClosePortFileIoStatement.WithType.WAIT, closePortFileIOStatement.getWithType());
  174. {
  175. final List<Using> usings = closePortFileIOStatement.getUsings();
  176. final Using using = usings.get(0);
  177. assertEquals(Using.UsingType.CLOSE_DISPOSITION, using.getUsingType());
  178. {
  179. final CloseDispositionPhrase closeDispositionPhrase = using.getCloseDispositionPhrase();
  180. assertEquals(CloseDispositionPhrase.UsingCloseDispositionType.ORDERLY,
  181. closeDispositionPhrase.getUsingCloseDispositionType());
  182. }
  183. }
  184. }
  185. }
  186. }
  187. {
  188. final CloseStatement closeStatement = (CloseStatement) procedureDivision.getStatements().get(3);
  189. assertEquals(StatementTypeEnum.CLOSE, closeStatement.getStatementType());
  190. {
  191. final CloseFile closeFile = closeStatement.getCloseFiles().get(0);
  192. {
  193. final Call call = closeFile.getFileCall();
  194. assertNotNull(call);
  195. assertEquals(CallType.FILE_CONTROL_ENTRY_CALL, call.getCallType());
  196. {
  197. final FileControlEntryCall fileControlEntryCall = (FileControlEntryCall) call;
  198. assertEquals(fileControlEntry4, fileControlEntryCall.getFileControlEntry());
  199. }
  200. }
  201. assertEquals(CloseFile.CloseFileType.PORT_FILE_IO, closeFile.getCloseFileType());
  202. {
  203. final ClosePortFileIoStatement closePortFileIOStatement = closeFile.getClosePortFileIOStatement();
  204. assertEquals(ClosePortFileIoStatement.WithType.NO_WAIT, closePortFileIOStatement.getWithType());
  205. {
  206. final List<Using> usings = closePortFileIOStatement.getUsings();
  207. final Using using = usings.get(0);
  208. assertEquals(Using.UsingType.ASSOCIATED_DATA, using.getUsingType());
  209. {
  210. final AssociatedDataPhrase associatedDataPhrase = using.getAssociatedDataPhrase();
  211. assertNotNull(associatedDataPhrase.getDataValueStmt());
  212. final IntegerLiteralValueStmt dataLiteralValueStmt = (IntegerLiteralValueStmt) associatedDataPhrase
  213. .getDataValueStmt();
  214. final IntegerLiteral literal = dataLiteralValueStmt.getLiteral();
  215. assertEquals(new BigDecimal(4), literal.getValue());
  216. }
  217. }
  218. }
  219. }
  220. }
  221. {
  222. final CloseStatement closeStatement = (CloseStatement) procedureDivision.getStatements().get(4);
  223. assertEquals(StatementTypeEnum.CLOSE, closeStatement.getStatementType());
  224. {
  225. final CloseFile closeFile = closeStatement.getCloseFiles().get(0);
  226. {
  227. final Call call = closeFile.getFileCall();
  228. assertNotNull(call);
  229. assertEquals(CallType.FILE_CONTROL_ENTRY_CALL, call.getCallType());
  230. {
  231. final FileControlEntryCall fileControlEntryCall = (FileControlEntryCall) call;
  232. assertEquals(fileControlEntry5, fileControlEntryCall.getFileControlEntry());
  233. }
  234. }
  235. assertEquals(CloseFile.CloseFileType.PORT_FILE_IO, closeFile.getCloseFileType());
  236. {
  237. final ClosePortFileIoStatement closePortFileIOStatement = closeFile.getClosePortFileIOStatement();
  238. assertEquals(ClosePortFileIoStatement.WithType.NO_WAIT, closePortFileIOStatement.getWithType());
  239. {
  240. final List<Using> usings = closePortFileIOStatement.getUsings();
  241. final Using using = usings.get(0);
  242. assertEquals(Using.UsingType.ASSOCIATED_DATA_LENGTH, using.getUsingType());
  243. {
  244. final AssociatedDataLengthPhrase associatedDataLengthPhrase = using
  245. .getAssociatedDataLengthPhrase();
  246. assertNotNull(associatedDataLengthPhrase.getDataLengthValueStmt());
  247. final CallValueStmt dataLengthCallValueStmt = (CallValueStmt) associatedDataLengthPhrase
  248. .getDataLengthValueStmt();
  249. assertEquals(CallType.UNDEFINED_CALL, dataLengthCallValueStmt.getCall().getCallType());
  250. }
  251. }
  252. }
  253. }
  254. }
  255. }
  256. }