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; | |
866e5b51 FC |
9 | import org.eclipse.linuxtools.ctf.core.event.types.Definition; |
10 | import org.eclipse.linuxtools.ctf.core.event.types.Encoding; | |
11 | import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; | |
12 | import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration; | |
13 | import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; | |
14 | import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; | |
15 | import org.eclipse.linuxtools.ctf.core.tests.TestParams; | |
13be1a8f | 16 | import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; |
866e5b51 FC |
17 | import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; |
18 | import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader; | |
ce2388e0 | 19 | import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; |
866e5b51 FC |
20 | import org.junit.After; |
21 | import org.junit.Before; | |
22 | import org.junit.Test; | |
23 | ||
24 | /** | |
25 | * The class <code>IntegerDefinitionTest</code> contains tests for the class | |
26 | * <code>{@link IntegerDefinition}</code>. | |
284fdee8 | 27 | * |
866e5b51 FC |
28 | * @author ematkho |
29 | * @version $Revision: 1.0 $ | |
30 | */ | |
31 | public class IntegerDefinitionTest { | |
32 | ||
33 | private IntegerDefinition fixture; | |
34 | ||
35 | /** | |
36 | * Launch the test. | |
284fdee8 | 37 | * |
866e5b51 FC |
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. | |
fd74e6c1 MK |
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, | |
fd74e6c1 | 91 | ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 8); |
866e5b51 FC |
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 | } | |
284fdee8 | 143 | } |