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
.io
.BitBuffer
;
10 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.Definition
;
11 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.Encoding
;
12 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IntegerDeclaration
;
13 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.SequenceDeclaration
;
14 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.SequenceDefinition
;
15 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDeclaration
;
16 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDefinition
;
17 import org
.junit
.After
;
18 import org
.junit
.Before
;
19 import org
.junit
.Test
;
22 * The class <code>SequenceDefinitionTest</code> contains tests for the class
23 * <code>{@link SequenceDefinition}</code>.
26 * @version $Revision: 1.0 $
28 public class SequenceDefinitionTest
{
30 private SequenceDefinition fixture
;
31 private final static int seqLen
= 15;
37 * the command line arguments
39 public static void main(String
[] args
) {
40 new org
.junit
.runner
.JUnitCore().run(SequenceDefinitionTest
.class);
44 * Perform pre-test initialization.
48 StructDeclaration structDec
;
49 StructDefinition structDef
;
51 IntegerDeclaration id
= new IntegerDeclaration(8, false, 8,
52 ByteOrder
.LITTLE_ENDIAN
, Encoding
.UTF8
);
53 String lengthName
= "LengthName"; //$NON-NLS-1$
54 structDec
= new StructDeclaration(0);
55 structDec
.addField(lengthName
, id
);
56 structDef
= new StructDefinition(structDec
, null, "x"); //$NON-NLS-1$
58 structDef
.lookupInteger(lengthName
).setValue(seqLen
);
59 SequenceDeclaration sd
= new SequenceDeclaration(lengthName
, id
);
60 fixture
= new SequenceDefinition(sd
, structDef
, "TestX"); //$NON-NLS-1$
61 BitBuffer input
= new BitBuffer(
62 java
.nio
.ByteBuffer
.allocateDirect(seqLen
* 8));
63 for (int i
= 0; i
< seqLen
; i
++) {
67 assert (fixture
!= null);
71 * Perform post-test clean-up.
74 public void tearDown() {
75 // Add additional tear down code here
78 private static SequenceDefinition
initNonString() {
79 StructDeclaration structDec
;
80 StructDefinition structDef
;
83 IntegerDeclaration id
= new IntegerDeclaration(len
, false, len
,
84 ByteOrder
.LITTLE_ENDIAN
, Encoding
.UTF8
);
85 String lengthName
= "LengthName"; //$NON-NLS-1$
86 structDec
= new StructDeclaration(0);
87 structDec
.addField(lengthName
, id
);
88 structDef
= new StructDefinition(structDec
, null, "x"); //$NON-NLS-1$
90 structDef
.lookupInteger(lengthName
).setValue(seqLen
);
91 SequenceDeclaration sd
= new SequenceDeclaration(lengthName
, id
);
92 SequenceDefinition ret
= new SequenceDefinition(sd
, structDef
, "TestX"); //$NON-NLS-1$
93 BitBuffer input
= new BitBuffer(
94 java
.nio
.ByteBuffer
.allocateDirect(seqLen
* len
));
95 for (int i
= 0; i
< seqLen
; i
++) {
104 * Run the SequenceDefinition(SequenceDeclaration,DefinitionScope,String)
108 public void testSequenceDefinition() {
109 assertNotNull(fixture
);
113 * Run the SequenceDeclaration getDeclaration() method test.
116 public void testGetDeclaration() {
117 SequenceDeclaration result
= fixture
.getDeclaration();
118 assertNotNull(result
);
122 * Run the Definition getElem(int) method test.
125 public void testGetElem() {
127 Definition result
= fixture
.getElem(i
);
128 assertNotNull(result
);
132 * Run the int getLength() method test.
135 public void testGetLength() {
136 int result
= fixture
.getLength();
138 assertEquals(seqLen
, result
);
142 * Run the boolean isString() method test.
145 public void testIsString() {
146 boolean result
= fixture
.isString();
151 * Run the void read(BitBuffer) method test.
154 public void testRead() {
155 BitBuffer input
= new BitBuffer(java
.nio
.ByteBuffer
.allocateDirect(128));
160 * Run the String toString() method test.
163 public void testToString() {
164 String result
= fixture
.toString();
165 assertNotNull(result
);
169 * Run the String toString() method test.
172 public void testToString_nonString() throws Exception
{
173 SequenceDefinition nonStringFixture
= initNonString();
174 String result
= nonStringFixture
.toString();
175 assertNotNull(result
);