Implement the new TMF Event Model
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / event / TmfEventFieldTest.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.ITmfEventField;
18 import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
19
20 /**
21 * <b><u>TmfEventFieldTest</u></b>
22 * <p>
23 * Test suite for the TmfEventField class.
24 */
25 @SuppressWarnings("nls")
26 public class TmfEventFieldTest extends TestCase {
27
28 // ------------------------------------------------------------------------
29 // Variables
30 // ------------------------------------------------------------------------
31
32 private final String fFieldId = "Field";
33 private final Object fValue1 = new String("Value");
34 private final Object fValue2 = new Integer(10);
35
36 private TmfEventField fField0;
37 private TmfEventField fField1;
38 private TmfEventField fField2;
39 private TmfEventField fField3;
40
41 // ------------------------------------------------------------------------
42 // Housekeeping
43 // ------------------------------------------------------------------------
44
45 /**
46 * @param name the test name
47 */
48 public TmfEventFieldTest(String name) {
49 super(name);
50 fField0 = new TmfEventField(fFieldId, fValue1, null);
51 fField1 = new TmfEventField(fFieldId, fValue1, null);
52 fField2 = new TmfEventField(fFieldId, fValue1, null);
53 fField3 = new TmfEventField(fFieldId, fValue2, null);
54 }
55
56 @Override
57 protected void setUp() throws Exception {
58 super.setUp();
59 }
60
61 @Override
62 protected void tearDown() throws Exception {
63 super.tearDown();
64 }
65
66 // ------------------------------------------------------------------------
67 // Constructors
68 // ------------------------------------------------------------------------
69
70 public void testTmfEventField() {
71 assertSame("getId", fFieldId, fField0.getName());
72 assertSame("getValue", fValue1, fField0.getValue());
73 }
74
75 public void testTmfEventFieldBadArg() {
76 try {
77 new TmfEventField(null, fValue1, null);
78 fail("null copy");
79 }
80 catch (IllegalArgumentException e) {
81 // Success
82 }
83 }
84
85 public void testTmfEventFieldCopy() {
86 TmfEventField original = new TmfEventField(fFieldId, fValue1, null);
87 TmfEventField field = new TmfEventField(original);
88 assertSame("getId", fFieldId, field.getName());
89 assertSame("getValue", fValue1, field.getValue());
90 }
91
92 public void testTmfEventFieldCopy2() {
93 try {
94 new TmfEventField(null);
95 fail("null copy");
96 }
97 catch (IllegalArgumentException e) {
98 // Success
99 }
100 }
101
102 // ------------------------------------------------------------------------
103 // Modifiers
104 // ------------------------------------------------------------------------
105
106 private class MyField extends TmfEventField {
107 public MyField(String id, Object value) {
108 super(id, value);
109 }
110 public MyField(TmfEventField field) {
111 super(field);
112 }
113 @Override
114 public void setValue(Object value, ITmfEventField[] subfields) {
115 super.setValue(value, subfields);
116 }
117 }
118
119 public void testSetValue() {
120 // TmfEventField original = new TmfEventField(fContent, fFieldId, fValue1);
121 TmfEventField original = new TmfEventField(fFieldId, fValue1, null);
122 TmfEventField field = new TmfEventField(original);
123
124 MyField myField = new MyField(field);
125 assertSame("getValue", fValue1, myField.getValue());
126
127 myField.setValue(fValue2, null);
128 assertSame("getValue", fValue2, myField.getValue());
129 }
130
131 // ------------------------------------------------------------------------
132 // equals
133 // ------------------------------------------------------------------------
134
135 public void testEqualsReflexivity() throws Exception {
136 assertTrue("equals", fField0.equals(fField0));
137 assertTrue("equals", fField3.equals(fField3));
138
139 assertTrue("equals", !fField0.equals(fField3));
140 assertTrue("equals", !fField3.equals(fField0));
141 }
142
143 public void testEqualsSymmetry() throws Exception {
144 assertTrue("equals", fField0.equals(fField1));
145 assertTrue("equals", fField1.equals(fField0));
146
147 assertTrue("equals", !fField0.equals(fField3));
148 assertTrue("equals", !fField3.equals(fField0));
149 }
150
151 public void testEqualsTransivity() throws Exception {
152 assertTrue("equals", fField0.equals(fField1));
153 assertTrue("equals", fField1.equals(fField2));
154 assertTrue("equals", fField0.equals(fField2));
155 }
156
157 public void testEqualsNull() throws Exception {
158 assertTrue("equals", !fField0.equals(null));
159 assertTrue("equals", !fField3.equals(null));
160 }
161
162 // ------------------------------------------------------------------------
163 // hashCode
164 // ------------------------------------------------------------------------
165
166 public void testHashCode() throws Exception {
167 assertTrue("hashCode", fField0.hashCode() == fField1.hashCode());
168 assertTrue("hashCode", fField0.hashCode() != fField3.hashCode());
169 }
170
171 // ------------------------------------------------------------------------
172 // toString
173 // ------------------------------------------------------------------------
174
175 public void testToString() {
176 String expected1 = "TmfEventField [fFieldId=" + fFieldId + ", fValue=" + fValue1.toString() + "]";
177 // TmfEventField field = new TmfEventField(fContent, fFieldId, fValue1);
178 TmfEventField field = new TmfEventField(fFieldId, fValue1, null);
179 assertEquals("toString", expected1, field.toString());
180
181 String expected2 = "TmfEventField [fFieldId=" + fFieldId + ", fValue=" + fValue2.toString() + "]";
182 // field = new TmfEventField(fContent, fFieldId, fValue2);
183 field = new TmfEventField(fFieldId, fValue2, null);
184 assertEquals("toString", expected2, field.toString());
185 }
186
187 }
This page took 0.034193 seconds and 5 git commands to generate.