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 / ArrayDeclaration2Test.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 13
7b4f13e6
MK
14import static org.junit.Assert.assertEquals;
15import static org.junit.Assert.assertFalse;
e00e6663 16import static org.junit.Assert.assertNotEquals;
7b4f13e6
MK
17import static org.junit.Assert.assertNotNull;
18import static org.junit.Assert.assertTrue;
9639bf3a 19
a4fa4e36 20import java.nio.ByteBuffer;
9639bf3a 21import java.nio.ByteOrder;
866e5b51 22
680f9173 23import org.eclipse.tracecompass.ctf.core.CTFException;
f357bcd4
AM
24import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer;
25import org.eclipse.tracecompass.ctf.core.event.scope.IDefinitionScope;
26import org.eclipse.tracecompass.ctf.core.event.types.AbstractArrayDefinition;
27import org.eclipse.tracecompass.ctf.core.event.types.CompoundDeclaration;
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.StringDeclaration;
32import org.eclipse.tracecompass.ctf.core.tests.io.Util;
f357bcd4 33import org.eclipse.tracecompass.internal.ctf.core.event.types.ArrayDeclaration;
866e5b51
FC
34import org.junit.Before;
35import org.junit.Test;
36
37/**
7b4f13e6 38 * The class <code>ArrayDeclaration2Test</code> contains tests for the class
866e5b51 39 * <code>{@link ArrayDeclaration}</code>.
4bd7f2db 40 *
7b4f13e6 41 * @author Matthew Khouzam
866e5b51
FC
42 * @version $Revision: 1.0 $
43 */
7b4f13e6 44public class ArrayDeclaration2Test {
866e5b51
FC
45
46 private ArrayDeclaration fixture;
47
866e5b51
FC
48 /**
49 * Perform pre-test initialization.
50 */
51 @Before
52 public void setUp() {
d890ec37 53 fixture = new ArrayDeclaration(1, StringDeclaration.getStringDeclaration(Encoding.UTF8));
866e5b51
FC
54 }
55
866e5b51
FC
56 /**
57 * Run the ArrayDeclaration(int,Declaration) constructor test.
58 */
59 @Test
60 public void testArrayDeclaration() {
61 int length = 1;
d890ec37 62 IDeclaration elemType = StringDeclaration.getStringDeclaration(Encoding.UTF8);
866e5b51
FC
63 ArrayDeclaration result = new ArrayDeclaration(length, elemType);
64
65 assertNotNull(result);
4a9c1f07 66 String left = "[declaration] array[";
866e5b51
FC
67 String right = result.toString().substring(0, left.length());
68 assertEquals(left, right);
69 assertEquals(1, result.getLength());
70 }
71
72 /**
73 * Run the ArrayDefinition createDefinition(DefinitionScope,String) method
74 * test.
a4fa4e36 75 *
680f9173 76 * @throws CTFException
a4fa4e36 77 * error in the bitbuffer
866e5b51
FC
78 */
79 @Test
680f9173 80 public void testCreateDefinition() throws CTFException {
4a9c1f07 81 String fieldName = "";
866e5b51 82 IDefinitionScope definitionScope = null;
7b4f13e6 83 AbstractArrayDefinition result;
a4fa4e36 84 byte[] array = { 't', 'e', 's', 't', '\0', 't', 'h', 'i', 's', '\0' };
aefc5c83 85 BitBuffer bb = new BitBuffer(Util.testMemory(ByteBuffer.wrap(array)));
a4fa4e36 86 result = fixture.createDefinition(definitionScope, fieldName, bb);
866e5b51
FC
87
88 assertNotNull(result);
89 }
90
91 /**
92 * Run the Declaration getElementType() method test.
93 */
94 @Test
95 public void testGetElementType() {
96 IDeclaration result = fixture.getElementType();
97 assertNotNull(result);
98 }
99
100 /**
101 * Run the int getLength() method test.
102 */
103 @Test
104 public void testGetLength() {
105 int result = fixture.getLength();
106 assertEquals(1, result);
107 }
108
9639bf3a
MK
109 /**
110 * Run the boolean isString() method test.
111 */
112 @Test
113 public void testIsString_ownDefs() {
a4fa4e36 114 // it's an array of strings, not a string
9639bf3a
MK
115 assertFalse(fixture.isString());
116 }
117
118 /**
119 * Run the boolean isString() method test.
120 */
121 @Test
122 public void testIsString_complex() {
a4fa4e36
MK
123 final IntegerDeclaration id = IntegerDeclaration.createDeclaration(8, false, 16,
124 ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 8);
9377d173 125 CompoundDeclaration ad = new ArrayDeclaration(0, id);
9639bf3a
MK
126
127 boolean result = ad.isString();
128
129 assertTrue(result);
130 }
131
866e5b51
FC
132 /**
133 * Run the String toString() method test.
134 */
135 @Test
136 public void testToString() {
137 String result = fixture.toString();
4a9c1f07 138 String left = "[declaration] array[";
866e5b51
FC
139 String right = result.substring(0, left.length());
140
141 assertEquals(left, right);
142 }
e00e6663
MK
143
144 /**
145 * Test the hashcode
146 */
147 @Test
148 public void hashcodeTest() {
149 assertEquals(2016, fixture.hashCode());
d890ec37 150 assertEquals(new ArrayDeclaration(1, StringDeclaration.getStringDeclaration(Encoding.UTF8)).hashCode(), fixture.hashCode());
e00e6663
MK
151 }
152
153 /**
154 * Test the equals
155 */
156 @Test
157 public void equalsTest() {
158 ArrayDeclaration a = new ArrayDeclaration(1, IntegerDeclaration.INT_32B_DECL);
159 ArrayDeclaration b = new ArrayDeclaration(2, IntegerDeclaration.INT_32B_DECL);
d890ec37 160 ArrayDeclaration c = new ArrayDeclaration(1, StringDeclaration.getStringDeclaration(Encoding.UTF8));
e00e6663
MK
161 ArrayDeclaration d = new ArrayDeclaration(1, IntegerDeclaration.INT_32B_DECL);
162 assertNotEquals(a, null);
163 assertNotEquals(a, new Object());
164 assertNotEquals(a, b);
165 assertNotEquals(a, c);
166 assertEquals(a, d);
167 assertEquals(a, a);
168 assertNotEquals(b, a);
169 assertNotEquals(c, a);
170 assertEquals(d, a);
171 assertEquals(a, a);
f9d7c59f
MK
172 assertFalse(a.isBinaryEquivalent(b));
173 assertFalse(b.isBinaryEquivalent(a));
174 assertFalse(a.isBinaryEquivalent(c));
175 assertFalse(c.isBinaryEquivalent(a));
176 assertTrue(a.isBinaryEquivalent(d));
177 assertTrue(d.isBinaryEquivalent(a));
178 assertTrue(a.isBinaryEquivalent(a));
e00e6663 179 }
866e5b51 180}
This page took 0.096107 seconds and 5 git commands to generate.