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
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
27 import org
.junit
.Before
;
28 import org
.junit
.Test
;
31 * The class <code>EnumDefinitionTest</code> contains tests for the class
32 * <code>{@link EnumDefinition}</code>.
35 * @version $Revision: 1.0 $
37 public class EnumDefinitionTest
{
39 private EnumDefinition fixture
;
42 * Perform pre-test initialization.
46 EnumDeclaration declaration
= new EnumDeclaration(
47 new IntegerDeclaration(1, false, 1, ByteOrder
.BIG_ENDIAN
,
48 Encoding
.ASCII
, null, 8));
49 declaration
.add(0, 10, "a");
50 declaration
.add(11, 20, "b");
51 String fieldName
= "";
53 fixture
= new EnumDefinition(declaration
, null, fieldName
);
57 * Run the EnumDefinition(EnumDeclaration,DefinitionScope,String)
61 public void testEnumDefinition() {
62 assertNotNull(fixture
);
66 * Run the String getValue() method test.
69 public void testGetValue() {
70 String result
= fixture
.getValue();
72 assertNotNull(result
);
76 * Run the long getIntegerValue() method test.
79 public void testGetIntegerValue_one() {
80 fixture
.setIntegerValue(1L);
81 long result
= fixture
.getIntegerValue();
83 assertEquals(1L, result
);
87 * Run the String getValue() method test.
90 public void testGetIntegerValue_zero() {
91 fixture
.setIntegerValue(0);
92 long result
= fixture
.getIntegerValue();
94 assertTrue(0 == result
);
98 * Run the void read(BitBuffer) method test.
99 * @throws CTFReaderException error
102 public void testRead() throws CTFReaderException
{
103 fixture
.setIntegerValue(1L);
104 BitBuffer input
= new BitBuffer(ByteBuffer
.allocateDirect(128));
110 * Run the String toString() method test.
113 public void testToString() {
114 fixture
.setIntegerValue(16);
115 String result
= fixture
.toString();
117 assertEquals("{ value = b, container = 16 }", result
);