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
.core
.tests
.trace
;
15 import junit
.framework
.TestCase
;
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
;
22 * <b><u>TmfLocationTest</u></b>
24 * Test suite for the TmfLocation class.
26 @SuppressWarnings("nls")
27 public class TmfLocationTest
extends TestCase
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
33 String aString
= "some location";
35 TmfTimestamp aTimestamp
= new TmfTimestamp();
37 TmfLocation
<String
> fLocation1
;
38 TmfLocation
<Long
> fLocation2
;
39 TmfLocation
<TmfTimestamp
> fLocation3
;
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
46 * @param name the test name
48 public TmfLocationTest(String name
) {
53 protected void setUp() throws Exception
{
55 fLocation1
= new TmfLocation
<String
>(aString
);
56 fLocation2
= new TmfLocation
<Long
>(aLong
);
57 fLocation3
= new TmfLocation
<TmfTimestamp
>(aTimestamp
);
61 protected void tearDown() throws Exception
{
65 // ------------------------------------------------------------------------
67 // ------------------------------------------------------------------------
69 public void testTmfLocation() {
70 assertEquals("TmfLocation", aString
, fLocation1
.getLocation());
71 assertEquals("TmfLocation", aLong
, fLocation2
.getLocation());
72 assertEquals("TmfLocation", aTimestamp
, fLocation3
.getLocation());
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
);
80 assertEquals("TmfLocation", aString
, location1
.getLocation());
81 assertEquals("TmfLocation", aLong
, location2
.getLocation());
82 assertEquals("TmfLocation", aTimestamp
, location3
.getLocation());
85 public void testTmfLocationCopy2() throws Exception
{
87 new TmfLocation
<Long
>((TmfLocation
<Long
>) null);
90 catch (IllegalArgumentException e
) {
95 // ------------------------------------------------------------------------
97 // ------------------------------------------------------------------------
99 public void testSetLocation() {
100 String aString2
= "some other location";
101 Long aLong2
= 1234567L;
102 TmfTimestamp aTimestamp2
= (TmfTimestamp
) TmfTimestamp
.BigBang
;
104 fLocation1
.setLocation(aString2
);
105 fLocation2
.setLocation(aLong2
);
106 fLocation3
.setLocation(aTimestamp2
);
108 assertEquals("TmfLocation", aString2
, fLocation1
.getLocation());
109 assertEquals("TmfLocation", aLong2
, fLocation2
.getLocation());
110 assertEquals("TmfLocation", aTimestamp2
, fLocation3
.getLocation());
113 // ------------------------------------------------------------------------
115 // ------------------------------------------------------------------------
117 public void testEqualsReflexivity() throws Exception
{
118 assertTrue("equals", fLocation1
.equals(fLocation1
));
119 assertTrue("equals", fLocation2
.equals(fLocation2
));
121 assertTrue("equals", !fLocation1
.equals(fLocation2
));
122 assertTrue("equals", !fLocation2
.equals(fLocation1
));
125 public void testEqualsSymmetry() throws Exception
{
126 TmfLocation
<String
> location1
= new TmfLocation
<String
>(aString
);
127 TmfLocation
<Long
> location2
= new TmfLocation
<Long
>(aLong
);
129 assertTrue("equals", location1
.equals(fLocation1
));
130 assertTrue("equals", fLocation1
.equals(location1
));
132 assertTrue("equals", location2
.equals(fLocation2
));
133 assertTrue("equals", fLocation2
.equals(location2
));
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
);
141 assertTrue("equals", location1
.equals(location2
));
142 assertTrue("equals", location2
.equals(location3
));
143 assertTrue("equals", location1
.equals(location3
));
146 public void testEqualsNull() throws Exception
{
147 assertTrue("equals", !fLocation1
.equals(null));
148 assertTrue("equals", !fLocation1
.equals(null));
151 // ------------------------------------------------------------------------
153 // ------------------------------------------------------------------------
155 public void testHashCode() throws Exception
{
156 TmfLocation
<String
> location1
= new TmfLocation
<String
>(aString
);
157 TmfLocation
<Long
> location2
= new TmfLocation
<Long
>(aLong
);
159 assertTrue("hashCode", fLocation1
.hashCode() == location1
.hashCode());
160 assertTrue("hashCode", fLocation2
.hashCode() == location2
.hashCode());
162 assertTrue("hashCode", fLocation1
.hashCode() != location2
.hashCode());
163 assertTrue("hashCode", fLocation2
.hashCode() != location1
.hashCode());
166 // ------------------------------------------------------------------------
168 // ------------------------------------------------------------------------
170 public void testToString() {
171 String aString
= "some location";
173 TmfTimestamp aTimestamp
= new TmfTimestamp();
175 TmfLocation
<String
> location1
= new TmfLocation
<String
>(aString
);
176 TmfLocation
<Long
> location2
= new TmfLocation
<Long
>(aLong
);
177 TmfLocation
<TmfTimestamp
> location3
= new TmfLocation
<TmfTimestamp
>(aTimestamp
);
179 assertEquals("TmfLocation", aString
.toString(), location1
.toString());
180 assertEquals("TmfLocation", aLong
.toString(), location2
.toString());
181 assertEquals("TmfLocation", aTimestamp
.toString(), location3
.toString());
184 // ------------------------------------------------------------------------
186 // ------------------------------------------------------------------------
188 public void testClone() {
190 TmfLocation
<String
> location1
= fLocation1
.clone();
191 TmfLocation
<Long
> location2
= fLocation2
.clone();
192 TmfLocation
<TmfTimestamp
> location3
= fLocation3
.clone();
194 assertEquals("TmfLocation", aString
.toString(), location1
.toString());
195 assertEquals("TmfLocation", aLong
.toString(), location2
.toString());
196 assertEquals("TmfLocation", aTimestamp
.toString(), location3
.toString());
198 catch (InternalError e
) {
203 public class MyCloneableClass
implements Cloneable
, Comparable
<MyCloneableClass
> {
204 private String fName
;
205 public MyCloneableClass(String name
) {
209 public String
toString() {
213 public MyCloneableClass
clone() {
214 MyCloneableClass clone
= null;
216 clone
= (MyCloneableClass
) super.clone();
218 } catch (CloneNotSupportedException e
) {
223 public int compareTo(MyCloneableClass o
) {
228 public void testCloneCloneable() {
230 MyCloneableClass myClass
= new MyCloneableClass("myClass");
231 TmfLocation
<MyCloneableClass
> myLocation
= new TmfLocation
<MyCloneableClass
>(myClass
);
232 TmfLocation
<MyCloneableClass
> location4
= myLocation
.clone();
234 assertEquals("TmfLocation", myClass
.toString(), location4
.toString());
236 catch (InternalError e
) {
241 public class MyUnCloneableClass
implements Comparable
<MyUnCloneableClass
> {
242 private String fName
;
243 public MyUnCloneableClass(String name
) {
247 public String
toString() {
251 public Object
clone() throws CloneNotSupportedException
{
252 throw new CloneNotSupportedException();
255 public int compareTo(MyUnCloneableClass o
) {
260 public void testCloneUnCloneable() {
262 MyUnCloneableClass myClass
= new MyUnCloneableClass("myClass");
263 TmfLocation
<MyUnCloneableClass
> myLocation
= new TmfLocation
<MyUnCloneableClass
>(myClass
);
267 catch (InternalError e
) {