1 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.types
;
3 import static org
.junit
.Assert
.assertEquals
;
4 import static org
.junit
.Assert
.assertNotNull
;
5 import static org
.junit
.Assert
.assertNull
;
7 import java
.nio
.ByteOrder
;
8 import java
.util
.HashMap
;
10 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.ArrayDeclaration
;
11 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.ArrayDefinition
;
12 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.Definition
;
13 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.Encoding
;
14 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.EnumDeclaration
;
15 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.EnumDefinition
;
16 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.FloatDeclaration
;
17 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IDefinitionScope
;
18 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IntegerDeclaration
;
19 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IntegerDefinition
;
20 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.SequenceDefinition
;
21 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StringDeclaration
;
22 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StringDefinition
;
23 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDeclaration
;
24 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDefinition
;
25 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.VariantDeclaration
;
26 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.VariantDefinition
;
27 import org
.junit
.After
;
28 import org
.junit
.Before
;
29 import org
.junit
.Test
;
32 * The class <code>VariantDefinitionTest</code> contains tests for the class
33 * <code>{@link VariantDefinition}</code>.
36 * @version $Revision: 1.0 $
38 @SuppressWarnings("javadoc")
39 public class VariantDefinitionTest
{
41 private VariantDefinition fixture
;
47 * the command line arguments
49 public static void main(String
[] args
) {
50 new org
.junit
.runner
.JUnitCore().run(VariantDefinitionTest
.class);
52 StructDefinition structDefinition
;
53 private static final String TEST_STRUCT_ID
= "testStruct"; //$NON-NLS-1$
55 private static final String ENUM_7
= "g"; //$NON-NLS-1$
56 private static final String ENUM_6
= "f"; //$NON-NLS-1$
57 private static final String ENUM_5
= "e"; //$NON-NLS-1$
58 private static final String ENUM_4
= "d"; //$NON-NLS-1$
59 private static final String ENUM_3
= "c"; //$NON-NLS-1$
60 private static final String ENUM_2
= "b"; //$NON-NLS-1$
61 private static final String ENUM_1
= "a"; //$NON-NLS-1$
63 private static final String TAG_ID
= "a"; //$NON-NLS-1$
65 // private static final String INT_ID = "_id"; //$NON-NLS-1$
67 // private static final String STRING_ID = "_args"; //$NON-NLS-1$
69 // private static final String ENUM_ID = "_enumArgs"; //$NON-NLS-1$
71 // private static final String SEQUENCE_ID = "_seq"; //$NON-NLS-1$
73 private static final String LENGTH_SEQ
= "_len"; //$NON-NLS-1$
74 private static final String VAR_FIELD_NAME
= "var"; //$NON-NLS-1$
75 private static final String ENUM_8
= null;
77 * Perform pre-test initialization.
79 * Not sure it needs to be that complicated, oh well...
81 * @throws CTFReaderException
85 StructDeclaration sDec
= new StructDeclaration(12);
86 StructDeclaration smallStruct
= new StructDeclaration(8);
87 IntegerDeclaration iDec
= new IntegerDeclaration(32, false, 32, ByteOrder
.BIG_ENDIAN
, Encoding
.NONE
, null, 8);
88 IntegerDeclaration lenDec
= new IntegerDeclaration(8, false, 8, ByteOrder
.BIG_ENDIAN
, Encoding
.NONE
, null, 8);
89 StringDeclaration strDec
= new StringDeclaration();
90 EnumDeclaration enDec
= new EnumDeclaration(iDec
);
91 // SequenceDeclaration seqDec = new SequenceDeclaration(LENGTH_SEQ, iDec);
92 VariantDeclaration varDec
= new VariantDeclaration();
93 EnumDeclaration tagDec
= new EnumDeclaration(iDec
);
94 ArrayDeclaration arrDec
= new ArrayDeclaration(2, iDec
);
95 FloatDeclaration fDec
= new FloatDeclaration(8, 24, ByteOrder
.BIG_ENDIAN
, 8);
96 tagDec
.add(0, 1, ENUM_1
);
97 tagDec
.add(2, 3, ENUM_2
);
98 tagDec
.add(4, 5, ENUM_3
);
99 //tagDec.add(6, 7, ENUM_4); // this should not work
100 tagDec
.add(8, 9, ENUM_5
);
101 tagDec
.add(10, 11, ENUM_6
);
102 tagDec
.add(12, 13, ENUM_7
);
103 varDec
.addField(ENUM_4
, lenDec
);
104 varDec
.addField(ENUM_7
, fDec
);
105 varDec
.addField(ENUM_6
, smallStruct
);
106 varDec
.addField(ENUM_5
, enDec
);
107 //varDec.addField(ENUM_4, seqDec);// this should not work
108 varDec
.addField(ENUM_3
, arrDec
);
109 varDec
.addField(ENUM_2
, iDec
);
110 varDec
.addField(ENUM_1
, strDec
);
112 sDec
.addField(TAG_ID
, tagDec
);
113 sDec
.addField(LENGTH_SEQ
, lenDec
);
114 // sDec.addField(SEQUENCE_ID, seqDec);
116 sDec
.addField(VAR_FIELD_NAME
, varDec
);
117 varDec
.setTag(TAG_ID
);
119 structDefinition
= sDec
.createDefinition(null, TEST_STRUCT_ID
);
120 fixture
= (VariantDefinition
) structDefinition
.getDefinitions().get(VAR_FIELD_NAME
);
124 * Perform post-test clean-up.
127 public void tearDown() {
128 // Add additional tear down code here
132 * Run the VariantDefinition(VariantDeclaration,DefinitionScope,String)
134 * @throws CTFReaderException
137 public void testVariantDefinition() {
138 VariantDeclaration declaration
= new VariantDeclaration();
139 declaration
.setTag(""); //$NON-NLS-1$
140 VariantDeclaration variantDeclaration
= new VariantDeclaration();
141 variantDeclaration
.setTag(""); //$NON-NLS-1$
142 VariantDefinition variantDefinition
= new VariantDefinition(
143 variantDeclaration
, structDefinition
, ""); //$NON-NLS-1$
144 IDefinitionScope definitionScope
= new StructDefinition(
145 new StructDeclaration(1L), variantDefinition
, ""); //$NON-NLS-1$
146 String fieldName
= ""; //$NON-NLS-1$
148 VariantDefinition result
= new VariantDefinition(declaration
,
149 definitionScope
, fieldName
);
150 assertNotNull(result
);
154 * Run the Definition getCurrentField() method test.
157 public void testGetCurrentField() {
158 Definition result
= fixture
.getCurrentField();
160 fixture
.setCurrentField(ENUM_1
);
161 result
= fixture
.getCurrentField();
162 assertNotNull(result
);
166 * Run the String getCurrentFieldName() method test.
169 public void testGetCurrentFieldName() {
170 fixture
.setCurrentField(ENUM_1
);
171 String result
= fixture
.getCurrentFieldName();
172 assertNotNull(result
);
176 * Run the VariantDeclaration getDeclaration() method test.
179 public void testGetDeclaration() {
180 VariantDeclaration result
= fixture
.getDeclaration();
181 assertNotNull(result
);
185 * Run the HashMap<String, Definition> getDefinitions() method test.
188 public void testGetDefinitions() {
189 HashMap
<String
, Definition
> result
= fixture
.getDefinitions();
190 assertNotNull(result
);
194 * Run the String getPath() method test.
197 public void testGetPath() {
198 String result
= fixture
.getPath();
199 assertNotNull(result
);
203 * Run the EnumDefinition getTagDefinition() method test.
206 public void testGetTagDefinition() {
207 EnumDefinition result
= fixture
.getTagDefinition();
208 assertNotNull(result
);
212 * Run the ArrayDefinition lookupArray(String) method test.
215 public void testLookupArray() {
216 ArrayDefinition result
= fixture
.lookupArray(ENUM_3
);
217 assertNotNull(result
);
221 * Run the Definition lookupDefinition(String) method test.
224 public void testLookupDefinition() {
225 Definition result
= fixture
.lookupDefinition(ENUM_1
);
226 assertNotNull(result
);
230 * Run the EnumDefinition lookupEnum(String) method test.
233 public void testLookupEnum() {
234 EnumDefinition result
= fixture
.lookupEnum(ENUM_5
);
235 assertNotNull(result
);
239 * Run the IntegerDefinition lookupInteger(String) method test.
242 public void testLookupInteger() {
243 IntegerDefinition result
= fixture
.lookupInteger(ENUM_2
);
244 assertNotNull(result
);
248 * Run the SequenceDefinition lookupSequence(String) method test.
251 public void testLookupSequence_1() {
252 SequenceDefinition result
= fixture
.lookupSequence(ENUM_4
);
257 * Run the StringDefinition lookupString(String) method test.
260 public void testLookupString() {
261 StringDefinition result
= fixture
.lookupString(ENUM_1
);
262 assertNotNull(result
);
266 * Run the StructDefinition lookupStruct(String) method test.
269 public void testLookupStruct() {
270 StructDefinition result
= fixture
.lookupStruct(ENUM_6
);
271 assertNotNull(result
);
275 * Run the VariantDefinition lookupVariant(String) method test.
278 public void testLookupVariant() {
279 VariantDefinition result
= fixture
.lookupVariant(ENUM_8
);
284 * Run the void setCurrentField(String) method test.
287 public void testSetCurrentField() {
288 fixture
.setCurrentField(ENUM_1
);
292 * Run the void setDeclaration(VariantDeclaration) method test.
295 public void testSetDeclaration() {
296 VariantDeclaration declaration
= new VariantDeclaration();
297 fixture
.setDeclaration(declaration
);
301 * Run the void setDefinitions(HashMap<String,Definition>) method test.
304 public void testSetDefinitions() {
305 HashMap
<String
, Definition
> definitions
= new HashMap
<String
, Definition
>();
306 fixture
.setDefinitions(definitions
);
310 * Run the void setTagDefinition(EnumDefinition) method test.
312 * @throws CTFReaderException
315 public void testSetTagDefinition(){
316 VariantDeclaration vDecl
;
317 VariantDefinition vDef
;
318 StructDefinition structDef
;
319 EnumDefinition tagDefinition
;
320 String fName
= ""; //$NON-NLS-1$
322 vDecl
= new VariantDeclaration();
324 vDef
= new VariantDefinition(vDecl
, structDefinition
, fName
);
325 structDef
= new StructDefinition(new StructDeclaration(1L), vDef
, fName
);
326 tagDefinition
= new EnumDefinition(new EnumDeclaration(
327 new IntegerDeclaration(1, true, 1, ByteOrder
.BIG_ENDIAN
,
328 Encoding
.ASCII
, fName
, 8)), structDef
, fName
);
330 fixture
.setTagDefinition(tagDefinition
);
334 * Run the String toString() method test.
337 public void testToString() {
338 String result
= fixture
.toString();
339 assertEquals("{ null = null }", result
); //$NON-NLS-1$
341 fixture
.setCurrentField(ENUM_2
);
342 result
= fixture
.toString();
343 assertEquals("{ b = 0 }", result
); //$NON-NLS-1$