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
.tests
.event
;
15 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimeRange
;
16 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
18 import junit
.framework
.TestCase
;
21 * <b><u>TmfTimeRangeTest</u></b>
23 * Test suite for the TmfTimeRange class.
25 public class TmfTimeRangeTest
extends TestCase
{
28 // ------------------------------------------------------------------------
30 // ------------------------------------------------------------------------
32 public TmfTimeRangeTest(String name
) {
37 protected void setUp() throws Exception
{
42 protected void tearDown() throws Exception
{
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
50 public void testConstructor() throws Exception
{
51 TmfTimestamp ts1
= new TmfTimestamp(12345);
52 TmfTimestamp ts2
= new TmfTimestamp(12350);
53 TmfTimeRange range
= new TmfTimeRange(ts1
, ts2
);
54 assertEquals("startTime", ts1
, range
.getStartTime());
55 assertEquals("endTime", ts2
, range
.getEndTime());
58 public void testBadConstructor() throws Exception
{
60 new TmfTimeRange(TmfTimestamp
.BigBang
, null);
63 catch (IllegalArgumentException e
) {
68 new TmfTimeRange(null, TmfTimestamp
.BigCrunch
);
71 catch (IllegalArgumentException e
) {
76 public void testOpenRange1() throws Exception
{
77 TmfTimestamp ts2
= new TmfTimestamp(12350);
78 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, ts2
);
79 assertEquals("startTime", TmfTimestamp
.BigBang
, range
.getStartTime());
80 assertEquals("endTime", ts2
, range
.getEndTime());
83 public void testOpenRange2() throws Exception
{
84 TmfTimestamp ts1
= new TmfTimestamp(12345);
85 TmfTimeRange range
= new TmfTimeRange(ts1
, TmfTimestamp
.BigCrunch
);
86 assertEquals("startTime", ts1
, range
.getStartTime());
87 assertEquals("endTime", TmfTimestamp
.BigCrunch
, range
.getEndTime());
90 public void testOpenRange3() throws Exception
{
91 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
92 assertEquals("startTime", TmfTimestamp
.BigBang
, range
.getStartTime());
93 assertEquals("endTime", TmfTimestamp
.BigCrunch
, range
.getEndTime());
96 public void testCopyConstructor() throws Exception
{
97 TmfTimestamp ts1
= new TmfTimestamp(12345);
98 TmfTimestamp ts2
= new TmfTimestamp(12350);
99 TmfTimeRange range0
= new TmfTimeRange(ts1
, ts2
);
100 TmfTimeRange range1
= new TmfTimeRange(range0
);
102 assertEquals("startTime", ts1
, range1
.getStartTime());
103 assertEquals("endTime", ts2
, range1
.getEndTime());
105 TmfTimeRange range2
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
106 TmfTimeRange range3
= new TmfTimeRange(range2
);
107 assertEquals("startTime", TmfTimestamp
.BigBang
, range3
.getStartTime());
108 assertEquals("endTime", TmfTimestamp
.BigCrunch
, range3
.getEndTime());
111 public void testCopyConstructor2() throws Exception
{
113 new TmfTimeRange(null);
116 catch (IllegalArgumentException e
) {
121 // ------------------------------------------------------------------------
123 // ------------------------------------------------------------------------
125 public void testEqualsReflexivity() throws Exception
{
126 TmfTimestamp ts1
= new TmfTimestamp(12345);
127 TmfTimestamp ts2
= new TmfTimestamp(12350);
128 TmfTimeRange range1
= new TmfTimeRange(ts1
, ts2
);
129 TmfTimeRange range2
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
131 assertTrue("equals", range1
.equals(range1
));
132 assertTrue("equals", range2
.equals(range2
));
134 assertTrue("equals", !range1
.equals(range2
));
135 assertTrue("equals", !range2
.equals(range1
));
138 public void testEqualsSymmetry() throws Exception
{
139 TmfTimestamp ts1
= new TmfTimestamp(12345);
140 TmfTimestamp ts2
= new TmfTimestamp(12350);
141 TmfTimeRange range1a
= new TmfTimeRange(ts1
, ts2
);
142 TmfTimeRange range1b
= new TmfTimeRange(ts1
, ts2
);
144 TmfTimeRange range2a
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
145 TmfTimeRange range2b
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
147 assertTrue("equals", range1a
.equals(range1b
));
148 assertTrue("equals", range1b
.equals(range1a
));
150 assertTrue("equals", range2a
.equals(range2b
));
151 assertTrue("equals", range2b
.equals(range2a
));
154 public void testEqualsTransivity() throws Exception
{
155 TmfTimestamp ts1
= new TmfTimestamp(12345);
156 TmfTimestamp ts2
= new TmfTimestamp(12350);
157 TmfTimeRange range1a
= new TmfTimeRange(ts1
, ts2
);
158 TmfTimeRange range1b
= new TmfTimeRange(ts1
, ts2
);
159 TmfTimeRange range1c
= new TmfTimeRange(ts1
, ts2
);
161 assertTrue("equals", range1a
.equals(range1b
));
162 assertTrue("equals", range1b
.equals(range1c
));
163 assertTrue("equals", range1a
.equals(range1c
));
166 public void testEqualsConsistency() throws Exception
{
167 TmfTimestamp ts1
= new TmfTimestamp(12345);
168 TmfTimestamp ts2
= new TmfTimestamp(12350);
169 TmfTimeRange range1a
= new TmfTimeRange(ts1
, ts2
);
170 TmfTimeRange range1b
= new TmfTimeRange(ts1
, ts2
);
172 assertTrue("equals", range1a
.equals(range1a
));
173 assertTrue("equals", range1a
.equals(range1a
));
175 assertTrue("equals", range1b
.equals(range1b
));
176 assertTrue("equals", range1b
.equals(range1b
));
179 public void testEqualsNull() throws Exception
{
180 TmfTimestamp ts1
= new TmfTimestamp(12345);
181 TmfTimestamp ts2
= new TmfTimestamp(12350);
182 TmfTimeRange range1
= new TmfTimeRange(ts1
, ts2
);
184 assertTrue("equals", !range1
.equals(null));
187 // ------------------------------------------------------------------------
189 // ------------------------------------------------------------------------
191 public void testToString() throws Exception
{
192 TmfTimestamp ts1
= new TmfTimestamp(12345);
193 TmfTimestamp ts2
= new TmfTimestamp(12350);
194 TmfTimeRange range
= new TmfTimeRange(ts1
, ts2
);
196 String expected
= "[TmfTimeRange(" + ts1
+ ":" + ts2
+ ")]";
197 assertEquals("toString", expected
, range
.toString());
200 // ------------------------------------------------------------------------
202 // ------------------------------------------------------------------------
204 public void testContains() throws Exception
{
205 TmfTimestamp ts1
= new TmfTimestamp(12345);
206 TmfTimestamp ts2
= new TmfTimestamp(12350);
207 TmfTimeRange range
= new TmfTimeRange(ts1
, ts2
);
209 assertTrue("contains (lower bound)", range
.contains(new TmfTimestamp(12345)));
210 assertTrue("contains (higher bound)", range
.contains(new TmfTimestamp(12350)));
211 assertTrue("contains (within bounds)", range
.contains(new TmfTimestamp(12346)));
213 assertFalse("contains (low value)", range
.contains(new TmfTimestamp(12340)));
214 assertFalse("contains (high value)", range
.contains(new TmfTimestamp(12351)));