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