Update the CTF tests to the previous change
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / types / IntegerDefinitionTest.java
CommitLineData
866e5b51
FC
1package org.eclipse.linuxtools.ctf.core.tests.types;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertNotNull;
5
6import java.nio.ByteOrder;
7
8import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
9import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
10import org.eclipse.linuxtools.ctf.core.event.types.Definition;
11import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
12import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
13import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
14import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
15import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
16import org.eclipse.linuxtools.ctf.core.tests.TestParams;
17import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
18import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
19import org.junit.After;
20import org.junit.Before;
21import org.junit.Test;
22
23/**
24 * The class <code>IntegerDefinitionTest</code> contains tests for the class
25 * <code>{@link IntegerDefinition}</code>.
26 *
27 * @author ematkho
28 * @version $Revision: 1.0 $
29 */
30public class IntegerDefinitionTest {
31
32 private IntegerDefinition fixture;
33
34 /**
35 * Launch the test.
36 *
37 * @param args
38 * the command line arguments
39 */
40 public static void main(String[] args) {
41 new org.junit.runner.JUnitCore().run(IntegerDefinitionTest.class);
42 }
43
44 /**
45 * Perform pre-test initialization. We know the structDef won't be null (or
46 * else the tests will fail), so we can safely suppress the warning.
47 */
48 @Before
49 public void setUp() {
50 CTFTrace trace = TestParams.createTrace();
51 CTFTraceReader tr = new CTFTraceReader(trace);
52 String name = ""; //$NON-NLS-1$
53 StructDefinition structDef = null;
54 boolean found = false;
55
56 while (tr.hasMoreEvents() && !found) {
57 tr.advance();
58 EventDefinition ed = tr.getCurrentEventDef();
59 for (String key : ed.fields.getDefinitions().keySet()) {
60 structDef = ed.fields;
61 Definition d = structDef.lookupDefinition(key);
62 if (d instanceof IntegerDefinition) {
63 found = true;
64 name = key;
65 break;
66 }
67 }
68 }
69 assert (structDef != null);
70 fixture = structDef.lookupInteger(name);
71 }
72
73 /**
74 * Perform post-test clean-up.
75 */
76 @After
77 public void tearDown() {
78 // Add additional tear down code here
79 }
80
81 /**
82 * Run the IntegerDefinition(IntegerDeclaration,DefinitionScope,String)
83 * constructor test.
84 */
85 @Test
86 public void testIntegerDefinition() {
87 IntegerDeclaration declaration = new IntegerDeclaration(1, true, 1,
88 ByteOrder.BIG_ENDIAN, Encoding.ASCII);
89 IDefinitionScope definitionScope = null;
90 String fieldName = ""; //$NON-NLS-1$
91
92 IntegerDefinition result = new IntegerDefinition(declaration,
93 definitionScope, fieldName);
94 assertNotNull(result);
95 }
96
97 /**
98 * Run the IntegerDeclaration getDeclaration() method test.
99 */
100 @Test
101 public void testGetDeclaration() {
102 fixture.setValue(1L);
103
104 IntegerDeclaration result = fixture.getDeclaration();
105 assertNotNull(result);
106 }
107
108 /**
109 * Run the long getValue() method test.
110 */
111 @Test
112 public void testGetValue() {
113 fixture.setValue(1L);
114
115 long result = fixture.getValue();
116 assertEquals(1L, result);
117 }
118
119 /**
120 * Run the void read(BitBuffer) method test.
121 */
122 @Test
123 public void testRead() {
124 fixture.setValue(1L);
125 BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
126
127 fixture.read(input);
128 }
129
130 /**
131 * Run the String toString() method test.
132 */
133 @Test
134 public void testToString() {
135 fixture.setValue(1L);
136
137 String result = fixture.toString();
138 assertNotNull(result);
139 }
140}
This page took 0.028382 seconds and 5 git commands to generate.