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
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.types
;
14 import static org
.junit
.Assert
.assertEquals
;
15 import static org
.junit
.Assert
.assertNotNull
;
16 import static org
.junit
.Assert
.assertTrue
;
18 import java
.nio
.ByteOrder
;
20 import org
.eclipse
.linuxtools
.ctf
.core
.event
.io
.BitBuffer
;
21 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.Definition
;
22 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.Encoding
;
23 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IntegerDeclaration
;
24 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.SequenceDeclaration
;
25 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.SequenceDefinition
;
26 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDeclaration
;
27 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDefinition
;
28 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
29 import org
.junit
.Before
;
30 import org
.junit
.Test
;
33 * The class <code>SequenceDefinitionTest</code> contains tests for the class
34 * <code>{@link SequenceDefinition}</code>.
37 * @version $Revision: 1.0 $
39 @SuppressWarnings("javadoc")
40 public class SequenceDefinitionTest
{
42 private SequenceDefinition fixture
;
43 private final static int seqLen
= 15;
46 * Perform pre-test initialization.
47 * @throws CTFReaderException
50 public void setUp() throws CTFReaderException
{
51 StructDeclaration structDec
;
52 StructDefinition structDef
;
54 IntegerDeclaration id
= new IntegerDeclaration(8, false, 8,
55 ByteOrder
.LITTLE_ENDIAN
, Encoding
.UTF8
, null, 8);
56 String lengthName
= "LengthName";
57 structDec
= new StructDeclaration(0);
58 structDec
.addField(lengthName
, id
);
59 structDef
= new StructDefinition(structDec
, null, "x");
61 structDef
.lookupInteger(lengthName
).setValue(seqLen
);
62 SequenceDeclaration sd
= new SequenceDeclaration(lengthName
, id
);
63 fixture
= new SequenceDefinition(sd
, structDef
, "TestX");
64 BitBuffer input
= new BitBuffer(
65 java
.nio
.ByteBuffer
.allocateDirect(seqLen
* 8));
66 for (int i
= 0; i
< seqLen
; i
++) {
70 assert (fixture
!= null);
73 private static SequenceDefinition
initNonString() throws CTFReaderException
{
74 StructDeclaration structDec
;
75 StructDefinition structDef
;
78 IntegerDeclaration id
= new IntegerDeclaration(len
, false, len
,
79 ByteOrder
.LITTLE_ENDIAN
, Encoding
.UTF8
, null,8);
80 String lengthName
= "LengthName";
81 structDec
= new StructDeclaration(0);
82 structDec
.addField(lengthName
, id
);
83 structDef
= new StructDefinition(structDec
, null, "x");
85 structDef
.lookupInteger(lengthName
).setValue(seqLen
);
86 SequenceDeclaration sd
= new SequenceDeclaration(lengthName
, id
);
87 SequenceDefinition ret
= new SequenceDefinition(sd
, structDef
, "TestX");
88 BitBuffer input
= new BitBuffer(
89 java
.nio
.ByteBuffer
.allocateDirect(seqLen
* len
));
90 for (int i
= 0; i
< seqLen
; i
++) {
99 * Run the SequenceDefinition(SequenceDeclaration,DefinitionScope,String)
103 public void testSequenceDefinition() {
104 assertNotNull(fixture
);
108 * Run the SequenceDeclaration getDeclaration() method test.
111 public void testGetDeclaration() {
112 SequenceDeclaration result
= fixture
.getDeclaration();
113 assertNotNull(result
);
117 * Run the Definition getElem(int) method test.
120 public void testGetElem() {
122 Definition result
= fixture
.getElem(i
);
123 assertNotNull(result
);
127 * Run the int getLength() method test.
130 public void testGetLength() {
131 int result
= fixture
.getLength();
133 assertEquals(seqLen
, result
);
137 * Run the boolean isString() method test.
140 public void testIsString() {
141 boolean result
= fixture
.isString();
146 * Run the void read(BitBuffer) method test.
147 * @throws CTFReaderException error
150 public void testRead() throws CTFReaderException
{
151 BitBuffer input
= new BitBuffer(java
.nio
.ByteBuffer
.allocateDirect(128));
156 * Run the String toString() method test.
159 public void testToString() {
160 String result
= fixture
.toString();
161 assertNotNull(result
);
165 * Run the String toString() method test.
168 public void testToString_nonString() throws Exception
{
169 fixture
= initNonString();
170 String result
= fixture
.toString();
171 assertNotNull(result
);