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