ctf: Rename packages to org.eclipse.tracecompass.*
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core.tests / src / org / eclipse / tracecompass / ctf / core / tests / types / EnumDeclarationTest.java
CommitLineData
4bd7f2db
AM
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
f357bcd4 12package org.eclipse.tracecompass.ctf.core.tests.types;
866e5b51
FC
13
14import static org.junit.Assert.assertEquals;
15import static org.junit.Assert.assertNotNull;
16import static org.junit.Assert.assertNull;
17import static org.junit.Assert.assertTrue;
18
a4fa4e36 19import java.nio.ByteBuffer;
866e5b51
FC
20import java.nio.ByteOrder;
21
f357bcd4
AM
22import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer;
23import org.eclipse.tracecompass.ctf.core.event.scope.IDefinitionScope;
24import org.eclipse.tracecompass.ctf.core.event.types.Encoding;
25import org.eclipse.tracecompass.ctf.core.event.types.EnumDeclaration;
26import org.eclipse.tracecompass.ctf.core.event.types.EnumDefinition;
27import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration;
28import org.eclipse.tracecompass.ctf.core.tests.io.Util;
29import org.eclipse.tracecompass.ctf.core.trace.CTFReaderException;
866e5b51
FC
30import org.junit.Before;
31import org.junit.Test;
32
33/**
34 * The class <code>EnumDeclarationTest</code> contains tests for the class
35 * <code>{@link EnumDeclaration}</code>.
284fdee8 36 *
866e5b51
FC
37 * @author ematkho
38 * @version $Revision: 1.0 $
39 */
40public class EnumDeclarationTest {
41
42 private EnumDeclaration fixture;
43
866e5b51
FC
44 /**
45 * Perform pre-test initialization.
46 */
47 @Before
48 public void setUp() {
a4fa4e36
MK
49 fixture = new EnumDeclaration(IntegerDeclaration.createDeclaration(1, false, 1,
50 ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 8));
866e5b51
FC
51 }
52
866e5b51
FC
53 /**
54 * Run the EnumDeclaration(IntegerDeclaration) constructor test.
55 */
56 @Test
57 public void testEnumDeclaration() {
a4fa4e36
MK
58 IntegerDeclaration containerType = IntegerDeclaration.createDeclaration(1, false, 1,
59 ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 8);
866e5b51
FC
60
61 EnumDeclaration result = new EnumDeclaration(containerType);
62
63 assertNotNull(result);
4a9c1f07 64 String left = "[declaration] enum[";
866e5b51
FC
65 assertEquals(left, result.toString().substring(0, left.length()));
66 }
67
68 /**
69 * Run the boolean add(long,long,String) method test.
70 */
71 @Test
72 public void testAdd() {
73 long low = 1L;
74 long high = 1L;
4a9c1f07 75 String label = "";
866e5b51
FC
76
77 boolean result = fixture.add(low, high, label);
78
79 assertTrue(result);
80 }
81
82 /**
83 * Run the EnumDefinition createDefinition(DefinitionScope,String) method
84 * test.
a4fa4e36
MK
85 *
86 * @throws CTFReaderException
87 * out of bounds error, won't happen
866e5b51
FC
88 */
89 @Test
a4fa4e36 90 public void testCreateDefinition() throws CTFReaderException {
866e5b51 91 IDefinitionScope definitionScope = null;
4a9c1f07 92 String fieldName = "";
a4fa4e36 93 byte[] array = { 't', 'e', 's', 't', '\0', 't', 'h', 'i', 's', '\0' };
aefc5c83 94 BitBuffer bb = new BitBuffer(Util.testMemory(ByteBuffer.wrap(array)));
866e5b51
FC
95
96 EnumDefinition result = fixture.createDefinition(definitionScope,
a4fa4e36 97 fieldName, bb);
866e5b51
FC
98
99 assertNotNull(result);
100 }
101
866e5b51
FC
102 /**
103 * Run the String query(long) method test.
104 */
105 @Test
106 public void testQuery() {
107 long value = 0;
108 String result = fixture.query(value);
109
110 assertNull(result);
111 }
112
113 /**
114 * Run the String toString() method test.
115 */
116 @Test
117 public void testToString() {
118 String result = fixture.toString();
119
4a9c1f07 120 String left = "[declaration] enum[";
866e5b51
FC
121 assertEquals(left, result.substring(0, left.length()));
122 }
123}
This page took 0.053992 seconds and 5 git commands to generate.