1 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.event
;
3 import static org
.junit
.Assert
.assertEquals
;
4 import static org
.junit
.Assert
.assertNotNull
;
6 import java
.nio
.ByteBuffer
;
7 import java
.nio
.ByteOrder
;
9 import org
.eclipse
.linuxtools
.ctf
.core
.event
.io
.BitBuffer
;
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
.IntegerDeclaration
;
15 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IntegerDefinition
;
16 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.SequenceDeclaration
;
17 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.SequenceDefinition
;
18 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StringDeclaration
;
19 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StringDefinition
;
20 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDeclaration
;
21 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDefinition
;
22 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
23 import org
.junit
.After
;
24 import org
.junit
.Before
;
25 import org
.junit
.Test
;
28 * The class <code>CTFEventFieldTest</code> contains tests for the class
29 * <code>{@link CTFEventField}</code>.
32 * @version $Revision: 1.0 $
34 @SuppressWarnings("javadoc")
35 public class CTFEventFieldTest
{
37 private static final String fieldName
= "id"; //$NON-NLS-1$
41 * Perform pre-test initialization.
45 // add additional set up code here
49 * Perform post-test clean-up.
52 public void tearDown() {
53 // Add additional tear down code here
60 * the command line arguments
62 public static void main(String
[] args
) {
63 new org
.junit
.runner
.JUnitCore().run(CTFEventFieldTest
.class);
67 * Run the CTFEventField parseField(Definition,String) method test.
68 * @throws CTFReaderException
71 public void testParseField_complex() throws CTFReaderException
{
73 IntegerDeclaration id
= new IntegerDeclaration(len
, false, len
,
74 ByteOrder
.LITTLE_ENDIAN
, Encoding
.ASCII
, null, 32);
75 String lengthName
= "LengthName"; //$NON-NLS-1$
76 StructDeclaration structDec
= new StructDeclaration(0);
77 structDec
.addField(lengthName
, id
);
78 StructDefinition structDef
= new StructDefinition(structDec
, null,
81 structDef
.lookupInteger(lengthName
).setValue(32);
82 SequenceDeclaration sd
= new SequenceDeclaration(lengthName
, id
);
83 Definition fieldDef
= new SequenceDefinition(sd
, structDef
, "TestX"); //$NON-NLS-1$
84 ByteBuffer byb
= ByteBuffer
.allocate(1024);
85 for (int i
= 0; i
< 1024; i
++) {
88 BitBuffer bb
= new BitBuffer(byb
);
91 assertNotNull(fieldDef
);
95 * Run the CTFEventField parseField(Definition,String) method test.
96 * @throws CTFReaderException
99 public void testParseField_simple() {
100 final StringDeclaration elemType
= new StringDeclaration();
101 Definition fieldDef
= elemType
.createDefinition(null, fieldName
);
103 assertNotNull(fieldDef
);
107 * Run the CTFEventField parseField(Definition,String) method test.
110 public void testParseField_simple2() {
111 IntegerDefinition fieldDef
= new IntegerDefinition(
112 new IntegerDeclaration(1, true, 1, ByteOrder
.BIG_ENDIAN
,
113 Encoding
.ASCII
, null, 8), null, fieldName
);
114 fieldDef
.setValue(1L);
116 assertNotNull(fieldDef
);
123 public void testParseField_simple3() {
124 StringDefinition fieldDef
= new StringDefinition(
125 new StringDeclaration(), null, fieldName
);
126 fieldDef
.setString(new StringBuilder("Hello World")); //$NON-NLS-1$
128 String other
= "\"Hello World\""; //$NON-NLS-1$
129 assertNotNull(fieldDef
);
130 assertEquals(fieldDef
.toString(), other
);
134 * Run the CTFEventField parseField(Definition,String) method test.
137 public void testParseField_manual() {
138 Definition fieldDef
= new ArrayDefinition(new ArrayDeclaration(20,
139 new IntegerDeclaration(8, false, 8, null, Encoding
.UTF8
, null, 8)),
141 ((IntegerDefinition
) ((ArrayDefinition
) fieldDef
).getDefinitions()[0]).setValue('H');
142 ((IntegerDefinition
) ((ArrayDefinition
) fieldDef
).getDefinitions()[1]).setValue('e');
143 ((IntegerDefinition
) ((ArrayDefinition
) fieldDef
).getDefinitions()[2]).setValue('l');
144 ((IntegerDefinition
) ((ArrayDefinition
) fieldDef
).getDefinitions()[3]).setValue('l');
145 ((IntegerDefinition
) ((ArrayDefinition
) fieldDef
).getDefinitions()[4]).setValue('o');
146 ((IntegerDefinition
) ((ArrayDefinition
) fieldDef
).getDefinitions()[5]).setValue(' ');
147 ((IntegerDefinition
) ((ArrayDefinition
) fieldDef
).getDefinitions()[6]).setValue('W');
148 ((IntegerDefinition
) ((ArrayDefinition
) fieldDef
).getDefinitions()[7]).setValue('o');
149 ((IntegerDefinition
) ((ArrayDefinition
) fieldDef
).getDefinitions()[8]).setValue('r');
150 ((IntegerDefinition
) ((ArrayDefinition
) fieldDef
).getDefinitions()[9]).setValue('l');
151 ((IntegerDefinition
) ((ArrayDefinition
) fieldDef
).getDefinitions()[10]).setValue('d');
152 ((IntegerDefinition
) ((ArrayDefinition
) fieldDef
).getDefinitions()[11]).setValue(0);
154 assertNotNull(fieldDef
);
158 * Run the CTFEventField parseField(Definition,String) method test.
161 public void testParseField_manual2() {
162 Definition fieldDef
= new ArrayDefinition(new ArrayDeclaration(12,
163 new IntegerDeclaration(32, false, 32, null, null, null, 8)), null,
165 ((IntegerDefinition
) ((ArrayDefinition
) fieldDef
).getDefinitions()[0]).setValue('H');
166 ((IntegerDefinition
) ((ArrayDefinition
) fieldDef
).getDefinitions()[1]).setValue('e');
167 ((IntegerDefinition
) ((ArrayDefinition
) fieldDef
).getDefinitions()[2]).setValue('l');
168 ((IntegerDefinition
) ((ArrayDefinition
) fieldDef
).getDefinitions()[3]).setValue('l');
169 ((IntegerDefinition
) ((ArrayDefinition
) fieldDef
).getDefinitions()[4]).setValue('o');
170 ((IntegerDefinition
) ((ArrayDefinition
) fieldDef
).getDefinitions()[5]).setValue(' ');
171 ((IntegerDefinition
) ((ArrayDefinition
) fieldDef
).getDefinitions()[6]).setValue('W');
172 ((IntegerDefinition
) ((ArrayDefinition
) fieldDef
).getDefinitions()[7]).setValue('o');
173 ((IntegerDefinition
) ((ArrayDefinition
) fieldDef
).getDefinitions()[8]).setValue('r');
174 ((IntegerDefinition
) ((ArrayDefinition
) fieldDef
).getDefinitions()[9]).setValue('l');
175 ((IntegerDefinition
) ((ArrayDefinition
) fieldDef
).getDefinitions()[10]).setValue('d');
176 ((IntegerDefinition
) ((ArrayDefinition
) fieldDef
).getDefinitions()[11]).setValue(0);
178 assertNotNull(fieldDef
);
179 String other
= "[ 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 0 ]"; //$NON-NLS-1$
180 assertEquals(other
, fieldDef
.toString());