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