1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.tests
.event
;
15 import junit
.framework
.TestCase
;
17 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventType
;
18 import org
.eclipse
.linuxtools
.tmf
.event
.TmfNoSuchFieldException
;
21 * <b><u>TmfEventTypeTest</u></b>
23 * JUnit test suite for the TmfEventType class.
25 public class TmfEventTypeTest
extends TestCase
{
27 // ------------------------------------------------------------------------
29 // ------------------------------------------------------------------------
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
};
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
);
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
48 * @param name the test name
50 public TmfEventTypeTest(String name
) {
55 protected void setUp() throws Exception
{
60 protected void tearDown() throws Exception
{
64 // ------------------------------------------------------------------------
66 // ------------------------------------------------------------------------
68 public void testTmfEventTypeDefault() {
69 TmfEventType type
= new TmfEventType();
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");
81 public void testTmfEventType() {
82 TmfEventType type
= new TmfEventType(fTypeId
, fLabels
);
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");
96 assertEquals("getFieldIndex", 0, type
.getFieldIndex("Dummy"));
97 fail("getFieldIndex: inexistant field");
98 } catch (TmfNoSuchFieldException e
) {
104 fail("getLabel: inexistant field");
105 } catch (TmfNoSuchFieldException e
) {
110 public void testTmfEventType2() {
112 @SuppressWarnings("unused")
113 TmfEventType type
= new TmfEventType(fTypeId
, null);
114 fail("TmfEventType: bad constructor");
115 } catch (IllegalArgumentException e
) {
120 public void testTmfEventType3() {
122 @SuppressWarnings("unused")
123 TmfEventType type
= new TmfEventType(null, fLabels
);
124 fail("TmfEventType: bad constructor");
125 } catch (IllegalArgumentException e
) {
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());
138 public void testTmfEventSourceCopy2() {
140 @SuppressWarnings("unused")
141 TmfEventType type
= new TmfEventType(null);
144 catch (IllegalArgumentException e
) {
149 // ------------------------------------------------------------------------
151 // ------------------------------------------------------------------------
153 public void testEqualsReflexivity() throws Exception
{
154 assertTrue("equals", fType0
.equals(fType0
));
155 assertTrue("equals", fType3
.equals(fType3
));
157 assertTrue("equals", !fType0
.equals(fType3
));
158 assertTrue("equals", !fType3
.equals(fType0
));
161 public void testEqualsSymmetry() throws Exception
{
162 assertTrue("equals", fType0
.equals(fType1
));
163 assertTrue("equals", fType1
.equals(fType0
));
165 assertTrue("equals", !fType0
.equals(fType3
));
166 assertTrue("equals", !fType3
.equals(fType0
));
169 public void testEqualsTransivity() throws Exception
{
170 assertTrue("equals", fType0
.equals(fType1
));
171 assertTrue("equals", fType1
.equals(fType2
));
172 assertTrue("equals", fType0
.equals(fType2
));
175 public void testEqualsNull() throws Exception
{
176 assertTrue("equals", !fType0
.equals(null));
177 assertTrue("equals", !fType3
.equals(null));
180 // ------------------------------------------------------------------------
182 // ------------------------------------------------------------------------
184 public void testHashCode() throws Exception
{
185 assertTrue("hashCode", fType0
.hashCode() == fType1
.hashCode());
186 assertTrue("hashCode", fType0
.hashCode() != fType3
.hashCode());
189 // ------------------------------------------------------------------------
191 // ------------------------------------------------------------------------
193 public void testToString() {
194 String expected1
= "[TmfEventType:" + TmfEventType
.DEFAULT_TYPE_ID
+ "]";
195 TmfEventType type1
= new TmfEventType();
196 assertEquals("toString", expected1
, type1
.toString());
198 String expected2
= "[TmfEventType:" + fTypeId
+ "]";
199 TmfEventType type2
= new TmfEventType(fTypeId
, fLabels
);
200 assertEquals("toString", expected2
, type2
.toString());