ctf: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.ctf.core.tests / src / org / eclipse / tracecompass / ctf / core / tests / trace / CTFStreamInputPacketIndexEntryTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2015 Ericsson
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
11
12 package org.eclipse.tracecompass.ctf.core.tests.trace;
13
14 import static org.junit.Assert.assertEquals;
15 import static org.junit.Assert.assertFalse;
16 import static org.junit.Assert.assertNotNull;
17 import static org.junit.Assert.assertNull;
18 import static org.junit.Assert.assertTrue;
19
20 import java.nio.ByteBuffer;
21 import java.nio.ByteOrder;
22
23 import org.eclipse.tracecompass.ctf.core.CTFException;
24 import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer;
25 import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope;
26 import org.eclipse.tracecompass.ctf.core.event.types.Encoding;
27 import org.eclipse.tracecompass.ctf.core.event.types.EnumDeclaration;
28 import org.eclipse.tracecompass.ctf.core.event.types.FloatDeclaration;
29 import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration;
30 import org.eclipse.tracecompass.ctf.core.event.types.StringDeclaration;
31 import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration;
32 import org.eclipse.tracecompass.ctf.core.event.types.StructDefinition;
33 import org.eclipse.tracecompass.ctf.core.trace.ICTFPacketDescriptor;
34 import org.eclipse.tracecompass.internal.ctf.core.trace.StreamInputPacketIndexEntry;
35 import org.junit.Before;
36 import org.junit.Test;
37
38 /**
39 * The class <code>StreamInputPacketIndexEntryTest</code> contains tests for the
40 * class <code>{@link StreamInputPacketIndexEntry}</code>.
41 *
42 * @author ematkho
43 * @version $Revision: 1.0 $
44 */
45 public class CTFStreamInputPacketIndexEntryTest {
46
47 private ICTFPacketDescriptor fixture;
48
49 /**
50 * Perform pre-test initialization.
51 */
52 @Before
53 public void setUp() {
54 fixture = new StreamInputPacketIndexEntry(1L, 1L);
55 }
56
57 /**
58 * Run the StreamInputPacketIndexEntry(long) constructor test.
59 */
60 @Test
61 public void testStreamInputPacketIndexEntry_1() {
62 String expectedResult = "StreamInputPacketIndexEntry [offsetBits=1, " +
63 "timestampBegin=" + Long.MIN_VALUE +
64 ", timestampEnd=" + Long.MAX_VALUE +
65 "]";
66
67 assertNotNull(fixture);
68 assertEquals(expectedResult, fixture.toString());
69 assertEquals(1, fixture.getOffsetBits());
70 assertEquals(0, fixture.getOffsetBytes());
71 }
72
73 /**
74 * Test the constructor
75 *
76 * @throws CTFException
77 * exception
78 */
79 @Test
80 public void testStreamInputPacketIndexEntryConstructor1() throws CTFException {
81 StructDeclaration sd = new StructDeclaration(8);
82 sd.addField("timestamp_begin", IntegerDeclaration.INT_32B_DECL);
83 sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL);
84 sd.addField("load_factor", new FloatDeclaration(24, 8, ByteOrder.nativeOrder(), 8));
85 sd.addField("target", StringDeclaration.getStringDeclaration(Encoding.ASCII));
86 sd.addField("Enum", new EnumDeclaration(IntegerDeclaration.INT_8_DECL));
87 @SuppressWarnings("null")
88 BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
89 bb.getByteBuffer().putInt(100);
90 bb.getByteBuffer().putInt(200);
91 bb.getByteBuffer().putFloat((float) .75);
92 bb.getByteBuffer().put(("Test").getBytes());
93 bb.getByteBuffer().put((byte) 0);
94 bb.getByteBuffer().put((byte) 0);
95 StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb);
96 ICTFPacketDescriptor sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 0);
97 assertNull(sipie.getTarget());
98 assertEquals(100, sipie.getTimestampBegin());
99 assertEquals(200, sipie.getTimestampEnd());
100 }
101
102 /**
103 * Test the constructor
104 *
105 * @throws CTFException
106 * exception
107 */
108 @Test
109 public void testStreamInputPacketIndexEntryConstructor2() throws CTFException {
110 StructDeclaration sd = new StructDeclaration(8);
111 sd.addField("timestamp_begin", IntegerDeclaration.INT_32B_DECL);
112 sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL);
113 sd.addField("content_size", IntegerDeclaration.INT_32B_DECL);
114 sd.addField("target", StringDeclaration.getStringDeclaration(Encoding.ASCII));
115 sd.addField("Enum", new EnumDeclaration(IntegerDeclaration.INT_8_DECL));
116 @SuppressWarnings("null")
117 BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
118 bb.getByteBuffer().putInt(100);
119 bb.getByteBuffer().putInt(200);
120 bb.getByteBuffer().putInt(128);
121 bb.getByteBuffer().put(("Test").getBytes());
122 bb.getByteBuffer().put((byte) 0);
123 bb.getByteBuffer().put((byte) 0);
124 StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb);
125 ICTFPacketDescriptor sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 0);
126 assertNull(sipie.getTarget());
127 assertEquals(100, sipie.getTimestampBegin());
128 assertEquals(200, sipie.getTimestampEnd());
129 }
130
131 /**
132 * Test the constructor
133 *
134 * @throws CTFException
135 * exception
136 */
137 @Test
138 public void testStreamInputPacketIndexEntryConstructor3() throws CTFException {
139 StructDeclaration sd = new StructDeclaration(8);
140 sd.addField("timestamp_begin", IntegerDeclaration.INT_32B_DECL);
141 sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL);
142 sd.addField("packet_size", IntegerDeclaration.INT_32B_DECL);
143 sd.addField("target", StringDeclaration.getStringDeclaration(Encoding.ASCII));
144 sd.addField("Enum", new EnumDeclaration(IntegerDeclaration.INT_8_DECL));
145 sd.addField("intruder", new StructDeclaration(8));
146 @SuppressWarnings("null")
147 BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
148 bb.getByteBuffer().putInt(100);
149 bb.getByteBuffer().putInt(200);
150 bb.getByteBuffer().putInt(128);
151 bb.getByteBuffer().put(("Test").getBytes());
152 bb.getByteBuffer().put((byte) 0);
153 bb.getByteBuffer().put((byte) 0);
154 StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb);
155 ICTFPacketDescriptor sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 0);
156 assertNull(sipie.getTarget());
157 assertEquals(100, sipie.getTimestampBegin());
158 assertEquals(200, sipie.getTimestampEnd());
159 assertTrue(sipie.includes(150));
160 assertFalse(sipie.includes(10));
161 assertFalse(sipie.includes(250));
162 }
163
164 /**
165 * Test the constructor
166 *
167 * @throws CTFException
168 * exception
169 */
170 @Test
171 public void testStreamInputPacketIndexEntryConstructor4() throws CTFException {
172 StructDeclaration sd = new StructDeclaration(8);
173 sd.addField("content_size", IntegerDeclaration.INT_32B_DECL);
174 sd.addField("target", StringDeclaration.getStringDeclaration(Encoding.ASCII));
175 sd.addField("Enum", new EnumDeclaration(IntegerDeclaration.INT_8_DECL));
176 @SuppressWarnings("null")
177 BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
178 bb.getByteBuffer().putInt(0);
179 bb.getByteBuffer().put(("Test").getBytes());
180 bb.getByteBuffer().put((byte) 0);
181 bb.getByteBuffer().put((byte) 0);
182 StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb);
183 ICTFPacketDescriptor sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 0);
184 assertNull(sipie.getTarget());
185 assertEquals(Long.MIN_VALUE, sipie.getTimestampBegin());
186 assertEquals(Long.MAX_VALUE, sipie.getTimestampEnd());
187 }
188
189 /**
190 * Test the constructor
191 *
192 * @throws CTFException
193 * exception
194 */
195 @Test
196 public void testStreamInputPacketIndexEntryConstructor5() throws CTFException {
197 StructDeclaration sd = new StructDeclaration(8);
198 sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL);
199 sd.addField("content_size", IntegerDeclaration.INT_32B_DECL);
200 sd.addField("device", StringDeclaration.getStringDeclaration(Encoding.ASCII));
201 sd.addField("Enum", new EnumDeclaration(IntegerDeclaration.INT_8_DECL));
202 @SuppressWarnings("null")
203 BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
204 bb.getByteBuffer().putInt(-1);
205 bb.getByteBuffer().putInt(0);
206 bb.getByteBuffer().put(("Test66").getBytes());
207 bb.getByteBuffer().put((byte) 0);
208 bb.getByteBuffer().put((byte) 0);
209 StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb);
210 ICTFPacketDescriptor sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 0);
211 assertEquals(Long.MIN_VALUE, sipie.getTimestampBegin());
212 assertEquals(Long.MAX_VALUE, sipie.getTimestampEnd());
213 assertEquals("Test66", sipie.getTarget());
214 assertEquals(66, sipie.getTargetId());
215 }
216
217 /**
218 * Test the constructor
219 *
220 * @throws CTFException
221 * exception
222 */
223 @Test
224 public void testStreamInputPacketIndexEntryConstructor6() throws CTFException {
225 StructDeclaration sd = new StructDeclaration(8);
226 sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL);
227 sd.addField("content_size", IntegerDeclaration.INT_32B_DECL);
228 sd.addField("cpu_id", IntegerDeclaration.INT_32B_DECL);
229 sd.addField("events_discarded", IntegerDeclaration.INT_32B_DECL);
230 @SuppressWarnings("null")
231 BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
232 bb.getByteBuffer().putInt(-1);
233 bb.getByteBuffer().putInt(0);
234 bb.getByteBuffer().putInt(66);
235 bb.getByteBuffer().putInt(300);
236 StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb);
237 ICTFPacketDescriptor sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 100);
238 assertEquals(Long.MIN_VALUE, sipie.getTimestampBegin());
239 assertEquals(Long.MAX_VALUE, sipie.getTimestampEnd());
240 assertEquals("CPU66", sipie.getTarget());
241 assertEquals(66, sipie.getTargetId());
242 assertEquals(200, sipie.getLostEvents());
243 assertEquals(0, sipie.getOffsetBits());
244 assertEquals(1024, sipie.getPacketSizeBits());
245 }
246
247 /**
248 * Run the String toString() method test.
249 *
250 * @throws CTFException
251 * won't happen
252 */
253 @Test
254 public void testToString() throws CTFException {
255
256 String expectedResult = "StreamInputPacketIndexEntry [offsetBits=0, timestampBegin=0, timestampEnd=0]";
257 StructDeclaration sd = new StructDeclaration(8);
258 sd.addField("timestamp_begin", IntegerDeclaration.INT_32B_DECL);
259 sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL);
260 @SuppressWarnings("null")
261 BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
262
263 StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb);
264 assertEquals(expectedResult, new StreamInputPacketIndexEntry(0, sdef, 10000, 0).toString());
265 }
266 }
This page took 0.052478 seconds and 5 git commands to generate.