1 | package de.uka.ipd.sdq.pcm.transformations.tests; |
2 | |
3 | import org.junit.Assert; |
4 | import org.junit.Before; |
5 | import org.junit.Test; |
6 | |
7 | import de.uka.ipd.sdq.pcm.repository.CollectionDataType; |
8 | import de.uka.ipd.sdq.pcm.repository.CompositeDataType; |
9 | import de.uka.ipd.sdq.pcm.repository.InnerDeclaration; |
10 | import de.uka.ipd.sdq.pcm.repository.OperationSignature; |
11 | import de.uka.ipd.sdq.pcm.repository.Parameter; |
12 | import de.uka.ipd.sdq.pcm.repository.PrimitiveDataType; |
13 | import de.uka.ipd.sdq.pcm.repository.PrimitiveTypeEnum; |
14 | import de.uka.ipd.sdq.pcm.repository.RepositoryFactory; |
15 | import de.uka.ipd.sdq.pcm.transformations.BytesizeComputationForSignature; |
16 | |
17 | public class BytesizeComputationForSignatureTest { |
18 | |
19 | private OperationSignature testSig1; |
20 | private OperationSignature testSig2; |
21 | private OperationSignature testSig3; |
22 | |
23 | @Before |
24 | public void setUp(){ |
25 | RepositoryFactory factory = RepositoryFactory.eINSTANCE; |
26 | |
27 | testSig1 = factory.createOperationSignature(); |
28 | |
29 | |
30 | Parameter param1 = factory.createParameter(); |
31 | PrimitiveDataType primDT = factory.createPrimitiveDataType(); |
32 | primDT.setType(PrimitiveTypeEnum.INT); |
33 | param1.setParameterName("param1"); |
34 | param1.setDataType__Parameter(primDT); |
35 | testSig1.getParameters__OperationSignature().add(param1); |
36 | |
37 | Parameter param2 = factory.createParameter(); |
38 | CollectionDataType collDT = factory.createCollectionDataType(); |
39 | collDT.setEntityName("SomeCollection"); |
40 | collDT.setInnerType_CollectionDataType(primDT); |
41 | |
42 | param2.setDataType__Parameter(collDT); |
43 | param2.setParameterName("param2"); |
44 | //param2.setModifier__Parameter(ParameterModifier.OUT); |
45 | testSig1.getParameters__OperationSignature().add(param2); |
46 | |
47 | |
48 | Parameter param3 = factory.createParameter(); |
49 | CompositeDataType compDT = factory.createCompositeDataType(); |
50 | compDT.setEntityName("SomeComposite"); |
51 | param3.setDataType__Parameter(compDT); |
52 | param3.setParameterName("param3"); |
53 | |
54 | InnerDeclaration innerDecl1 = factory.createInnerDeclaration(); |
55 | innerDecl1.setEntityName("innerParam1"); |
56 | innerDecl1.setDatatype_InnerDeclaration(primDT); |
57 | compDT.getInnerDeclaration_CompositeDataType().add(innerDecl1); |
58 | |
59 | InnerDeclaration innerDecl2 = factory.createInnerDeclaration(); |
60 | innerDecl2.setEntityName("innerParam2"); |
61 | innerDecl2.setDatatype_InnerDeclaration(primDT); |
62 | compDT.getInnerDeclaration_CompositeDataType().add(innerDecl2); |
63 | |
64 | InnerDeclaration innerDecl3 = factory.createInnerDeclaration(); |
65 | innerDecl3.setEntityName("innerParam3"); |
66 | innerDecl3.setDatatype_InnerDeclaration(collDT); |
67 | compDT.getInnerDeclaration_CompositeDataType().add(innerDecl3); |
68 | |
69 | InnerDeclaration innerDecl4 = factory.createInnerDeclaration(); |
70 | innerDecl4.setEntityName("innerParam4"); |
71 | |
72 | CompositeDataType compDT2 = factory.createCompositeDataType(); |
73 | compDT2.setEntityName("AnotherComposite"); |
74 | innerDecl4.setDatatype_InnerDeclaration(compDT2); |
75 | InnerDeclaration innerInnerDecl1 = factory.createInnerDeclaration(); |
76 | innerInnerDecl1.setEntityName("innerInnerParam1"); |
77 | innerInnerDecl1.setDatatype_InnerDeclaration(primDT); |
78 | compDT2.getInnerDeclaration_CompositeDataType().add(innerInnerDecl1); |
79 | |
80 | compDT.getInnerDeclaration_CompositeDataType().add(innerDecl4); |
81 | |
82 | |
83 | testSig1.getParameters__OperationSignature().add(param3); |
84 | |
85 | } |
86 | |
87 | @Before |
88 | public void setUp2(){ |
89 | RepositoryFactory factory = RepositoryFactory.eINSTANCE; |
90 | |
91 | testSig2 = factory.createOperationSignature(); |
92 | |
93 | Parameter param1 = factory.createParameter(); |
94 | PrimitiveDataType primDT = factory.createPrimitiveDataType(); |
95 | primDT.setType(PrimitiveTypeEnum.INT); |
96 | param1.setParameterName("param1"); |
97 | param1.setDataType__Parameter(primDT); |
98 | testSig2.getParameters__OperationSignature().add(param1); |
99 | |
100 | Parameter param2 = factory.createParameter(); |
101 | CollectionDataType collDT = factory.createCollectionDataType(); |
102 | collDT.setEntityName("SomeCollection"); |
103 | param2.setDataType__Parameter(collDT); |
104 | param2.setParameterName("param2"); |
105 | testSig2.getParameters__OperationSignature().add(param2); |
106 | |
107 | |
108 | CollectionDataType collDT2 = factory.createCollectionDataType(); |
109 | collDT2.setEntityName("SomeCollection2"); |
110 | collDT2.setInnerType_CollectionDataType(primDT); |
111 | |
112 | collDT.setInnerType_CollectionDataType(collDT2); |
113 | |
114 | } |
115 | |
116 | @Before |
117 | public void setUp3(){ |
118 | RepositoryFactory factory = RepositoryFactory.eINSTANCE; |
119 | |
120 | testSig3 = factory.createOperationSignature(); |
121 | |
122 | Parameter param1 = factory.createParameter(); |
123 | PrimitiveDataType primDT = factory.createPrimitiveDataType(); |
124 | primDT.setType(PrimitiveTypeEnum.INT); |
125 | param1.setParameterName("param1"); |
126 | param1.setDataType__Parameter(primDT); |
127 | testSig3.getParameters__OperationSignature().add(param1); |
128 | |
129 | Parameter param2 = factory.createParameter(); |
130 | CollectionDataType collDT = factory.createCollectionDataType(); |
131 | collDT.setEntityName("SomeCollection"); |
132 | param2.setDataType__Parameter(collDT); |
133 | param2.setParameterName("param2"); |
134 | testSig3.getParameters__OperationSignature().add(param2); |
135 | |
136 | CompositeDataType compDT = factory.createCompositeDataType(); |
137 | compDT.setEntityName("SomeComposite"); |
138 | |
139 | InnerDeclaration innerDecl1 = factory.createInnerDeclaration(); |
140 | innerDecl1.setEntityName("innerParam1"); |
141 | innerDecl1.setDatatype_InnerDeclaration(primDT); |
142 | compDT.getInnerDeclaration_CompositeDataType().add(innerDecl1); |
143 | |
144 | InnerDeclaration innerDecl2 = factory.createInnerDeclaration(); |
145 | innerDecl2.setEntityName("innerParam2"); |
146 | innerDecl2.setDatatype_InnerDeclaration(primDT); |
147 | compDT.getInnerDeclaration_CompositeDataType().add(innerDecl2); |
148 | |
149 | collDT.setInnerType_CollectionDataType(compDT); |
150 | } |
151 | |
152 | @Test |
153 | public void testGetByteSize(){ |
154 | String actual = BytesizeComputationForSignature.getBytesizeForSignature(testSig1, BytesizeComputationForSignature.Modifier.IN); |
155 | Assert.assertEquals("param1.BYTESIZE + " + |
156 | "param2.NUMBER_OF_ELEMENTS * param2.INNER.BYTESIZE + " + |
157 | "(param3.innerParam1.BYTESIZE + " + |
158 | "param3.innerParam2.BYTESIZE + " + |
159 | "param3.innerParam3.NUMBER_OF_ELEMENTS * param3.innerParam3.INNER.BYTESIZE + " + |
160 | "(param3.innerParam4.innerInnerParam1.BYTESIZE))", actual); |
161 | } |
162 | |
163 | @Test |
164 | public void testGetByteSize2(){ |
165 | String actual2 = BytesizeComputationForSignature.getBytesizeForSignature(testSig2, BytesizeComputationForSignature.Modifier.IN); |
166 | Assert.assertEquals("param1.BYTESIZE + " + |
167 | "param2.NUMBER_OF_ELEMENTS * param2.INNER.NUMBER_OF_ELEMENTS * param2.INNER.INNER.BYTESIZE", actual2); |
168 | |
169 | } |
170 | |
171 | @Test |
172 | public void testGetByteSize3(){ |
173 | String actual = BytesizeComputationForSignature.getBytesizeForSignature(testSig3, BytesizeComputationForSignature.Modifier.IN); |
174 | Assert.assertEquals("param1.BYTESIZE + " + |
175 | "param2.NUMBER_OF_ELEMENTS * (param2.INNER.innerParam1.BYTESIZE + param2.INNER.innerParam2.BYTESIZE)", actual); |
176 | |
177 | } |
178 | } |