rcp: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core.tests / src / org / eclipse / tracecompass / ctf / core / tests / types / EnumDeclarationTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 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.tracecompass.ctf.core.tests.types;
13
14 import static org.junit.Assert.assertEquals;
15 import static org.junit.Assert.assertNotEquals;
16 import static org.junit.Assert.assertNotNull;
17 import static org.junit.Assert.assertNull;
18 import static org.junit.Assert.assertTrue;
19
20 import java.nio.ByteBuffer;
21 import java.nio.ByteOrder;
22
23 import org.eclipse.tracecompass.ctf.core.CTFException;
24 import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer;
25 import org.eclipse.tracecompass.ctf.core.event.scope.IDefinitionScope;
26 import org.eclipse.tracecompass.ctf.core.event.types.Encoding;
27 import org.eclipse.tracecompass.ctf.core.event.types.EnumDeclaration;
28 import org.eclipse.tracecompass.ctf.core.event.types.EnumDefinition;
29 import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration;
30 import org.eclipse.tracecompass.ctf.core.tests.io.Util;
31 import org.junit.Before;
32 import org.junit.Test;
33
34 /**
35 * The class <code>EnumDeclarationTest</code> contains tests for the class
36 * <code>{@link EnumDeclaration}</code>.
37 *
38 * @author ematkho
39 * @version $Revision: 1.0 $
40 */
41 public class EnumDeclarationTest {
42
43 private EnumDeclaration fixture;
44
45 /**
46 * Perform pre-test initialization.
47 */
48 @Before
49 public void setUp() {
50 fixture = new EnumDeclaration(IntegerDeclaration.createDeclaration(1, false, 1,
51 ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 8));
52 }
53
54 /**
55 * Run the EnumDeclaration(IntegerDeclaration) constructor test.
56 */
57 @Test
58 public void testEnumDeclaration() {
59 IntegerDeclaration containerType = IntegerDeclaration.createDeclaration(1, false, 1,
60 ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 8);
61
62 EnumDeclaration result = new EnumDeclaration(containerType);
63
64 assertNotNull(result);
65 String left = "[declaration] enum[";
66 assertEquals(left, result.toString().substring(0, left.length()));
67 }
68
69 /**
70 * Run the boolean add(long,long,String) method test.
71 */
72 @Test
73 public void testAdd() {
74 long low = 1L;
75 long high = 1L;
76 String label = "";
77
78 boolean result = fixture.add(low, high, label);
79
80 assertTrue(result);
81 }
82
83 /**
84 * Run the EnumDefinition createDefinition(DefinitionScope,String) method
85 * test.
86 *
87 * @throws CTFException
88 * out of bounds error, won't happen
89 */
90 @Test
91 public void testCreateDefinition() throws CTFException {
92 IDefinitionScope definitionScope = null;
93 String fieldName = "";
94 byte[] array = { 't', 'e', 's', 't', '\0', 't', 'h', 'i', 's', '\0' };
95 BitBuffer bb = new BitBuffer(Util.testMemory(ByteBuffer.wrap(array)));
96
97 EnumDefinition result = fixture.createDefinition(definitionScope,
98 fieldName, bb);
99
100 assertNotNull(result);
101 }
102
103 /**
104 * Run the String query(long) method test.
105 */
106 @Test
107 public void testQuery() {
108 long value = 0;
109 String result = fixture.query(value);
110
111 assertNull(result);
112 }
113
114 /**
115 * Run the String toString() method test.
116 */
117 @Test
118 public void testToString() {
119 String result = fixture.toString();
120
121 String left = "[declaration] enum[";
122 assertEquals(left, result.substring(0, left.length()));
123 }
124
125 /**
126 * Test the hashcode
127 */
128 @Test
129 public void hashcodeTest() {
130 EnumDeclaration b = new EnumDeclaration(IntegerDeclaration.createDeclaration(1, false, 1,
131 ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 8));
132 assertEquals(b.hashCode(), fixture.hashCode());
133 fixture.add(0, 1, "hello");
134 fixture.add(2, 3, "kitty");
135 b.add(0, 1, "hello");
136 b.add(2, 3, "kitty");
137 assertEquals(fixture.hashCode(), b.hashCode());
138
139 }
140
141 /**
142 * Test the equals
143 */
144 @Test
145 public void equalsTest() {
146 EnumDeclaration a = new EnumDeclaration(IntegerDeclaration.INT_8_DECL);
147 EnumDeclaration b = new EnumDeclaration(IntegerDeclaration.INT_8_DECL);
148 b.add(2, 19, "hi");
149 EnumDeclaration c = new EnumDeclaration(IntegerDeclaration.INT_32B_DECL);
150 EnumDeclaration d = new EnumDeclaration(IntegerDeclaration.INT_8_DECL);
151 assertNotEquals(a, null);
152 assertNotEquals(a, new Object());
153 assertNotEquals(a, b);
154 assertNotEquals(a, c);
155 assertNotEquals(b, c);
156 assertEquals(a, d);
157 assertNotEquals(b, a);
158 assertNotEquals(c, a);
159 assertNotEquals(c, b);
160 assertEquals(d, a);
161 a.add(2, 19, "hi");
162 assertEquals(a, a);
163 assertEquals(a, b);
164 assertEquals(b, a);
165 assertNotEquals(a, d);
166 assertNotEquals(d, a);
167 d.add(2, 22, "hi");
168 assertNotEquals(a, d);
169 assertNotEquals(d, a);
170 }
171
172 }
This page took 0.034652 seconds and 5 git commands to generate.