Revert "ss: accelerate state system creation by 25% by coalescing intervals"
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core.tests / src / org / eclipse / tracecompass / ctf / core / tests / types / SequenceDeclaration2Test.java
CommitLineData
4bd7f2db 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2013, 2014 Ericsson
4bd7f2db
AM
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;
f9d7c59f 15import static org.junit.Assert.assertFalse;
e00e6663 16import static org.junit.Assert.assertNotEquals;
866e5b51 17import static org.junit.Assert.assertNotNull;
f9d7c59f 18import static org.junit.Assert.assertTrue;
866e5b51 19
a4fa4e36 20import java.nio.ByteBuffer;
866e5b51
FC
21import java.nio.ByteOrder;
22
a4fa4e36 23import org.eclipse.jdt.annotation.NonNull;
453a59f0 24import org.eclipse.tracecompass.ctf.core.CTFReaderException;
f357bcd4
AM
25import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer;
26import org.eclipse.tracecompass.ctf.core.event.types.AbstractArrayDefinition;
27import org.eclipse.tracecompass.ctf.core.event.types.Definition;
28import org.eclipse.tracecompass.ctf.core.event.types.Encoding;
29import org.eclipse.tracecompass.ctf.core.event.types.IDeclaration;
30import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration;
31import org.eclipse.tracecompass.ctf.core.event.types.IntegerDefinition;
32import org.eclipse.tracecompass.ctf.core.event.types.StringDeclaration;
33import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration;
34import org.eclipse.tracecompass.ctf.core.event.types.StructDefinition;
f357bcd4 35import org.eclipse.tracecompass.internal.ctf.core.event.types.SequenceDeclaration;
866e5b51
FC
36import org.junit.Before;
37import org.junit.Test;
38
a4fa4e36
MK
39import com.google.common.collect.ImmutableList;
40
866e5b51
FC
41/**
42 * The class <code>SequenceDeclarationTest</code> contains tests for the class
43 * <code>{@link SequenceDeclaration}</code>.
284fdee8 44 *
866e5b51
FC
45 * @author ematkho
46 * @version $Revision: 1.0 $
47 */
be6df2d8 48@SuppressWarnings("javadoc")
7b4f13e6 49public class SequenceDeclaration2Test {
866e5b51 50
e00e6663
MK
51 @NonNull
52 private static final String FIELD_NAME = "LengthName";
866e5b51 53
a4fa4e36 54 private SequenceDeclaration fixture;
e00e6663
MK
55 @NonNull
56 private BitBuffer input = new BitBuffer();
866e5b51
FC
57
58 @Before
59 public void setUp() {
d890ec37 60 fixture = new SequenceDeclaration(FIELD_NAME, StringDeclaration.getStringDeclaration(Encoding.UTF8));
a4fa4e36
MK
61 byte array[] = { 't', 'e', 's', 't', '\0', 't', 'h', 'i', 's', '\0' };
62 ByteBuffer byb = ByteBuffer.wrap(array);
e00e6663 63 if (byb == null) {
aefc5c83
MK
64 throw new IllegalStateException("Failed to allocate memory");
65 }
a4fa4e36 66 input = new BitBuffer(byb);
866e5b51
FC
67 }
68
866e5b51
FC
69 /**
70 * Run the SequenceDeclaration(String,Declaration) constructor test.
71 */
72 @Test
73 public void testSequenceDeclaration() {
4a9c1f07 74 String lengthName = "";
d890ec37 75 IDeclaration elemType = StringDeclaration.getStringDeclaration(Encoding.UTF8);
866e5b51 76
4a9c1f07 77 SequenceDeclaration result = new SequenceDeclaration(lengthName, elemType);
866e5b51 78 assertNotNull(result);
4a9c1f07 79 String string = "[declaration] sequence[";
866e5b51
FC
80 assertEquals(string, result.toString().substring(0, string.length()));
81 }
82
83 /**
84 * Run the SequenceDefinition createDefinition(DefinitionScope,String)
85 * method test.
a4fa4e36
MK
86 *
87 * @throws CTFReaderException
88 * an error in the bitbuffer
866e5b51
FC
89 */
90 @Test
a4fa4e36
MK
91 public void testCreateDefinition() throws CTFReaderException {
92 long seqLen = 2;
93 IntegerDeclaration id = IntegerDeclaration.createDeclaration(8, false, 8,
94 ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 32);
866e5b51 95 StructDeclaration structDec = new StructDeclaration(0);
a4fa4e36
MK
96 structDec.addField(FIELD_NAME, id);
97 StructDefinition structDef = new StructDefinition(
98 structDec,
99 null,
100 "x",
101 ImmutableList.of(FIELD_NAME),
102 new Definition[] {
103 new IntegerDefinition(
104 id,
105 null,
106 FIELD_NAME,
107 seqLen)
108 });
7b4f13e6 109 AbstractArrayDefinition result = fixture.createDefinition(structDef, FIELD_NAME, input);
866e5b51
FC
110 assertNotNull(result);
111 }
112
113 /**
114 * Run the Declaration getElementType() method test.
115 */
116 @Test
117 public void testGetElementType() {
118 IDeclaration result = fixture.getElementType();
119 assertNotNull(result);
120 }
121
122 /**
123 * Run the String toString() method test.
124 */
125 @Test
126 public void testToString() {
127 String result = fixture.toString();
4a9c1f07 128 String left = "[declaration] sequence[";
866e5b51
FC
129 assertEquals(left, result.substring(0, left.length()));
130 }
e00e6663
MK
131
132 /**
133 * Test the hashcode
134 */
135 @Test
136 public void hashcodeTest() {
137 assertEquals(-1140774256, fixture.hashCode());
138 SequenceDeclaration a = new SequenceDeclaration("Hi", IntegerDeclaration.INT_32B_DECL);
139 SequenceDeclaration b = new SequenceDeclaration("Hello", IntegerDeclaration.INT_32B_DECL);
d890ec37 140 SequenceDeclaration c = new SequenceDeclaration("Hi", StringDeclaration.getStringDeclaration(Encoding.UTF8));
e00e6663
MK
141 SequenceDeclaration d = new SequenceDeclaration("Hi", IntegerDeclaration.INT_32B_DECL);
142 assertNotEquals(a.hashCode(), b.hashCode());
143 assertNotEquals(a.hashCode(), c.hashCode());
144 assertEquals(a.hashCode(), d.hashCode());
145 }
146
147 /**
148 * Test the equals
149 */
150 @Test
151 public void equalsTest() {
152 SequenceDeclaration a = new SequenceDeclaration("Hi", IntegerDeclaration.INT_32B_DECL);
153 SequenceDeclaration b = new SequenceDeclaration("Hello", IntegerDeclaration.INT_32B_DECL);
d890ec37 154 SequenceDeclaration c = new SequenceDeclaration("Hi", StringDeclaration.getStringDeclaration(Encoding.UTF8));
e00e6663
MK
155 SequenceDeclaration d = new SequenceDeclaration("Hi", IntegerDeclaration.INT_32B_DECL);
156 assertNotEquals(a, null);
157 assertNotEquals(a, new Object());
158 assertNotEquals(a, b);
159 assertNotEquals(a, c);
160 assertEquals(a, d);
161 assertNotEquals(b, a);
162 assertNotEquals(c, a);
163 assertEquals(d, a);
164 assertEquals(a, a);
f9d7c59f
MK
165 assertFalse(a.isBinaryEquivalent(b));
166 assertFalse(a.isBinaryEquivalent(c));
167 assertTrue(a.isBinaryEquivalent(d));
168 assertFalse(b.isBinaryEquivalent(a));
169 assertFalse(c.isBinaryEquivalent(a));
170 assertTrue(d.isBinaryEquivalent(a));
171 assertTrue(a.isBinaryEquivalent(a));
e00e6663
MK
172 }
173
866e5b51 174}
This page took 0.0636 seconds and 5 git commands to generate.