Commit | Line | Data |
---|---|---|
866e5b51 FC |
1 | package org.eclipse.linuxtools.ctf.core.tests.types; |
2 | ||
3 | import static org.junit.Assert.assertEquals; | |
4 | import static org.junit.Assert.assertNotNull; | |
5 | ||
6 | import java.nio.ByteOrder; | |
7 | ||
8 | import org.eclipse.linuxtools.ctf.core.event.EventDefinition; | |
9 | import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; | |
10 | import org.eclipse.linuxtools.ctf.core.event.types.Definition; | |
11 | import org.eclipse.linuxtools.ctf.core.event.types.Encoding; | |
12 | import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; | |
13 | import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration; | |
14 | import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; | |
15 | import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; | |
16 | import org.eclipse.linuxtools.ctf.core.tests.TestParams; | |
17 | import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; | |
18 | import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader; | |
19 | import org.junit.After; | |
20 | import org.junit.Before; | |
21 | import 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 | */ | |
30 | public 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 | } |