TMF: Implementation of UstMemoryAnalysisModule requirements
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / 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
6c13869b 15package org.eclipse.linuxtools.tmf.core.tests.event;
d18dd09b 16
6e1886bc
AM
17import static org.junit.Assert.assertEquals;
18import static org.junit.Assert.assertFalse;
19import static org.junit.Assert.assertNull;
20import static org.junit.Assert.assertTrue;
21import static org.junit.Assert.fail;
cbd4ad82 22
9ee9135e 23import org.eclipse.linuxtools.tmf.core.event.ITmfEventType;
4c564a2d 24import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
6c13869b 25import org.eclipse.linuxtools.tmf.core.event.TmfEventType;
6e1886bc 26import org.junit.Test;
d18dd09b
ASL
27
28/**
75d42a16 29 * Test suite for the TmfEventType class.
d18dd09b 30 */
cad06250 31@SuppressWarnings("javadoc")
6e1886bc 32public class TmfEventTypeTest {
d18dd09b 33
cbd4ad82 34 // ------------------------------------------------------------------------
cbbcc354 35 // Variables
cbd4ad82
FC
36 // ------------------------------------------------------------------------
37
9ee9135e
FC
38 private final String fContext1 = "JUnit context 1";
39 private final String fContext2 = "JUnit context 2";
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";
085d898f 46
39f9eadb
FC
47 private final String[] fLabels0 = new String[] { };
48 private final String[] fLabels1 = new String[] { fLabel0, fLabel1 };
49 private final String[] fLabels2 = new String[] { fLabel1, fLabel0, fLabel1 };
d18dd09b 50
de126dbb
FC
51 private final ITmfEventType fType0 = new TmfEventType(fContext1, fTypeId1, TmfEventField.makeRoot(fLabels0));
52 private final ITmfEventType fType1 = new TmfEventType(fContext1, fTypeId2, TmfEventField.makeRoot(fLabels1));
53 private final ITmfEventType fType2 = new TmfEventType(fContext2, fTypeId1, TmfEventField.makeRoot(fLabels2));
54 private final ITmfEventType fType3 = new TmfEventType(fContext2, fTypeId2, TmfEventField.makeRoot(fLabels1));
cbd4ad82 55
cbbcc354 56 // ------------------------------------------------------------------------
57 // Constructors
58 // ------------------------------------------------------------------------
59
6e1886bc 60 @Test
9ee9135e 61 public void testDefaultConstructor() {
085d898f 62 final ITmfEventType type = new TmfEventType();
9b749023
AM
63 assertEquals("getContext", ITmfEventType.DEFAULT_CONTEXT_ID, type.getContext());
64 assertEquals("getName", ITmfEventType.DEFAULT_TYPE_ID, type.getName());
9ee9135e 65 assertNull("getRootField", type.getRootField());
8b63ffb9 66 assertEquals("getFieldNames", 0, type.getFieldNames().length);
9ee9135e
FC
67 assertNull("getFieldName", type.getFieldName(0));
68 }
69
6e1886bc 70 @Test
9ee9135e 71 public void testFullConstructor() {
085d898f 72 final ITmfEventType type0 = new TmfEventType(fContext1, fTypeId1, TmfEventField.makeRoot(fLabels0));
9ee9135e
FC
73 assertEquals("getContext", fContext1, type0.getContext());
74 assertEquals("getName", fTypeId1, type0.getName());
75 assertEquals("getRootField", TmfEventField.makeRoot(fLabels0), type0.getRootField());
085d898f 76 final String[] labels0 = type0.getFieldNames();
9ee9135e 77 assertEquals("getFieldNames length", fLabels0.length, labels0.length);
9b749023 78 for (int i = 0; i < labels0.length; i++) {
9ee9135e 79 assertEquals("getFieldNames", fLabels0[i], labels0[i]);
9b749023 80 }
9ee9135e
FC
81 assertNull("getFieldName", type0.getFieldName(labels0.length));
82
085d898f 83 final ITmfEventType type1 = new TmfEventType(fContext1, fTypeId1, TmfEventField.makeRoot(fLabels1));
9ee9135e
FC
84 assertEquals("getContext", fContext1, type1.getContext());
85 assertEquals("getName", fTypeId1, type1.getName());
86 assertEquals("getRootField", TmfEventField.makeRoot(fLabels1), type1.getRootField());
085d898f 87 final String[] labels1 = type1.getFieldNames();
9ee9135e 88 assertEquals("getFieldNames length", fLabels1.length, labels1.length);
9b749023 89 for (int i = 0; i < labels1.length; i++) {
9ee9135e 90 assertEquals("getFieldNames", fLabels1[i], labels1[i]);
9b749023 91 }
9ee9135e
FC
92 assertNull("getFieldName", type1.getFieldName(labels1.length));
93
085d898f 94 final ITmfEventType type2 = new TmfEventType(fContext2, fTypeId2, TmfEventField.makeRoot(fLabels2));
9ee9135e
FC
95 assertEquals("getContext", fContext2, type2.getContext());
96 assertEquals("getName", fTypeId2, type2.getName());
97 assertEquals("getRootField", TmfEventField.makeRoot(fLabels2), type2.getRootField());
085d898f 98 final String[] labels2 = type2.getFieldNames();
9ee9135e 99 assertEquals("getFieldNames length", fLabels2.length, labels2.length);
9b749023 100 for (int i = 0; i < labels2.length; i++) {
9ee9135e 101 assertEquals("getFieldNames", fLabels2[i], labels2[i]);
9b749023 102 }
9ee9135e
FC
103 assertNull("getFieldName", type2.getFieldName(labels2.length));
104 }
105
6e1886bc 106 @Test
9ee9135e 107 public void testConstructorCornerCases() {
cbbcc354 108 try {
9ee9135e
FC
109 new TmfEventType(null, fTypeId1, null);
110 fail("TmfEventType: null context");
085d898f 111 } catch (final IllegalArgumentException e) {
cbbcc354 112 }
cbbcc354 113
cbbcc354 114 try {
9ee9135e
FC
115 new TmfEventType(fContext1, null, null);
116 fail("TmfEventType: null type");
085d898f 117 } catch (final IllegalArgumentException e) {
cbbcc354 118 }
119 }
120
6e1886bc 121 @Test
9ee9135e 122 public void testCopyConstructor() {
085d898f
FC
123 final TmfEventType original = new TmfEventType(fContext1, fTypeId1, TmfEventField.makeRoot(fLabels1));
124 final TmfEventType copy = new TmfEventType(original);
cbbcc354 125
9ee9135e
FC
126 assertEquals("getContext", fContext1, copy.getContext());
127 assertEquals("getName", fTypeId1, copy.getName());
128 assertEquals("getRootField", TmfEventField.makeRoot(fLabels1), copy.getRootField());
085d898f 129 final String[] labels1 = copy.getFieldNames();
9ee9135e 130 assertEquals("getFieldNames length", fLabels1.length, labels1.length);
9b749023 131 for (int i = 0; i < labels1.length; i++) {
9ee9135e 132 assertEquals("getFieldNames", fLabels1[i], labels1[i]);
9b749023 133 }
9ee9135e 134 assertNull("getFieldName", copy.getFieldName(labels1.length));
cbbcc354 135 }
136
6e1886bc 137 @Test
9ee9135e 138 public void testCopyConstructorCornerCases() {
cbbcc354 139 try {
9ee9135e 140 new TmfEventType(null);
75d42a16 141 fail("TmfEventType: null argument");
085d898f 142 } catch (final IllegalArgumentException e) {
cbbcc354 143 }
144 }
145
9ee9135e
FC
146 // ------------------------------------------------------------------------
147 // hashCode
148 // ------------------------------------------------------------------------
149
6e1886bc 150 @Test
54a7a54c 151 public void testHashCode() {
085d898f 152 final TmfEventType copy1 = new TmfEventType(fType0);
9ee9135e
FC
153
154 assertTrue("hashCode", fType0.hashCode() == copy1.hashCode());
155 assertTrue("hashCode", fType0.hashCode() != fType3.hashCode());
156 }
157
cbbcc354 158 // ------------------------------------------------------------------------
159 // equals
160 // ------------------------------------------------------------------------
161
6e1886bc 162 @Test
54a7a54c 163 public void testEqualsReflexivity() {
cbbcc354 164 assertTrue("equals", fType0.equals(fType0));
165 assertTrue("equals", fType3.equals(fType3));
166
39f9eadb
FC
167 assertFalse("equals", fType0.equals(fType3));
168 assertFalse("equals", fType3.equals(fType0));
cbbcc354 169 }
170
6e1886bc 171 @Test
54a7a54c 172 public void testEqualsSymmetry() {
085d898f 173 final TmfEventType copy0 = new TmfEventType(fType0);
9ee9135e
FC
174 assertTrue("equals", fType0.equals(copy0));
175 assertTrue("equals", copy0.equals(fType0));
085d898f
FC
176
177 final TmfEventType copy1 = new TmfEventType(fType1);
9ee9135e
FC
178 assertTrue("equals", fType1.equals(copy1));
179 assertTrue("equals", copy1.equals(fType1));
085d898f
FC
180
181 final TmfEventType copy2 = new TmfEventType(fType2);
9ee9135e
FC
182 assertTrue("equals", fType2.equals(copy2));
183 assertTrue("equals", copy2.equals(fType2));
cbbcc354 184 }
d18dd09b 185
6e1886bc 186 @Test
54a7a54c 187 public void testEqualsTransivity() {
9ee9135e
FC
188 TmfEventType copy1 = new TmfEventType(fType1);
189 TmfEventType copy2 = new TmfEventType(copy1);
190 assertTrue("equals", fType1.equals(copy1));
191 assertTrue("equals", copy1.equals(copy2));
192 assertTrue("equals", fType1.equals(copy2));
193
194 copy1 = new TmfEventType(fType2);
195 copy2 = new TmfEventType(copy1);
196 assertTrue("equals", fType2.equals(copy1));
197 assertTrue("equals", copy1.equals(copy2));
198 assertTrue("equals", fType2.equals(copy2));
199
200 copy1 = new TmfEventType(fType3);
201 copy2 = new TmfEventType(copy1);
202 assertTrue("equals", fType3.equals(copy1));
203 assertTrue("equals", copy1.equals(copy2));
204 assertTrue("equals", fType3.equals(copy2));
cbbcc354 205 }
206
6e1886bc 207 @Test
54a7a54c 208 public void testEqualsNull() {
9ee9135e
FC
209 assertFalse("equals", fType0.equals(null));
210 assertFalse("equals", fType3.equals(null));
cbbcc354 211 }
212
6e1886bc 213 @Test
54a7a54c 214 public void testNonEquals() {
9ee9135e
FC
215 assertFalse("equals", fType0.equals(fType1));
216 assertFalse("equals", fType1.equals(fType2));
217 assertFalse("equals", fType2.equals(fType3));
218 assertFalse("equals", fType3.equals(fType0));
cbbcc354 219 }
085d898f 220
6e1886bc 221 @Test
54a7a54c 222 public void testNonEqualsClasses() {
9ee9135e
FC
223 assertFalse("equals", fType1.equals(fLabels1));
224 }
085d898f 225
cbd4ad82 226 // ------------------------------------------------------------------------
cbbcc354 227 // toString
cbd4ad82 228 // ------------------------------------------------------------------------
d18dd09b 229
6e1886bc 230 @Test
cbbcc354 231 public void testToString() {
9b749023
AM
232 final String expected1 = "TmfEventType [fContext=" + ITmfEventType.DEFAULT_CONTEXT_ID +
233 ", fTypeId=" + ITmfEventType.DEFAULT_TYPE_ID + "]";
085d898f 234 final TmfEventType type1 = new TmfEventType();
cbbcc354 235 assertEquals("toString", expected1, type1.toString());
236
085d898f
FC
237 final String expected2 = "TmfEventType [fContext=" + fContext1 + ", fTypeId=" + fTypeId1 + "]";
238 final TmfEventType type2 = new TmfEventType(fContext1, fTypeId1, TmfEventField.makeRoot(fLabels1));
cbbcc354 239 assertEquals("toString", expected2, type2.toString());
240 }
d18dd09b
ASL
241
242}
This page took 0.0636 seconds and 5 git commands to generate.