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
.assertNotNull
;
16 import java
.nio
.ByteBuffer
;
17 import java
.nio
.ByteOrder
;
19 import org
.eclipse
.linuxtools
.ctf
.core
.event
.io
.BitBuffer
;
20 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.Definition
;
21 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.Encoding
;
22 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IDefinition
;
23 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IntegerDeclaration
;
24 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IntegerDefinition
;
25 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDeclaration
;
26 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDefinition
;
27 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
28 import org
.eclipse
.linuxtools
.internal
.ctf
.core
.event
.types
.ByteArrayDefinition
;
29 import org
.eclipse
.linuxtools
.internal
.ctf
.core
.event
.types
.SequenceDeclaration
;
30 import org
.junit
.Before
;
31 import org
.junit
.Test
;
33 import com
.google
.common
.collect
.ImmutableList
;
36 * The class <code>SequenceDefinition2Test</code> contains tests for the class
37 * <code>{@link SequenceDefinition2}</code>.
40 * @version $Revision: 1.0 $
42 @SuppressWarnings("javadoc")
43 public class SequenceDefinition2Test
{
45 private ByteArrayDefinition fixture
;
46 private final static int seqLen
= 15;
48 private static ImmutableList
<String
> wrap(String s
) {
49 return ImmutableList
.<String
> builder().add(s
).build();
53 * Perform pre-test initialization.
55 * @throws CTFReaderException
58 public void setUp() throws CTFReaderException
{
59 fixture
= initString();
62 private static ByteArrayDefinition
initString() throws CTFReaderException
{
63 StructDeclaration structDec
;
64 StructDefinition structDef
;
67 IntegerDeclaration id
= IntegerDeclaration
.createDeclaration(len
, false, len
,
68 ByteOrder
.LITTLE_ENDIAN
, Encoding
.UTF8
, "", 8);
69 String lengthName
= "LengthName";
70 structDec
= new StructDeclaration(0);
71 structDec
.addField(lengthName
, id
);
73 structDef
= new StructDefinition(structDec
, null, "x", wrap(lengthName
), new Definition
[] { new IntegerDefinition(id
, null, lengthName
, seqLen
) });
75 SequenceDeclaration sd
= new SequenceDeclaration(lengthName
, id
);
76 ByteBuffer allocateDirect
= java
.nio
.ByteBuffer
.allocateDirect(seqLen
* len
);
77 if( allocateDirect
== null){
78 throw new IllegalStateException("Failed to allocate memory");
80 BitBuffer input
= new BitBuffer(allocateDirect
);
81 for (int i
= 0; i
< seqLen
; i
++) {
85 ByteArrayDefinition ret
= (ByteArrayDefinition
) sd
.createDefinition(structDef
, "TestX", input
);
91 * Run the FixedStringDefinition(SequenceDeclaration,DefinitionScope,String)
95 public void testFixedStringDefinition() {
96 assertNotNull(fixture
);
100 * Run the SequenceDeclaration getDeclaration() method test.
103 public void testGetDeclaration() {
104 SequenceDeclaration result
= (SequenceDeclaration
) fixture
.getDeclaration();
105 assertNotNull(result
);
109 * Run the Definition getElem(int) method test.
112 public void testGetElem() {
114 IDefinition result
= fixture
.getDefinitions().get(i
);
115 assertNotNull(result
);
119 * Run the String toString() method test.
122 public void testToString() {
123 String result
= fixture
.toString();
124 assertNotNull(result
);