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
;
16 import static org
.junit
.Assert
.assertTrue
;
18 import java
.nio
.ByteOrder
;
20 import org
.eclipse
.linuxtools
.ctf
.core
.event
.io
.BitBuffer
;
21 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.Definition
;
22 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.Encoding
;
23 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IntegerDeclaration
;
24 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.SequenceDeclaration
;
25 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.SequenceDefinition
;
26 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDeclaration
;
27 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDefinition
;
28 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
29 import org
.junit
.After
;
30 import org
.junit
.Before
;
31 import org
.junit
.Test
;
34 * The class <code>SequenceDefinitionTest</code> contains tests for the class
35 * <code>{@link SequenceDefinition}</code>.
38 * @version $Revision: 1.0 $
40 @SuppressWarnings("javadoc")
41 public class SequenceDefinitionTest
{
43 private SequenceDefinition fixture
;
44 private final static int seqLen
= 15;
50 * the command line arguments
52 public static void main(String
[] args
) {
53 new org
.junit
.runner
.JUnitCore().run(SequenceDefinitionTest
.class);
57 * Perform pre-test initialization.
58 * @throws CTFReaderException
61 public void setUp() throws CTFReaderException
{
62 StructDeclaration structDec
;
63 StructDefinition structDef
;
65 IntegerDeclaration id
= new IntegerDeclaration(8, false, 8,
66 ByteOrder
.LITTLE_ENDIAN
, Encoding
.UTF8
, null, 8);
67 String lengthName
= "LengthName";
68 structDec
= new StructDeclaration(0);
69 structDec
.addField(lengthName
, id
);
70 structDef
= new StructDefinition(structDec
, null, "x");
72 structDef
.lookupInteger(lengthName
).setValue(seqLen
);
73 SequenceDeclaration sd
= new SequenceDeclaration(lengthName
, id
);
74 fixture
= new SequenceDefinition(sd
, structDef
, "TestX");
75 BitBuffer input
= new BitBuffer(
76 java
.nio
.ByteBuffer
.allocateDirect(seqLen
* 8));
77 for (int i
= 0; i
< seqLen
; i
++) {
81 assert (fixture
!= null);
85 * Perform post-test clean-up.
88 public void tearDown() {
89 // Add additional tear down code here
92 private static SequenceDefinition
initNonString() throws CTFReaderException
{
93 StructDeclaration structDec
;
94 StructDefinition structDef
;
97 IntegerDeclaration id
= new IntegerDeclaration(len
, false, len
,
98 ByteOrder
.LITTLE_ENDIAN
, Encoding
.UTF8
, null,8);
99 String lengthName
= "LengthName";
100 structDec
= new StructDeclaration(0);
101 structDec
.addField(lengthName
, id
);
102 structDef
= new StructDefinition(structDec
, null, "x");
104 structDef
.lookupInteger(lengthName
).setValue(seqLen
);
105 SequenceDeclaration sd
= new SequenceDeclaration(lengthName
, id
);
106 SequenceDefinition ret
= new SequenceDefinition(sd
, structDef
, "TestX");
107 BitBuffer input
= new BitBuffer(
108 java
.nio
.ByteBuffer
.allocateDirect(seqLen
* len
));
109 for (int i
= 0; i
< seqLen
; i
++) {
118 * Run the SequenceDefinition(SequenceDeclaration,DefinitionScope,String)
122 public void testSequenceDefinition() {
123 assertNotNull(fixture
);
127 * Run the SequenceDeclaration getDeclaration() method test.
130 public void testGetDeclaration() {
131 SequenceDeclaration result
= fixture
.getDeclaration();
132 assertNotNull(result
);
136 * Run the Definition getElem(int) method test.
139 public void testGetElem() {
141 Definition result
= fixture
.getElem(i
);
142 assertNotNull(result
);
146 * Run the int getLength() method test.
149 public void testGetLength() {
150 int result
= fixture
.getLength();
152 assertEquals(seqLen
, result
);
156 * Run the boolean isString() method test.
159 public void testIsString() {
160 boolean result
= fixture
.isString();
165 * Run the void read(BitBuffer) method test.
168 public void testRead() {
169 BitBuffer input
= new BitBuffer(java
.nio
.ByteBuffer
.allocateDirect(128));
174 * Run the String toString() method test.
177 public void testToString() {
178 String result
= fixture
.toString();
179 assertNotNull(result
);
183 * Run the String toString() method test.
186 public void testToString_nonString() throws Exception
{
187 fixture
= initNonString();
188 String result
= fixture
.toString();
189 assertNotNull(result
);