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
.assertNull
;
17 import static org
.junit
.Assert
.assertTrue
;
19 import java
.nio
.ByteBuffer
;
20 import java
.nio
.ByteOrder
;
22 import org
.eclipse
.linuxtools
.ctf
.core
.event
.io
.BitBuffer
;
23 import org
.eclipse
.linuxtools
.ctf
.core
.event
.scope
.IDefinitionScope
;
24 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.Encoding
;
25 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.EnumDeclaration
;
26 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.EnumDefinition
;
27 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IntegerDeclaration
;
28 import org
.eclipse
.linuxtools
.ctf
.core
.tests
.io
.Util
;
29 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
30 import org
.junit
.Before
;
31 import org
.junit
.Test
;
34 * The class <code>EnumDeclarationTest</code> contains tests for the class
35 * <code>{@link EnumDeclaration}</code>.
38 * @version $Revision: 1.0 $
40 public class EnumDeclarationTest
{
42 private EnumDeclaration fixture
;
45 * Perform pre-test initialization.
49 fixture
= new EnumDeclaration(IntegerDeclaration
.createDeclaration(1, false, 1,
50 ByteOrder
.BIG_ENDIAN
, Encoding
.ASCII
, "", 8));
54 * Run the EnumDeclaration(IntegerDeclaration) constructor test.
57 public void testEnumDeclaration() {
58 IntegerDeclaration containerType
= IntegerDeclaration
.createDeclaration(1, false, 1,
59 ByteOrder
.BIG_ENDIAN
, Encoding
.ASCII
, "", 8);
61 EnumDeclaration result
= new EnumDeclaration(containerType
);
63 assertNotNull(result
);
64 String left
= "[declaration] enum[";
65 assertEquals(left
, result
.toString().substring(0, left
.length()));
69 * Run the boolean add(long,long,String) method test.
72 public void testAdd() {
77 boolean result
= fixture
.add(low
, high
, label
);
83 * Run the EnumDefinition createDefinition(DefinitionScope,String) method
86 * @throws CTFReaderException
87 * out of bounds error, won't happen
90 public void testCreateDefinition() throws CTFReaderException
{
91 IDefinitionScope definitionScope
= null;
92 String fieldName
= "";
93 byte[] array
= { 't', 'e', 's', 't', '\0', 't', 'h', 'i', 's', '\0' };
94 BitBuffer bb
= new BitBuffer(Util
.testMemory(ByteBuffer
.wrap(array
)));
96 EnumDefinition result
= fixture
.createDefinition(definitionScope
,
99 assertNotNull(result
);
103 * Run the String query(long) method test.
106 public void testQuery() {
108 String result
= fixture
.query(value
);
114 * Run the String toString() method test.
117 public void testToString() {
118 String result
= fixture
.toString();
120 String left
= "[declaration] enum[";
121 assertEquals(left
, result
.substring(0, left
.length()));