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
.TmfContext
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfLocation
;
23 * <b><u>TmfContextTest</u></b>
25 * Test suite for the TmfContext class.
27 @SuppressWarnings("nls")
28 public class TmfContextTest
extends TestCase
{
30 // ------------------------------------------------------------------------
32 // ------------------------------------------------------------------------
34 final String aString
= "some location";
35 final Long aLong
= 12345L;
36 final TmfTimestamp aTimestamp
= new TmfTimestamp();
38 final TmfLocation
<String
> fLocation1
= new TmfLocation
<String
>(aString
);
39 final TmfLocation
<Long
> fLocation2
= new TmfLocation
<Long
>(aLong
);
40 final TmfLocation
<ITmfTimestamp
> fLocation3
= new TmfLocation
<ITmfTimestamp
>(aTimestamp
);
42 final long fRank1
= 1;
43 final long fRank2
= 2;
44 final long fRank3
= 3;
46 final TmfContext fContext1
= new TmfContext(fLocation1
, fRank1
);
47 final TmfContext fContext2
= new TmfContext(fLocation2
, fRank2
);
48 final TmfContext fContext3
= new TmfContext(fLocation3
, fRank3
);
50 // ------------------------------------------------------------------------
52 // ------------------------------------------------------------------------
55 * @param name the test name
57 public TmfContextTest(String name
) {
62 protected void setUp() throws Exception
{
67 protected void tearDown() throws Exception
{
71 // ------------------------------------------------------------------------
73 // ------------------------------------------------------------------------
75 public void testTmfContextDefault() {
76 TmfContext context
= new TmfContext();
77 assertEquals("getLocation", null, context
.getLocation());
78 assertEquals("getRank", TmfContext
.UNKNOWN_RANK
, context
.getRank());
81 public void testTmfContextNoRank() {
82 TmfContext context1
= new TmfContext(fLocation1
);
83 TmfContext context2
= new TmfContext(fLocation2
);
84 TmfContext context3
= new TmfContext(fLocation3
);
86 assertEquals("getLocation", fLocation1
, context1
.getLocation());
87 assertEquals("getLocation", fLocation2
, context2
.getLocation());
88 assertEquals("getLocation", fLocation3
, context3
.getLocation());
90 assertEquals("getRank", TmfContext
.UNKNOWN_RANK
, context1
.getRank());
91 assertEquals("getRank", TmfContext
.UNKNOWN_RANK
, context2
.getRank());
92 assertEquals("getRank", TmfContext
.UNKNOWN_RANK
, context3
.getRank());
95 public void testTmfContext() {
96 assertEquals("getLocation", fLocation1
, fContext1
.getLocation());
97 assertEquals("getLocation", fLocation2
, fContext2
.getLocation());
98 assertEquals("getLocation", fLocation3
, fContext3
.getLocation());
100 assertEquals("getRank", fRank1
, fContext1
.getRank());
101 assertEquals("getRank", fRank2
, fContext2
.getRank());
102 assertEquals("getRank", fRank3
, fContext3
.getRank());
105 public void testTmfContextCopy() {
106 TmfContext context1
= new TmfContext(fContext1
);
107 TmfContext context2
= new TmfContext(fContext2
);
108 TmfContext context3
= new TmfContext(fContext3
);
110 assertEquals("getLocation", fLocation1
, context1
.getLocation());
111 assertEquals("getLocation", fLocation2
, context2
.getLocation());
112 assertEquals("getLocation", fLocation3
, context3
.getLocation());
114 assertEquals("getRank", fRank1
, context1
.getRank());
115 assertEquals("getRank", fRank2
, context2
.getRank());
116 assertEquals("getRank", fRank3
, context3
.getRank());
119 // ------------------------------------------------------------------------
121 // ------------------------------------------------------------------------
123 public void testEqualsReflexivity() throws Exception
{
124 assertTrue("equals", fContext1
.equals(fContext1
));
125 assertTrue("equals", fContext2
.equals(fContext2
));
127 assertTrue("equals", !fContext1
.equals(fContext2
));
128 assertTrue("equals", !fContext2
.equals(fContext1
));
131 public void testEqualsSymmetry() throws Exception
{
132 TmfContext context1
= new TmfContext(fContext1
);
133 TmfContext context2
= new TmfContext(fContext2
);
135 assertTrue("equals", context1
.equals(fContext1
));
136 assertTrue("equals", fContext1
.equals(context1
));
138 assertTrue("equals", context2
.equals(fContext2
));
139 assertTrue("equals", fContext2
.equals(context2
));
142 public void testEqualsTransivity() throws Exception
{
143 TmfContext context1
= new TmfContext(fContext1
);
144 TmfContext context2
= new TmfContext(context1
);
145 TmfContext context3
= new TmfContext(context2
);
147 assertTrue("equals", context1
.equals(context2
));
148 assertTrue("equals", context2
.equals(context3
));
149 assertTrue("equals", context1
.equals(context3
));
152 public void testEqualsNull() throws Exception
{
153 assertTrue("equals", !fContext1
.equals(null));
154 assertTrue("equals", !fContext2
.equals(null));
157 // ------------------------------------------------------------------------
159 // ------------------------------------------------------------------------
161 public void testHashCode() throws Exception
{
162 TmfContext context1
= new TmfContext(fContext1
);
163 TmfContext context2
= new TmfContext(fContext2
);
165 assertTrue("hashCode", fContext1
.hashCode() == context1
.hashCode());
166 assertTrue("hashCode", fContext2
.hashCode() == context2
.hashCode());
168 assertTrue("hashCode", fContext1
.hashCode() != context2
.hashCode());
169 assertTrue("hashCode", fContext2
.hashCode() != context1
.hashCode());
172 // ------------------------------------------------------------------------
174 // ------------------------------------------------------------------------
176 public void testToString() {
177 String expected1
= "[TmfContext(" + fLocation1
+ "," + 1 + ")]";
178 String expected2
= "[TmfContext(" + fLocation2
+ "," + 2 + ")]";
179 String expected3
= "[TmfContext(" + fLocation3
+ "," + 3 + ")]";
181 assertEquals("toString", expected1
, fContext1
.toString());
182 assertEquals("toString", expected2
, fContext2
.toString());
183 assertEquals("toString", expected3
, fContext3
.toString());
186 // ------------------------------------------------------------------------
188 // ------------------------------------------------------------------------
190 public void testClone() {
192 TmfContext context1
= fContext1
.clone();
193 TmfContext context2
= fContext2
.clone();
194 TmfContext context3
= fContext3
.clone();
196 assertEquals("clone", context1
, fContext1
);
197 assertEquals("clone", context2
, fContext2
);
198 assertEquals("clone", context3
, fContext3
);
200 catch (InternalError e
) {
205 // ------------------------------------------------------------------------
206 // setLocation, setRank, updateRank
207 // ------------------------------------------------------------------------
209 public void testSetLocation() {
210 TmfContext context1
= new TmfContext(fContext1
);
211 context1
.setLocation(fContext2
.getLocation());
213 assertEquals("getLocation", fLocation2
, context1
.getLocation());
214 assertEquals("getRank", 1, context1
.getRank());
217 public void testSetRank() {
218 TmfContext context1
= new TmfContext(fContext1
);
219 context1
.setRank(fContext2
.getRank());
221 assertEquals("getLocation", fLocation1
, context1
.getLocation());
222 assertEquals("getRank", fRank2
, context1
.getRank());
225 public void testUpdatetRank() {
226 TmfContext context1
= new TmfContext(fContext1
);
228 context1
.updateRank(0);
229 assertEquals("getRank", fRank1
, context1
.getRank());
231 context1
.updateRank(-1);
232 assertEquals("getRank", fRank1
- 1, context1
.getRank());
234 context1
.updateRank(2);
235 assertEquals("getRank", fRank1
+ 1, context1
.getRank());
This page took 0.038117 seconds and 5 git commands to generate.