1 /*******************************************************************************
2 * Copyright (c) 2011, 2012 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 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.tmf
.ui
.tests
.views
.uml2sd
.loader
;
14 import java
.util
.List
;
16 import junit
.framework
.Test
;
17 import junit
.framework
.TestCase
;
18 import junit
.framework
.TestSuite
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfRangeSynchSignal
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTimeSynchSignal
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.GraphNode
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.loader
.TmfSyncMessage
;
28 * Test cases for time synchronization handling.
30 * @author Bernd Hufmann
33 public class TmfUml2SDSyncLoaderTimeTest
extends TestCase
{
35 // ------------------------------------------------------------------------
37 // ------------------------------------------------------------------------
38 // Test case 001 expected values
39 final static private Uml2SDTestTimestamp TC_001_TIME_VALUE
= new Uml2SDTestTimestamp(9788642228395L);
40 final static private String TC_001_MESSAGE_NAME
= "START_GAME_REPLY"; //$NON-NLS-1$
41 final static private int TC_001_PAGE_VALUE
= 0;
42 final static private int TC_001_START_OCCURRANCE
= 6;
43 final static private int TC_001_END_OCCURRANCE
= TC_001_START_OCCURRANCE
;
44 final static private String TC_001_START_LIFELINE
= IUml2SDTestConstants
.MASTER_PLAYER_NAME
;
45 final static private String TC_001_END_LIFELINE
= IUml2SDTestConstants
.FIRST_PLAYER_NAME
;
47 // Test case 002 expected values
48 final static private Uml2SDTestTimestamp TC_002_TIME_VALUE
= new Uml2SDTestTimestamp(9789689830722L);
49 final static private String TC_002_MESSAGE_NAME
= "PAUSE_GAME_REQUEST"; //$NON-NLS-1$
50 final static private int TC_002_PAGE_VALUE
= 2;
51 final static private int TC_002_START_OCCURRANCE
= 7;
52 final static private int TC_002_END_OCCURRANCE
= TC_002_START_OCCURRANCE
;
53 final static private String TC_002_START_LIFELINE
= IUml2SDTestConstants
.FIRST_PLAYER_NAME
;
54 final static private String TC_002_END_LIFELINE
= IUml2SDTestConstants
.MASTER_PLAYER_NAME
;
56 // Test case 003 expected values
57 final static private Uml2SDTestTimestamp TC_003_TIME_VALUE
= new Uml2SDTestTimestamp(9790750000000L);
58 final static private int TC_003_PAGE_VALUE
= 4;
60 // Test case 004 expected values
61 final static private int TC_004_PAGE_VALUE
= 0;
63 // Test case 005 expected values
64 final static private int TC_005_PAGE_VALUE
= IUml2SDTestConstants
.TOTAL_NUMBER_OF_PAGES
- 1;
66 // Test case 006 expected values
67 final static private Uml2SDTestTimestamp TC_006_TIME_VALUE
= new Uml2SDTestTimestamp(9792420661655L);
68 final static private int TC_006_PAGE_VALUE
= 4;
69 final static private int TC_006_START_OCCURRANCE
= IUml2SDTestConstants
.MAX_MESSEAGES_PER_PAGE
;
70 final static private int TC_006_END_OCCURRANCE
= TC_006_START_OCCURRANCE
;
72 // Test case 007 expected values
73 final static private Uml2SDTestTimestamp TC_007_TIME_VALUE
= new Uml2SDTestTimestamp(9792420756010L);
74 final static private int TC_007_PAGE_VALUE
= 5;
75 final static private int TC_007_START_OCCURRANCE
= 1;
76 final static private int TC_007_END_OCCURRANCE
= TC_007_START_OCCURRANCE
;
78 // Test case 008 expected values
79 final static private Uml2SDTestTimestamp TC_008_TIME_VALUE
= new Uml2SDTestTimestamp(9788642228395L);
80 final static private int TC_008_PAGE_VALUE
= 0;
81 final static private Uml2SDTestTimestamp TC_008_START_TIME_VALUE
= new Uml2SDTestTimestamp(9788642228395L);
82 final static private Uml2SDTestTimestamp TC_008_END_TIME_VALUE
= new Uml2SDTestTimestamp(9789164833324L);
84 // Test case 009 expected values
85 final static private Uml2SDTestTimestamp TC_009_TIME_VALUE
= new Uml2SDTestTimestamp(9789689220871L);
86 final static private int TC_009_PAGE_VALUE
= 1;
87 final static private Uml2SDTestTimestamp TC_009_START_TIME_VALUE
= TC_009_TIME_VALUE
;
88 final static private Uml2SDTestTimestamp TC_009_END_TIME_VALUE
= new Uml2SDTestTimestamp(9789773881426L);
90 private Uml2SDTestFacility fFacility
;
92 // ------------------------------------------------------------------------
94 // ------------------------------------------------------------------------
97 * Returns test setup used when executing test case stand-alone.
98 * @return Test setup class
100 public static Test
suite() {
101 return new Uml2SDTestSetup(new TestSuite(TmfUml2SDSyncLoaderTimeTest
.class));
104 // ------------------------------------------------------------------------
106 // ------------------------------------------------------------------------
110 public TmfUml2SDSyncLoaderTimeTest() {
113 // ------------------------------------------------------------------------
115 // ------------------------------------------------------------------------
117 public void setUp() throws Exception
{
119 fFacility
= Uml2SDTestFacility
.getInstance();
120 fFacility
.selectExperiment();
125 public void tearDown() throws Exception
{
126 fFacility
.disposeExperiment();
132 * Main method with test cases.
134 @SuppressWarnings("nls")
135 public void testTimeHandling() {
138 * Description: Verify synchToTime (exact time in page), selection of message in page
139 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToMessageInPage()
140 * Expected result: Correct message is selected.
142 fFacility
.getTrace().broadcast(new TmfTimeSynchSignal(this, TC_001_TIME_VALUE
));
143 fFacility
.getLoader().waitForCompletion();
144 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
145 assertEquals("synchToTime", TC_001_PAGE_VALUE
, fFacility
.getLoader().currentPage());
146 List
<GraphNode
> selection
= fFacility
.getSdView().getSDWidget().getSelection();
147 assertNotNull(selection
);
148 assertEquals("synchToTime", 1, selection
.size());
149 assertTrue(selection
.get(0) instanceof TmfSyncMessage
);
150 TmfSyncMessage msg
= (TmfSyncMessage
) selection
.get(0);
151 assertEquals("synchToTime", TC_001_MESSAGE_NAME
, msg
.getName());
152 assertEquals("synchToTime", 0, TC_001_TIME_VALUE
.compareTo(msg
.getStartTime(), false));
153 assertEquals("synchToTime", TC_001_START_OCCURRANCE
, msg
.getStartOccurrence());
154 assertEquals("synchToTime", TC_001_END_OCCURRANCE
, msg
.getEndOccurrence());
155 assertEquals("synchToTime", TC_001_START_LIFELINE
, msg
.getStartLifeline().getName());
156 assertEquals("synchToTime", TC_001_END_LIFELINE
, msg
.getEndLifeline().getName());
160 * Description: Verify synchToTime (exact time outside of page), selection of message in page
161 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
162 * Expected result: Correct message is selected.
164 fFacility
.getTrace().broadcast(new TmfTimeSynchSignal(this, TC_002_TIME_VALUE
));
165 fFacility
.getLoader().waitForCompletion();
166 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
167 assertEquals("synchToTime", TC_002_PAGE_VALUE
, fFacility
.getLoader().currentPage());
168 selection
= fFacility
.getSdView().getSDWidget().getSelection();
169 assertNotNull("synchToTime", selection
);
170 assertEquals("synchToTime", 1, selection
.size());
171 assertTrue("synchToTime", selection
.get(0) instanceof TmfSyncMessage
);
172 msg
= (TmfSyncMessage
) selection
.get(0);
173 assertEquals("synchToTime", TC_002_MESSAGE_NAME
, msg
.getName());
174 assertEquals(0, TC_002_TIME_VALUE
.compareTo(msg
.getStartTime(), false));
175 assertEquals("synchToTime", TC_002_START_OCCURRANCE
, msg
.getStartOccurrence());
176 assertEquals("synchToTime", TC_002_END_OCCURRANCE
, msg
.getEndOccurrence());
177 assertEquals(TC_002_START_LIFELINE
, msg
.getStartLifeline().getName());
178 assertEquals(TC_002_END_LIFELINE
, msg
.getEndLifeline().getName());
183 * Description: Verify synchToTime (timestamp doesn't exist in trace), no selection of message in page
184 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
185 * Expected result: Move to correct page, currentTime is updated so that focus on the currentTime, but no selection.
187 fFacility
.getLoader().firstPage();
189 fFacility
.getTrace().broadcast(new TmfTimeSynchSignal(this, TC_003_TIME_VALUE
));
190 fFacility
.getLoader().waitForCompletion();
191 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
192 assertEquals("synchToTime", 0, TC_003_TIME_VALUE
.compareTo(fFacility
.getLoader().getCurrentTime(), false));
193 assertEquals("synchToTime", TC_003_PAGE_VALUE
, fFacility
.getLoader().currentPage());
194 selection
= fFacility
.getSdView().getSDWidget().getSelection();
195 assertNotNull("synchToTime", selection
);
196 assertEquals("synchToTime", 0, selection
.size());
200 * Description: Verify synchToTime (timestamp < experiment time range start)
201 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
202 * Expected result: Move to first page, focus on the beginning of the page, but no selection.
204 fFacility
.getTrace().broadcast(new TmfTimeSynchSignal(this, TmfTimestamp
.BIG_BANG
));
205 fFacility
.getLoader().waitForCompletion();
206 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
207 assertEquals("synchToTime", TC_004_PAGE_VALUE
, fFacility
.getLoader().currentPage());
208 selection
= fFacility
.getSdView().getSDWidget().getSelection();
209 assertNotNull("synchToTime", selection
);
210 assertEquals("synchToTime", 0, selection
.size());
214 * Description: Verify synchToTime (timestamp > experiment time range end)
215 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
216 * Expected result: Move to last page, focus on the end of the page, but no selection.
218 fFacility
.getTrace().broadcast(new TmfTimeSynchSignal(this, TmfTimestamp
.BIG_CRUNCH
));
219 fFacility
.getLoader().waitForCompletion();
220 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
221 assertEquals("synchToTime", TC_005_PAGE_VALUE
, fFacility
.getLoader().currentPage());
222 selection
= fFacility
.getSdView().getSDWidget().getSelection();
223 assertNotNull(selection
);
224 assertEquals("synchToTime", 0, selection
.size());
228 * Description: Verify synchToTime (timestamp of last message in page)
229 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage(), loader.moveToMessageInPage()
230 * Expected result: Move to correct page, selection of last message in page.
232 fFacility
.getTrace().broadcast(new TmfTimeSynchSignal(this, TC_006_TIME_VALUE
));
233 fFacility
.getLoader().waitForCompletion();
234 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
235 assertEquals("synchToTime", TC_006_PAGE_VALUE
, fFacility
.getLoader().currentPage());
236 selection
= fFacility
.getSdView().getSDWidget().getSelection();
237 assertNotNull("synchToTime", selection
);
238 assertEquals("synchToTime", 1, selection
.size());
239 msg
= (TmfSyncMessage
) selection
.get(0);
240 assertEquals("synchToTime", TC_006_START_OCCURRANCE
, msg
.getStartOccurrence());
241 assertEquals("synchToTime", TC_006_END_OCCURRANCE
, msg
.getEndOccurrence());
245 * Description: Verify synchToTime (timestamp of first message in page)
246 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
247 * Expected result: Move to correct page, selection of last message in page.
249 fFacility
.getTrace().broadcast(new TmfTimeSynchSignal(this, TC_007_TIME_VALUE
));
250 fFacility
.getLoader().waitForCompletion();
251 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
252 assertEquals("synchToTime", TC_007_PAGE_VALUE
, fFacility
.getLoader().currentPage());
253 selection
= fFacility
.getSdView().getSDWidget().getSelection();
254 assertNotNull("synchToTime", selection
);
255 msg
= (TmfSyncMessage
) selection
.get(0);
256 assertEquals("synchToTime", 1, selection
.size());
257 assertEquals("synchToTime", TC_007_START_OCCURRANCE
, msg
.getStartOccurrence());
258 assertEquals("synchToTime", TC_007_END_OCCURRANCE
, msg
.getEndOccurrence());
262 * Description: Verify time range signal (start, end time and current time are in same page)
263 * Verified Methods: loader.synchToTimeRange(), loader.moveToMessage(), loader.moveToMessageInPage()
264 * Expected result: Move to correct page(=page of start time of range), set focus on start time of range, but no selection of message.
266 // 9788.642228395 (page 0) -> 9789.164833324 (page 0) with selected time 9788.642228395 (page 0)
267 fFacility
.getLoader().firstPage();
268 TmfTimeRange range
= new TmfTimeRange(TC_008_START_TIME_VALUE
, TC_008_END_TIME_VALUE
);
269 fFacility
.getLoader().waitForCompletion();
270 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
271 fFacility
.getTrace().broadcast(new TmfRangeSynchSignal(this, range
, TC_008_TIME_VALUE
));
272 assertEquals("synchToTimeRange", TC_008_PAGE_VALUE
, fFacility
.getLoader().currentPage());
273 assertNotNull("synchToTimeRange", fFacility
.getLoader().getCurrentTime());
274 assertEquals("synchToTimeRange", 0, TC_008_TIME_VALUE
.compareTo(fFacility
.getLoader().getCurrentTime(), false));
275 selection
= fFacility
.getSdView().getSDWidget().getSelection();
276 // We actually don't want something to be selected!!!
277 assertNotNull("synchToTimeRange", selection
);
278 assertEquals("synchToTimeRange", 0, selection
.size());
282 * Description: Verify time range signal (start and end time are across 2 pages)
283 * Verified Methods: loader.synchToTimeRange(), loader.moveToMessage(), loader.moveToPage()
284 * Expected result: Move to correct page (=page of start time of range), set focus on start time of range, but no selection of message.
286 range
= new TmfTimeRange(TC_009_START_TIME_VALUE
, TC_009_END_TIME_VALUE
);
287 fFacility
.getTrace().broadcast(new TmfRangeSynchSignal(this, range
, TC_009_TIME_VALUE
));
288 fFacility
.getLoader().waitForCompletion();
289 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
290 assertEquals("synchToTimeRange", TC_009_PAGE_VALUE
, fFacility
.getLoader().currentPage());
291 assertNotNull("synchToTimeRange", fFacility
.getLoader().getCurrentTime());
292 assertEquals("synchToTimeRange", 0, TC_009_TIME_VALUE
.compareTo(fFacility
.getLoader().getCurrentTime(), false));
293 selection
= fFacility
.getSdView().getSDWidget().getSelection();
294 // We actually don't want something to be selected!!!
295 assertNotNull("synchToTimeRange", selection
);
296 assertEquals("synchToTimeRange", 0, selection
.size());