ctf: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / types / SequenceDeclaration2Test.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.ByteBuffer;
18 import java.nio.ByteOrder;
19
20 import org.eclipse.jdt.annotation.NonNull;
21 import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
22 import org.eclipse.linuxtools.ctf.core.event.types.AbstractArrayDefinition;
23 import org.eclipse.linuxtools.ctf.core.event.types.Definition;
24 import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
25 import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
26 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
27 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
28 import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
29 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
30 import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
31 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
32 import org.eclipse.linuxtools.internal.ctf.core.event.types.SequenceDeclaration;
33 import org.junit.Before;
34 import org.junit.Test;
35
36 import com.google.common.collect.ImmutableList;
37
38 /**
39 * The class <code>SequenceDeclarationTest</code> contains tests for the class
40 * <code>{@link SequenceDeclaration}</code>.
41 *
42 * @author ematkho
43 * @version $Revision: 1.0 $
44 */
45 @SuppressWarnings("javadoc")
46 public class SequenceDeclaration2Test {
47
48 @NonNull private static final String FIELD_NAME = "LengthName";
49
50 private SequenceDeclaration fixture;
51 @NonNull private BitBuffer input = new BitBuffer();
52
53 @Before
54 public void setUp() {
55 fixture = new SequenceDeclaration(FIELD_NAME, new StringDeclaration());
56 byte array[] = { 't', 'e', 's', 't', '\0', 't', 'h', 'i', 's', '\0' };
57 ByteBuffer byb = ByteBuffer.wrap(array);
58 if( byb == null){
59 throw new IllegalStateException("Failed to allocate memory");
60 }
61 input = new BitBuffer(byb);
62 }
63
64 /**
65 * Run the SequenceDeclaration(String,Declaration) constructor test.
66 */
67 @Test
68 public void testSequenceDeclaration() {
69 String lengthName = "";
70 IDeclaration elemType = new StringDeclaration();
71
72 SequenceDeclaration result = new SequenceDeclaration(lengthName, elemType);
73 assertNotNull(result);
74 String string = "[declaration] sequence[";
75 assertEquals(string, result.toString().substring(0, string.length()));
76 }
77
78 /**
79 * Run the SequenceDefinition createDefinition(DefinitionScope,String)
80 * method test.
81 *
82 * @throws CTFReaderException
83 * an error in the bitbuffer
84 */
85 @Test
86 public void testCreateDefinition() throws CTFReaderException {
87 long seqLen = 2;
88 IntegerDeclaration id = IntegerDeclaration.createDeclaration(8, false, 8,
89 ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 32);
90 StructDeclaration structDec = new StructDeclaration(0);
91 structDec.addField(FIELD_NAME, id);
92 StructDefinition structDef = new StructDefinition(
93 structDec,
94 null,
95 "x",
96 ImmutableList.of(FIELD_NAME),
97 new Definition[] {
98 new IntegerDefinition(
99 id,
100 null,
101 FIELD_NAME,
102 seqLen)
103 });
104 AbstractArrayDefinition result = fixture.createDefinition(structDef, FIELD_NAME, input);
105 assertNotNull(result);
106 }
107
108 /**
109 * Run the Declaration getElementType() method test.
110 */
111 @Test
112 public void testGetElementType() {
113 IDeclaration result = fixture.getElementType();
114 assertNotNull(result);
115 }
116
117 /**
118 * Run the String toString() method test.
119 */
120 @Test
121 public void testToString() {
122 String result = fixture.toString();
123 String left = "[declaration] sequence[";
124 assertEquals(left, result.substring(0, left.length()));
125 }
126 }
This page took 0.049228 seconds and 5 git commands to generate.