[Bug309731] Fixed a problem with generic requests and component registration/deregist...
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.tests / src / org / eclipse / linuxtools / tmf / tests / event / TmfEventTypeTest.java
1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
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
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.tests.event;
14
15 import junit.framework.TestCase;
16
17 import org.eclipse.linuxtools.tmf.event.TmfEventType;
18 import org.eclipse.linuxtools.tmf.event.TmfNoSuchFieldException;
19
20 /**
21 * <b><u>TmfEventTypeTest</u></b>
22 * <p>
23 * JUnit test suite for the TmfEventType class.
24 */
25 public class TmfEventTypeTest extends TestCase {
26
27 // ------------------------------------------------------------------------
28 // Variables
29 // ------------------------------------------------------------------------
30
31 private final String fTypeId = "Some type";
32 private final String fTypeId2 = "Some other type";
33 private final String fLabel0 = "label1";
34 private final String fLabel1 = "label2";
35 private final String[] fLabels = new String[] { fLabel0, fLabel1 };
36 private final String[] fLabels2 = new String[] { fLabel1, fLabel0 };
37
38 private final TmfEventType fType0 = new TmfEventType(fTypeId, fLabels);
39 private final TmfEventType fType1 = new TmfEventType(fTypeId, fLabels);
40 private final TmfEventType fType2 = new TmfEventType(fTypeId, fLabels);
41 private final TmfEventType fType3 = new TmfEventType(fTypeId2, fLabels2);
42
43 // ------------------------------------------------------------------------
44 // Housekeeping
45 // ------------------------------------------------------------------------
46
47 /**
48 * @param name the test name
49 */
50 public TmfEventTypeTest(String name) {
51 super(name);
52 }
53
54 @Override
55 protected void setUp() throws Exception {
56 super.setUp();
57 }
58
59 @Override
60 protected void tearDown() throws Exception {
61 super.tearDown();
62 }
63
64 // ------------------------------------------------------------------------
65 // Constructors
66 // ------------------------------------------------------------------------
67
68 public void testTmfEventTypeDefault() {
69 TmfEventType type = new TmfEventType();
70 try {
71 assertEquals("getTypeId", TmfEventType.DEFAULT_TYPE_ID, type.getTypeId());
72 assertEquals("getNbFields", 1, type.getNbFields());
73 assertEquals("getFieldIndex", 0, type.getFieldIndex(TmfEventType.DEFAULT_LABELS[0]));
74 assertEquals("getLabels", TmfEventType.DEFAULT_LABELS, type.getLabels());
75 assertEquals("getLabel", TmfEventType.DEFAULT_LABELS[0], type.getLabel(0));
76 } catch (TmfNoSuchFieldException e) {
77 fail("getFieldIndex: no such field");
78 }
79 }
80
81 public void testTmfEventType() {
82 TmfEventType type = new TmfEventType(fTypeId, fLabels);
83 try {
84 assertEquals("getTypeId", fTypeId, type.getTypeId());
85 assertEquals("getNbFields", fLabels.length, type.getNbFields());
86 assertEquals("getFieldIndex", 0, type.getFieldIndex(fLabel0));
87 assertEquals("getFieldIndex", 1, type.getFieldIndex(fLabel1));
88 assertEquals("getLabels", fLabels, type.getLabels());
89 assertEquals("getLabel", fLabel0, type.getLabel(0));
90 assertEquals("getLabel", fLabel1, type.getLabel(1));
91 } catch (TmfNoSuchFieldException e) {
92 fail("getFieldIndex: no such field");
93 }
94
95 try {
96 assertEquals("getFieldIndex", 0, type.getFieldIndex("Dummy"));
97 fail("getFieldIndex: inexistant field");
98 } catch (TmfNoSuchFieldException e) {
99 // Success
100 }
101
102 try {
103 type.getLabel(10);
104 fail("getLabel: inexistant field");
105 } catch (TmfNoSuchFieldException e) {
106 // Success
107 }
108 }
109
110 public void testTmfEventType2() {
111 try {
112 @SuppressWarnings("unused")
113 TmfEventType type = new TmfEventType(fTypeId, null);
114 fail("TmfEventType: bad constructor");
115 } catch (IllegalArgumentException e) {
116 // Success
117 }
118 }
119
120 public void testTmfEventType3() {
121 try {
122 @SuppressWarnings("unused")
123 TmfEventType type = new TmfEventType(null, fLabels);
124 fail("TmfEventType: bad constructor");
125 } catch (IllegalArgumentException e) {
126 // Success
127 }
128 }
129
130 public void testTmfEventTypeCopy() {
131 TmfEventType original = new TmfEventType(fTypeId, fLabels);
132 TmfEventType type = new TmfEventType(original);
133 assertEquals("getTypeId", fTypeId, type.getTypeId());
134 assertEquals("getNbFields", fLabels.length, type.getNbFields());
135 assertEquals("getLabels", fLabels, type.getLabels());
136 }
137
138 public void testTmfEventSourceCopy2() {
139 try {
140 @SuppressWarnings("unused")
141 TmfEventType type = new TmfEventType(null);
142 fail("null copy");
143 }
144 catch (IllegalArgumentException e) {
145 // Success
146 }
147 }
148
149 // ------------------------------------------------------------------------
150 // equals
151 // ------------------------------------------------------------------------
152
153 public void testEqualsReflexivity() throws Exception {
154 assertTrue("equals", fType0.equals(fType0));
155 assertTrue("equals", fType3.equals(fType3));
156
157 assertTrue("equals", !fType0.equals(fType3));
158 assertTrue("equals", !fType3.equals(fType0));
159 }
160
161 public void testEqualsSymmetry() throws Exception {
162 assertTrue("equals", fType0.equals(fType1));
163 assertTrue("equals", fType1.equals(fType0));
164
165 assertTrue("equals", !fType0.equals(fType3));
166 assertTrue("equals", !fType3.equals(fType0));
167 }
168
169 public void testEqualsTransivity() throws Exception {
170 assertTrue("equals", fType0.equals(fType1));
171 assertTrue("equals", fType1.equals(fType2));
172 assertTrue("equals", fType0.equals(fType2));
173 }
174
175 public void testEqualsConsistency() throws Exception {
176 assertTrue("equals", fType0.equals(fType0));
177 assertTrue("equals", fType0.equals(fType0));
178
179 assertTrue("equals", fType3.equals(fType3));
180 assertTrue("equals", fType3.equals(fType3));
181 }
182
183 public void testEqualsNull() throws Exception {
184 assertTrue("equals", !fType0.equals(null));
185 assertTrue("equals", !fType3.equals(null));
186 }
187
188 // ------------------------------------------------------------------------
189 // hashCode
190 // ------------------------------------------------------------------------
191
192 public void testHashCode() throws Exception {
193 assertTrue("hashCode", fType0.hashCode() == fType1.hashCode());
194 assertTrue("hashCode", fType0.hashCode() != fType3.hashCode());
195 }
196
197 // ------------------------------------------------------------------------
198 // toString
199 // ------------------------------------------------------------------------
200
201 public void testToString() {
202 String expected1 = "[TmfEventType:" + TmfEventType.DEFAULT_TYPE_ID + "]";
203 TmfEventType type1 = new TmfEventType();
204 assertEquals("toString", expected1, type1.toString());
205
206 String expected2 = "[TmfEventType:" + fTypeId + "]";
207 TmfEventType type2 = new TmfEventType(fTypeId, fLabels);
208 assertEquals("toString", expected2, type2.toString());
209 }
210
211 }
This page took 0.036483 seconds and 6 git commands to generate.