(no commit message)
[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 org.eclipse.linuxtools.tmf.event.TmfEventType;
16 import org.eclipse.linuxtools.tmf.event.TmfNoSuchFieldException;
17
18 import junit.framework.TestCase;
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 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 };
31
32 // ========================================================================
33 // Housekeeping
34 // ========================================================================
35
36 public TmfEventTypeTest(String name) {
37 super(name);
38 }
39
40 @Override
41 protected void setUp() throws Exception {
42 super.setUp();
43 }
44
45 @Override
46 protected void tearDown() throws Exception {
47 super.tearDown();
48 }
49
50 // ========================================================================
51 // Constructors
52 // ========================================================================
53
54 public void testTmfEventTypeDefault() {
55 TmfEventType type = new TmfEventType();
56 try {
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");
64 }
65 }
66
67 public void testTmfEventType() {
68 TmfEventType type = new TmfEventType(fTypeId, fLabels);
69 try {
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");
79 }
80
81 try {
82 assertEquals("getFieldIndex", 0, type.getFieldIndex("Dummy"));
83 fail("getFieldIndex: inexistant field");
84 } catch (TmfNoSuchFieldException e) {
85 // Success
86 }
87 }
88
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());
95 }
96
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());
103 }
104
105 // public void testCloneDeepCopy() {
106 // fail("Not yet implemented");
107 // }
108
109 // ========================================================================
110 // Operators
111 // ========================================================================
112
113 public void testToString() {
114 String expected1 = "[TmfEventType:" + TmfEventType.DEFAULT_TYPE_ID + "]";
115 TmfEventType type1 = new TmfEventType();
116 assertEquals("toString", expected1, type1.toString());
117
118 String expected2 = "[TmfEventType:" + fTypeId + "]";
119 TmfEventType type2 = new TmfEventType(fTypeId, fLabels);
120 assertEquals("toString", expected2, type2.toString());
121 }
122
123 }
This page took 0.034306 seconds and 6 git commands to generate.