import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.bindings.keys.IKeyLookup;
+import org.eclipse.jface.bindings.keys.KeyStroke;
+import org.eclipse.jface.bindings.keys.ParseException;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
+import org.eclipse.swtbot.swt.finder.results.Result;
import org.eclipse.swtbot.swt.finder.results.VoidResult;
import org.eclipse.swtbot.swt.finder.waits.Conditions;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor;
import org.eclipse.ui.WorkbenchException;
import org.hamcrest.Matcher;
-
/**
* SWTBot Helper functions
*
*/
public final class SWTBotUtils {
- private SWTBotUtils() {}
+ private SWTBotUtils() {
+ }
private static final String TRACING_PERSPECTIVE_ID = TracingPerspectiveFactory.ID;
* @param tracePath
* the path of the trace file (absolute or relative)
* @param traceType
- * the trace type id (eg:
- * org.eclipse.linuxtools.btf.trace)
+ * the trace type id (eg: org.eclipse.linuxtools.btf.trace)
*/
public static void openTrace(final String projectName, final String tracePath, final String traceType) {
openTrace(projectName, tracePath, traceType, true);
* @param tracePath
* the path of the trace file (absolute or relative)
* @param traceType
- * the trace type id (eg:
- * org.eclipse.linuxtools.btf.trace)
+ * the trace type id (eg: org.eclipse.linuxtools.btf.trace)
* @param delay
* delay and wait for jobs
*/
* @param bot
* a given workbench bot
* @param projectName
- * the name of the project (it needs to exist or else it would time out)
+ * the name of the project (it needs to exist or else it would
+ * time out)
* @return a {@link SWTBotTreeItem} of the "Traces" directory
*/
public static SWTBotTreeItem selectTracesFolder(SWTWorkbenchBot bot, String projectName) {
}
waitForJobs();
}
+
+ /**
+ * Maximize a table
+ *
+ * @param tableBot
+ * the {@link SWTBotTable} table
+ */
+ public static void maximizeTable(SWTBotTable tableBot) {
+ try {
+ tableBot.pressShortcut(KeyStroke.getInstance(IKeyLookup.CTRL_NAME + "+"), KeyStroke.getInstance("M"));
+ } catch (ParseException e) {
+ fail();
+ }
+ }
+
+ /**
+ * Get the bounds of a cell (SWT.Rectangle) for the specified row and column
+ * index in a table
+ *
+ * @param table
+ * the table
+ * @param row
+ * the row of the table to look up
+ * @param col
+ * the column of the table to look up
+ * @return the bounds in display relative coordinates
+ */
+ public static Rectangle getCellBounds(final Table table, final int row, final int col) {
+ return UIThreadRunnable.syncExec(new Result<Rectangle>() {
+ @Override
+ public Rectangle run() {
+ TableItem item = table.getItem(row);
+ Rectangle bounds = item.getBounds(col);
+ Point p = table.toDisplay(bounds.x, bounds.y);
+ Rectangle rect = new Rectangle(p.x, p.y, bounds.width, bounds.height);
+ return rect;
+ }
+ });
+ }
}
CallsiteEventsInTableTest.class,
CollapseEventsInTableTest.class,
ColorsViewTest.class,
+ FilterColorEditorTest.class,
FilterViewerTest.class,
FontEventEditorTest.class,
MovableColumnEventsEditorTest.class,
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
-import org.eclipse.jface.bindings.keys.IKeyLookup;
-import org.eclipse.jface.bindings.keys.KeyStroke;
-import org.eclipse.jface.bindings.keys.ParseException;
-import org.eclipse.tracecompass.internal.tmf.core.Activator;
-import org.eclipse.tracecompass.tmf.core.tests.TmfCoreTestPlugin;
-import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimePreferencesConstants;
-import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestampFormat;
-import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
+import org.eclipse.tracecompass.internal.tmf.core.Activator;
+import org.eclipse.tracecompass.tmf.core.tests.TmfCoreTestPlugin;
+import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimePreferencesConstants;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestampFormat;
+import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
import org.eclipse.ui.IEditorReference;
import org.hamcrest.Matcher;
import org.junit.AfterClass;
SWTBotTable tableBot = editorBot.bot().table();
// Maximize editor area
- maximizeTable(tableBot);
+ SWTBotUtils.maximizeTable(tableBot);
tableBot.click(1, 0);
// Open source code location
final SWTBotEditor sourceEditorBot = fBot.editor(matcher);
assertTrue(sourceEditorBot.isActive());
- maximizeTable(tableBot);
+ SWTBotUtils.maximizeTable(tableBot);
fBot.closeAllEditors();
SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot);
}
-
- private static void maximizeTable(SWTBotTable tableBot) {
- try {
- tableBot.pressShortcut(KeyStroke.getInstance(IKeyLookup.CTRL_NAME + "+"), KeyStroke.getInstance("M"));
- } catch (ParseException e) {
- fail();
- }
- }
-
}
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
-import org.eclipse.jface.bindings.keys.IKeyLookup;
-import org.eclipse.jface.bindings.keys.KeyStroke;
-import org.eclipse.jface.bindings.keys.ParseException;
-import org.eclipse.tracecompass.internal.tmf.core.Activator;
-import org.eclipse.tracecompass.tmf.core.tests.TmfCoreTestPlugin;
-import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimePreferencesConstants;
-import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestampFormat;
-import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
-import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
+import org.eclipse.tracecompass.internal.tmf.core.Activator;
+import org.eclipse.tracecompass.tmf.core.tests.TmfCoreTestPlugin;
+import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimePreferencesConstants;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestampFormat;
+import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
+import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
SWTBotTable tableBot = editorBot.bot().table();
/* Maximize editor area */
- maximizeTable(tableBot);
+ SWTBotUtils.maximizeTable(tableBot);
tableBot.click(1, 0);
/* Collapse Events */
fBot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "Jan 1 01:01:01", 1, 1));
assertEquals("Timestamp", "Jan 1 01:01:01", tableBot.cell(1, 1));
- maximizeTable(tableBot);
+ SWTBotUtils.maximizeTable(tableBot);
fBot.closeAllEditors();
SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot);
}
-
- private static void maximizeTable(SWTBotTable tableBot) {
- try {
- tableBot.pressShortcut(KeyStroke.getInstance(IKeyLookup.CTRL_NAME + "+"), KeyStroke.getInstance("M"));
- } catch (ParseException e) {
- fail();
- }
- }
-
}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ui.swtbot.tests.viewers.events;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Logger;
+import org.apache.log4j.SimpleLayout;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
+import org.eclipse.tracecompass.tmf.core.tests.TmfCoreTestPlugin;
+import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ImageHelper;
+import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.google.common.collect.HashMultiset;
+import com.google.common.collect.Multiset;
+
+/**
+ * SWTBot test for testing highlighting
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class FilterColorEditorTest {
+
+ private static final int TIMESTAMP_COLUMN = 1;
+ private static final int SOURCE_COLUMN = 2;
+ private static final int MESSAGE_COLUMN = 6;
+ private static final RGB YELLOW = new RGB(255, 255, 0);
+ private static final String TRACE_PROJECT_NAME = "test";
+ private static final String COLUMN_TRACE = "syslog_collapse";
+ private static final String COLUMN_TRACE_PATH = "testfiles/" + COLUMN_TRACE;
+ private static final String COLUMN_TRACE_TYPE = "org.eclipse.linuxtools.tmf.tests.stubs.trace.text.testsyslog";
+
+ private static File fTestFile = null;
+
+ private static SWTWorkbenchBot fBot;
+
+ /** The Log4j logger instance. */
+ private static final Logger fLogger = Logger.getRootLogger();
+ private SWTBotTable fTableBot;
+ private static final int ROW = 8;
+ private RGB fForeground;
+ private RGB fBackground;
+
+ /**
+ * Test Class setup
+ */
+ @BeforeClass
+ public static void init() {
+ SWTBotUtils.failIfUIThread();
+
+ /* set up test trace */
+ URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(COLUMN_TRACE_PATH), null);
+ URI uri;
+ try {
+ uri = FileLocator.toFileURL(location).toURI();
+ fTestFile = new File(uri);
+ } catch (URISyntaxException | IOException e) {
+ fail(e.getMessage());
+ }
+
+ assumeTrue(fTestFile.exists());
+
+ /* Set up for swtbot */
+ SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
+ SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
+
+ fLogger.removeAllAppenders();
+ fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
+ fBot = new SWTWorkbenchBot();
+
+ /* Close welcome view */
+ SWTBotUtils.closeView("Welcome", fBot);
+
+ /* Switch perspectives */
+ SWTBotUtils.switchToTracingPerspective();
+
+ /* Finish waiting for eclipse to load */
+ SWTBotUtils.waitForJobs();
+ }
+
+ /**
+ * Test class tear down method.
+ */
+ @AfterClass
+ public static void tearDown() {
+ fLogger.removeAllAppenders();
+ }
+
+ /**
+ * Bring up the table
+ */
+ @Before
+ public void setup() {
+ SWTBotUtils.createProject(TRACE_PROJECT_NAME);
+
+ // Open the actual trace
+ SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), COLUMN_TRACE_TYPE);
+ SWTBotEditor editorBot = SWTBotUtils.activateEditor(fBot, fTestFile.getName());
+
+ fTableBot = editorBot.bot().table();
+ fBackground = fTableBot.backgroundColor().getRGB();
+ fForeground = fTableBot.foregroundColor().getRGB();
+
+ SWTBotUtils.maximizeTable(fTableBot);
+ }
+
+ /**
+ * Remove the project
+ */
+ @After
+ public void cleanup() {
+ SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot);
+ SWTBotUtils.waitForJobs();
+ }
+
+ /**
+ * Test basic highlight
+ */
+ @Test
+ public void testHighlight() {
+ final Rectangle cellBounds = SWTBotUtils.getCellBounds(fTableBot.widget, ROW, SOURCE_COLUMN);
+
+ Multiset<RGB> colorBefore = ImageHelper.grabImage(cellBounds).getHistogram();
+ // Select source column and enter regex
+ fTableBot.click(0, SOURCE_COLUMN);
+ fBot.text().typeText("HostF\n", 100);
+ // make sure selected row is not matching row
+ fTableBot.select(ROW - 1);
+ Multiset<RGB> colorAfter = ImageHelper.grabImage(cellBounds).getHistogram();
+
+ assertTrue(colorBefore.contains(fBackground));
+ assertTrue(colorBefore.contains(fForeground));
+ assertFalse(colorBefore.contains(YELLOW));
+
+ assertTrue(colorAfter.contains(fBackground));
+ assertTrue(colorAfter.contains(fForeground));
+ assertTrue(colorAfter.contains(YELLOW));
+ Multiset<RGB> diff = HashMultiset.create();
+ /*
+ * make the histogram difference This will allow us to verify what has
+ * changed in the two images. Hopefully the sum will be zero
+ */
+ for (RGB entry : colorAfter.elementSet()) {
+ diff.add(entry, Math.abs(colorAfter.count(entry) - colorBefore.count(entry)));
+ }
+ /*
+ * Check that the background became yellow
+ */
+ assertEquals(diff.count(fBackground), (diff.count(YELLOW)));
+ }
+
+ /**
+ * Test highlighting multiple elements in a message
+ */
+ @Test
+ public void testMultiHighlightMessage() {
+ final Rectangle cellBounds = SWTBotUtils.getCellBounds(fTableBot.widget, ROW, MESSAGE_COLUMN);
+
+ ImageHelper before = ImageHelper.grabImage(cellBounds);
+ // enter regex in message column
+ fTableBot.click(0, MESSAGE_COLUMN);
+ fBot.text().typeText("e\n", 100);
+ // make sure matching item is not selected
+ fTableBot.select(ROW - 1);
+ ImageHelper after = ImageHelper.grabImage(cellBounds);
+
+ Multiset<RGB> colorBefore = before.getHistogram();
+ Multiset<RGB> colorAfter = after.getHistogram();
+
+ assertTrue(colorBefore.contains(fBackground));
+ assertTrue(colorBefore.contains(fForeground));
+ assertFalse(colorBefore.contains(YELLOW));
+
+ assertTrue(colorAfter.contains(fBackground));
+ assertTrue(colorAfter.contains(fForeground));
+ assertTrue(colorAfter.contains(YELLOW));
+
+ int start = -1;
+ int end;
+ List<Point> intervals = new ArrayList<>();
+ List<RGB> pixelRow = after.getPixelRow(2);
+ for (int i = 1; i < pixelRow.size(); i++) {
+ RGB prevPixel = pixelRow.get(i - 1);
+ RGB pixel = pixelRow.get(i);
+ if (prevPixel.equals(fBackground) && pixel.equals(YELLOW)) {
+ start = i;
+ }
+ if (prevPixel.equals(YELLOW) && pixel.equals(fBackground)) {
+ end = i;
+ if (start == -1) {
+ fail();
+ }
+ intervals.add(new Point(start, end));
+ }
+ }
+ assertEquals(2, intervals.size());
+ }
+
+ /**
+ * Switch to filter and back
+ */
+ @Test
+ public void testSwitchToFilter() {
+ final Rectangle cellBounds = SWTBotUtils.getCellBounds(fTableBot.widget, ROW, TIMESTAMP_COLUMN);
+ ImageHelper before = ImageHelper.grabImage(cellBounds);
+ // enter regex in message column
+ fTableBot.click(0, TIMESTAMP_COLUMN);
+ fBot.text().typeText("00\n", 100);
+ // make sure matching column is not selected
+ fTableBot.select(ROW - 1);
+ ImageHelper after = ImageHelper.grabImage(cellBounds);
+ // toggle filter mode
+ fTableBot.click(0, 0);
+ ImageHelper afterFilter = ImageHelper.grabImage(cellBounds);
+ // toggle search mode
+ fTableBot.click(0, 0);
+
+ List<RGB> beforeLine = before.getPixelRow(2);
+ List<RGB> afterLine = after.getPixelRow(2);
+ List<RGB> afterFilterLine = afterFilter.getPixelRow(2);
+
+ assertEquals(beforeLine.size(), afterLine.size());
+ assertEquals(beforeLine.size(), afterFilterLine.size());
+ for (int i = 0; i < beforeLine.size(); i++) {
+ RGB afterFilterPixel = afterFilterLine.get(i);
+ RGB beforePixel = beforeLine.get(i);
+ RGB afterPixel = afterLine.get(i);
+
+ assertEquals(beforePixel, afterFilterPixel);
+ if (!afterPixel.equals(YELLOW)) {
+ assertEquals(beforePixel, afterPixel);
+ } else {
+ assertNotEquals(YELLOW, beforePixel);
+ }
+
+ }
+ assertEquals(beforeLine, afterFilterLine);
+ assertNotEquals(afterLine, beforeLine);
+ }
+}
import org.apache.log4j.SimpleLayout;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
-import org.eclipse.jface.bindings.keys.IKeyLookup;
-import org.eclipse.jface.bindings.keys.KeyStroke;
-import org.eclipse.jface.bindings.keys.ParseException;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
SWTBotTable tableBot = editorBot.bot().table();
// Maximize editor area
- maximizeTable(tableBot);
+ SWTBotUtils.maximizeTable(tableBot);
tableBot.contextMenu("Show Raw").click();
tableBot.setFocus();
tableBot.click(4, 1);
}
});
}
-
- private static void maximizeTable(SWTBotTable tableBot) {
- try {
- tableBot.pressShortcut(KeyStroke.getInstance(IKeyLookup.CTRL_NAME + "+"), KeyStroke.getInstance("M"));
- } catch (ParseException e) {
- fail();
- }
- }
-
}
import org.apache.log4j.SimpleLayout;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
-import org.eclipse.jface.bindings.keys.IKeyLookup;
-import org.eclipse.jface.bindings.keys.KeyStroke;
-import org.eclipse.jface.bindings.keys.ParseException;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
SWTBotTable tableBot = editorBot.bot().table();
// Maximize editor area
- maximizeTable(tableBot);
+ SWTBotUtils.maximizeTable(tableBot);
// Verify that source code was actually opened
assertArrayEquals("Before reorder", BEFORE_COLS, tableBot.columns().toArray());
editorBot = SWTBotUtils.activateEditor(fBot, fTestFile.getName());
tableBot = editorBot.bot().table();
// Maximize editor area
- maximizeTable(tableBot);
+ SWTBotUtils.maximizeTable(tableBot);
assertArrayEquals("After reorder", AFTER_COLS, tableBot.columns().toArray());
// close and re-open
editorBot.close();
editorBot = SWTBotUtils.activateEditor(fBot, fTestFile.getName());
tableBot = editorBot.bot().table();
// Maximize editor area
- maximizeTable(tableBot);
+ SWTBotUtils.maximizeTable(tableBot);
assertNull("After reset", TmfTraceColumnManager.loadColumnOrder(COLUMN_TRACE_TYPE));
assertArrayEquals("After reset", BEFORE_COLS, tableBot.columns().toArray());
fBot.closeAllEditors();
SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot);
}
-
- private static void maximizeTable(SWTBotTable tableBot) {
- try {
- tableBot.pressShortcut(KeyStroke.getInstance(IKeyLookup.CTRL_NAME + "+"), KeyStroke.getInstance("M"));
- } catch (ParseException e) {
- fail();
- }
- }
-
}