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
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
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 @SuppressWarnings("javadoc")
30 public class SequenceDefinitionTest
{
32 private SequenceDefinition fixture
;
33 private final static int seqLen
= 15;
39 * the command line arguments
41 public static void main(String
[] args
) {
42 new org
.junit
.runner
.JUnitCore().run(SequenceDefinitionTest
.class);
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"; //$NON-NLS-1$
57 structDec
= new StructDeclaration(0);
58 structDec
.addField(lengthName
, id
);
59 structDef
= new StructDefinition(structDec
, null, "x"); //$NON-NLS-1$
61 structDef
.lookupInteger(lengthName
).setValue(seqLen
);
62 SequenceDeclaration sd
= new SequenceDeclaration(lengthName
, id
);
63 fixture
= new SequenceDefinition(sd
, structDef
, "TestX"); //$NON-NLS-1$
64 BitBuffer input
= new BitBuffer(
65 java
.nio
.ByteBuffer
.allocateDirect(seqLen
* 8));
66 for (int i
= 0; i
< seqLen
; i
++) {
70 assert (fixture
!= null);
74 * Perform post-test clean-up.
77 public void tearDown() {
78 // Add additional tear down code here
81 private static SequenceDefinition
initNonString() throws CTFReaderException
{
82 StructDeclaration structDec
;
83 StructDefinition structDef
;
86 IntegerDeclaration id
= new IntegerDeclaration(len
, false, len
,
87 ByteOrder
.LITTLE_ENDIAN
, Encoding
.UTF8
, null,8);
88 String lengthName
= "LengthName"; //$NON-NLS-1$
89 structDec
= new StructDeclaration(0);
90 structDec
.addField(lengthName
, id
);
91 structDef
= new StructDefinition(structDec
, null, "x"); //$NON-NLS-1$
93 structDef
.lookupInteger(lengthName
).setValue(seqLen
);
94 SequenceDeclaration sd
= new SequenceDeclaration(lengthName
, id
);
95 SequenceDefinition ret
= new SequenceDefinition(sd
, structDef
, "TestX"); //$NON-NLS-1$
96 BitBuffer input
= new BitBuffer(
97 java
.nio
.ByteBuffer
.allocateDirect(seqLen
* len
));
98 for (int i
= 0; i
< seqLen
; i
++) {
107 * Run the SequenceDefinition(SequenceDeclaration,DefinitionScope,String)
111 public void testSequenceDefinition() {
112 assertNotNull(fixture
);
116 * Run the SequenceDeclaration getDeclaration() method test.
119 public void testGetDeclaration() {
120 SequenceDeclaration result
= fixture
.getDeclaration();
121 assertNotNull(result
);
125 * Run the Definition getElem(int) method test.
128 public void testGetElem() {
130 Definition result
= fixture
.getElem(i
);
131 assertNotNull(result
);
135 * Run the int getLength() method test.
138 public void testGetLength() {
139 int result
= fixture
.getLength();
141 assertEquals(seqLen
, result
);
145 * Run the boolean isString() method test.
148 public void testIsString() {
149 boolean result
= fixture
.isString();
154 * Run the void read(BitBuffer) method test.
157 public void testRead() {
158 BitBuffer input
= new BitBuffer(java
.nio
.ByteBuffer
.allocateDirect(128));
163 * Run the String toString() method test.
166 public void testToString() {
167 String result
= fixture
.toString();
168 assertNotNull(result
);
172 * Run the String toString() method test.
175 public void testToString_nonString() throws Exception
{
176 fixture
= initNonString();
177 String result
= fixture
.toString();
178 assertNotNull(result
);