ctf: Disable NLS warnings in test plugin
[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.After;
30import org.junit.Before;
31import org.junit.Test;
32
33/**
34 * The class <code>SequenceDefinitionTest</code> contains tests for the class
35 * <code>{@link SequenceDefinition}</code>.
284fdee8 36 *
866e5b51
FC
37 * @author ematkho
38 * @version $Revision: 1.0 $
39 */
be6df2d8 40@SuppressWarnings("javadoc")
866e5b51
FC
41public class SequenceDefinitionTest {
42
43 private SequenceDefinition fixture;
44 private final static int seqLen = 15;
45
46 /**
47 * Launch the test.
284fdee8 48 *
866e5b51
FC
49 * @param args
50 * the command line arguments
51 */
52 public static void main(String[] args) {
53 new org.junit.runner.JUnitCore().run(SequenceDefinitionTest.class);
54 }
55
56 /**
57 * Perform pre-test initialization.
fd74e6c1 58 * @throws CTFReaderException
866e5b51
FC
59 */
60 @Before
25a9b50c 61 public void setUp() throws CTFReaderException {
866e5b51
FC
62 StructDeclaration structDec;
63 StructDefinition structDef;
64
65 IntegerDeclaration id = new IntegerDeclaration(8, false, 8,
fd74e6c1 66 ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null, 8);
4a9c1f07 67 String lengthName = "LengthName";
866e5b51
FC
68 structDec = new StructDeclaration(0);
69 structDec.addField(lengthName, id);
4a9c1f07 70 structDef = new StructDefinition(structDec, null, "x");
866e5b51
FC
71
72 structDef.lookupInteger(lengthName).setValue(seqLen);
73 SequenceDeclaration sd = new SequenceDeclaration(lengthName, id);
4a9c1f07 74 fixture = new SequenceDefinition(sd, structDef, "TestX");
866e5b51
FC
75 BitBuffer input = new BitBuffer(
76 java.nio.ByteBuffer.allocateDirect(seqLen * 8));
77 for (int i = 0; i < seqLen; i++) {
78 input.putInt(i);
79 }
80 fixture.read(input);
81 assert (fixture != null);
82 }
83
84 /**
85 * Perform post-test clean-up.
86 */
87 @After
88 public void tearDown() {
89 // Add additional tear down code here
90 }
91
25a9b50c 92 private static SequenceDefinition initNonString() throws CTFReaderException {
866e5b51
FC
93 StructDeclaration structDec;
94 StructDefinition structDef;
95
96 int len = 32;
97 IntegerDeclaration id = new IntegerDeclaration(len, false, len,
fd74e6c1 98 ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null,8);
4a9c1f07 99 String lengthName = "LengthName";
866e5b51
FC
100 structDec = new StructDeclaration(0);
101 structDec.addField(lengthName, id);
4a9c1f07 102 structDef = new StructDefinition(structDec, null, "x");
866e5b51
FC
103
104 structDef.lookupInteger(lengthName).setValue(seqLen);
105 SequenceDeclaration sd = new SequenceDeclaration(lengthName, id);
4a9c1f07 106 SequenceDefinition ret = new SequenceDefinition(sd, structDef, "TestX");
866e5b51
FC
107 BitBuffer input = new BitBuffer(
108 java.nio.ByteBuffer.allocateDirect(seqLen * len));
109 for (int i = 0; i < seqLen; i++) {
110 input.putInt(i);
111 }
112 ret.read(input);
113 assertNotNull(ret);
114 return ret;
115 }
116
117 /**
118 * Run the SequenceDefinition(SequenceDeclaration,DefinitionScope,String)
119 * constructor test.
120 */
121 @Test
122 public void testSequenceDefinition() {
123 assertNotNull(fixture);
124 }
125
126 /**
127 * Run the SequenceDeclaration getDeclaration() method test.
128 */
129 @Test
130 public void testGetDeclaration() {
131 SequenceDeclaration result = fixture.getDeclaration();
132 assertNotNull(result);
133 }
134
135 /**
136 * Run the Definition getElem(int) method test.
137 */
138 @Test
139 public void testGetElem() {
140 int i = 1;
141 Definition result = fixture.getElem(i);
142 assertNotNull(result);
143 }
144
145 /**
146 * Run the int getLength() method test.
147 */
148 @Test
149 public void testGetLength() {
150 int result = fixture.getLength();
151
152 assertEquals(seqLen, result);
153 }
154
155 /**
156 * Run the boolean isString() method test.
157 */
158 @Test
159 public void testIsString() {
160 boolean result = fixture.isString();
161 assertTrue(result);
162 }
163
164 /**
165 * Run the void read(BitBuffer) method test.
166 */
167 @Test
168 public void testRead() {
169 BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
170 fixture.read(input);
171 }
172
173 /**
174 * Run the String toString() method test.
175 */
176 @Test
177 public void testToString() {
178 String result = fixture.toString();
179 assertNotNull(result);
180 }
181
182 /**
183 * Run the String toString() method test.
184 */
185 @Test
186 public void testToString_nonString() throws Exception {
024373d7
MK
187 fixture = initNonString();
188 String result = fixture.toString();
866e5b51
FC
189 assertNotNull(result);
190 }
191}
This page took 0.045743 seconds and 5 git commands to generate.