ctf: Disable NLS warnings in test plugin
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / types / VariantDefinitionTest.java
... / ...
CommitLineData
1/*******************************************************************************
2 * Copyright (c) 2013 Ericsson
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
11
12package org.eclipse.linuxtools.ctf.core.tests.types;
13
14import static org.junit.Assert.assertEquals;
15import static org.junit.Assert.assertNotNull;
16import static org.junit.Assert.assertNull;
17
18import java.nio.ByteOrder;
19import java.util.HashMap;
20
21import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
22import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
23import org.eclipse.linuxtools.ctf.core.event.types.Definition;
24import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
25import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration;
26import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition;
27import org.eclipse.linuxtools.ctf.core.event.types.FloatDeclaration;
28import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
29import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
30import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
31import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition;
32import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
33import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
34import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
35import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
36import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
37import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition;
38import org.junit.After;
39import org.junit.Before;
40import org.junit.Test;
41
42/**
43 * The class <code>VariantDefinitionTest</code> contains tests for the class
44 * <code>{@link VariantDefinition}</code>.
45 *
46 * @author ematkho
47 * @version $Revision: 1.0 $
48 */
49@SuppressWarnings("javadoc")
50public class VariantDefinitionTest {
51
52 private VariantDefinition fixture;
53
54 /**
55 * Launch the test.
56 *
57 * @param args
58 * the command line arguments
59 */
60 public static void main(String[] args) {
61 new org.junit.runner.JUnitCore().run(VariantDefinitionTest.class);
62 }
63
64 StructDefinition structDefinition;
65 private static final String TEST_STRUCT_ID = "testStruct";
66
67 private static final String ENUM_7 = "g";
68 private static final String ENUM_6 = "f";
69 private static final String ENUM_5 = "e";
70 private static final String ENUM_4 = "d";
71 private static final String ENUM_3 = "c";
72 private static final String ENUM_2 = "b";
73 private static final String ENUM_1 = "a";
74
75 private static final String TAG_ID = "a";
76
77// private static final String INT_ID = "_id";
78// private static final String STRING_ID = "_args";
79// private static final String ENUM_ID = "_enumArgs";
80// private static final String SEQUENCE_ID = "_seq";
81
82 private static final String LENGTH_SEQ = "_len";
83 private static final String VAR_FIELD_NAME = "var";
84 private static final String ENUM_8 = null;
85 /**
86 * Perform pre-test initialization.
87 *
88 * Not sure it needs to be that complicated, oh well...
89 *
90 * @throws CTFReaderException
91 */
92 @Before
93 public void setUp() {
94 StructDeclaration sDec = new StructDeclaration(12);
95 StructDeclaration smallStruct = new StructDeclaration(8);
96 IntegerDeclaration iDec = new IntegerDeclaration(32, false, 32, ByteOrder.BIG_ENDIAN, Encoding.NONE, null, 8);
97 IntegerDeclaration lenDec = new IntegerDeclaration(8, false, 8, ByteOrder.BIG_ENDIAN, Encoding.NONE, null, 8);
98 StringDeclaration strDec = new StringDeclaration();
99 EnumDeclaration enDec = new EnumDeclaration(iDec);
100// SequenceDeclaration seqDec = new SequenceDeclaration(LENGTH_SEQ, iDec);
101 VariantDeclaration varDec = new VariantDeclaration();
102 EnumDeclaration tagDec = new EnumDeclaration(iDec);
103 ArrayDeclaration arrDec = new ArrayDeclaration(2, iDec);
104 FloatDeclaration fDec = new FloatDeclaration(8, 24, ByteOrder.BIG_ENDIAN, 8);
105 tagDec.add(0, 1, ENUM_1);
106 tagDec.add(2, 3, ENUM_2);
107 tagDec.add(4, 5, ENUM_3);
108 //tagDec.add(6, 7, ENUM_4); // this should not work
109 tagDec.add(8, 9, ENUM_5);
110 tagDec.add(10, 11, ENUM_6);
111 tagDec.add(12, 13, ENUM_7);
112 varDec.addField(ENUM_4, lenDec);
113 varDec.addField(ENUM_7, fDec);
114 varDec.addField(ENUM_6, smallStruct);
115 varDec.addField(ENUM_5, enDec);
116 //varDec.addField(ENUM_4, seqDec);// this should not work
117 varDec.addField(ENUM_3, arrDec);
118 varDec.addField(ENUM_2, iDec);
119 varDec.addField(ENUM_1, strDec);
120
121 sDec.addField(TAG_ID, tagDec);
122 sDec.addField(LENGTH_SEQ, lenDec);
123// sDec.addField(SEQUENCE_ID, seqDec);
124
125 sDec.addField(VAR_FIELD_NAME, varDec);
126 varDec.setTag(TAG_ID);
127
128 structDefinition = sDec.createDefinition(null, TEST_STRUCT_ID);
129 fixture = (VariantDefinition) structDefinition.getDefinitions().get(VAR_FIELD_NAME);
130 }
131
132 /**
133 * Perform post-test clean-up.
134 */
135 @After
136 public void tearDown() {
137 // Add additional tear down code here
138 }
139
140 /**
141 * Run the VariantDefinition(VariantDeclaration,DefinitionScope,String)
142 *
143 * @throws CTFReaderException
144 */
145 @Test
146 public void testVariantDefinition() {
147 VariantDeclaration declaration = new VariantDeclaration();
148 declaration.setTag("");
149 VariantDeclaration variantDeclaration = new VariantDeclaration();
150 variantDeclaration.setTag("");
151 VariantDefinition variantDefinition = new VariantDefinition(
152 variantDeclaration, structDefinition, "");
153 IDefinitionScope definitionScope = new StructDefinition(
154 new StructDeclaration(1L), variantDefinition, "");
155 String fieldName = "";
156
157 VariantDefinition result = new VariantDefinition(declaration,
158 definitionScope, fieldName);
159 assertNotNull(result);
160 }
161
162 /**
163 * Run the Definition getCurrentField() method test.
164 */
165 @Test
166 public void testGetCurrentField() {
167 Definition result = fixture.getCurrentField();
168 assertNull(result);
169 fixture.setCurrentField(ENUM_1);
170 result = fixture.getCurrentField();
171 assertNotNull(result);
172 }
173
174 /**
175 * Run the String getCurrentFieldName() method test.
176 */
177 @Test
178 public void testGetCurrentFieldName() {
179 fixture.setCurrentField(ENUM_1);
180 String result = fixture.getCurrentFieldName();
181 assertNotNull(result);
182 }
183
184 /**
185 * Run the VariantDeclaration getDeclaration() method test.
186 */
187 @Test
188 public void testGetDeclaration() {
189 VariantDeclaration result = fixture.getDeclaration();
190 assertNotNull(result);
191 }
192
193 /**
194 * Run the HashMap<String, Definition> getDefinitions() method test.
195 */
196 @Test
197 public void testGetDefinitions() {
198 HashMap<String, Definition> result = fixture.getDefinitions();
199 assertNotNull(result);
200 }
201
202 /**
203 * Run the String getPath() method test.
204 */
205 @Test
206 public void testGetPath() {
207 String result = fixture.getPath();
208 assertNotNull(result);
209 }
210
211 /**
212 * Run the EnumDefinition getTagDefinition() method test.
213 */
214 @Test
215 public void testGetTagDefinition() {
216 EnumDefinition result = fixture.getTagDefinition();
217 assertNotNull(result);
218 }
219
220 /**
221 * Run the ArrayDefinition lookupArray(String) method test.
222 */
223 @Test
224 public void testLookupArray() {
225 ArrayDefinition result = fixture.lookupArray(ENUM_3);
226 assertNotNull(result);
227 }
228
229 /**
230 * Run the Definition lookupDefinition(String) method test.
231 */
232 @Test
233 public void testLookupDefinition() {
234 Definition result = fixture.lookupDefinition(ENUM_1);
235 assertNotNull(result);
236 }
237
238 /**
239 * Run the EnumDefinition lookupEnum(String) method test.
240 */
241 @Test
242 public void testLookupEnum() {
243 EnumDefinition result = fixture.lookupEnum(ENUM_5);
244 assertNotNull(result);
245 }
246
247 /**
248 * Run the IntegerDefinition lookupInteger(String) method test.
249 */
250 @Test
251 public void testLookupInteger() {
252 IntegerDefinition result = fixture.lookupInteger(ENUM_2);
253 assertNotNull(result);
254 }
255
256 /**
257 * Run the SequenceDefinition lookupSequence(String) method test.
258 */
259 @Test
260 public void testLookupSequence_1() {
261 SequenceDefinition result = fixture.lookupSequence(ENUM_4);
262 assertNull(result);
263 }
264
265 /**
266 * Run the StringDefinition lookupString(String) method test.
267 */
268 @Test
269 public void testLookupString() {
270 StringDefinition result = fixture.lookupString(ENUM_1);
271 assertNotNull(result);
272 }
273
274 /**
275 * Run the StructDefinition lookupStruct(String) method test.
276 */
277 @Test
278 public void testLookupStruct() {
279 StructDefinition result = fixture.lookupStruct(ENUM_6);
280 assertNotNull(result);
281 }
282
283 /**
284 * Run the VariantDefinition lookupVariant(String) method test.
285 */
286 @Test
287 public void testLookupVariant() {
288 VariantDefinition result = fixture.lookupVariant(ENUM_8);
289 assertNull(result);
290 }
291
292 /**
293 * Run the void setCurrentField(String) method test.
294 */
295 @Test
296 public void testSetCurrentField() {
297 fixture.setCurrentField(ENUM_1);
298 }
299
300 /**
301 * Run the void setDeclaration(VariantDeclaration) method test.
302 */
303 @Test
304 public void testSetDeclaration() {
305 VariantDeclaration declaration = new VariantDeclaration();
306 fixture.setDeclaration(declaration);
307 }
308
309 /**
310 * Run the void setDefinitions(HashMap<String,Definition>) method test.
311 */
312 @Test
313 public void testSetDefinitions() {
314 HashMap<String, Definition> definitions = new HashMap<String, Definition>();
315 fixture.setDefinitions(definitions);
316 }
317
318 /**
319 * Run the void setTagDefinition(EnumDefinition) method test.
320 *
321 * @throws CTFReaderException
322 */
323 @Test
324 public void testSetTagDefinition(){
325 VariantDeclaration vDecl;
326 VariantDefinition vDef;
327 StructDefinition structDef;
328 EnumDefinition tagDefinition;
329 String fName = "";
330
331 vDecl = new VariantDeclaration();
332 vDecl.setTag(fName);
333 vDef = new VariantDefinition(vDecl, structDefinition, fName);
334 structDef = new StructDefinition(new StructDeclaration(1L), vDef, fName);
335 tagDefinition = new EnumDefinition(new EnumDeclaration(
336 new IntegerDeclaration(1, true, 1, ByteOrder.BIG_ENDIAN,
337 Encoding.ASCII, fName, 8)), structDef, fName);
338
339 fixture.setTagDefinition(tagDefinition);
340 }
341
342 /**
343 * Run the String toString() method test.
344 */
345 @Test
346 public void testToString() {
347 String result = fixture.toString();
348 assertEquals("{ null = null }", result);
349
350 fixture.setCurrentField(ENUM_2);
351 result = fixture.toString();
352 assertEquals("{ b = 0 }", result);
353 }
354}
This page took 0.025452 seconds and 5 git commands to generate.