ctf: potential memory optimization
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / types / SequenceDeclarationTest.java
CommitLineData
4bd7f2db
AM
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
866e5b51
FC
12package org.eclipse.linuxtools.ctf.core.tests.types;
13
14import static org.junit.Assert.assertEquals;
15import static org.junit.Assert.assertNotNull;
16
17import java.nio.ByteOrder;
18
19import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
20import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
21import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
22import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration;
23import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition;
24import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
25import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
26import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
866e5b51
FC
27import org.junit.Before;
28import org.junit.Test;
29
30/**
31 * The class <code>SequenceDeclarationTest</code> contains tests for the class
32 * <code>{@link SequenceDeclaration}</code>.
284fdee8 33 *
866e5b51
FC
34 * @author ematkho
35 * @version $Revision: 1.0 $
36 */
be6df2d8 37@SuppressWarnings("javadoc")
866e5b51
FC
38public class SequenceDeclarationTest {
39
40 private SequenceDeclaration fixture;
41
4a9c1f07 42 static final String fieldName = "LengthName";
866e5b51
FC
43
44 @Before
45 public void setUp() {
ce2388e0 46 fixture = new SequenceDeclaration(fieldName, new StringDeclaration());
866e5b51
FC
47 }
48
866e5b51
FC
49 /**
50 * Run the SequenceDeclaration(String,Declaration) constructor test.
51 */
52 @Test
53 public void testSequenceDeclaration() {
4a9c1f07 54 String lengthName = "";
866e5b51
FC
55 IDeclaration elemType = new StringDeclaration();
56
4a9c1f07 57 SequenceDeclaration result = new SequenceDeclaration(lengthName, elemType);
866e5b51 58 assertNotNull(result);
4a9c1f07 59 String string = "[declaration] sequence[";
866e5b51
FC
60 assertEquals(string, result.toString().substring(0, string.length()));
61 }
62
63 /**
64 * Run the SequenceDefinition createDefinition(DefinitionScope,String)
65 * method test.
66 */
67 @Test
68 public void testCreateDefinition() {
69 IntegerDeclaration id = new IntegerDeclaration(8, false, 8,
fd74e6c1 70 ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null, 32);
ce2388e0 71
866e5b51
FC
72 StructDeclaration structDec = new StructDeclaration(0);
73 structDec.addField(fieldName, id);
4a9c1f07 74 StructDefinition structDef = new StructDefinition(structDec, null, "x");
866e5b51
FC
75 long seqLen = 10;
76 structDef.lookupInteger(fieldName).setValue(seqLen);
4a9c1f07 77 SequenceDefinition result = this.fixture.createDefinition(structDef, fieldName);
866e5b51
FC
78 assertNotNull(result);
79 }
80
81 /**
82 * Run the Declaration getElementType() method test.
83 */
84 @Test
85 public void testGetElementType() {
86 IDeclaration result = fixture.getElementType();
87 assertNotNull(result);
88 }
89
90 /**
91 * Run the String toString() method test.
92 */
93 @Test
94 public void testToString() {
95 String result = fixture.toString();
4a9c1f07 96 String left = "[declaration] sequence[";
866e5b51
FC
97 assertEquals(left, result.substring(0, left.length()));
98 }
99}
This page took 0.040633 seconds and 5 git commands to generate.