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 org
.eclipse
.linuxtools
.tmf
.event
.TmfEventType
;
16 import org
.eclipse
.linuxtools
.tmf
.event
.TmfNoSuchFieldException
;
18 import junit
.framework
.TestCase
;
21 * <b><u>TmfEventTypeTest</u></b>
23 * JUnit test suite for the TmfEventType class.
25 public class TmfEventTypeTest
extends TestCase
{
27 private final String fTypeId
= "Some type";
28 private final String fLabel0
= "label1";
29 private final String fLabel1
= "label2";
30 private final String
[] fLabels
= new String
[] { fLabel0
, fLabel1
};
32 // ========================================================================
34 // ========================================================================
36 public TmfEventTypeTest(String name
) {
41 protected void setUp() throws Exception
{
46 protected void tearDown() throws Exception
{
50 // ========================================================================
52 // ========================================================================
54 public void testTmfEventTypeDefault() {
55 TmfEventType type
= new TmfEventType();
57 assertEquals("getTypeId", TmfEventType
.DEFAULT_TYPE_ID
, type
.getTypeId());
58 assertEquals("getNbFields", 1, type
.getNbFields());
59 assertEquals("getFieldIndex", 0, type
.getFieldIndex(TmfEventType
.DEFAULT_LABELS
[0]));
60 assertEquals("getLabels", TmfEventType
.DEFAULT_LABELS
, type
.getLabels());
61 assertEquals("getLabel", TmfEventType
.DEFAULT_LABELS
[0], type
.getLabel(0));
62 } catch (TmfNoSuchFieldException e
) {
63 fail("getFieldIndex: no such field");
67 public void testTmfEventType() {
68 TmfEventType type
= new TmfEventType(fTypeId
, fLabels
);
70 assertEquals("getTypeId", fTypeId
, type
.getTypeId());
71 assertEquals("getNbFields", fLabels
.length
, type
.getNbFields());
72 assertEquals("getFieldIndex", 0, type
.getFieldIndex(fLabel0
));
73 assertEquals("getFieldIndex", 1, type
.getFieldIndex(fLabel1
));
74 assertEquals("getLabels", fLabels
, type
.getLabels());
75 assertEquals("getLabel", fLabel0
, type
.getLabel(0));
76 assertEquals("getLabel", fLabel1
, type
.getLabel(1));
77 } catch (TmfNoSuchFieldException e
) {
78 fail("getFieldIndex: no such field");
82 assertEquals("getFieldIndex", 0, type
.getFieldIndex("Dummy"));
83 fail("getFieldIndex: inexistant field");
84 } catch (TmfNoSuchFieldException e
) {
89 public void testTmfEventTypeCopy() {
90 TmfEventType original
= new TmfEventType(fTypeId
, fLabels
);
91 TmfEventType type
= new TmfEventType(original
);
92 assertEquals("getTypeId", fTypeId
, type
.getTypeId());
93 assertEquals("getNbFields", fLabels
.length
, type
.getNbFields());
94 assertEquals("getLabels", fLabels
, type
.getLabels());
97 public void testCloneShallowCopy() {
98 TmfEventType original
= new TmfEventType(fTypeId
, fLabels
);
99 TmfEventType type
= original
.clone();
100 assertEquals("getTypeId", fTypeId
, type
.getTypeId());
101 assertEquals("getNbFields", fLabels
.length
, type
.getNbFields());
102 assertEquals("getLabels", fLabels
, type
.getLabels());
105 // public void testCloneDeepCopy() {
106 // fail("Not yet implemented");
109 // ========================================================================
111 // ========================================================================
113 public void testToString() {
114 String expected1
= "[TmfEventType:" + TmfEventType
.DEFAULT_TYPE_ID
+ "]";
115 TmfEventType type1
= new TmfEventType();
116 assertEquals("toString", expected1
, type1
.toString());
118 String expected2
= "[TmfEventType:" + fTypeId
+ "]";
119 TmfEventType type2
= new TmfEventType(fTypeId
, fLabels
);
120 assertEquals("toString", expected2
, type2
.toString());