-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathCallStatementTest.java
168 lines (135 loc) · 6.73 KB
/
CallStatementTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package io.proleap.cobol.asg.procedure.call;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.io.File;
import java.math.BigDecimal;
import org.junit.Test;
import io.proleap.cobol.CobolTestBase;
import io.proleap.cobol.asg.metamodel.CompilationUnit;
import io.proleap.cobol.asg.metamodel.Literal;
import io.proleap.cobol.asg.metamodel.Program;
import io.proleap.cobol.asg.metamodel.ProgramUnit;
import io.proleap.cobol.asg.metamodel.call.Call.CallType;
import io.proleap.cobol.asg.metamodel.procedure.ProcedureDivision;
import io.proleap.cobol.asg.metamodel.procedure.StatementTypeEnum;
import io.proleap.cobol.asg.metamodel.procedure.call.ByContent;
import io.proleap.cobol.asg.metamodel.procedure.call.ByContentPhrase;
import io.proleap.cobol.asg.metamodel.procedure.call.ByReference;
import io.proleap.cobol.asg.metamodel.procedure.call.ByReferencePhrase;
import io.proleap.cobol.asg.metamodel.procedure.call.ByValue;
import io.proleap.cobol.asg.metamodel.procedure.call.ByValuePhrase;
import io.proleap.cobol.asg.metamodel.procedure.call.CallStatement;
import io.proleap.cobol.asg.metamodel.procedure.call.GivingPhrase;
import io.proleap.cobol.asg.metamodel.procedure.call.UsingParameter;
import io.proleap.cobol.asg.metamodel.procedure.call.UsingPhrase;
import io.proleap.cobol.asg.metamodel.valuestmt.CallValueStmt;
import io.proleap.cobol.asg.metamodel.valuestmt.LiteralValueStmt;
import io.proleap.cobol.asg.metamodel.valuestmt.ValueStmt;
import io.proleap.cobol.asg.runner.impl.CobolParserRunnerImpl;
import io.proleap.cobol.preprocessor.CobolPreprocessor.CobolSourceFormatEnum;
public class CallStatementTest extends CobolTestBase {
@Test
public void test() throws Exception {
final File inputFile = new File("src/test/resources/io/proleap/cobol/asg/procedure/call/CallStatement.cbl");
final Program program = new CobolParserRunnerImpl().analyzeFile(inputFile, CobolSourceFormatEnum.TANDEM);
final CompilationUnit compilationUnit = program.getCompilationUnit("CallStatement");
final ProgramUnit programUnit = compilationUnit.getProgramUnit();
final ProcedureDivision procedureDivision = programUnit.getProcedureDivision();
assertEquals(0, procedureDivision.getParagraphs().size());
assertEquals(1, procedureDivision.getStatements().size());
{
final CallStatement callStatement = (CallStatement) procedureDivision.getStatements().get(0);
assertEquals(StatementTypeEnum.CALL, callStatement.getStatementType());
{
final ValueStmt programValueStmt = callStatement.getProgramValueStmt();
assertNotNull(programValueStmt);
final CallValueStmt programCallValueStmt = (CallValueStmt) programValueStmt;
assertEquals(CallType.UNDEFINED_CALL, programCallValueStmt.getCall().getCallType());
}
{
final GivingPhrase givingPhrase = callStatement.getGivingPhrase();
assertNotNull(givingPhrase.getGivingCall());
assertEquals(CallType.UNDEFINED_CALL, givingPhrase.getGivingCall().getCallType());
}
{
final UsingPhrase usingPhrase = callStatement.getUsingPhrase();
assertEquals(3, usingPhrase.getUsingParameters().size());
{
final UsingParameter parameter = usingPhrase.getUsingParameters().get(0);
assertEquals(UsingParameter.ParameterType.REFERENCE, parameter.getParameterType());
{
final ByReferencePhrase byReferencePhrase = parameter.getByReferencePhrase();
assertEquals(2, byReferencePhrase.getByReferences().size());
{
final ByReference byReference = byReferencePhrase.getByReferences().get(0);
assertEquals(ByReference.ByReferenceType.INTEGER, byReference.getByReferenceType());
final CallValueStmt callValueStmt = (CallValueStmt) byReference.getValueStmt();
assertEquals(CallType.UNDEFINED_CALL, callValueStmt.getCall().getCallType());
}
{
final ByReference byReference = byReferencePhrase.getByReferences().get(1);
assertNull(byReference.getByReferenceType());
final CallValueStmt callValueStmt = (CallValueStmt) byReference.getValueStmt();
assertEquals(CallType.UNDEFINED_CALL, callValueStmt.getCall().getCallType());
}
}
}
{
final UsingParameter parameter = usingPhrase.getUsingParameters().get(1);
assertEquals(UsingParameter.ParameterType.VALUE, parameter.getParameterType());
final ByValuePhrase byValuePhrase = parameter.getByValuePhrase();
assertEquals(3, byValuePhrase.getByValues().size());
{
final ByValue byValue = byValuePhrase.getByValues().get(0);
final ValueStmt valueStmt = byValue.getValueStmt();
final LiteralValueStmt literalValueStmt = (LiteralValueStmt) valueStmt;
final Literal literal = literalValueStmt.getLiteral();
assertEquals(BigDecimal.ONE, literal.getValue());
}
{
final ByValue byValue = byValuePhrase.getByValues().get(1);
final ValueStmt valueStmt = byValue.getValueStmt();
final LiteralValueStmt literalValueStmt = (LiteralValueStmt) valueStmt;
final Literal literal = literalValueStmt.getLiteral();
assertEquals(new BigDecimal(2), literal.getValue());
}
{
final ByValue byValue = byValuePhrase.getByValues().get(2);
assertNotNull(byValue.getValueStmt());
}
}
{
final UsingParameter parameter = usingPhrase.getUsingParameters().get(2);
assertEquals(UsingParameter.ParameterType.CONTENT, parameter.getParameterType());
{
final ByContentPhrase byContentPhrase = parameter.getByContentPhrase();
assertEquals(3, byContentPhrase.getByContents().size());
{
final ByContent byContent = byContentPhrase.getByContents().get(0);
assertEquals(ByContent.ByContentType.ADDRESS_OF, byContent.getByContentType());
assertNotNull(byContent.getValueStmt());
final CallValueStmt callValueStmt = (CallValueStmt) byContent.getValueStmt();
assertEquals(CallType.UNDEFINED_CALL, callValueStmt.getCall().getCallType());
}
{
final ByContent byContent = byContentPhrase.getByContents().get(1);
assertEquals(ByContent.ByContentType.LENGTH_OF, byContent.getByContentType());
assertNotNull(byContent.getValueStmt());
final CallValueStmt callValueStmt = (CallValueStmt) byContent.getValueStmt();
assertEquals(CallType.UNDEFINED_CALL, callValueStmt.getCall().getCallType());
}
{
final ByContent byContent = byContentPhrase.getByContents().get(2);
assertNull(byContent.getByContentType());
assertNotNull(byContent.getValueStmt());
final LiteralValueStmt literalValueStmt = (LiteralValueStmt) byContent.getValueStmt();
final Literal literal = literalValueStmt.getLiteral();
assertEquals(new BigDecimal(4), literal.getValue());
}
}
}
}
}
}
}