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