Commit | Line | Data |
---|---|---|
d18dd09b | 1 | /******************************************************************************* |
75d42a16 | 2 | * Copyright (c) 2009, 2012 Ericsson |
d18dd09b | 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 | |
8 | * | |
9 | * Contributors: | |
10 | * Francois Chouinard - Initial API and implementation | |
75d42a16 | 11 | * Francois Chouinard - Adjusted for new Event Model |
d18dd09b ASL |
12 | *******************************************************************************/ |
13 | ||
6c13869b | 14 | package org.eclipse.linuxtools.tmf.core.tests.event; |
d18dd09b | 15 | |
cbd4ad82 FC |
16 | import junit.framework.TestCase; |
17 | ||
9ee9135e | 18 | import org.eclipse.linuxtools.tmf.core.event.ITmfEventType; |
4c564a2d | 19 | import org.eclipse.linuxtools.tmf.core.event.TmfEventField; |
6c13869b | 20 | import org.eclipse.linuxtools.tmf.core.event.TmfEventType; |
d18dd09b ASL |
21 | |
22 | /** | |
23 | * <b><u>TmfEventTypeTest</u></b> | |
24 | * <p> | |
75d42a16 | 25 | * Test suite for the TmfEventType class. |
d18dd09b | 26 | */ |
3b38ea61 | 27 | @SuppressWarnings("nls") |
d18dd09b ASL |
28 | public class TmfEventTypeTest extends TestCase { |
29 | ||
cbd4ad82 | 30 | // ------------------------------------------------------------------------ |
cbbcc354 | 31 | // Variables |
cbd4ad82 FC |
32 | // ------------------------------------------------------------------------ |
33 | ||
9ee9135e FC |
34 | private final String fContext1 = "JUnit context 1"; |
35 | private final String fContext2 = "JUnit context 2"; | |
36 | ||
37 | private final String fTypeId1 = "Some type"; | |
cbbcc354 | 38 | private final String fTypeId2 = "Some other type"; |
9ee9135e | 39 | |
cbbcc354 | 40 | private final String fLabel0 = "label1"; |
41 | private final String fLabel1 = "label2"; | |
9ee9135e FC |
42 | |
43 | private final String[] fLabels0 = new String[] { }; | |
cbbcc354 | 44 | private final String[] fLabels1 = new String[] { fLabel0, fLabel1 }; |
9ee9135e | 45 | private final String[] fLabels2 = new String[] { fLabel1, fLabel0, fLabel1 }; |
d18dd09b | 46 | |
9ee9135e FC |
47 | private final TmfEventType fType0 = new TmfEventType(fContext1, fTypeId1, TmfEventField.makeRoot(fLabels0)); |
48 | private final TmfEventType fType1 = new TmfEventType(fContext1, fTypeId2, TmfEventField.makeRoot(fLabels1)); | |
49 | private final TmfEventType fType2 = new TmfEventType(fContext2, fTypeId1, TmfEventField.makeRoot(fLabels2)); | |
50 | private final TmfEventType fType3 = new TmfEventType(fContext2, fTypeId2, TmfEventField.makeRoot(fLabels1)); | |
cbd4ad82 | 51 | |
cbd4ad82 | 52 | // ------------------------------------------------------------------------ |
cbbcc354 | 53 | // Housekeeping |
54 | // ------------------------------------------------------------------------ | |
55 | ||
56 | /** | |
57 | * @param name the test name | |
58 | */ | |
59 | public TmfEventTypeTest(String name) { | |
60 | super(name); | |
61 | } | |
62 | ||
63 | @Override | |
64 | protected void setUp() throws Exception { | |
65 | super.setUp(); | |
66 | } | |
67 | ||
68 | @Override | |
69 | protected void tearDown() throws Exception { | |
70 | super.tearDown(); | |
71 | } | |
72 | ||
73 | // ------------------------------------------------------------------------ | |
74 | // Constructors | |
75 | // ------------------------------------------------------------------------ | |
76 | ||
9ee9135e FC |
77 | public void testDefaultConstructor() { |
78 | ITmfEventType type = new TmfEventType(); | |
79 | assertEquals("getContext", TmfEventType.DEFAULT_CONTEXT_ID, type.getContext()); | |
80 | assertEquals("getName", TmfEventType.DEFAULT_TYPE_ID, type.getName()); | |
81 | assertNull("getRootField", type.getRootField()); | |
82 | assertNull("getFieldNames", type.getFieldNames()); | |
83 | assertNull("getFieldName", type.getFieldName(0)); | |
84 | } | |
85 | ||
86 | public void testFullConstructor() { | |
87 | ITmfEventType type0 = new TmfEventType(fContext1, fTypeId1, TmfEventField.makeRoot(fLabels0)); | |
88 | assertEquals("getContext", fContext1, type0.getContext()); | |
89 | assertEquals("getName", fTypeId1, type0.getName()); | |
90 | assertEquals("getRootField", TmfEventField.makeRoot(fLabels0), type0.getRootField()); | |
91 | String[] labels0 = type0.getFieldNames(); | |
92 | assertEquals("getFieldNames length", fLabels0.length, labels0.length); | |
93 | for (int i = 0; i < labels0.length; i++) { | |
94 | assertEquals("getFieldNames", fLabels0[i], labels0[i]); | |
95 | } | |
96 | assertNull("getFieldName", type0.getFieldName(labels0.length)); | |
97 | ||
98 | ITmfEventType type1 = new TmfEventType(fContext1, fTypeId1, TmfEventField.makeRoot(fLabels1)); | |
99 | assertEquals("getContext", fContext1, type1.getContext()); | |
100 | assertEquals("getName", fTypeId1, type1.getName()); | |
101 | assertEquals("getRootField", TmfEventField.makeRoot(fLabels1), type1.getRootField()); | |
102 | String[] labels1 = type1.getFieldNames(); | |
103 | assertEquals("getFieldNames length", fLabels1.length, labels1.length); | |
104 | for (int i = 0; i < labels1.length; i++) { | |
105 | assertEquals("getFieldNames", fLabels1[i], labels1[i]); | |
106 | } | |
107 | assertNull("getFieldName", type1.getFieldName(labels1.length)); | |
108 | ||
109 | ITmfEventType type2 = new TmfEventType(fContext2, fTypeId2, TmfEventField.makeRoot(fLabels2)); | |
110 | assertEquals("getContext", fContext2, type2.getContext()); | |
111 | assertEquals("getName", fTypeId2, type2.getName()); | |
112 | assertEquals("getRootField", TmfEventField.makeRoot(fLabels2), type2.getRootField()); | |
113 | String[] labels2 = type2.getFieldNames(); | |
114 | assertEquals("getFieldNames length", fLabels2.length, labels2.length); | |
115 | for (int i = 0; i < labels2.length; i++) { | |
116 | assertEquals("getFieldNames", fLabels2[i], labels2[i]); | |
117 | } | |
118 | assertNull("getFieldName", type2.getFieldName(labels2.length)); | |
119 | } | |
120 | ||
121 | public void testConstructorCornerCases() { | |
cbbcc354 | 122 | try { |
9ee9135e FC |
123 | new TmfEventType(null, fTypeId1, null); |
124 | fail("TmfEventType: null context"); | |
cbbcc354 | 125 | } catch (IllegalArgumentException e) { |
cbbcc354 | 126 | } |
cbbcc354 | 127 | |
cbbcc354 | 128 | try { |
9ee9135e FC |
129 | new TmfEventType(fContext1, null, null); |
130 | fail("TmfEventType: null type"); | |
cbbcc354 | 131 | } catch (IllegalArgumentException e) { |
cbbcc354 | 132 | } |
133 | } | |
134 | ||
9ee9135e FC |
135 | public void testCopyConstructor() { |
136 | TmfEventType original = new TmfEventType(fContext1, fTypeId1, TmfEventField.makeRoot(fLabels1)); | |
cbbcc354 | 137 | TmfEventType copy = new TmfEventType(original); |
cbbcc354 | 138 | |
9ee9135e FC |
139 | assertEquals("getContext", fContext1, copy.getContext()); |
140 | assertEquals("getName", fTypeId1, copy.getName()); | |
141 | assertEquals("getRootField", TmfEventField.makeRoot(fLabels1), copy.getRootField()); | |
142 | String[] labels1 = copy.getFieldNames(); | |
143 | assertEquals("getFieldNames length", fLabels1.length, labels1.length); | |
144 | for (int i = 0; i < labels1.length; i++) { | |
145 | assertEquals("getFieldNames", fLabels1[i], labels1[i]); | |
cbbcc354 | 146 | } |
9ee9135e | 147 | assertNull("getFieldName", copy.getFieldName(labels1.length)); |
cbbcc354 | 148 | } |
149 | ||
9ee9135e | 150 | public void testCopyConstructorCornerCases() { |
cbbcc354 | 151 | try { |
9ee9135e | 152 | new TmfEventType(null); |
75d42a16 | 153 | fail("TmfEventType: null argument"); |
cbbcc354 | 154 | } catch (IllegalArgumentException e) { |
cbbcc354 | 155 | } |
156 | } | |
157 | ||
9ee9135e FC |
158 | // ------------------------------------------------------------------------ |
159 | // clone | |
160 | // ------------------------------------------------------------------------ | |
161 | ||
162 | public class MyEventType extends TmfEventType { | |
163 | ||
164 | @Override | |
165 | public boolean equals(Object other) { | |
166 | return super.equals(other); | |
167 | } | |
168 | ||
169 | @Override | |
170 | public MyEventType clone() { | |
171 | return (MyEventType) super.clone(); | |
172 | } | |
173 | } | |
174 | ||
175 | public void testClone() throws Exception { | |
176 | ITmfEventType clone = fType1.clone(); | |
177 | assertEquals("clone", fType1, clone); | |
178 | } | |
179 | ||
180 | public void testClone2() throws Exception { | |
181 | ITmfEventType type = new TmfEventType(); | |
182 | ITmfEventType clone = type.clone(); | |
183 | assertEquals("clone", clone, type); | |
184 | } | |
185 | ||
186 | // ------------------------------------------------------------------------ | |
187 | // hashCode | |
188 | // ------------------------------------------------------------------------ | |
189 | ||
190 | public void testHashCode() throws Exception { | |
191 | TmfEventType copy1 = new TmfEventType(fType0); | |
192 | ||
193 | assertTrue("hashCode", fType0.hashCode() == copy1.hashCode()); | |
194 | assertTrue("hashCode", fType0.hashCode() != fType3.hashCode()); | |
195 | } | |
196 | ||
cbbcc354 | 197 | // ------------------------------------------------------------------------ |
198 | // equals | |
199 | // ------------------------------------------------------------------------ | |
200 | ||
201 | public void testEqualsReflexivity() throws Exception { | |
202 | assertTrue("equals", fType0.equals(fType0)); | |
203 | assertTrue("equals", fType3.equals(fType3)); | |
204 | ||
205 | assertTrue("equals", !fType0.equals(fType3)); | |
206 | assertTrue("equals", !fType3.equals(fType0)); | |
207 | } | |
208 | ||
209 | public void testEqualsSymmetry() throws Exception { | |
9ee9135e FC |
210 | TmfEventType copy0 = new TmfEventType(fType0); |
211 | assertTrue("equals", fType0.equals(copy0)); | |
212 | assertTrue("equals", copy0.equals(fType0)); | |
213 | ||
214 | TmfEventType copy1 = new TmfEventType(fType1); | |
215 | assertTrue("equals", fType1.equals(copy1)); | |
216 | assertTrue("equals", copy1.equals(fType1)); | |
217 | ||
218 | TmfEventType copy2 = new TmfEventType(fType2); | |
219 | assertTrue("equals", fType2.equals(copy2)); | |
220 | assertTrue("equals", copy2.equals(fType2)); | |
cbbcc354 | 221 | } |
d18dd09b | 222 | |
cbbcc354 | 223 | public void testEqualsTransivity() throws Exception { |
9ee9135e FC |
224 | TmfEventType copy1 = new TmfEventType(fType1); |
225 | TmfEventType copy2 = new TmfEventType(copy1); | |
226 | assertTrue("equals", fType1.equals(copy1)); | |
227 | assertTrue("equals", copy1.equals(copy2)); | |
228 | assertTrue("equals", fType1.equals(copy2)); | |
229 | ||
230 | copy1 = new TmfEventType(fType2); | |
231 | copy2 = new TmfEventType(copy1); | |
232 | assertTrue("equals", fType2.equals(copy1)); | |
233 | assertTrue("equals", copy1.equals(copy2)); | |
234 | assertTrue("equals", fType2.equals(copy2)); | |
235 | ||
236 | copy1 = new TmfEventType(fType3); | |
237 | copy2 = new TmfEventType(copy1); | |
238 | assertTrue("equals", fType3.equals(copy1)); | |
239 | assertTrue("equals", copy1.equals(copy2)); | |
240 | assertTrue("equals", fType3.equals(copy2)); | |
cbbcc354 | 241 | } |
242 | ||
243 | public void testEqualsNull() throws Exception { | |
9ee9135e FC |
244 | assertFalse("equals", fType0.equals(null)); |
245 | assertFalse("equals", fType3.equals(null)); | |
cbbcc354 | 246 | } |
247 | ||
9ee9135e FC |
248 | public void testNonEquals() throws Exception { |
249 | assertFalse("equals", fType0.equals(fType1)); | |
250 | assertFalse("equals", fType1.equals(fType2)); | |
251 | assertFalse("equals", fType2.equals(fType3)); | |
252 | assertFalse("equals", fType3.equals(fType0)); | |
cbbcc354 | 253 | } |
9ee9135e FC |
254 | |
255 | public void testEqualsNonType() throws Exception { | |
256 | assertFalse("equals", fType1.equals(fLabels1)); | |
257 | } | |
258 | ||
cbd4ad82 | 259 | // ------------------------------------------------------------------------ |
cbbcc354 | 260 | // toString |
cbd4ad82 | 261 | // ------------------------------------------------------------------------ |
d18dd09b | 262 | |
cbbcc354 | 263 | public void testToString() { |
264 | String expected1 = "TmfEventType [fContext=" + TmfEventType.DEFAULT_CONTEXT_ID + | |
4c564a2d | 265 | ", fTypeId=" + TmfEventType.DEFAULT_TYPE_ID + "]"; |
cbbcc354 | 266 | TmfEventType type1 = new TmfEventType(); |
267 | assertEquals("toString", expected1, type1.toString()); | |
268 | ||
9ee9135e FC |
269 | String expected2 = "TmfEventType [fContext=" + fContext1 + ", fTypeId=" + fTypeId1 + "]"; |
270 | TmfEventType type2 = new TmfEventType(fContext1, fTypeId1, TmfEventField.makeRoot(fLabels1)); | |
cbbcc354 | 271 | assertEquals("toString", expected2, type2.toString()); |
272 | } | |
d18dd09b ASL |
273 | |
274 | } |