common: Annotate some methods in ByteBuffer
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.ctf.core.tests / src / org / eclipse / tracecompass / ctf / core / tests / types / SequenceDefinition2Test.java
CommitLineData
4bd7f2db 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2013, 2014 Ericsson
4bd7f2db
AM
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
f357bcd4 12package org.eclipse.tracecompass.ctf.core.tests.types;
866e5b51 13
866e5b51 14import static org.junit.Assert.assertNotNull;
866e5b51 15
aefc5c83 16import java.nio.ByteBuffer;
866e5b51
FC
17import java.nio.ByteOrder;
18
680f9173 19import org.eclipse.tracecompass.ctf.core.CTFException;
f357bcd4
AM
20import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer;
21import org.eclipse.tracecompass.ctf.core.event.types.Definition;
22import org.eclipse.tracecompass.ctf.core.event.types.Encoding;
23import org.eclipse.tracecompass.ctf.core.event.types.IDefinition;
24import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration;
25import org.eclipse.tracecompass.ctf.core.event.types.IntegerDefinition;
26import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration;
27import org.eclipse.tracecompass.ctf.core.event.types.StructDefinition;
f357bcd4
AM
28import org.eclipse.tracecompass.internal.ctf.core.event.types.ByteArrayDefinition;
29import org.eclipse.tracecompass.internal.ctf.core.event.types.SequenceDeclaration;
866e5b51
FC
30import org.junit.Before;
31import org.junit.Test;
32
33/**
7b4f13e6
MK
34 * The class <code>SequenceDefinition2Test</code> contains tests for the class
35 * <code>{@link SequenceDefinition2}</code>.
284fdee8 36 *
866e5b51
FC
37 * @author ematkho
38 * @version $Revision: 1.0 $
39 */
be6df2d8 40@SuppressWarnings("javadoc")
7b4f13e6 41public class SequenceDefinition2Test {
866e5b51 42
7b4f13e6 43 private ByteArrayDefinition fixture;
866e5b51
FC
44 private final static int seqLen = 15;
45
866e5b51
FC
46 /**
47 * Perform pre-test initialization.
a4fa4e36 48 *
680f9173 49 * @throws CTFException
866e5b51
FC
50 */
51 @Before
680f9173 52 public void setUp() throws CTFException {
7b4f13e6 53 fixture = initString();
866e5b51
FC
54 }
55
680f9173 56 private static ByteArrayDefinition initString() throws CTFException {
866e5b51
FC
57 StructDeclaration structDec;
58 StructDefinition structDef;
59
7b4f13e6 60 int len = 8;
a4fa4e36
MK
61 IntegerDeclaration id = IntegerDeclaration.createDeclaration(len, false, len,
62 ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 8);
4a9c1f07 63 String lengthName = "LengthName";
866e5b51
FC
64 structDec = new StructDeclaration(0);
65 structDec.addField(lengthName, id);
866e5b51 66
8e0c9d81 67 structDef = new StructDefinition(structDec, null, "x", new Definition[] { new IntegerDefinition(id, null, lengthName, seqLen) });
a4fa4e36 68
866e5b51 69 SequenceDeclaration sd = new SequenceDeclaration(lengthName, id);
56b1f7d4 70 ByteBuffer allocateDirect = ByteBuffer.allocateDirect(seqLen * len);
aefc5c83 71 BitBuffer input = new BitBuffer(allocateDirect);
866e5b51
FC
72 for (int i = 0; i < seqLen; i++) {
73 input.putInt(i);
74 }
a4fa4e36 75
7b4f13e6 76 ByteArrayDefinition ret = (ByteArrayDefinition) sd.createDefinition(structDef, "TestX", input);
866e5b51
FC
77 assertNotNull(ret);
78 return ret;
79 }
80
81 /**
7b4f13e6 82 * Run the FixedStringDefinition(SequenceDeclaration,DefinitionScope,String)
866e5b51
FC
83 * constructor test.
84 */
85 @Test
7b4f13e6 86 public void testFixedStringDefinition() {
866e5b51
FC
87 assertNotNull(fixture);
88 }
89
90 /**
91 * Run the SequenceDeclaration getDeclaration() method test.
92 */
93 @Test
94 public void testGetDeclaration() {
7b4f13e6 95 SequenceDeclaration result = (SequenceDeclaration) fixture.getDeclaration();
866e5b51
FC
96 assertNotNull(result);
97 }
98
99 /**
100 * Run the Definition getElem(int) method test.
101 */
102 @Test
103 public void testGetElem() {
104 int i = 1;
cc98c947 105 IDefinition result = fixture.getDefinitions().get(i);
866e5b51
FC
106 assertNotNull(result);
107 }
108
866e5b51
FC
109 /**
110 * Run the String toString() method test.
111 */
112 @Test
113 public void testToString() {
114 String result = fixture.toString();
115 assertNotNull(result);
116 }
117
866e5b51 118}
This page took 0.069945 seconds and 5 git commands to generate.