Move CTFTraceCallsitePerformance test to performance tests
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / ui / swtbot / tests / viewers / events / TestTraceOffsetting.java
CommitLineData
a5c211e1
MK
1/*******************************************************************************
2 * Copyright (c) 2015 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 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
12
13package org.eclipse.tracecompass.tmf.ui.swtbot.tests.viewers.events;
14
15import static org.junit.Assert.assertEquals;
16
17import java.io.File;
18import java.io.IOException;
19
20import org.apache.log4j.ConsoleAppender;
21import org.apache.log4j.Logger;
22import org.apache.log4j.SimpleLayout;
23import org.eclipse.jface.bindings.keys.KeyStroke;
24import org.eclipse.swt.SWT;
25import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
26import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
27import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
28import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
29import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
30import org.eclipse.tracecompass.tmf.core.io.BufferedRandomAccessFile;
31import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
32import org.junit.After;
33import org.junit.Before;
34import org.junit.Test;
35
36/**
37 * Test trace offsetting
38 *
39 * @author Matthew Khouzam
40 */
41public class TestTraceOffsetting {
42
43 private static final String TRACE_START = "<trace>";
44 private static final String EVENT_BEGIN = "<event timestamp=\"";
45 private static final String EVENT_MIDDLE = " \" name=\"event\"><field name=\"field\" value=\"";
46 private static final String EVENT_END = "\" type=\"int\" />" + "</event>";
47 private static final String TRACE_END = "</trace>";
48
49 private static final String PROJET_NAME = "TestForOffsetting";
50 private static final int NUM_EVENTS = 100;
51
52 /** The Log4j logger instance. */
53 private static final Logger fLogger = Logger.getRootLogger();
54 private static SWTWorkbenchBot fBot;
55
56 private static String makeEvent(int ts, int val) {
57 return EVENT_BEGIN + Integer.toString(ts) + EVENT_MIDDLE + Integer.toString(val) + EVENT_END + "\n";
58 }
59
60 private File fLocation;
61
62 /**
63 * Initialization, creates a temp trace
64 *
65 * @throws IOException
66 * should not happen
67 */
68 @Before
69 public void init() throws IOException {
70 SWTBotUtils.failIfUIThread();
71 Thread.currentThread().setName("SWTBot Thread"); // for the debugger
72 /* set up for swtbot */
73 SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
74 fLogger.addAppender(new ConsoleAppender(new SimpleLayout()));
75 fBot = new SWTWorkbenchBot();
76
77 SWTBotUtils.closeView("welcome", fBot);
78
79 SWTBotUtils.switchToTracingPerspective();
80 /* finish waiting for eclipse to load */
81 SWTBotUtils.waitForJobs();
82 fLocation = File.createTempFile("sample", ".xml");
83 try (BufferedRandomAccessFile braf = new BufferedRandomAccessFile(fLocation, "rw")) {
84 braf.writeBytes(TRACE_START);
85 for (int i = 0; i < NUM_EVENTS; i++) {
86 braf.writeBytes(makeEvent(i * 100, i % 4));
87 }
88 braf.writeBytes(TRACE_END);
89 }
90 }
91
92 /**
93 * Delete file
94 */
95 @After
96 public void cleanup() {
97 fLocation.delete();
98 }
99
100 /**
101 * Test offsetting by 99 ns
102 */
103 @Test
104 public void testOffsetting() {
105 SWTBotUtils.createProject(PROJET_NAME);
106 SWTBotUtils.openTrace(PROJET_NAME, fLocation.getAbsolutePath(), "org.eclipse.linuxtools.tmf.core.tests.xmlstub");
107 SWTBotTreeItem treeItem = SWTBotUtils.selectTracesFolder(fBot, PROJET_NAME);
108 SWTBotTable eventsTableBot = fBot.activeEditor().bot().table();
109 String timestamp = eventsTableBot.cell(1, 1);
110 assertEquals("19:00:00.000 000 000", timestamp);
111 treeItem.select();
112 treeItem.getItems()[0].contextMenu("Apply Time Offset...").click();
113 SWTBotUtils.waitForJobs();
114 // set offset to 99 ns
115 SWTBotShell shell = fBot.shell("Apply time offset");
116 shell.setFocus();
117 SWTBotTreeItem[] allItems = fBot.tree().getAllItems();
118 final SWTBotTreeItem swtBotTreeItem = allItems[0];
119 swtBotTreeItem.select();
120 swtBotTreeItem.click(1);
121 KeyStroke[] keyStrokes = new KeyStroke[1];
122 keyStrokes[0] = KeyStroke.getInstance('9');
123 swtBotTreeItem.pressShortcut(keyStrokes);
124 keyStrokes[0] = KeyStroke.getInstance('9');
125 swtBotTreeItem.pressShortcut(keyStrokes);
126 keyStrokes[0] = KeyStroke.getInstance(SWT.CR);
127 swtBotTreeItem.pressShortcut(keyStrokes);
128 SWTBotUtils.waitForJobs();
129 fBot.button("OK").click();
130 // re-open trace
131 SWTBotUtils.openTrace(PROJET_NAME, fLocation.getAbsolutePath(), "org.eclipse.linuxtools.tmf.core.tests.xmlstub");
132 SWTBotUtils.waitForJobs();
133
134 timestamp = eventsTableBot.cell(1, 1);
135 assertEquals("19:00:00.000 000 000", timestamp);
136 SWTBotUtils.deleteProject(PROJET_NAME, fBot);
137 }
138
139}
This page took 0.045312 seconds and 5 git commands to generate.