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