ctf: Update copyright headers and add missing ones
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / types / SequenceDeclarationTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013 Ericsson
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
11
12 package org.eclipse.linuxtools.ctf.core.tests.types;
13
14 import static org.junit.Assert.assertEquals;
15 import static org.junit.Assert.assertNotNull;
16
17 import java.nio.ByteOrder;
18
19 import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
20 import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
21 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
22 import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration;
23 import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition;
24 import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
25 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
26 import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
27 import org.junit.After;
28 import org.junit.Before;
29 import org.junit.Test;
30
31 /**
32 * The class <code>SequenceDeclarationTest</code> contains tests for the class
33 * <code>{@link SequenceDeclaration}</code>.
34 *
35 * @author ematkho
36 * @version $Revision: 1.0 $
37 */
38 @SuppressWarnings("javadoc")
39 public class SequenceDeclarationTest {
40
41 private SequenceDeclaration fixture;
42
43 static final String fieldName = "LengthName"; //$NON-NLS-1$
44 /**
45 * Launch the test.
46 *
47 * @param args
48 * the command line arguments
49 */
50 public static void main(String[] args) {
51 new org.junit.runner.JUnitCore().run(SequenceDeclarationTest.class);
52 }
53
54 @Before
55 public void setUp() {
56 fixture = new SequenceDeclaration(fieldName, new StringDeclaration());
57 }
58
59 @After
60 public void tearDown() {
61 // Add additional tear down code here
62 }
63
64 /**
65 * Run the SequenceDeclaration(String,Declaration) constructor test.
66 */
67 @Test
68 public void testSequenceDeclaration() {
69 String lengthName = ""; //$NON-NLS-1$
70 IDeclaration elemType = new StringDeclaration();
71
72 SequenceDeclaration result = new SequenceDeclaration(lengthName,
73 elemType);
74 assertNotNull(result);
75 String string = "[declaration] sequence["; //$NON-NLS-1$
76 assertEquals(string, result.toString().substring(0, string.length()));
77 }
78
79 /**
80 * Run the SequenceDefinition createDefinition(DefinitionScope,String)
81 * method test.
82 */
83 @Test
84 public void testCreateDefinition() {
85 IntegerDeclaration id = new IntegerDeclaration(8, false, 8,
86 ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null, 32);
87
88 StructDeclaration structDec = new StructDeclaration(0);
89 structDec.addField(fieldName, id);
90 StructDefinition structDef = new StructDefinition(structDec, null, "x"); //$NON-NLS-1$
91 long seqLen = 10;
92 structDef.lookupInteger(fieldName).setValue(seqLen);
93 SequenceDefinition result = this.fixture.createDefinition(structDef,
94 fieldName);
95 assertNotNull(result);
96 }
97
98 /**
99 * Run the Declaration getElementType() method test.
100 */
101 @Test
102 public void testGetElementType() {
103 IDeclaration result = fixture.getElementType();
104 assertNotNull(result);
105 }
106
107 /**
108 * Run the String toString() method test.
109 */
110 @Test
111 public void testToString() {
112 String result = fixture.toString();
113 String left = "[declaration] sequence["; //$NON-NLS-1$
114 assertEquals(left, result.substring(0, left.length()));
115 }
116 }
This page took 0.040683 seconds and 5 git commands to generate.