1 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.types
;
3 import static org
.junit
.Assert
.assertEquals
;
4 import static org
.junit
.Assert
.assertNotNull
;
5 import static org
.junit
.Assert
.assertTrue
;
7 import java
.nio
.ByteOrder
;
9 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.Definition
;
10 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.Encoding
;
11 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IntegerDeclaration
;
12 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.SequenceDeclaration
;
13 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.SequenceDefinition
;
14 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDeclaration
;
15 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDefinition
;
16 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
17 import org
.eclipse
.linuxtools
.internal
.ctf
.core
.event
.io
.BitBuffer
;
18 import org
.junit
.After
;
19 import org
.junit
.Before
;
20 import org
.junit
.Test
;
23 * The class <code>SequenceDefinitionTest</code> contains tests for the class
24 * <code>{@link SequenceDefinition}</code>.
27 * @version $Revision: 1.0 $
29 public class SequenceDefinitionTest
{
31 private SequenceDefinition fixture
;
32 private final static int seqLen
= 15;
38 * the command line arguments
40 public static void main(String
[] args
) {
41 new org
.junit
.runner
.JUnitCore().run(SequenceDefinitionTest
.class);
45 * Perform pre-test initialization.
46 * @throws CTFReaderException
49 public void setUp() throws CTFReaderException
{
50 StructDeclaration structDec
;
51 StructDefinition structDef
;
53 IntegerDeclaration id
= new IntegerDeclaration(8, false, 8,
54 ByteOrder
.LITTLE_ENDIAN
, Encoding
.UTF8
, null, 8);
55 String lengthName
= "LengthName"; //$NON-NLS-1$
56 structDec
= new StructDeclaration(0);
57 structDec
.addField(lengthName
, id
);
58 structDef
= new StructDefinition(structDec
, null, "x"); //$NON-NLS-1$
60 structDef
.lookupInteger(lengthName
).setValue(seqLen
);
61 SequenceDeclaration sd
= new SequenceDeclaration(lengthName
, id
);
62 fixture
= new SequenceDefinition(sd
, structDef
, "TestX"); //$NON-NLS-1$
63 BitBuffer input
= new BitBuffer(
64 java
.nio
.ByteBuffer
.allocateDirect(seqLen
* 8));
65 for (int i
= 0; i
< seqLen
; i
++) {
69 assert (fixture
!= null);
73 * Perform post-test clean-up.
76 public void tearDown() {
77 // Add additional tear down code here
80 private static SequenceDefinition
initNonString() throws CTFReaderException
{
81 StructDeclaration structDec
;
82 StructDefinition structDef
;
85 IntegerDeclaration id
= new IntegerDeclaration(len
, false, len
,
86 ByteOrder
.LITTLE_ENDIAN
, Encoding
.UTF8
, null,8);
87 String lengthName
= "LengthName"; //$NON-NLS-1$
88 structDec
= new StructDeclaration(0);
89 structDec
.addField(lengthName
, id
);
90 structDef
= new StructDefinition(structDec
, null, "x"); //$NON-NLS-1$
92 structDef
.lookupInteger(lengthName
).setValue(seqLen
);
93 SequenceDeclaration sd
= new SequenceDeclaration(lengthName
, id
);
94 SequenceDefinition ret
= new SequenceDefinition(sd
, structDef
, "TestX"); //$NON-NLS-1$
95 BitBuffer input
= new BitBuffer(
96 java
.nio
.ByteBuffer
.allocateDirect(seqLen
* len
));
97 for (int i
= 0; i
< seqLen
; i
++) {
106 * Run the SequenceDefinition(SequenceDeclaration,DefinitionScope,String)
110 public void testSequenceDefinition() {
111 assertNotNull(fixture
);
115 * Run the SequenceDeclaration getDeclaration() method test.
118 public void testGetDeclaration() {
119 SequenceDeclaration result
= fixture
.getDeclaration();
120 assertNotNull(result
);
124 * Run the Definition getElem(int) method test.
127 public void testGetElem() {
129 Definition result
= fixture
.getElem(i
);
130 assertNotNull(result
);
134 * Run the int getLength() method test.
137 public void testGetLength() {
138 int result
= fixture
.getLength();
140 assertEquals(seqLen
, result
);
144 * Run the boolean isString() method test.
147 public void testIsString() {
148 boolean result
= fixture
.isString();
153 * Run the void read(BitBuffer) method test.
156 public void testRead() {
157 BitBuffer input
= new BitBuffer(java
.nio
.ByteBuffer
.allocateDirect(128));
162 * Run the String toString() method test.
165 public void testToString() {
166 String result
= fixture
.toString();
167 assertNotNull(result
);
171 * Run the String toString() method test.
174 public void testToString_nonString() throws Exception
{
175 fixture
= initNonString();
176 String result
= fixture
.toString();
177 assertNotNull(result
);