1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.tests
.trace
;
15 import junit
.framework
.TestCase
;
17 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
18 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfLocation
;
21 * <b><u>TmfLocationTest</u></b>
23 * Test suite for the TmfLocation class.
25 @SuppressWarnings("nls")
26 public class TmfLocationTest
extends TestCase
{
28 // ------------------------------------------------------------------------
30 // ------------------------------------------------------------------------
32 String aString
= "some location";
34 TmfTimestamp aTimestamp
= new TmfTimestamp();
36 TmfLocation
<String
> fLocation1
;
37 TmfLocation
<Long
> fLocation2
;
38 TmfLocation
<TmfTimestamp
> fLocation3
;
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
45 * @param name the test name
47 public TmfLocationTest(String name
) {
52 protected void setUp() throws Exception
{
54 fLocation1
= new TmfLocation
<String
>(aString
);
55 fLocation2
= new TmfLocation
<Long
>(aLong
);
56 fLocation3
= new TmfLocation
<TmfTimestamp
>(aTimestamp
);
60 protected void tearDown() throws Exception
{
64 // ------------------------------------------------------------------------
66 // ------------------------------------------------------------------------
68 public void testTmfLocation() {
69 assertEquals("TmfLocation", aString
, fLocation1
.getLocation());
70 assertEquals("TmfLocation", aLong
, fLocation2
.getLocation());
71 assertEquals("TmfLocation", aTimestamp
, fLocation3
.getLocation());
74 public void testTmfLocationCopy() {
75 TmfLocation
<String
> location1
= new TmfLocation
<String
>(fLocation1
);
76 TmfLocation
<Long
> location2
= new TmfLocation
<Long
>(fLocation2
);
77 TmfLocation
<TmfTimestamp
> location3
= new TmfLocation
<TmfTimestamp
>(fLocation3
);
79 assertEquals("TmfLocation", aString
, location1
.getLocation());
80 assertEquals("TmfLocation", aLong
, location2
.getLocation());
81 assertEquals("TmfLocation", aTimestamp
, location3
.getLocation());
84 public void testTmfLocationCopy2() throws Exception
{
86 new TmfLocation
<Long
>((TmfLocation
<Long
>) null);
89 catch (IllegalArgumentException e
) {
94 // ------------------------------------------------------------------------
96 // ------------------------------------------------------------------------
98 public void testSetLocation() {
99 String aString2
= "some other location";
100 Long aLong2
= 1234567L;
101 TmfTimestamp aTimestamp2
= TmfTimestamp
.BigBang
;
103 fLocation1
.setLocation(aString2
);
104 fLocation2
.setLocation(aLong2
);
105 fLocation3
.setLocation(aTimestamp2
);
107 assertEquals("TmfLocation", aString2
, fLocation1
.getLocation());
108 assertEquals("TmfLocation", aLong2
, fLocation2
.getLocation());
109 assertEquals("TmfLocation", aTimestamp2
, fLocation3
.getLocation());
112 // ------------------------------------------------------------------------
114 // ------------------------------------------------------------------------
116 public void testEqualsReflexivity() throws Exception
{
117 assertTrue("equals", fLocation1
.equals(fLocation1
));
118 assertTrue("equals", fLocation2
.equals(fLocation2
));
120 assertTrue("equals", !fLocation1
.equals(fLocation2
));
121 assertTrue("equals", !fLocation2
.equals(fLocation1
));
124 public void testEqualsSymmetry() throws Exception
{
125 TmfLocation
<String
> location1
= new TmfLocation
<String
>(aString
);
126 TmfLocation
<Long
> location2
= new TmfLocation
<Long
>(aLong
);
128 assertTrue("equals", location1
.equals(fLocation1
));
129 assertTrue("equals", fLocation1
.equals(location1
));
131 assertTrue("equals", location2
.equals(fLocation2
));
132 assertTrue("equals", fLocation2
.equals(location2
));
135 public void testEqualsTransivity() throws Exception
{
136 TmfLocation
<String
> location1
= new TmfLocation
<String
>(aString
);
137 TmfLocation
<String
> location2
= new TmfLocation
<String
>(aString
);
138 TmfLocation
<String
> location3
= new TmfLocation
<String
>(aString
);
140 assertTrue("equals", location1
.equals(location2
));
141 assertTrue("equals", location2
.equals(location3
));
142 assertTrue("equals", location1
.equals(location3
));
145 public void testEqualsNull() throws Exception
{
146 assertTrue("equals", !fLocation1
.equals(null));
147 assertTrue("equals", !fLocation1
.equals(null));
150 // ------------------------------------------------------------------------
152 // ------------------------------------------------------------------------
154 public void testHashCode() throws Exception
{
155 TmfLocation
<String
> location1
= new TmfLocation
<String
>(aString
);
156 TmfLocation
<Long
> location2
= new TmfLocation
<Long
>(aLong
);
158 assertTrue("hashCode", fLocation1
.hashCode() == location1
.hashCode());
159 assertTrue("hashCode", fLocation2
.hashCode() == location2
.hashCode());
161 assertTrue("hashCode", fLocation1
.hashCode() != location2
.hashCode());
162 assertTrue("hashCode", fLocation2
.hashCode() != location1
.hashCode());
165 // ------------------------------------------------------------------------
167 // ------------------------------------------------------------------------
169 public void testToString() {
170 String aString
= "some location";
172 TmfTimestamp aTimestamp
= new TmfTimestamp();
174 TmfLocation
<String
> location1
= new TmfLocation
<String
>(aString
);
175 TmfLocation
<Long
> location2
= new TmfLocation
<Long
>(aLong
);
176 TmfLocation
<TmfTimestamp
> location3
= new TmfLocation
<TmfTimestamp
>(aTimestamp
);
178 assertEquals("TmfLocation", aString
.toString(), location1
.toString());
179 assertEquals("TmfLocation", aLong
.toString(), location2
.toString());
180 assertEquals("TmfLocation", aTimestamp
.toString(), location3
.toString());
183 // ------------------------------------------------------------------------
185 // ------------------------------------------------------------------------
187 public void testClone() {
189 TmfLocation
<String
> location1
= fLocation1
.clone();
190 TmfLocation
<Long
> location2
= fLocation2
.clone();
191 TmfLocation
<TmfTimestamp
> location3
= fLocation3
.clone();
193 assertEquals("TmfLocation", aString
.toString(), location1
.toString());
194 assertEquals("TmfLocation", aLong
.toString(), location2
.toString());
195 assertEquals("TmfLocation", aTimestamp
.toString(), location3
.toString());
197 catch (InternalError e
) {
202 public class MyCloneableClass
implements Cloneable
, Comparable
<MyCloneableClass
> {
203 private String fName
;
204 public MyCloneableClass(String name
) {
208 public String
toString() {
212 public MyCloneableClass
clone() {
213 MyCloneableClass clone
= null;
215 clone
= (MyCloneableClass
) super.clone();
217 } catch (CloneNotSupportedException e
) {
222 public int compareTo(MyCloneableClass o
) {
227 public void testCloneCloneable() {
229 MyCloneableClass myClass
= new MyCloneableClass("myClass");
230 TmfLocation
<MyCloneableClass
> myLocation
= new TmfLocation
<MyCloneableClass
>(myClass
);
231 TmfLocation
<MyCloneableClass
> location4
= myLocation
.clone();
233 assertEquals("TmfLocation", myClass
.toString(), location4
.toString());
235 catch (InternalError e
) {
240 public class MyUnCloneableClass
implements Comparable
<MyUnCloneableClass
> {
241 private String fName
;
242 public MyUnCloneableClass(String name
) {
246 public String
toString() {
250 public Object
clone() throws CloneNotSupportedException
{
251 throw new CloneNotSupportedException();
254 public int compareTo(MyUnCloneableClass o
) {
259 public void testCloneUnCloneable() {
261 MyUnCloneableClass myClass
= new MyUnCloneableClass("myClass");
262 TmfLocation
<MyUnCloneableClass
> myLocation
= new TmfLocation
<MyUnCloneableClass
>(myClass
);
266 catch (InternalError e
) {