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
.TmfCheckpoint
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfLocation
;
23 * <b><u>TmfCheckpointTest</u></b>
25 * Test suite for the TmfCheckpoint class.
27 @SuppressWarnings("nls")
28 public class TmfCheckpointTest
extends TestCase
{
30 // ------------------------------------------------------------------------
32 // ------------------------------------------------------------------------
34 ITmfTimestamp fTimestamp1
= new TmfTimestamp();
35 ITmfTimestamp fTimestamp2
= TmfTimestamp
.BigBang
;
36 ITmfTimestamp fTimestamp3
= TmfTimestamp
.BigCrunch
;
41 TmfLocation
<Long
> fLocation1
= new TmfLocation
<Long
>(aLong1
);
42 TmfLocation
<Long
> fLocation2
= new TmfLocation
<Long
>(aLong2
);
43 TmfLocation
<Long
> fLocation3
= new TmfLocation
<Long
>(aLong3
);
45 TmfCheckpoint fCheckpoint1
= new TmfCheckpoint(fTimestamp1
, fLocation1
);
46 TmfCheckpoint fCheckpoint2
= new TmfCheckpoint(fTimestamp2
, fLocation2
);
47 TmfCheckpoint fCheckpoint3
= new TmfCheckpoint(fTimestamp3
, fLocation3
);
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
54 * @param name the test name
56 public TmfCheckpointTest(String name
) {
61 protected void setUp() throws Exception
{
66 protected void tearDown() throws Exception
{
70 // ------------------------------------------------------------------------
72 // ------------------------------------------------------------------------
74 public void testTmfCheckpoint() {
75 assertEquals("TmfCheckpoint", fTimestamp1
, fCheckpoint1
.getTimestamp());
76 assertEquals("TmfCheckpoint", fLocation1
, fCheckpoint1
.getLocation());
79 public void testTmfLocationCopy() {
80 TmfCheckpoint checkpoint
= new TmfCheckpoint(fCheckpoint1
);
82 assertEquals("TmfCheckpoint", fTimestamp1
, checkpoint
.getTimestamp());
83 assertEquals("TmfCheckpoint", fLocation1
, checkpoint
.getLocation());
86 public void testTmfLocationCopy2() throws Exception
{
88 new TmfCheckpoint(null);
91 catch (IllegalArgumentException e
) {
96 // ------------------------------------------------------------------------
98 // ------------------------------------------------------------------------
100 public void testEqualsReflexivity() throws Exception
{
101 assertTrue("equals", fCheckpoint1
.equals(fCheckpoint1
));
102 assertTrue("equals", fCheckpoint2
.equals(fCheckpoint2
));
104 assertTrue("equals", !fCheckpoint1
.equals(fCheckpoint2
));
105 assertTrue("equals", !fCheckpoint2
.equals(fCheckpoint1
));
108 public void testEqualsSymmetry() throws Exception
{
109 TmfCheckpoint checkpoint1
= new TmfCheckpoint(fCheckpoint1
);
110 TmfCheckpoint checkpoint2
= new TmfCheckpoint(fCheckpoint2
);
112 assertTrue("equals", checkpoint1
.equals(fCheckpoint1
));
113 assertTrue("equals", fCheckpoint1
.equals(checkpoint1
));
115 assertTrue("equals", checkpoint2
.equals(fCheckpoint2
));
116 assertTrue("equals", fCheckpoint2
.equals(checkpoint2
));
119 public void testEqualsTransivity() throws Exception
{
120 TmfCheckpoint checkpoint1
= new TmfCheckpoint(fCheckpoint1
);
121 TmfCheckpoint checkpoint2
= new TmfCheckpoint(checkpoint1
);
122 TmfCheckpoint checkpoint3
= new TmfCheckpoint(checkpoint2
);
124 assertTrue("equals", checkpoint1
.equals(checkpoint2
));
125 assertTrue("equals", checkpoint2
.equals(checkpoint3
));
126 assertTrue("equals", checkpoint1
.equals(checkpoint3
));
129 public void testEqualsNull() throws Exception
{
130 assertTrue("equals", !fCheckpoint1
.equals(null));
131 assertTrue("equals", !fCheckpoint2
.equals(null));
134 // ------------------------------------------------------------------------
136 // ------------------------------------------------------------------------
138 public void testHashCode() throws Exception
{
139 TmfCheckpoint checkpoint1
= new TmfCheckpoint(fCheckpoint1
);
140 TmfCheckpoint checkpoint2
= new TmfCheckpoint(fCheckpoint2
);
142 assertTrue("hashCode", fCheckpoint1
.hashCode() == checkpoint1
.hashCode());
143 assertTrue("hashCode", fCheckpoint2
.hashCode() == checkpoint2
.hashCode());
145 assertTrue("hashCode", fCheckpoint1
.hashCode() != checkpoint2
.hashCode());
146 assertTrue("hashCode", fCheckpoint2
.hashCode() != checkpoint1
.hashCode());
149 // ------------------------------------------------------------------------
151 // ------------------------------------------------------------------------
153 public void testToString() {
154 String expected1
= "[TmfCheckpoint(" + fCheckpoint1
.getTimestamp() + "," +
155 fCheckpoint1
.getLocation() + ")]";
156 String expected2
= "[TmfCheckpoint(" + fCheckpoint2
.getTimestamp() + "," +
157 fCheckpoint2
.getLocation() + ")]";
158 String expected3
= "[TmfCheckpoint(" + fCheckpoint3
.getTimestamp() + "," +
159 fCheckpoint3
.getLocation() + ")]";
161 assertEquals("toString", expected1
, fCheckpoint1
.toString());
162 assertEquals("toString", expected2
, fCheckpoint2
.toString());
163 assertEquals("toString", expected3
, fCheckpoint3
.toString());
166 // ------------------------------------------------------------------------
168 // ------------------------------------------------------------------------
170 public void testCompareTo() {
171 assertEquals("compareTo", 0, fCheckpoint1
.compareTo(fCheckpoint1
));
172 assertEquals("compareTo", 1, fCheckpoint1
.compareTo(fCheckpoint2
));
173 assertEquals("compareTo", -1, fCheckpoint1
.compareTo(fCheckpoint3
));
175 assertEquals("compareTo", -1, fCheckpoint2
.compareTo(fCheckpoint1
));
176 assertEquals("compareTo", 0, fCheckpoint2
.compareTo(fCheckpoint2
));
177 assertEquals("compareTo", -1, fCheckpoint2
.compareTo(fCheckpoint3
));
179 assertEquals("compareTo", 1, fCheckpoint3
.compareTo(fCheckpoint1
));
180 assertEquals("compareTo", 1, fCheckpoint3
.compareTo(fCheckpoint2
));
181 assertEquals("compareTo", 0, fCheckpoint3
.compareTo(fCheckpoint3
));