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