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