Monster merge from the integration branch. Still some problems left and JUnits failing.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.tests / src / org / eclipse / linuxtools / tmf / tests / trace / TmfContextTest.java
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.TmfContext;
19 import org.eclipse.linuxtools.tmf.trace.TmfLocation;
20
21 /**
22 * <b><u>TmfContextTest</u></b>
23 * <p>
24 * Test suite for the TmfContext class.
25 */
26 public class TmfContextTest extends TestCase {
27
28 // ------------------------------------------------------------------------
29 // Variables
30 // ------------------------------------------------------------------------
31
32 final String aString = "some location";
33 final Long aLong = 12345L;
34 final TmfTimestamp aTimestamp = new TmfTimestamp();
35
36 final TmfLocation<String> fLocation1 = new TmfLocation<String>(aString);
37 final TmfLocation<Long> fLocation2 = new TmfLocation<Long>(aLong);
38 final TmfLocation<TmfTimestamp> fLocation3 = new TmfLocation<TmfTimestamp>(aTimestamp);
39
40 final long fRank1 = 1;
41 final long fRank2 = 2;
42 final long fRank3 = 3;
43
44 final TmfContext fContext1 = new TmfContext(fLocation1, fRank1);
45 final TmfContext fContext2 = new TmfContext(fLocation2, fRank2);
46 final TmfContext fContext3 = new TmfContext(fLocation3, fRank3);
47
48 // ------------------------------------------------------------------------
49 // Housekeeping
50 // ------------------------------------------------------------------------
51
52 /**
53 * @param name the test name
54 */
55 public TmfContextTest(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 testTmfContextDefault() {
74 TmfContext context = new TmfContext();
75 assertEquals("getLocation", null, context.getLocation());
76 assertEquals("getRank", TmfContext.UNKNOWN_RANK, context.getRank());
77 }
78
79 public void testTmfContextNoRank() {
80 TmfContext context1 = new TmfContext(fLocation1);
81 TmfContext context2 = new TmfContext(fLocation2);
82 TmfContext context3 = new TmfContext(fLocation3);
83
84 assertEquals("getLocation", fLocation1, context1.getLocation());
85 assertEquals("getLocation", fLocation2, context2.getLocation());
86 assertEquals("getLocation", fLocation3, context3.getLocation());
87
88 assertEquals("getRank", TmfContext.UNKNOWN_RANK, context1.getRank());
89 assertEquals("getRank", TmfContext.UNKNOWN_RANK, context2.getRank());
90 assertEquals("getRank", TmfContext.UNKNOWN_RANK, context3.getRank());
91 }
92
93 public void testTmfContext() {
94 assertEquals("getLocation", fLocation1, fContext1.getLocation());
95 assertEquals("getLocation", fLocation2, fContext2.getLocation());
96 assertEquals("getLocation", fLocation3, fContext3.getLocation());
97
98 assertEquals("getRank", fRank1, fContext1.getRank());
99 assertEquals("getRank", fRank2, fContext2.getRank());
100 assertEquals("getRank", fRank3, fContext3.getRank());
101 }
102
103 public void testTmfContextCopy() {
104 TmfContext context1 = new TmfContext(fContext1);
105 TmfContext context2 = new TmfContext(fContext2);
106 TmfContext context3 = new TmfContext(fContext3);
107
108 assertEquals("getLocation", fLocation1, context1.getLocation());
109 assertEquals("getLocation", fLocation2, context2.getLocation());
110 assertEquals("getLocation", fLocation3, context3.getLocation());
111
112 assertEquals("getRank", fRank1, context1.getRank());
113 assertEquals("getRank", fRank2, context2.getRank());
114 assertEquals("getRank", fRank3, context3.getRank());
115 }
116
117 // ------------------------------------------------------------------------
118 // equals
119 // ------------------------------------------------------------------------
120
121 public void testEqualsReflexivity() throws Exception {
122 assertTrue("equals", fContext1.equals(fContext1));
123 assertTrue("equals", fContext2.equals(fContext2));
124
125 assertTrue("equals", !fContext1.equals(fContext2));
126 assertTrue("equals", !fContext2.equals(fContext1));
127 }
128
129 public void testEqualsSymmetry() throws Exception {
130 TmfContext context1 = new TmfContext(fContext1);
131 TmfContext context2 = new TmfContext(fContext2);
132
133 assertTrue("equals", context1.equals(fContext1));
134 assertTrue("equals", fContext1.equals(context1));
135
136 assertTrue("equals", context2.equals(fContext2));
137 assertTrue("equals", fContext2.equals(context2));
138 }
139
140 public void testEqualsTransivity() throws Exception {
141 TmfContext context1 = new TmfContext(fContext1);
142 TmfContext context2 = new TmfContext(context1);
143 TmfContext context3 = new TmfContext(context2);
144
145 assertTrue("equals", context1.equals(context2));
146 assertTrue("equals", context2.equals(context3));
147 assertTrue("equals", context1.equals(context3));
148 }
149
150 public void testEqualsNull() throws Exception {
151 assertTrue("equals", !fContext1.equals(null));
152 assertTrue("equals", !fContext2.equals(null));
153 }
154
155 // ------------------------------------------------------------------------
156 // hashCode
157 // ------------------------------------------------------------------------
158
159 public void testHashCode() throws Exception {
160 TmfContext context1 = new TmfContext(fContext1);
161 TmfContext context2 = new TmfContext(fContext2);
162
163 assertTrue("hashCode", fContext1.hashCode() == context1.hashCode());
164 assertTrue("hashCode", fContext2.hashCode() == context2.hashCode());
165
166 assertTrue("hashCode", fContext1.hashCode() != context2.hashCode());
167 assertTrue("hashCode", fContext2.hashCode() != context1.hashCode());
168 }
169
170 // ------------------------------------------------------------------------
171 // toString
172 // ------------------------------------------------------------------------
173
174 public void testToString() {
175 String expected1 = "[TmfContext(" + fLocation1 + "," + 1 + ")]";
176 String expected2 = "[TmfContext(" + fLocation2 + "," + 2 + ")]";
177 String expected3 = "[TmfContext(" + fLocation3 + "," + 3 + ")]";
178
179 assertEquals("toString", expected1, fContext1.toString());
180 assertEquals("toString", expected2, fContext2.toString());
181 assertEquals("toString", expected3, fContext3.toString());
182 }
183
184 // ------------------------------------------------------------------------
185 // clone
186 // ------------------------------------------------------------------------
187
188 public void testClone() {
189 try {
190 TmfContext context1 = fContext1.clone();
191 TmfContext context2 = fContext2.clone();
192 TmfContext context3 = fContext3.clone();
193
194 assertEquals("clone", context1, fContext1);
195 assertEquals("clone", context2, fContext2);
196 assertEquals("clone", context3, fContext3);
197 }
198 catch (InternalError e) {
199 fail("clone()");
200 }
201 }
202
203 // ------------------------------------------------------------------------
204 // setLocation, setRank, updateRank
205 // ------------------------------------------------------------------------
206
207 public void testSetLocation() {
208 TmfContext context1 = new TmfContext(fContext1);
209 context1.setLocation(fContext2.getLocation());
210
211 assertEquals("getLocation", fLocation2, context1.getLocation());
212 assertEquals("getRank", 1, context1.getRank());
213 }
214
215 public void testSetRank() {
216 TmfContext context1 = new TmfContext(fContext1);
217 context1.setRank(fContext2.getRank());
218
219 assertEquals("getLocation", fLocation1, context1.getLocation());
220 assertEquals("getRank", fRank2, context1.getRank());
221 }
222
223 public void testUpdatetRank() {
224 TmfContext context1 = new TmfContext(fContext1);
225
226 context1.updateRank(0);
227 assertEquals("getRank", fRank1, context1.getRank());
228
229 context1.updateRank(-1);
230 assertEquals("getRank", fRank1 - 1, context1.getRank());
231
232 context1.updateRank(2);
233 assertEquals("getRank", fRank1 + 1, context1.getRank());
234 }
235
236 }
This page took 0.035522 seconds and 5 git commands to generate.