Commit | Line | Data |
---|---|---|
d18dd09b ASL |
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.TmfCheckpoint; | |
19 | import org.eclipse.linuxtools.tmf.trace.TmfLocation; | |
20 | ||
21 | /** | |
22 | * <b><u>TmfCheckpointTest</u></b> | |
23 | * <p> | |
24 | * Test suite for the TmfCheckpoint class. | |
25 | */ | |
26 | public class TmfCheckpointTest extends TestCase { | |
27 | ||
28 | // ------------------------------------------------------------------------ | |
29 | // Variables | |
30 | // ------------------------------------------------------------------------ | |
31 | ||
32 | TmfTimestamp fTimestamp1 = new TmfTimestamp(); | |
33 | TmfTimestamp fTimestamp2 = TmfTimestamp.BigBang; | |
34 | TmfTimestamp fTimestamp3 = TmfTimestamp.BigCrunch; | |
35 | ||
36 | Long aLong1 = 12345L; | |
37 | Long aLong2 = 23456L; | |
38 | Long aLong3 = 34567L; | |
39 | TmfLocation<Long> fLocation1 = new TmfLocation<Long>(aLong1); | |
40 | TmfLocation<Long> fLocation2 = new TmfLocation<Long>(aLong2); | |
41 | TmfLocation<Long> fLocation3 = new TmfLocation<Long>(aLong3); | |
42 | ||
43 | TmfCheckpoint fCheckpoint1 = new TmfCheckpoint(fTimestamp1, fLocation1); | |
44 | TmfCheckpoint fCheckpoint2 = new TmfCheckpoint(fTimestamp2, fLocation2); | |
45 | TmfCheckpoint fCheckpoint3 = new TmfCheckpoint(fTimestamp3, fLocation3); | |
46 | ||
47 | // ------------------------------------------------------------------------ | |
48 | // Housekeeping | |
49 | // ------------------------------------------------------------------------ | |
50 | ||
51 | /** | |
52 | * @param name the test name | |
53 | */ | |
54 | public TmfCheckpointTest(String name) { | |
55 | super(name); | |
56 | } | |
57 | ||
58 | @Override | |
59 | protected void setUp() throws Exception { | |
60 | super.setUp(); | |
61 | } | |
62 | ||
63 | @Override | |
64 | protected void tearDown() throws Exception { | |
65 | super.tearDown(); | |
66 | } | |
67 | ||
68 | // ------------------------------------------------------------------------ | |
69 | // Constructors | |
70 | // ------------------------------------------------------------------------ | |
71 | ||
72 | public void testTmfCheckpoint() { | |
73 | assertEquals("TmfCheckpoint", fTimestamp1, fCheckpoint1.getTimestamp()); | |
74 | assertEquals("TmfCheckpoint", fLocation1, fCheckpoint1.getLocation()); | |
75 | } | |
76 | ||
77 | public void testTmfLocationCopy() { | |
78 | TmfCheckpoint checkpoint = new TmfCheckpoint(fCheckpoint1); | |
79 | ||
80 | assertEquals("TmfCheckpoint", fTimestamp1, checkpoint.getTimestamp()); | |
81 | assertEquals("TmfCheckpoint", fLocation1, checkpoint.getLocation()); | |
82 | } | |
83 | ||
84 | public void testTmfLocationCopy2() throws Exception { | |
85 | try { | |
86 | new TmfCheckpoint(null); | |
87 | fail("null copy"); | |
88 | } | |
89 | catch (IllegalArgumentException e) { | |
90 | // Success | |
91 | } | |
92 | } | |
93 | ||
94 | // ------------------------------------------------------------------------ | |
95 | // equals | |
96 | // ------------------------------------------------------------------------ | |
97 | ||
98 | public void testEqualsReflexivity() throws Exception { | |
99 | assertTrue("equals", fCheckpoint1.equals(fCheckpoint1)); | |
100 | assertTrue("equals", fCheckpoint2.equals(fCheckpoint2)); | |
101 | ||
102 | assertTrue("equals", !fCheckpoint1.equals(fCheckpoint2)); | |
103 | assertTrue("equals", !fCheckpoint2.equals(fCheckpoint1)); | |
104 | } | |
105 | ||
106 | public void testEqualsSymmetry() throws Exception { | |
107 | TmfCheckpoint checkpoint1 = new TmfCheckpoint(fCheckpoint1); | |
108 | TmfCheckpoint checkpoint2 = new TmfCheckpoint(fCheckpoint2); | |
109 | ||
110 | assertTrue("equals", checkpoint1.equals(fCheckpoint1)); | |
111 | assertTrue("equals", fCheckpoint1.equals(checkpoint1)); | |
112 | ||
113 | assertTrue("equals", checkpoint2.equals(fCheckpoint2)); | |
114 | assertTrue("equals", fCheckpoint2.equals(checkpoint2)); | |
115 | } | |
116 | ||
117 | public void testEqualsTransivity() throws Exception { | |
118 | TmfCheckpoint checkpoint1 = new TmfCheckpoint(fCheckpoint1); | |
119 | TmfCheckpoint checkpoint2 = new TmfCheckpoint(checkpoint1); | |
120 | TmfCheckpoint checkpoint3 = new TmfCheckpoint(checkpoint2); | |
121 | ||
122 | assertTrue("equals", checkpoint1.equals(checkpoint2)); | |
123 | assertTrue("equals", checkpoint2.equals(checkpoint3)); | |
124 | assertTrue("equals", checkpoint1.equals(checkpoint3)); | |
125 | } | |
126 | ||
127 | public void testEqualsNull() throws Exception { | |
128 | assertTrue("equals", !fCheckpoint1.equals(null)); | |
129 | assertTrue("equals", !fCheckpoint2.equals(null)); | |
130 | } | |
131 | ||
132 | // ------------------------------------------------------------------------ | |
133 | // hashCode | |
134 | // ------------------------------------------------------------------------ | |
135 | ||
136 | public void testHashCode() throws Exception { | |
137 | TmfCheckpoint checkpoint1 = new TmfCheckpoint(fCheckpoint1); | |
138 | TmfCheckpoint checkpoint2 = new TmfCheckpoint(fCheckpoint2); | |
139 | ||
140 | assertTrue("hashCode", fCheckpoint1.hashCode() == checkpoint1.hashCode()); | |
141 | assertTrue("hashCode", fCheckpoint2.hashCode() == checkpoint2.hashCode()); | |
142 | ||
143 | assertTrue("hashCode", fCheckpoint1.hashCode() != checkpoint2.hashCode()); | |
144 | assertTrue("hashCode", fCheckpoint2.hashCode() != checkpoint1.hashCode()); | |
145 | } | |
146 | ||
147 | // ------------------------------------------------------------------------ | |
148 | // toString | |
149 | // ------------------------------------------------------------------------ | |
150 | ||
151 | public void testToString() { | |
152 | String expected1 = "[TmfCheckpoint(" + fCheckpoint1.getTimestamp() + "," + | |
153 | fCheckpoint1.getLocation() + ")]"; | |
154 | String expected2 = "[TmfCheckpoint(" + fCheckpoint2.getTimestamp() + "," + | |
155 | fCheckpoint2.getLocation() + ")]"; | |
156 | String expected3 = "[TmfCheckpoint(" + fCheckpoint3.getTimestamp() + "," + | |
157 | fCheckpoint3.getLocation() + ")]"; | |
158 | ||
159 | assertEquals("toString", expected1, fCheckpoint1.toString()); | |
160 | assertEquals("toString", expected2, fCheckpoint2.toString()); | |
161 | assertEquals("toString", expected3, fCheckpoint3.toString()); | |
162 | } | |
163 | ||
164 | // ------------------------------------------------------------------------ | |
165 | // compareTo | |
166 | // ------------------------------------------------------------------------ | |
167 | ||
168 | public void testCompareTo() { | |
169 | assertEquals("compareTo", 0, fCheckpoint1.compareTo(fCheckpoint1)); | |
170 | assertEquals("compareTo", 1, fCheckpoint1.compareTo(fCheckpoint2)); | |
171 | assertEquals("compareTo", -1, fCheckpoint1.compareTo(fCheckpoint3)); | |
172 | ||
173 | assertEquals("compareTo", -1, fCheckpoint2.compareTo(fCheckpoint1)); | |
174 | assertEquals("compareTo", 0, fCheckpoint2.compareTo(fCheckpoint2)); | |
175 | assertEquals("compareTo", -1, fCheckpoint2.compareTo(fCheckpoint3)); | |
176 | ||
177 | assertEquals("compareTo", 1, fCheckpoint3.compareTo(fCheckpoint1)); | |
178 | assertEquals("compareTo", 1, fCheckpoint3.compareTo(fCheckpoint2)); | |
179 | assertEquals("compareTo", 0, fCheckpoint3.compareTo(fCheckpoint3)); | |
180 | } | |
181 | ||
182 | } |