5e312b6fd06b92e75405c6d08d8ad00936ee9380
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / types / SequenceDeclarationTest.java
1 package org.eclipse.linuxtools.ctf.core.tests.types;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
5
6 import java.nio.ByteOrder;
7
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;
19
20 /**
21 * The class <code>SequenceDeclarationTest</code> contains tests for the class
22 * <code>{@link SequenceDeclaration}</code>.
23 *
24 * @author ematkho
25 * @version $Revision: 1.0 $
26 */
27 public class SequenceDeclarationTest {
28
29 private SequenceDeclaration fixture;
30
31 /**
32 * Launch the test.
33 *
34 * @param args
35 * the command line arguments
36 */
37 public static void main(String[] args) {
38 new org.junit.runner.JUnitCore().run(SequenceDeclarationTest.class);
39 }
40
41 @Before
42 public void setUp() {
43 fixture = new SequenceDeclaration("", new StringDeclaration()); //$NON-NLS-1$
44 }
45
46 @After
47 public void tearDown() {
48 // Add additional tear down code here
49 }
50
51 /**
52 * Run the SequenceDeclaration(String,Declaration) constructor test.
53 */
54 @Test
55 public void testSequenceDeclaration() {
56 String lengthName = ""; //$NON-NLS-1$
57 IDeclaration elemType = new StringDeclaration();
58
59 SequenceDeclaration result = new SequenceDeclaration(lengthName,
60 elemType);
61 assertNotNull(result);
62 String string = "[declaration] sequence["; //$NON-NLS-1$
63 assertEquals(string, result.toString().substring(0, string.length()));
64 }
65
66 /**
67 * Run the SequenceDefinition createDefinition(DefinitionScope,String)
68 * method test.
69 */
70 @Test
71 public void testCreateDefinition() {
72 IntegerDeclaration id = new IntegerDeclaration(8, false, 8,
73 ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null);
74 String fieldName = "LengthName"; //$NON-NLS-1$
75 StructDeclaration structDec = new StructDeclaration(0);
76 structDec.addField(fieldName, id);
77 StructDefinition structDef = new StructDefinition(structDec, null, "x"); //$NON-NLS-1$
78 long seqLen = 10;
79 structDef.lookupInteger(fieldName).setValue(seqLen);
80 SequenceDefinition result = this.fixture.createDefinition(structDef,
81 fieldName);
82 assertNotNull(result);
83 }
84
85 /**
86 * Run the Declaration getElementType() method test.
87 */
88 @Test
89 public void testGetElementType() {
90 IDeclaration result = fixture.getElementType();
91 assertNotNull(result);
92 }
93
94 /**
95 * Run the String toString() method test.
96 */
97 @Test
98 public void testToString() {
99 String result = fixture.toString();
100 String left = "[declaration] sequence["; //$NON-NLS-1$
101 assertEquals(left, result.substring(0, left.length()));
102 }
103 }
This page took 0.038143 seconds and 5 git commands to generate.