1 /*******************************************************************************
2 * Copyright (c) 2015 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 * Matthew Khouzam - Initial API and implementation
11 * Patrick Tasse - Fix editor handling
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.viewers
.events
;
16 import static org
.junit
.Assert
.assertEquals
;
19 import java
.io
.IOException
;
21 import org
.apache
.log4j
.ConsoleAppender
;
22 import org
.apache
.log4j
.Logger
;
23 import org
.apache
.log4j
.SimpleLayout
;
24 import org
.eclipse
.jface
.bindings
.keys
.KeyStroke
;
25 import org
.eclipse
.swtbot
.eclipse
.finder
.SWTWorkbenchBot
;
26 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotEditor
;
27 import org
.eclipse
.swtbot
.swt
.finder
.junit
.SWTBotJunit4ClassRunner
;
28 import org
.eclipse
.swtbot
.swt
.finder
.utils
.SWTBotPreferences
;
29 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotShell
;
30 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTable
;
31 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTreeItem
;
32 import org
.eclipse
.tracecompass
.tmf
.core
.io
.BufferedRandomAccessFile
;
33 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.ConditionHelpers
;
34 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.SWTBotUtils
;
35 import org
.junit
.After
;
36 import org
.junit
.Before
;
37 import org
.junit
.Test
;
38 import org
.junit
.runner
.RunWith
;
41 * Test trace offsetting
43 * @author Matthew Khouzam
45 @RunWith(SWTBotJunit4ClassRunner
.class)
46 public class TestTraceOffsetting
{
48 private static final String TRACE_START
= "<trace>";
49 private static final String EVENT_BEGIN
= "<event timestamp=\"";
50 private static final String EVENT_MIDDLE
= " \" name=\"event\"><field name=\"field\" value=\"";
51 private static final String EVENT_END
= "\" type=\"int\" />" + "</event>";
52 private static final String TRACE_END
= "</trace>";
54 private static final String PROJET_NAME
= "TestForOffsetting";
55 private static final int NUM_EVENTS
= 100;
57 /** The Log4j logger instance. */
58 private static final Logger fLogger
= Logger
.getRootLogger();
59 private static SWTWorkbenchBot fBot
;
61 private static String
makeEvent(int ts
, int val
) {
62 return EVENT_BEGIN
+ Integer
.toString(ts
) + EVENT_MIDDLE
+ Integer
.toString(val
) + EVENT_END
+ "\n";
65 private File fLocation
;
68 * Initialization, creates a temp trace
74 public void init() throws IOException
{
75 SWTBotUtils
.initialize();
76 Thread
.currentThread().setName("SWTBot Thread"); // for the debugger
77 /* set up for swtbot */
78 SWTBotPreferences
.TIMEOUT
= 20000; /* 20 second timeout */
79 fLogger
.removeAllAppenders();
80 fLogger
.addAppender(new ConsoleAppender(new SimpleLayout()));
81 fBot
= new SWTWorkbenchBot();
83 SWTBotUtils
.closeView("welcome", fBot
);
85 SWTBotUtils
.switchToTracingPerspective();
86 /* finish waiting for eclipse to load */
87 SWTBotUtils
.waitForJobs();
88 fLocation
= File
.createTempFile("sample", ".xml");
89 try (BufferedRandomAccessFile braf
= new BufferedRandomAccessFile(fLocation
, "rw")) {
90 braf
.writeBytes(TRACE_START
);
91 for (int i
= 0; i
< NUM_EVENTS
; i
++) {
92 braf
.writeBytes(makeEvent(i
* 100, i
% 4));
94 braf
.writeBytes(TRACE_END
);
102 public void cleanup() {
104 fLogger
.removeAllAppenders();
108 * Test offsetting by 99 ns
111 public void testOffsetting() {
112 SWTBotUtils
.createProject(PROJET_NAME
);
113 SWTBotTreeItem traceFolderItem
= SWTBotUtils
.selectTracesFolder(fBot
, PROJET_NAME
);
114 SWTBotUtils
.openTrace(PROJET_NAME
, fLocation
.getAbsolutePath(), "org.eclipse.linuxtools.tmf.core.tests.xmlstub");
115 SWTBotEditor editor
= fBot
.editorByTitle(fLocation
.getName());
116 SWTBotTable eventsTableBot
= editor
.bot().table();
117 String timestamp
= eventsTableBot
.cell(1, 1);
118 assertEquals("19:00:00.000 000 000", timestamp
);
119 SWTBotTreeItem traceItem
= SWTBotUtils
.getTraceProjectItem(fBot
, traceFolderItem
, fLocation
.getName());
121 traceItem
.contextMenu("Apply Time Offset...").click();
122 SWTBotUtils
.waitForJobs();
123 // set offset to 99 ns
124 SWTBotShell shell
= fBot
.shell("Apply time offset");
126 SWTBotTreeItem
[] allItems
= fBot
.tree().getAllItems();
127 final SWTBotTreeItem swtBotTreeItem
= allItems
[0];
128 swtBotTreeItem
.select();
129 swtBotTreeItem
.click(1);
130 swtBotTreeItem
.pressShortcut(KeyStroke
.getInstance('9'));
131 swtBotTreeItem
.pressShortcut(KeyStroke
.getInstance('9'));
132 swtBotTreeItem
.pressShortcut(KeyStroke
.getInstance('\n'));
133 SWTBotUtils
.waitForJobs();
134 fBot
.button("OK").click();
136 // wait for trace to close
137 fBot
.waitWhile(ConditionHelpers
.isEditorOpened(fBot
, fLocation
.getName()));
140 SWTBotUtils
.openTrace(PROJET_NAME
, fLocation
.getAbsolutePath(), "org.eclipse.linuxtools.tmf.core.tests.xmlstub");
141 editor
= fBot
.editorByTitle(fLocation
.getName());
142 eventsTableBot
= editor
.bot().table();
143 timestamp
= eventsTableBot
.cell(1, 1);
144 assertEquals("19:00:00.000 000 099", timestamp
);
145 SWTBotUtils
.deleteProject(PROJET_NAME
, fBot
);