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