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
.core
.tests
.event
;
15 import junit
.framework
.TestCase
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventType
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfNoSuchFieldException
;
21 * <b><u>TmfEventTypeTest</u></b>
23 * JUnit test suite for the TmfEventType class.
25 @SuppressWarnings("nls")
26 public class TmfEventTypeTest
extends TestCase
{
28 // ------------------------------------------------------------------------
30 // ------------------------------------------------------------------------
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
};
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
);
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
49 * @param name the test name
51 public TmfEventTypeTest(String name
) {
56 protected void setUp() throws Exception
{
61 protected void tearDown() throws Exception
{
65 // ------------------------------------------------------------------------
67 // ------------------------------------------------------------------------
69 public void testTmfEventTypeDefault() {
70 TmfEventType type
= new TmfEventType();
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");
82 public void testTmfEventType() {
83 TmfEventType type
= new TmfEventType(fTypeId
, fLabels
);
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");
97 assertEquals("getFieldIndex", 0, type
.getFieldIndex("Dummy"));
98 fail("getFieldIndex: inexistant field");
99 } catch (TmfNoSuchFieldException e
) {
105 fail("getLabel: inexistant field");
106 } catch (TmfNoSuchFieldException e
) {
111 public void testTmfEventType2() {
113 @SuppressWarnings("unused")
114 TmfEventType type
= new TmfEventType(fTypeId
, null);
115 fail("TmfEventType: bad constructor");
116 } catch (IllegalArgumentException e
) {
121 public void testTmfEventType3() {
123 @SuppressWarnings("unused")
124 TmfEventType type
= new TmfEventType(null, fLabels
);
125 fail("TmfEventType: bad constructor");
126 } catch (IllegalArgumentException e
) {
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());
139 public void testTmfEventSourceCopy2() {
141 @SuppressWarnings("unused")
142 TmfEventType type
= new TmfEventType(null);
145 catch (IllegalArgumentException e
) {
150 // ------------------------------------------------------------------------
152 // ------------------------------------------------------------------------
154 public void testEqualsReflexivity() throws Exception
{
155 assertTrue("equals", fType0
.equals(fType0
));
156 assertTrue("equals", fType3
.equals(fType3
));
158 assertTrue("equals", !fType0
.equals(fType3
));
159 assertTrue("equals", !fType3
.equals(fType0
));
162 public void testEqualsSymmetry() throws Exception
{
163 assertTrue("equals", fType0
.equals(fType1
));
164 assertTrue("equals", fType1
.equals(fType0
));
166 assertTrue("equals", !fType0
.equals(fType3
));
167 assertTrue("equals", !fType3
.equals(fType0
));
170 public void testEqualsTransivity() throws Exception
{
171 assertTrue("equals", fType0
.equals(fType1
));
172 assertTrue("equals", fType1
.equals(fType2
));
173 assertTrue("equals", fType0
.equals(fType2
));
176 public void testEqualsNull() throws Exception
{
177 assertTrue("equals", !fType0
.equals(null));
178 assertTrue("equals", !fType3
.equals(null));
181 // ------------------------------------------------------------------------
183 // ------------------------------------------------------------------------
185 public void testHashCode() throws Exception
{
186 assertTrue("hashCode", fType0
.hashCode() == fType1
.hashCode());
187 assertTrue("hashCode", fType0
.hashCode() != fType3
.hashCode());
190 // ------------------------------------------------------------------------
192 // ------------------------------------------------------------------------
194 public void testToString() {
195 String expected1
= "[TmfEventType:" + TmfEventType
.DEFAULT_TYPE_ID
+ "]";
196 TmfEventType type1
= new TmfEventType();
197 assertEquals("toString", expected1
, type1
.toString());
199 String expected2
= "[TmfEventType:" + fTypeId
+ "]";
200 TmfEventType type2
= new TmfEventType(fTypeId
, fLabels
);
201 assertEquals("toString", expected2
, type2
.toString());