ctf: Clean up unit tests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / types / SequenceDefinitionTest.java
CommitLineData
4bd7f2db
AM
1/*******************************************************************************
2 * Copyright (c) 2013 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
866e5b51
FC
12package org.eclipse.linuxtools.ctf.core.tests.types;
13
14import static org.junit.Assert.assertEquals;
15import static org.junit.Assert.assertNotNull;
16import static org.junit.Assert.assertTrue;
17
18import java.nio.ByteOrder;
19
486efb2e 20import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
866e5b51
FC
21import org.eclipse.linuxtools.ctf.core.event.types.Definition;
22import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
23import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
24import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration;
25import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition;
26import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
27import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
25a9b50c 28import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
866e5b51
FC
29import org.junit.Before;
30import org.junit.Test;
31
32/**
33 * The class <code>SequenceDefinitionTest</code> contains tests for the class
34 * <code>{@link SequenceDefinition}</code>.
284fdee8 35 *
866e5b51
FC
36 * @author ematkho
37 * @version $Revision: 1.0 $
38 */
be6df2d8 39@SuppressWarnings("javadoc")
866e5b51
FC
40public class SequenceDefinitionTest {
41
42 private SequenceDefinition fixture;
43 private final static int seqLen = 15;
44
866e5b51
FC
45 /**
46 * Perform pre-test initialization.
fd74e6c1 47 * @throws CTFReaderException
866e5b51
FC
48 */
49 @Before
25a9b50c 50 public void setUp() throws CTFReaderException {
866e5b51
FC
51 StructDeclaration structDec;
52 StructDefinition structDef;
53
54 IntegerDeclaration id = new IntegerDeclaration(8, false, 8,
fd74e6c1 55 ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null, 8);
4a9c1f07 56 String lengthName = "LengthName";
866e5b51
FC
57 structDec = new StructDeclaration(0);
58 structDec.addField(lengthName, id);
4a9c1f07 59 structDef = new StructDefinition(structDec, null, "x");
866e5b51
FC
60
61 structDef.lookupInteger(lengthName).setValue(seqLen);
62 SequenceDeclaration sd = new SequenceDeclaration(lengthName, id);
4a9c1f07 63 fixture = new SequenceDefinition(sd, structDef, "TestX");
866e5b51
FC
64 BitBuffer input = new BitBuffer(
65 java.nio.ByteBuffer.allocateDirect(seqLen * 8));
66 for (int i = 0; i < seqLen; i++) {
67 input.putInt(i);
68 }
69 fixture.read(input);
70 assert (fixture != null);
71 }
72
25a9b50c 73 private static SequenceDefinition initNonString() throws CTFReaderException {
866e5b51
FC
74 StructDeclaration structDec;
75 StructDefinition structDef;
76
77 int len = 32;
78 IntegerDeclaration id = new IntegerDeclaration(len, false, len,
fd74e6c1 79 ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null,8);
4a9c1f07 80 String lengthName = "LengthName";
866e5b51
FC
81 structDec = new StructDeclaration(0);
82 structDec.addField(lengthName, id);
4a9c1f07 83 structDef = new StructDefinition(structDec, null, "x");
866e5b51
FC
84
85 structDef.lookupInteger(lengthName).setValue(seqLen);
86 SequenceDeclaration sd = new SequenceDeclaration(lengthName, id);
4a9c1f07 87 SequenceDefinition ret = new SequenceDefinition(sd, structDef, "TestX");
866e5b51
FC
88 BitBuffer input = new BitBuffer(
89 java.nio.ByteBuffer.allocateDirect(seqLen * len));
90 for (int i = 0; i < seqLen; i++) {
91 input.putInt(i);
92 }
93 ret.read(input);
94 assertNotNull(ret);
95 return ret;
96 }
97
98 /**
99 * Run the SequenceDefinition(SequenceDeclaration,DefinitionScope,String)
100 * constructor test.
101 */
102 @Test
103 public void testSequenceDefinition() {
104 assertNotNull(fixture);
105 }
106
107 /**
108 * Run the SequenceDeclaration getDeclaration() method test.
109 */
110 @Test
111 public void testGetDeclaration() {
112 SequenceDeclaration result = fixture.getDeclaration();
113 assertNotNull(result);
114 }
115
116 /**
117 * Run the Definition getElem(int) method test.
118 */
119 @Test
120 public void testGetElem() {
121 int i = 1;
122 Definition result = fixture.getElem(i);
123 assertNotNull(result);
124 }
125
126 /**
127 * Run the int getLength() method test.
128 */
129 @Test
130 public void testGetLength() {
131 int result = fixture.getLength();
132
133 assertEquals(seqLen, result);
134 }
135
136 /**
137 * Run the boolean isString() method test.
138 */
139 @Test
140 public void testIsString() {
141 boolean result = fixture.isString();
142 assertTrue(result);
143 }
144
145 /**
146 * Run the void read(BitBuffer) method test.
147 */
148 @Test
149 public void testRead() {
150 BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
151 fixture.read(input);
152 }
153
154 /**
155 * Run the String toString() method test.
156 */
157 @Test
158 public void testToString() {
159 String result = fixture.toString();
160 assertNotNull(result);
161 }
162
163 /**
164 * Run the String toString() method test.
165 */
166 @Test
167 public void testToString_nonString() throws Exception {
024373d7
MK
168 fixture = initNonString();
169 String result = fixture.toString();
866e5b51
FC
170 assertNotNull(result);
171 }
172}
This page took 0.04243 seconds and 5 git commands to generate.