1 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.types
;
3 import static org
.junit
.Assert
.assertEquals
;
4 import static org
.junit
.Assert
.assertNotNull
;
6 import java
.nio
.ByteOrder
;
8 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.Encoding
;
9 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IDeclaration
;
10 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IntegerDeclaration
;
11 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.SequenceDeclaration
;
12 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.SequenceDefinition
;
13 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StringDeclaration
;
14 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDeclaration
;
15 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDefinition
;
16 import org
.junit
.After
;
17 import org
.junit
.Before
;
18 import org
.junit
.Test
;
21 * The class <code>SequenceDeclarationTest</code> contains tests for the class
22 * <code>{@link SequenceDeclaration}</code>.
25 * @version $Revision: 1.0 $
27 @SuppressWarnings("javadoc")
28 public class SequenceDeclarationTest
{
30 private SequenceDeclaration fixture
;
32 static final String fieldName
= "LengthName"; //$NON-NLS-1$
37 * the command line arguments
39 public static void main(String
[] args
) {
40 new org
.junit
.runner
.JUnitCore().run(SequenceDeclarationTest
.class);
45 fixture
= new SequenceDeclaration(fieldName
, new StringDeclaration());
49 public void tearDown() {
50 // Add additional tear down code here
54 * Run the SequenceDeclaration(String,Declaration) constructor test.
57 public void testSequenceDeclaration() {
58 String lengthName
= ""; //$NON-NLS-1$
59 IDeclaration elemType
= new StringDeclaration();
61 SequenceDeclaration result
= new SequenceDeclaration(lengthName
,
63 assertNotNull(result
);
64 String string
= "[declaration] sequence["; //$NON-NLS-1$
65 assertEquals(string
, result
.toString().substring(0, string
.length()));
69 * Run the SequenceDefinition createDefinition(DefinitionScope,String)
73 public void testCreateDefinition() {
74 IntegerDeclaration id
= new IntegerDeclaration(8, false, 8,
75 ByteOrder
.LITTLE_ENDIAN
, Encoding
.UTF8
, null, 32);
77 StructDeclaration structDec
= new StructDeclaration(0);
78 structDec
.addField(fieldName
, id
);
79 StructDefinition structDef
= new StructDefinition(structDec
, null, "x"); //$NON-NLS-1$
81 structDef
.lookupInteger(fieldName
).setValue(seqLen
);
82 SequenceDefinition result
= this.fixture
.createDefinition(structDef
,
84 assertNotNull(result
);
88 * Run the Declaration getElementType() method test.
91 public void testGetElementType() {
92 IDeclaration result
= fixture
.getElementType();
93 assertNotNull(result
);
97 * Run the String toString() method test.
100 public void testToString() {
101 String result
= fixture
.toString();
102 String left
= "[declaration] sequence["; //$NON-NLS-1$
103 assertEquals(left
, result
.substring(0, left
.length()));