1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 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
.tracecompass
.ctf
.core
.tests
.types
;
14 import static org
.junit
.Assert
.assertEquals
;
15 import static org
.junit
.Assert
.assertNotEquals
;
16 import static org
.junit
.Assert
.assertNotNull
;
17 import static org
.junit
.Assert
.assertNull
;
18 import static org
.junit
.Assert
.assertTrue
;
20 import java
.nio
.ByteBuffer
;
21 import java
.nio
.ByteOrder
;
23 import org
.eclipse
.tracecompass
.ctf
.core
.CTFException
;
24 import org
.eclipse
.tracecompass
.ctf
.core
.event
.io
.BitBuffer
;
25 import org
.eclipse
.tracecompass
.ctf
.core
.event
.scope
.IDefinitionScope
;
26 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.Encoding
;
27 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.EnumDeclaration
;
28 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.EnumDefinition
;
29 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.IntegerDeclaration
;
30 import org
.eclipse
.tracecompass
.ctf
.core
.tests
.io
.Util
;
31 import org
.junit
.Before
;
32 import org
.junit
.Test
;
35 * The class <code>EnumDeclarationTest</code> contains tests for the class
36 * <code>{@link EnumDeclaration}</code>.
39 * @version $Revision: 1.0 $
41 public class EnumDeclarationTest
{
43 private EnumDeclaration fixture
;
46 * Perform pre-test initialization.
50 fixture
= new EnumDeclaration(IntegerDeclaration
.createDeclaration(1, false, 1,
51 ByteOrder
.BIG_ENDIAN
, Encoding
.ASCII
, "", 8));
55 * Run the EnumDeclaration(IntegerDeclaration) constructor test.
58 public void testEnumDeclaration() {
59 IntegerDeclaration containerType
= IntegerDeclaration
.createDeclaration(1, false, 1,
60 ByteOrder
.BIG_ENDIAN
, Encoding
.ASCII
, "", 8);
62 EnumDeclaration result
= new EnumDeclaration(containerType
);
64 assertNotNull(result
);
65 String left
= "[declaration] enum[";
66 assertEquals(left
, result
.toString().substring(0, left
.length()));
70 * Run the boolean add(long,long,String) method test.
73 public void testAdd() {
78 boolean result
= fixture
.add(low
, high
, label
);
84 * Run the EnumDefinition createDefinition(DefinitionScope,String) method
87 * @throws CTFException
88 * out of bounds error, won't happen
91 public void testCreateDefinition() throws CTFException
{
92 IDefinitionScope definitionScope
= null;
93 String fieldName
= "";
94 byte[] array
= { 't', 'e', 's', 't', '\0', 't', 'h', 'i', 's', '\0' };
95 BitBuffer bb
= new BitBuffer(Util
.testMemory(ByteBuffer
.wrap(array
)));
97 EnumDefinition result
= fixture
.createDefinition(definitionScope
,
100 assertNotNull(result
);
104 * Run the String query(long) method test.
107 public void testQuery() {
109 String result
= fixture
.query(value
);
115 * Run the String toString() method test.
118 public void testToString() {
119 String result
= fixture
.toString();
121 String left
= "[declaration] enum[";
122 assertEquals(left
, result
.substring(0, left
.length()));
129 public void hashcodeTest() {
130 EnumDeclaration b
= new EnumDeclaration(IntegerDeclaration
.createDeclaration(1, false, 1,
131 ByteOrder
.BIG_ENDIAN
, Encoding
.ASCII
, "", 8));
132 assertEquals(b
.hashCode(), fixture
.hashCode());
133 fixture
.add(0, 1, "hello");
134 fixture
.add(2, 3, "kitty");
135 b
.add(0, 1, "hello");
136 b
.add(2, 3, "kitty");
137 assertEquals(fixture
.hashCode(), b
.hashCode());
145 public void equalsTest() {
146 EnumDeclaration a
= new EnumDeclaration(IntegerDeclaration
.INT_8_DECL
);
147 EnumDeclaration b
= new EnumDeclaration(IntegerDeclaration
.INT_8_DECL
);
149 EnumDeclaration c
= new EnumDeclaration(IntegerDeclaration
.INT_32B_DECL
);
150 EnumDeclaration d
= new EnumDeclaration(IntegerDeclaration
.INT_8_DECL
);
151 assertNotEquals(a
, null);
152 assertNotEquals(a
, new Object());
153 assertNotEquals(a
, b
);
154 assertNotEquals(a
, c
);
155 assertNotEquals(b
, c
);
157 assertNotEquals(b
, a
);
158 assertNotEquals(c
, a
);
159 assertNotEquals(c
, b
);
165 assertNotEquals(a
, d
);
166 assertNotEquals(d
, a
);
168 assertNotEquals(a
, d
);
169 assertNotEquals(d
, a
);