TMF: Close sequence diagram view after sequence diagram tests
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui.tests / src / org / eclipse / tracecompass / tmf / ui / tests / views / uml2sd / loader / TmfUml2SDSyncLoaderTimeTest.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2014 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 * Bernd Hufmann - Initial API and implementation
11 * Alexandre Montplaisir - Port to JUnit4
12 * Patrick Tasse - Support selection range
13 *******************************************************************************/
14
15 package org.eclipse.tracecompass.tmf.ui.tests.views.uml2sd.loader;
16
17 import static org.junit.Assert.assertEquals;
18 import static org.junit.Assert.assertNotNull;
19 import static org.junit.Assert.assertTrue;
20
21 import java.util.List;
22
23 import org.eclipse.jdt.annotation.NonNull;
24 import org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal;
25 import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
26 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
27 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
28 import org.eclipse.tracecompass.tmf.ui.views.uml2sd.core.GraphNode;
29 import org.eclipse.tracecompass.tmf.ui.views.uml2sd.loader.TmfSyncMessage;
30 import org.junit.AfterClass;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33
34 /**
35 * Test cases for time synchronization handling.
36 *
37 * @author Bernd Hufmann
38 */
39 public class TmfUml2SDSyncLoaderTimeTest {
40
41 // ------------------------------------------------------------------------
42 // Attributes
43 // ------------------------------------------------------------------------
44
45 // Test case 001 expected values
46 final static private @NonNull Uml2SDTestTimestamp TC_001_TIME_VALUE = new Uml2SDTestTimestamp(9788642228395L);
47 final static private String TC_001_MESSAGE_NAME = "START_GAME_REPLY";
48 final static private int TC_001_PAGE_VALUE = 0;
49 final static private int TC_001_START_OCCURRANCE = 6;
50 final static private int TC_001_END_OCCURRANCE = TC_001_START_OCCURRANCE;
51 final static private String TC_001_START_LIFELINE = IUml2SDTestConstants.MASTER_PLAYER_NAME;
52 final static private String TC_001_END_LIFELINE = IUml2SDTestConstants.FIRST_PLAYER_NAME;
53
54 // Test case 002 expected values
55 final static private @NonNull Uml2SDTestTimestamp TC_002_TIME_VALUE = new Uml2SDTestTimestamp(9789689830722L);
56 final static private String TC_002_MESSAGE_NAME = "PAUSE_GAME_REQUEST";
57 final static private int TC_002_PAGE_VALUE = 2;
58 final static private int TC_002_START_OCCURRANCE = 7;
59 final static private int TC_002_END_OCCURRANCE = TC_002_START_OCCURRANCE;
60 final static private String TC_002_START_LIFELINE = IUml2SDTestConstants.FIRST_PLAYER_NAME;
61 final static private String TC_002_END_LIFELINE = IUml2SDTestConstants.MASTER_PLAYER_NAME;
62
63 // Test case 003 expected values
64 final static private @NonNull Uml2SDTestTimestamp TC_003_TIME_VALUE = new Uml2SDTestTimestamp(9790750000000L);
65 final static private int TC_003_PAGE_VALUE = 4;
66
67 // Test case 004 expected values
68 final static private int TC_004_PAGE_VALUE = 0;
69
70 // Test case 005 expected values
71 final static private int TC_005_PAGE_VALUE = IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES - 1;
72
73 // Test case 006 expected values
74 final static private @NonNull Uml2SDTestTimestamp TC_006_TIME_VALUE = new Uml2SDTestTimestamp(9792420661655L);
75 final static private int TC_006_PAGE_VALUE = 4;
76 final static private int TC_006_START_OCCURRANCE = IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE;
77 final static private int TC_006_END_OCCURRANCE = TC_006_START_OCCURRANCE;
78
79 // Test case 007 expected values
80 final static private @NonNull Uml2SDTestTimestamp TC_007_TIME_VALUE = new Uml2SDTestTimestamp(9792420756010L);
81 final static private int TC_007_PAGE_VALUE = 5;
82 final static private int TC_007_START_OCCURRANCE = 1;
83 final static private int TC_007_END_OCCURRANCE = TC_007_START_OCCURRANCE;
84
85 // Test case 008 expected values
86 final static private @NonNull Uml2SDTestTimestamp TC_008_TIME_VALUE = new Uml2SDTestTimestamp(9788642228395L);
87 final static private int TC_008_PAGE_VALUE = 0;
88 final static private @NonNull Uml2SDTestTimestamp TC_008_START_TIME_VALUE = new Uml2SDTestTimestamp(9788642228395L);
89 final static private @NonNull Uml2SDTestTimestamp TC_008_END_TIME_VALUE = new Uml2SDTestTimestamp(9789164833324L);
90
91 // Test case 009 expected values
92 final static private @NonNull Uml2SDTestTimestamp TC_009_TIME_VALUE = new Uml2SDTestTimestamp(9789689220871L);
93 final static private int TC_009_PAGE_VALUE = 1;
94 final static private @NonNull Uml2SDTestTimestamp TC_009_START_TIME_VALUE = TC_009_TIME_VALUE;
95 final static private @NonNull Uml2SDTestTimestamp TC_009_END_TIME_VALUE = new Uml2SDTestTimestamp(9789773881426L);
96
97 // Fields used in tests
98 private static Uml2SDTestFacility fFacility;
99 private static List<GraphNode> selection;
100 private static TmfSyncMessage msg;
101
102 // ------------------------------------------------------------------------
103 // Operations
104 // ------------------------------------------------------------------------
105
106 /**
107 * Initialization
108 */
109 @BeforeClass
110 public static void setUpClass() {
111 fFacility = Uml2SDTestFacility.getInstance();
112 fFacility.init();
113 fFacility.selectExperiment();
114 }
115
116 /**
117 * Cleanup
118 */
119 @AfterClass
120 public static void tearDownClass() {
121 fFacility.disposeExperiment();
122 fFacility.dispose();
123 fFacility = null;
124 }
125
126 /**
127 * Test Case: 001
128 * Description: Verify synchToTime (exact time in page), selection of message in page
129 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToMessageInPage()
130 * Expected result: Correct message is selected.
131 */
132 @Test
133 public void verifySynchToTimeInPage() {
134 fFacility.getTrace().broadcast(new TmfSelectionRangeUpdatedSignal(this, TC_001_TIME_VALUE));
135 fFacility.getLoader().waitForCompletion();
136 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
137 assertEquals("synchToTime", TC_001_PAGE_VALUE, fFacility.getLoader().currentPage());
138 selection = fFacility.getSdView().getSDWidget().getSelection();
139 assertNotNull(selection);
140 assertEquals("synchToTime", 1, selection.size());
141 assertTrue(selection.get(0) instanceof TmfSyncMessage);
142 msg = (TmfSyncMessage) selection.get(0);
143 assertEquals("synchToTime", TC_001_MESSAGE_NAME, msg.getName());
144 assertEquals("synchToTime", 0, TC_001_TIME_VALUE.compareTo(msg.getStartTime()));
145 assertEquals("synchToTime", TC_001_START_OCCURRANCE, msg.getStartOccurrence());
146 assertEquals("synchToTime", TC_001_END_OCCURRANCE, msg.getEndOccurrence());
147 assertEquals("synchToTime", TC_001_START_LIFELINE, msg.getStartLifeline().getName());
148 assertEquals("synchToTime", TC_001_END_LIFELINE, msg.getEndLifeline().getName());
149 }
150
151 /**
152 * Test Case: 002
153 * Description: Verify synchToTime (exact time outside of page), selection of message in page
154 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
155 * Expected result: Correct message is selected.
156 */
157 @Test
158 public void verifySynchToTimeOutsidePage() {
159 fFacility.getTrace().broadcast(new TmfSelectionRangeUpdatedSignal(this, TC_002_TIME_VALUE));
160 fFacility.getLoader().waitForCompletion();
161 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
162 assertEquals("synchToTime", TC_002_PAGE_VALUE, fFacility.getLoader().currentPage());
163 selection = fFacility.getSdView().getSDWidget().getSelection();
164 assertNotNull("synchToTime", selection);
165 assertEquals("synchToTime", 1, selection.size());
166 assertTrue("synchToTime", selection.get(0) instanceof TmfSyncMessage);
167 msg = (TmfSyncMessage) selection.get(0);
168 assertEquals("synchToTime", TC_002_MESSAGE_NAME, msg.getName());
169 assertEquals(0, TC_002_TIME_VALUE.compareTo(msg.getStartTime()));
170 assertEquals("synchToTime", TC_002_START_OCCURRANCE, msg.getStartOccurrence());
171 assertEquals("synchToTime", TC_002_END_OCCURRANCE, msg.getEndOccurrence());
172 assertEquals(TC_002_START_LIFELINE, msg.getStartLifeline().getName());
173 assertEquals(TC_002_END_LIFELINE, msg.getEndLifeline().getName());
174 }
175
176
177 /**
178 * Test Case: 003
179 * Description: Verify synchToTime (timestamp doesn't exist in trace), no selection of message in page
180 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
181 * Expected result: Move to correct page, currentTime is updated so that focus on the currentTime, but no selection.
182 */
183 @Test
184 public void verifySynchToTimeNonExisting() {
185 fFacility.getLoader().firstPage();
186
187 fFacility.getTrace().broadcast(new TmfSelectionRangeUpdatedSignal(this, TC_003_TIME_VALUE));
188 fFacility.getLoader().waitForCompletion();
189 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
190 assertEquals("synchToTime", 0, TC_003_TIME_VALUE.compareTo(fFacility.getLoader().getCurrentTime()));
191 assertEquals("synchToTime", TC_003_PAGE_VALUE, fFacility.getLoader().currentPage());
192 selection = fFacility.getSdView().getSDWidget().getSelection();
193 assertNotNull("synchToTime", selection);
194 assertEquals("synchToTime", 0, selection.size());
195 }
196
197 /**
198 * Test Case: 004
199 * Description: Verify synchToTime (timestamp < experiment time range start)
200 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
201 * Expected result: Move to first page, focus on the beginning of the page, but no selection.
202 */
203 @Test
204 public void verifySynchToTimeBeforeExpStart() {
205 fFacility.getTrace().broadcast(new TmfSelectionRangeUpdatedSignal(this, TmfTimestamp.BIG_BANG));
206 fFacility.getLoader().waitForCompletion();
207 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
208 assertEquals("synchToTime", TC_004_PAGE_VALUE, fFacility.getLoader().currentPage());
209 selection = fFacility.getSdView().getSDWidget().getSelection();
210 assertNotNull("synchToTime", selection);
211 assertEquals("synchToTime", 0, selection.size());
212 }
213
214 /**
215 * Test Case: 005
216 * Description: Verify synchToTime (timestamp > experiment time range end)
217 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
218 * Expected result: Move to last page, focus on the end of the page, but no selection.
219 */
220 @Test
221 public void verifySynchToTimeAfterExpEnd() {
222 fFacility.getTrace().broadcast(new TmfSelectionRangeUpdatedSignal(this, TmfTimestamp.BIG_CRUNCH));
223 fFacility.getLoader().waitForCompletion();
224 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
225 assertEquals("synchToTime", TC_005_PAGE_VALUE, fFacility.getLoader().currentPage());
226 selection = fFacility.getSdView().getSDWidget().getSelection();
227 assertNotNull(selection);
228 assertEquals("synchToTime", 0, selection.size());
229 }
230
231 /**
232 * Test Case: 006
233 * Description: Verify synchToTime (timestamp of last message in page)
234 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage(), loader.moveToMessageInPage()
235 * Expected result: Move to correct page, selection of last message in page.
236 */
237 @Test
238 public void verifySynchToTimeEqualsLast() {
239 fFacility.getTrace().broadcast(new TmfSelectionRangeUpdatedSignal(this, TC_006_TIME_VALUE));
240 fFacility.getLoader().waitForCompletion();
241 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
242 assertEquals("synchToTime", TC_006_PAGE_VALUE, fFacility.getLoader().currentPage());
243 selection = fFacility.getSdView().getSDWidget().getSelection();
244 assertNotNull("synchToTime", selection);
245 assertEquals("synchToTime", 1, selection.size());
246 msg = (TmfSyncMessage) selection.get(0);
247 assertEquals("synchToTime", TC_006_START_OCCURRANCE, msg.getStartOccurrence());
248 assertEquals("synchToTime", TC_006_END_OCCURRANCE, msg.getEndOccurrence());
249 }
250
251 /**
252 * Test Case: 007
253 * Description: Verify synchToTime (timestamp of first message in page)
254 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
255 * Expected result: Move to correct page, selection of last message in page.
256 */
257 @Test
258 public void verifySynchToTimeFirst() {
259 fFacility.getTrace().broadcast(new TmfSelectionRangeUpdatedSignal(this, TC_007_TIME_VALUE));
260 fFacility.getLoader().waitForCompletion();
261 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
262 assertEquals("synchToTime", TC_007_PAGE_VALUE, fFacility.getLoader().currentPage());
263 selection = fFacility.getSdView().getSDWidget().getSelection();
264 assertNotNull("synchToTime", selection);
265 msg = (TmfSyncMessage) selection.get(0);
266 assertEquals("synchToTime", 1, selection.size());
267 assertEquals("synchToTime", TC_007_START_OCCURRANCE, msg.getStartOccurrence());
268 assertEquals("synchToTime", TC_007_END_OCCURRANCE, msg.getEndOccurrence());
269 }
270
271 /**
272 * Test Case: 008
273 * Description: Verify time range signal (start, end time and current time are in same page)
274 * Verified Methods: loader.synchToTimeRange(), loader.moveToMessage(), loader.moveToMessageInPage()
275 * Expected result: Move to correct page(=page of start time of range), set focus on start time of range, but no selection of message.
276 */
277 @Test
278 public void verifyTimeRangeSamePage() {
279 // 9788.642228395 (page 0) -> 9789.164833324 (page 0) with selected time 9788.642228395 (page 0)
280 fFacility.getLoader().firstPage();
281 TmfTimeRange range = new TmfTimeRange(TC_008_START_TIME_VALUE, TC_008_END_TIME_VALUE);
282 fFacility.getLoader().waitForCompletion();
283 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
284 fFacility.getTrace().broadcast(new TmfWindowRangeUpdatedSignal(this, range));
285 assertEquals("synchToTimeRange", TC_008_PAGE_VALUE, fFacility.getLoader().currentPage());
286 assertNotNull("synchToTimeRange", fFacility.getLoader().getCurrentTime());
287 assertEquals("synchToTimeRange", 0, TC_008_TIME_VALUE.compareTo(fFacility.getLoader().getCurrentTime()));
288 selection = fFacility.getSdView().getSDWidget().getSelection();
289 // We actually don't want something to be selected!!!
290 assertNotNull("synchToTimeRange", selection);
291 assertEquals("synchToTimeRange", 0, selection.size());
292 }
293
294 /**
295 * Test Case: 009
296 * Description: Verify time range signal (start and end time are across 2 pages)
297 * Verified Methods: loader.synchToTimeRange(), loader.moveToMessage(), loader.moveToPage()
298 * Expected result: Move to correct page (=page of start time of range), set focus on start time of range, but no selection of message.
299 */
300 @Test
301 public void verifyTimeRangeDifferentPages() {
302 TmfTimeRange range = new TmfTimeRange(TC_009_START_TIME_VALUE, TC_009_END_TIME_VALUE);
303 fFacility.getTrace().broadcast(new TmfWindowRangeUpdatedSignal(this, range));
304 fFacility.getLoader().waitForCompletion();
305 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
306 assertEquals("synchToTimeRange", TC_009_PAGE_VALUE, fFacility.getLoader().currentPage());
307 assertNotNull("synchToTimeRange", fFacility.getLoader().getCurrentTime());
308 assertEquals("synchToTimeRange", 0, TC_009_TIME_VALUE.compareTo(fFacility.getLoader().getCurrentTime()));
309 selection = fFacility.getSdView().getSDWidget().getSelection();
310 // We actually don't want something to be selected!!!
311 assertNotNull("synchToTimeRange", selection);
312 assertEquals("synchToTimeRange", 0, selection.size());
313 }
314 }
This page took 0.039236 seconds and 5 git commands to generate.