Integrate the TmfEvent+ITmfTimestamp API
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / trace / TmfLocationTest.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 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.trace;
14
15 import junit.framework.TestCase;
16
17 import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
18 import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
19 import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
20
21 /**
22 * <b><u>TmfLocationTest</u></b>
23 * <p>
24 * Test suite for the TmfLocation class.
25 */
26 @SuppressWarnings("nls")
27 public class TmfLocationTest extends TestCase {
28
29 // ------------------------------------------------------------------------
30 // Variables
31 // ------------------------------------------------------------------------
32
33 String aString = "some location";
34 Long aLong = 12345L;
35 TmfTimestamp aTimestamp = new TmfTimestamp();
36
37 TmfLocation<String> fLocation1;
38 TmfLocation<Long> fLocation2;
39 TmfLocation<TmfTimestamp> fLocation3;
40
41 // ------------------------------------------------------------------------
42 // Housekeeping
43 // ------------------------------------------------------------------------
44
45 /**
46 * @param name the test name
47 */
48 public TmfLocationTest(String name) {
49 super(name);
50 }
51
52 @Override
53 protected void setUp() throws Exception {
54 super.setUp();
55 fLocation1 = new TmfLocation<String>(aString);
56 fLocation2 = new TmfLocation<Long>(aLong);
57 fLocation3 = new TmfLocation<TmfTimestamp>(aTimestamp);
58 }
59
60 @Override
61 protected void tearDown() throws Exception {
62 super.tearDown();
63 }
64
65 // ------------------------------------------------------------------------
66 // Constructors
67 // ------------------------------------------------------------------------
68
69 public void testTmfLocation() {
70 assertEquals("TmfLocation", aString, fLocation1.getLocation());
71 assertEquals("TmfLocation", aLong, fLocation2.getLocation());
72 assertEquals("TmfLocation", aTimestamp, fLocation3.getLocation());
73 }
74
75 public void testTmfLocationCopy() {
76 TmfLocation<String> location1 = new TmfLocation<String>(fLocation1);
77 TmfLocation<Long> location2 = new TmfLocation<Long>(fLocation2);
78 TmfLocation<TmfTimestamp> location3 = new TmfLocation<TmfTimestamp>(fLocation3);
79
80 assertEquals("TmfLocation", aString, location1.getLocation());
81 assertEquals("TmfLocation", aLong, location2.getLocation());
82 assertEquals("TmfLocation", aTimestamp, location3.getLocation());
83 }
84
85 public void testTmfLocationCopy2() throws Exception {
86 try {
87 new TmfLocation<Long>((TmfLocation<Long>) null);
88 fail("null copy");
89 }
90 catch (IllegalArgumentException e) {
91 // Success
92 }
93 }
94
95 // ------------------------------------------------------------------------
96 // setLocation
97 // ------------------------------------------------------------------------
98
99 public void testSetLocation() {
100 String aString2 = "some other location";
101 Long aLong2 = 1234567L;
102 TmfTimestamp aTimestamp2 = (TmfTimestamp) TmfTimestamp.BigBang;
103
104 fLocation1.setLocation(aString2);
105 fLocation2.setLocation(aLong2);
106 fLocation3.setLocation(aTimestamp2);
107
108 assertEquals("TmfLocation", aString2, fLocation1.getLocation());
109 assertEquals("TmfLocation", aLong2, fLocation2.getLocation());
110 assertEquals("TmfLocation", aTimestamp2, fLocation3.getLocation());
111 }
112
113 // ------------------------------------------------------------------------
114 // toEquals
115 // ------------------------------------------------------------------------
116
117 public void testEqualsReflexivity() throws Exception {
118 assertTrue("equals", fLocation1.equals(fLocation1));
119 assertTrue("equals", fLocation2.equals(fLocation2));
120
121 assertTrue("equals", !fLocation1.equals(fLocation2));
122 assertTrue("equals", !fLocation2.equals(fLocation1));
123 }
124
125 public void testEqualsSymmetry() throws Exception {
126 TmfLocation<String> location1 = new TmfLocation<String>(aString);
127 TmfLocation<Long> location2 = new TmfLocation<Long>(aLong);
128
129 assertTrue("equals", location1.equals(fLocation1));
130 assertTrue("equals", fLocation1.equals(location1));
131
132 assertTrue("equals", location2.equals(fLocation2));
133 assertTrue("equals", fLocation2.equals(location2));
134 }
135
136 public void testEqualsTransivity() throws Exception {
137 TmfLocation<String> location1 = new TmfLocation<String>(aString);
138 TmfLocation<String> location2 = new TmfLocation<String>(aString);
139 TmfLocation<String> location3 = new TmfLocation<String>(aString);
140
141 assertTrue("equals", location1.equals(location2));
142 assertTrue("equals", location2.equals(location3));
143 assertTrue("equals", location1.equals(location3));
144 }
145
146 public void testEqualsNull() throws Exception {
147 assertTrue("equals", !fLocation1.equals(null));
148 assertTrue("equals", !fLocation1.equals(null));
149 }
150
151 // ------------------------------------------------------------------------
152 // hashCode
153 // ------------------------------------------------------------------------
154
155 public void testHashCode() throws Exception {
156 TmfLocation<String> location1 = new TmfLocation<String>(aString);
157 TmfLocation<Long> location2 = new TmfLocation<Long>(aLong);
158
159 assertTrue("hashCode", fLocation1.hashCode() == location1.hashCode());
160 assertTrue("hashCode", fLocation2.hashCode() == location2.hashCode());
161
162 assertTrue("hashCode", fLocation1.hashCode() != location2.hashCode());
163 assertTrue("hashCode", fLocation2.hashCode() != location1.hashCode());
164 }
165
166 // ------------------------------------------------------------------------
167 // toString
168 // ------------------------------------------------------------------------
169
170 public void testToString() {
171 String aString = "some location";
172 Long aLong = 12345L;
173 TmfTimestamp aTimestamp = new TmfTimestamp();
174
175 TmfLocation<String> location1 = new TmfLocation<String>(aString);
176 TmfLocation<Long> location2 = new TmfLocation<Long>(aLong);
177 TmfLocation<TmfTimestamp> location3 = new TmfLocation<TmfTimestamp>(aTimestamp);
178
179 assertEquals("TmfLocation", aString.toString(), location1.toString());
180 assertEquals("TmfLocation", aLong.toString(), location2.toString());
181 assertEquals("TmfLocation", aTimestamp.toString(), location3.toString());
182 }
183
184 // ------------------------------------------------------------------------
185 // clone
186 // ------------------------------------------------------------------------
187
188 public void testClone() {
189 try {
190 TmfLocation<String> location1 = fLocation1.clone();
191 TmfLocation<Long> location2 = fLocation2.clone();
192 TmfLocation<TmfTimestamp> location3 = fLocation3.clone();
193
194 assertEquals("TmfLocation", aString.toString(), location1.toString());
195 assertEquals("TmfLocation", aLong.toString(), location2.toString());
196 assertEquals("TmfLocation", aTimestamp.toString(), location3.toString());
197 }
198 catch (InternalError e) {
199 fail("clone()");
200 }
201 }
202
203 public class MyCloneableClass implements Cloneable, Comparable<MyCloneableClass> {
204 private String fName;
205 public MyCloneableClass(String name) {
206 fName = name;
207 }
208 @Override
209 public String toString() {
210 return fName;
211 }
212 @Override
213 public MyCloneableClass clone() {
214 MyCloneableClass clone = null;
215 try {
216 clone = (MyCloneableClass) super.clone();
217 clone.fName = fName;
218 } catch (CloneNotSupportedException e) {
219 }
220 return clone;
221 }
222 @Override
223 public int compareTo(MyCloneableClass o) {
224 return 0;
225 }
226 }
227
228 public void testCloneCloneable() {
229 try {
230 MyCloneableClass myClass = new MyCloneableClass("myClass");
231 TmfLocation<MyCloneableClass> myLocation = new TmfLocation<MyCloneableClass>(myClass);
232 TmfLocation<MyCloneableClass> location4 = myLocation.clone();
233
234 assertEquals("TmfLocation", myClass.toString(), location4.toString());
235 }
236 catch (InternalError e) {
237 fail("clone()");
238 }
239 }
240
241 public class MyUnCloneableClass implements Comparable<MyUnCloneableClass> {
242 private String fName;
243 public MyUnCloneableClass(String name) {
244 fName = name;
245 }
246 @Override
247 public String toString() {
248 return fName;
249 }
250 @Override
251 public Object clone() throws CloneNotSupportedException {
252 throw new CloneNotSupportedException();
253 }
254 @Override
255 public int compareTo(MyUnCloneableClass o) {
256 return 0;
257 }
258 }
259
260 public void testCloneUnCloneable() {
261 try {
262 MyUnCloneableClass myClass = new MyUnCloneableClass("myClass");
263 TmfLocation<MyUnCloneableClass> myLocation = new TmfLocation<MyUnCloneableClass>(myClass);
264 myLocation.clone();
265 fail("clone()");
266 }
267 catch (InternalError e) {
268 // Success
269 }
270 }
271
272 }
This page took 0.038381 seconds and 6 git commands to generate.