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
.ByteOrder
;
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
.Before
;
28 import org
.junit
.Test
;
31 * The class <code>SequenceDeclarationTest</code> contains tests for the class
32 * <code>{@link SequenceDeclaration}</code>.
35 * @version $Revision: 1.0 $
37 @SuppressWarnings("javadoc")
38 public class SequenceDeclarationTest
{
40 private SequenceDeclaration fixture
;
42 static final String fieldName
= "LengthName";
46 fixture
= new SequenceDeclaration(fieldName
, new StringDeclaration());
50 * Run the SequenceDeclaration(String,Declaration) constructor test.
53 public void testSequenceDeclaration() {
54 String lengthName
= "";
55 IDeclaration elemType
= new StringDeclaration();
57 SequenceDeclaration result
= new SequenceDeclaration(lengthName
, elemType
);
58 assertNotNull(result
);
59 String string
= "[declaration] sequence[";
60 assertEquals(string
, result
.toString().substring(0, string
.length()));
64 * Run the SequenceDefinition createDefinition(DefinitionScope,String)
68 public void testCreateDefinition() {
69 IntegerDeclaration id
= new IntegerDeclaration(8, false, 8,
70 ByteOrder
.LITTLE_ENDIAN
, Encoding
.UTF8
, null, 32);
72 StructDeclaration structDec
= new StructDeclaration(0);
73 structDec
.addField(fieldName
, id
);
74 StructDefinition structDef
= new StructDefinition(structDec
, null, "x");
76 structDef
.lookupInteger(fieldName
).setValue(seqLen
);
77 SequenceDefinition result
= this.fixture
.createDefinition(structDef
, fieldName
);
78 assertNotNull(result
);
82 * Run the Declaration getElementType() method test.
85 public void testGetElementType() {
86 IDeclaration result
= fixture
.getElementType();
87 assertNotNull(result
);
91 * Run the String toString() method test.
94 public void testToString() {
95 String result
= fixture
.toString();
96 String left
= "[declaration] sequence[";
97 assertEquals(left
, result
.substring(0, left
.length()));