tmf: Axe the TmfEventTypeManager
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core.tests / src / org / eclipse / tracecompass / tmf / core / tests / event / TmfEventTypeTest.java
CommitLineData
d18dd09b 1/*******************************************************************************
61759503 2 * Copyright (c) 2009, 2013 Ericsson
9b749023 3 *
cbbcc354 4 * All rights reserved. This program and the accompanying materials are made
5 * available under the terms of the Eclipse Public License v1.0 which
d18dd09b
ASL
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
9b749023 8 *
d18dd09b
ASL
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
75d42a16 11 * Francois Chouinard - Adjusted for new Event Model
6e1886bc 12 * Alexandre Montplaisir - Port to JUnit4
d18dd09b
ASL
13 *******************************************************************************/
14
2bdf0193 15package org.eclipse.tracecompass.tmf.core.tests.event;
d18dd09b 16
b742c196 17import static org.junit.Assert.assertArrayEquals;
6e1886bc
AM
18import static org.junit.Assert.assertEquals;
19import static org.junit.Assert.assertFalse;
20import static org.junit.Assert.assertNull;
21import static org.junit.Assert.assertTrue;
22import static org.junit.Assert.fail;
cbd4ad82 23
b742c196
AM
24import java.util.Collection;
25
2bdf0193
AM
26import org.eclipse.tracecompass.tmf.core.event.ITmfEventType;
27import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
28import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
6e1886bc 29import org.junit.Test;
d18dd09b
ASL
30
31/**
75d42a16 32 * Test suite for the TmfEventType class.
d18dd09b 33 */
cad06250 34@SuppressWarnings("javadoc")
6e1886bc 35public class TmfEventTypeTest {
d18dd09b 36
cbd4ad82 37 // ------------------------------------------------------------------------
cbbcc354 38 // Variables
cbd4ad82
FC
39 // ------------------------------------------------------------------------
40
39f9eadb 41 private final String fTypeId1 = "Some type";
cbbcc354 42 private final String fTypeId2 = "Some other type";
9ee9135e 43
cbbcc354 44 private final String fLabel0 = "label1";
45 private final String fLabel1 = "label2";
b742c196 46 private final String fLabel2 = "label3";
085d898f 47
39f9eadb
FC
48 private final String[] fLabels0 = new String[] { };
49 private final String[] fLabels1 = new String[] { fLabel0, fLabel1 };
b742c196 50 private final String[] fLabels2 = new String[] { fLabel1, fLabel0, fLabel2 };
d18dd09b 51
e600c338
AM
52 private final ITmfEventType fType0 = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels0));
53 private final ITmfEventType fType1 = new TmfEventType(fTypeId2, TmfEventField.makeRoot(fLabels1));
54 private final ITmfEventType fType2 = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels2));
55 private final ITmfEventType fType3 = new TmfEventType(fTypeId2, TmfEventField.makeRoot(fLabels1));
cbd4ad82 56
cbbcc354 57 // ------------------------------------------------------------------------
58 // Constructors
59 // ------------------------------------------------------------------------
60
6e1886bc 61 @Test
9ee9135e 62 public void testDefaultConstructor() {
085d898f 63 final ITmfEventType type = new TmfEventType();
9b749023 64 assertEquals("getName", ITmfEventType.DEFAULT_TYPE_ID, type.getName());
9ee9135e 65 assertNull("getRootField", type.getRootField());
b742c196 66 assertEquals("getFieldNames", 0, type.getFieldNames().size());
9ee9135e
FC
67 }
68
6e1886bc 69 @Test
9ee9135e 70 public void testFullConstructor() {
e600c338 71 final ITmfEventType type0 = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels0));
9ee9135e
FC
72 assertEquals("getName", fTypeId1, type0.getName());
73 assertEquals("getRootField", TmfEventField.makeRoot(fLabels0), type0.getRootField());
b742c196
AM
74 final Collection<String> labels0 = type0.getFieldNames();
75 assertEquals("getFieldNames length", fLabels0.length, labels0.size());
76 assertArrayEquals(fLabels0, labels0.toArray(new String[labels0.size()]));
9ee9135e 77
e600c338 78 final ITmfEventType type1 = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels1));
9ee9135e
FC
79 assertEquals("getName", fTypeId1, type1.getName());
80 assertEquals("getRootField", TmfEventField.makeRoot(fLabels1), type1.getRootField());
b742c196
AM
81 final Collection<String> labels1 = type1.getFieldNames();
82 assertEquals("getFieldNames length", fLabels1.length, labels1.size());
83 assertArrayEquals(fLabels1, labels1.toArray(new String[labels1.size()]));
9ee9135e 84
e600c338 85 final ITmfEventType type2 = new TmfEventType(fTypeId2, TmfEventField.makeRoot(fLabels2));
9ee9135e
FC
86 assertEquals("getName", fTypeId2, type2.getName());
87 assertEquals("getRootField", TmfEventField.makeRoot(fLabels2), type2.getRootField());
b742c196
AM
88 final Collection<String> labels2 = type2.getFieldNames();
89 assertEquals("getFieldNames length", fLabels2.length, labels2.size());
90 assertArrayEquals(fLabels2, labels2.toArray(new String[labels2.size()]));
9ee9135e
FC
91 }
92
e600c338 93 @Test(expected = IllegalArgumentException.class)
9ee9135e 94 public void testConstructorCornerCases() {
e600c338 95 new TmfEventType(null, null);
cbbcc354 96 }
97
6e1886bc 98 @Test
9ee9135e 99 public void testCopyConstructor() {
e600c338 100 final TmfEventType original = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels1));
085d898f 101 final TmfEventType copy = new TmfEventType(original);
cbbcc354 102
9ee9135e
FC
103 assertEquals("getName", fTypeId1, copy.getName());
104 assertEquals("getRootField", TmfEventField.makeRoot(fLabels1), copy.getRootField());
b742c196
AM
105 final Collection<String> labels1 = copy.getFieldNames();
106 assertEquals("getFieldNames length", fLabels1.length, labels1.size());
107 assertArrayEquals(fLabels1, labels1.toArray(new String[labels1.size()]));
cbbcc354 108 }
109
6e1886bc 110 @Test
9ee9135e 111 public void testCopyConstructorCornerCases() {
cbbcc354 112 try {
9ee9135e 113 new TmfEventType(null);
75d42a16 114 fail("TmfEventType: null argument");
085d898f 115 } catch (final IllegalArgumentException e) {
cbbcc354 116 }
117 }
118
9ee9135e
FC
119 // ------------------------------------------------------------------------
120 // hashCode
121 // ------------------------------------------------------------------------
122
6e1886bc 123 @Test
54a7a54c 124 public void testHashCode() {
085d898f 125 final TmfEventType copy1 = new TmfEventType(fType0);
9ee9135e
FC
126
127 assertTrue("hashCode", fType0.hashCode() == copy1.hashCode());
128 assertTrue("hashCode", fType0.hashCode() != fType3.hashCode());
129 }
130
cbbcc354 131 // ------------------------------------------------------------------------
132 // equals
133 // ------------------------------------------------------------------------
134
6e1886bc 135 @Test
54a7a54c 136 public void testEqualsReflexivity() {
cbbcc354 137 assertTrue("equals", fType0.equals(fType0));
138 assertTrue("equals", fType3.equals(fType3));
139
39f9eadb
FC
140 assertFalse("equals", fType0.equals(fType3));
141 assertFalse("equals", fType3.equals(fType0));
cbbcc354 142 }
143
6e1886bc 144 @Test
54a7a54c 145 public void testEqualsSymmetry() {
085d898f 146 final TmfEventType copy0 = new TmfEventType(fType0);
9ee9135e
FC
147 assertTrue("equals", fType0.equals(copy0));
148 assertTrue("equals", copy0.equals(fType0));
085d898f
FC
149
150 final TmfEventType copy1 = new TmfEventType(fType1);
9ee9135e
FC
151 assertTrue("equals", fType1.equals(copy1));
152 assertTrue("equals", copy1.equals(fType1));
085d898f
FC
153
154 final TmfEventType copy2 = new TmfEventType(fType2);
9ee9135e
FC
155 assertTrue("equals", fType2.equals(copy2));
156 assertTrue("equals", copy2.equals(fType2));
cbbcc354 157 }
d18dd09b 158
6e1886bc 159 @Test
54a7a54c 160 public void testEqualsTransivity() {
9ee9135e
FC
161 TmfEventType copy1 = new TmfEventType(fType1);
162 TmfEventType copy2 = new TmfEventType(copy1);
163 assertTrue("equals", fType1.equals(copy1));
164 assertTrue("equals", copy1.equals(copy2));
165 assertTrue("equals", fType1.equals(copy2));
166
167 copy1 = new TmfEventType(fType2);
168 copy2 = new TmfEventType(copy1);
169 assertTrue("equals", fType2.equals(copy1));
170 assertTrue("equals", copy1.equals(copy2));
171 assertTrue("equals", fType2.equals(copy2));
172
173 copy1 = new TmfEventType(fType3);
174 copy2 = new TmfEventType(copy1);
175 assertTrue("equals", fType3.equals(copy1));
176 assertTrue("equals", copy1.equals(copy2));
177 assertTrue("equals", fType3.equals(copy2));
cbbcc354 178 }
179
6e1886bc 180 @Test
54a7a54c 181 public void testEqualsNull() {
9ee9135e
FC
182 assertFalse("equals", fType0.equals(null));
183 assertFalse("equals", fType3.equals(null));
cbbcc354 184 }
185
6e1886bc 186 @Test
54a7a54c 187 public void testNonEquals() {
9ee9135e
FC
188 assertFalse("equals", fType0.equals(fType1));
189 assertFalse("equals", fType1.equals(fType2));
190 assertFalse("equals", fType2.equals(fType3));
191 assertFalse("equals", fType3.equals(fType0));
cbbcc354 192 }
085d898f 193
6e1886bc 194 @Test
54a7a54c 195 public void testNonEqualsClasses() {
9ee9135e
FC
196 assertFalse("equals", fType1.equals(fLabels1));
197 }
085d898f 198
cbd4ad82 199 // ------------------------------------------------------------------------
cbbcc354 200 // toString
cbd4ad82 201 // ------------------------------------------------------------------------
d18dd09b 202
6e1886bc 203 @Test
cbbcc354 204 public void testToString() {
e600c338 205 final String expected1 = "TmfEventType [fTypeId=" + ITmfEventType.DEFAULT_TYPE_ID + "]";
085d898f 206 final TmfEventType type1 = new TmfEventType();
cbbcc354 207 assertEquals("toString", expected1, type1.toString());
208
e600c338
AM
209 final String expected2 = "TmfEventType [fTypeId=" + fTypeId1 + "]";
210 final TmfEventType type2 = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels1));
cbbcc354 211 assertEquals("toString", expected2, type2.toString());
212 }
d18dd09b
ASL
213
214}
This page took 0.073021 seconds and 5 git commands to generate.