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
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.types
;
14 import static org
.junit
.Assert
.assertEquals
;
15 import static org
.junit
.Assert
.assertNotNull
;
17 import java
.nio
.ByteBuffer
;
18 import java
.nio
.ByteOrder
;
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
;
36 import com
.google
.common
.collect
.ImmutableList
;
39 * The class <code>SequenceDeclarationTest</code> contains tests for the class
40 * <code>{@link SequenceDeclaration}</code>.
43 * @version $Revision: 1.0 $
45 @SuppressWarnings("javadoc")
46 public class SequenceDeclaration2Test
{
48 @NonNull private static final String FIELD_NAME
= "LengthName";
50 private SequenceDeclaration fixture
;
51 @NonNull private BitBuffer input
= new BitBuffer();
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
);
59 throw new IllegalStateException("Failed to allocate memory");
61 input
= new BitBuffer(byb
);
65 * Run the SequenceDeclaration(String,Declaration) constructor test.
68 public void testSequenceDeclaration() {
69 String lengthName
= "";
70 IDeclaration elemType
= new StringDeclaration();
72 SequenceDeclaration result
= new SequenceDeclaration(lengthName
, elemType
);
73 assertNotNull(result
);
74 String string
= "[declaration] sequence[";
75 assertEquals(string
, result
.toString().substring(0, string
.length()));
79 * Run the SequenceDefinition createDefinition(DefinitionScope,String)
82 * @throws CTFReaderException
83 * an error in the bitbuffer
86 public void testCreateDefinition() throws CTFReaderException
{
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(
96 ImmutableList
.of(FIELD_NAME
),
98 new IntegerDefinition(
104 AbstractArrayDefinition result
= fixture
.createDefinition(structDef
, FIELD_NAME
, input
);
105 assertNotNull(result
);
109 * Run the Declaration getElementType() method test.
112 public void testGetElementType() {
113 IDeclaration result
= fixture
.getElementType();
114 assertNotNull(result
);
118 * Run the String toString() method test.
121 public void testToString() {
122 String result
= fixture
.toString();
123 String left
= "[declaration] sequence[";
124 assertEquals(left
, result
.substring(0, left
.length()));