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
.ByteBuffer
;
19 import java
.nio
.ByteOrder
;
21 import org
.eclipse
.linuxtools
.ctf
.core
.event
.io
.BitBuffer
;
22 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.Encoding
;
23 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.EnumDeclaration
;
24 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.EnumDefinition
;
25 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IntegerDeclaration
;
26 import org
.junit
.Before
;
27 import org
.junit
.Test
;
30 * The class <code>EnumDefinitionTest</code> contains tests for the class
31 * <code>{@link EnumDefinition}</code>.
34 * @version $Revision: 1.0 $
36 public class EnumDefinitionTest
{
38 private EnumDefinition fixture
;
41 * Perform pre-test initialization.
45 EnumDeclaration declaration
= new EnumDeclaration(
46 new IntegerDeclaration(1, false, 1, ByteOrder
.BIG_ENDIAN
,
47 Encoding
.ASCII
, null, 8));
48 declaration
.add(0, 10, "a");
49 declaration
.add(11, 20, "b");
50 String fieldName
= "";
52 fixture
= new EnumDefinition(declaration
, null, fieldName
);
56 * Run the EnumDefinition(EnumDeclaration,DefinitionScope,String)
60 public void testEnumDefinition() {
61 assertNotNull(fixture
);
65 * Run the String getValue() method test.
68 public void testGetValue() {
69 String result
= fixture
.getValue();
71 assertNotNull(result
);
75 * Run the long getIntegerValue() method test.
78 public void testGetIntegerValue_one() {
79 fixture
.setIntegerValue(1L);
80 long result
= fixture
.getIntegerValue();
82 assertEquals(1L, result
);
86 * Run the String getValue() method test.
89 public void testGetIntegerValue_zero() {
90 fixture
.setIntegerValue(0);
91 long result
= fixture
.getIntegerValue();
93 assertTrue(0 == result
);
97 * Run the void read(BitBuffer) method test.
100 public void testRead() {
101 fixture
.setIntegerValue(1L);
102 BitBuffer input
= new BitBuffer(ByteBuffer
.allocateDirect(128));
108 * Run the String toString() method test.
111 public void testToString() {
112 fixture
.setIntegerValue(16);
113 String result
= fixture
.toString();
115 assertEquals("{ value = b, container = 16 }", result
);