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