20511a582047876cb66acf81c538a29011c241c7
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / types / EnumDefinitionTest.java
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
7 *
8 * Contributors:
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
11
12 package org.eclipse.linuxtools.ctf.core.tests.types;
13
14 import static org.junit.Assert.assertEquals;
15 import static org.junit.Assert.assertNotNull;
16 import static org.junit.Assert.assertTrue;
17
18 import java.nio.ByteBuffer;
19 import java.nio.ByteOrder;
20
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;
28
29 /**
30 * The class <code>EnumDefinitionTest</code> contains tests for the class
31 * <code>{@link EnumDefinition}</code>.
32 *
33 * @author ematkho
34 * @version $Revision: 1.0 $
35 */
36 public class EnumDefinitionTest {
37
38 private EnumDefinition fixture;
39
40 /**
41 * Perform pre-test initialization.
42 */
43 @Before
44 public void setUp() {
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 = "";
51
52 fixture = new EnumDefinition(declaration, null, fieldName);
53 }
54
55 /**
56 * Run the EnumDefinition(EnumDeclaration,DefinitionScope,String)
57 * constructor test.
58 */
59 @Test
60 public void testEnumDefinition() {
61 assertNotNull(fixture);
62 }
63
64 /**
65 * Run the String getValue() method test.
66 */
67 @Test
68 public void testGetValue() {
69 String result = fixture.getValue();
70
71 assertNotNull(result);
72 }
73
74 /**
75 * Run the long getIntegerValue() method test.
76 */
77 @Test
78 public void testGetIntegerValue_one() {
79 fixture.setIntegerValue(1L);
80 long result = fixture.getIntegerValue();
81
82 assertEquals(1L, result);
83 }
84
85 /**
86 * Run the String getValue() method test.
87 */
88 @Test
89 public void testGetIntegerValue_zero() {
90 fixture.setIntegerValue(0);
91 long result = fixture.getIntegerValue();
92
93 assertTrue(0 == result);
94 }
95
96 /**
97 * Run the void read(BitBuffer) method test.
98 */
99 @Test
100 public void testRead() {
101 fixture.setIntegerValue(1L);
102 BitBuffer input = new BitBuffer(ByteBuffer.allocateDirect(128));
103
104 fixture.read(input);
105 }
106
107 /**
108 * Run the String toString() method test.
109 */
110 @Test
111 public void testToString() {
112 fixture.setIntegerValue(16);
113 String result = fixture.toString();
114
115 assertEquals("{ value = b, container = 16 }", result);
116 }
117 }
This page took 0.042863 seconds and 5 git commands to generate.