lttng: Add a Binary Callsite aspect to the debug-info analysis
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / ui / swtbot / tests / viewers / events / FilterColorEditorTest.java
CommitLineData
328e5fe4
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;
16import static org.junit.Assert.assertFalse;
17import static org.junit.Assert.assertNotEquals;
18import static org.junit.Assert.assertTrue;
19import static org.junit.Assert.fail;
20import static org.junit.Assume.assumeTrue;
21
22import java.io.File;
23import java.io.IOException;
24import java.net.URI;
25import java.net.URISyntaxException;
26import java.net.URL;
27import java.util.ArrayList;
28import java.util.List;
29
30import org.apache.log4j.ConsoleAppender;
31import org.apache.log4j.Logger;
32import org.apache.log4j.SimpleLayout;
33import org.eclipse.core.runtime.FileLocator;
34import org.eclipse.core.runtime.Path;
2592b7f6 35import org.eclipse.jface.resource.ColorRegistry;
328e5fe4
MK
36import org.eclipse.swt.graphics.Point;
37import org.eclipse.swt.graphics.RGB;
38import org.eclipse.swt.graphics.Rectangle;
39import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
40import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
41import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
42import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
43import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
44import org.eclipse.tracecompass.tmf.core.tests.TmfCoreTestPlugin;
45import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ImageHelper;
46import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
2592b7f6 47import org.eclipse.ui.PlatformUI;
328e5fe4
MK
48import org.junit.After;
49import org.junit.AfterClass;
50import org.junit.Before;
51import org.junit.BeforeClass;
52import org.junit.Test;
53import org.junit.runner.RunWith;
54
328e5fe4
MK
55import com.google.common.collect.Multiset;
56
57/**
58 * SWTBot test for testing highlighting
59 */
60@RunWith(SWTBotJunit4ClassRunner.class)
61public class FilterColorEditorTest {
62
63 private static final int TIMESTAMP_COLUMN = 1;
64 private static final int SOURCE_COLUMN = 2;
65 private static final int MESSAGE_COLUMN = 6;
2592b7f6
PT
66 private static final RGB GREEN = new RGB(0, 255, 0);
67 private static final String HIGHLIGHT_COLOR_DEFINITION_ID = "org.eclipse.tracecompass.tmf.ui.color.eventtable.highlight"; //$NON-NLS-1$
328e5fe4
MK
68 private static final String TRACE_PROJECT_NAME = "test";
69 private static final String COLUMN_TRACE = "syslog_collapse";
70 private static final String COLUMN_TRACE_PATH = "testfiles/" + COLUMN_TRACE;
71 private static final String COLUMN_TRACE_TYPE = "org.eclipse.linuxtools.tmf.tests.stubs.trace.text.testsyslog";
72
73 private static File fTestFile = null;
74
75 private static SWTWorkbenchBot fBot;
76
77 /** The Log4j logger instance. */
78 private static final Logger fLogger = Logger.getRootLogger();
79 private SWTBotTable fTableBot;
80 private static final int ROW = 8;
81 private RGB fForeground;
82 private RGB fBackground;
2592b7f6 83 private RGB fHighlight;
328e5fe4
MK
84
85 /**
86 * Test Class setup
87 */
88 @BeforeClass
89 public static void init() {
90 SWTBotUtils.failIfUIThread();
91
92 /* set up test trace */
93 URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(COLUMN_TRACE_PATH), null);
94 URI uri;
95 try {
96 uri = FileLocator.toFileURL(location).toURI();
97 fTestFile = new File(uri);
98 } catch (URISyntaxException | IOException e) {
99 fail(e.getMessage());
100 }
101
102 assumeTrue(fTestFile.exists());
103
104 /* Set up for swtbot */
105 SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
106 SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
107
108 fLogger.removeAllAppenders();
109 fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
110 fBot = new SWTWorkbenchBot();
111
112 /* Close welcome view */
113 SWTBotUtils.closeView("Welcome", fBot);
114
115 /* Switch perspectives */
116 SWTBotUtils.switchToTracingPerspective();
117
118 /* Finish waiting for eclipse to load */
119 SWTBotUtils.waitForJobs();
120 }
121
122 /**
123 * Test class tear down method.
124 */
125 @AfterClass
126 public static void tearDown() {
127 fLogger.removeAllAppenders();
128 }
129
130 /**
131 * Bring up the table
132 */
133 @Before
134 public void setup() {
135 SWTBotUtils.createProject(TRACE_PROJECT_NAME);
136
137 // Open the actual trace
138 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), COLUMN_TRACE_TYPE);
139 SWTBotEditor editorBot = SWTBotUtils.activateEditor(fBot, fTestFile.getName());
140
141 fTableBot = editorBot.bot().table();
142 fBackground = fTableBot.backgroundColor().getRGB();
143 fForeground = fTableBot.foregroundColor().getRGB();
2592b7f6
PT
144 ColorRegistry colorRegistry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
145 fHighlight = colorRegistry.get(HIGHLIGHT_COLOR_DEFINITION_ID).getRGB();
328e5fe4
MK
146
147 SWTBotUtils.maximizeTable(fTableBot);
148 }
149
150 /**
151 * Remove the project
152 */
153 @After
154 public void cleanup() {
155 SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot);
156 SWTBotUtils.waitForJobs();
157 }
158
159 /**
160 * Test basic highlight
161 */
162 @Test
163 public void testHighlight() {
164 final Rectangle cellBounds = SWTBotUtils.getCellBounds(fTableBot.widget, ROW, SOURCE_COLUMN);
165
166 Multiset<RGB> colorBefore = ImageHelper.grabImage(cellBounds).getHistogram();
167 // Select source column and enter regex
168 fTableBot.click(0, SOURCE_COLUMN);
169 fBot.text().typeText("HostF\n", 100);
170 // make sure selected row is not matching row
171 fTableBot.select(ROW - 1);
172 Multiset<RGB> colorAfter = ImageHelper.grabImage(cellBounds).getHistogram();
173
174 assertTrue(colorBefore.contains(fBackground));
175 assertTrue(colorBefore.contains(fForeground));
2592b7f6 176 assertFalse(colorBefore.contains(fHighlight));
328e5fe4
MK
177
178 assertTrue(colorAfter.contains(fBackground));
179 assertTrue(colorAfter.contains(fForeground));
2592b7f6 180 assertTrue(colorAfter.contains(fHighlight));
3dadb8ca 181
328e5fe4 182 /*
2592b7f6 183 * Check that some background became highlighted.
328e5fe4 184 */
3dadb8ca 185 assertTrue(colorAfter.count(fBackground) < colorBefore.count(fBackground));
2592b7f6 186 assertTrue(colorAfter.count(fHighlight) > colorBefore.count(fHighlight));
328e5fe4
MK
187 }
188
189 /**
190 * Test highlighting multiple elements in a message
191 */
192 @Test
193 public void testMultiHighlightMessage() {
194 final Rectangle cellBounds = SWTBotUtils.getCellBounds(fTableBot.widget, ROW, MESSAGE_COLUMN);
195
196 ImageHelper before = ImageHelper.grabImage(cellBounds);
197 // enter regex in message column
198 fTableBot.click(0, MESSAGE_COLUMN);
199 fBot.text().typeText("e\n", 100);
200 // make sure matching item is not selected
201 fTableBot.select(ROW - 1);
202 ImageHelper after = ImageHelper.grabImage(cellBounds);
203
204 Multiset<RGB> colorBefore = before.getHistogram();
205 Multiset<RGB> colorAfter = after.getHistogram();
206
207 assertTrue(colorBefore.contains(fBackground));
208 assertTrue(colorBefore.contains(fForeground));
2592b7f6 209 assertFalse(colorBefore.contains(fHighlight));
328e5fe4
MK
210
211 assertTrue(colorAfter.contains(fBackground));
212 assertTrue(colorAfter.contains(fForeground));
2592b7f6 213 assertTrue(colorAfter.contains(fHighlight));
328e5fe4
MK
214
215 int start = -1;
216 int end;
217 List<Point> intervals = new ArrayList<>();
218 List<RGB> pixelRow = after.getPixelRow(2);
219 for (int i = 1; i < pixelRow.size(); i++) {
220 RGB prevPixel = pixelRow.get(i - 1);
221 RGB pixel = pixelRow.get(i);
2592b7f6 222 if (prevPixel.equals(fBackground) && pixel.equals(fHighlight)) {
328e5fe4
MK
223 start = i;
224 }
2592b7f6 225 if (prevPixel.equals(fHighlight) && pixel.equals(fBackground)) {
328e5fe4
MK
226 end = i;
227 if (start == -1) {
228 fail();
229 }
230 intervals.add(new Point(start, end));
231 }
232 }
233 assertEquals(2, intervals.size());
234 }
235
236 /**
237 * Switch to filter and back
238 */
239 @Test
240 public void testSwitchToFilter() {
241 final Rectangle cellBounds = SWTBotUtils.getCellBounds(fTableBot.widget, ROW, TIMESTAMP_COLUMN);
242 ImageHelper before = ImageHelper.grabImage(cellBounds);
243 // enter regex in message column
244 fTableBot.click(0, TIMESTAMP_COLUMN);
245 fBot.text().typeText("00\n", 100);
246 // make sure matching column is not selected
247 fTableBot.select(ROW - 1);
248 ImageHelper after = ImageHelper.grabImage(cellBounds);
249 // toggle filter mode
250 fTableBot.click(0, 0);
251 ImageHelper afterFilter = ImageHelper.grabImage(cellBounds);
328e5fe4
MK
252
253 List<RGB> beforeLine = before.getPixelRow(2);
254 List<RGB> afterLine = after.getPixelRow(2);
255 List<RGB> afterFilterLine = afterFilter.getPixelRow(2);
256
257 assertEquals(beforeLine.size(), afterLine.size());
258 assertEquals(beforeLine.size(), afterFilterLine.size());
259 for (int i = 0; i < beforeLine.size(); i++) {
260 RGB afterFilterPixel = afterFilterLine.get(i);
261 RGB beforePixel = beforeLine.get(i);
262 RGB afterPixel = afterLine.get(i);
263
264 assertEquals(beforePixel, afterFilterPixel);
2592b7f6 265 if (!afterPixel.equals(fHighlight)) {
328e5fe4
MK
266 assertEquals(beforePixel, afterPixel);
267 } else {
2592b7f6 268 assertNotEquals(fHighlight, beforePixel);
328e5fe4
MK
269 }
270
271 }
272 assertEquals(beforeLine, afterFilterLine);
273 assertNotEquals(afterLine, beforeLine);
274 }
2592b7f6
PT
275
276 /**
277 * Test highlight color preference
278 */
279 @Test
280 public void testPreference() {
281 // change the highlight color preference
282 ColorRegistry colorRegistry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
283 colorRegistry.put(HIGHLIGHT_COLOR_DEFINITION_ID, GREEN);
284
285 final Rectangle cellBounds = SWTBotUtils.getCellBounds(fTableBot.widget, ROW, SOURCE_COLUMN);
286
287 Multiset<RGB> colorBefore = ImageHelper.grabImage(cellBounds).getHistogram();
288 // Select source column and enter regex
289 fTableBot.click(0, SOURCE_COLUMN);
290 fBot.text().typeText("HostF\n", 100);
291 // make sure selected row is not matching row
292 fTableBot.select(ROW - 1);
293 Multiset<RGB> colorAfter = ImageHelper.grabImage(cellBounds).getHistogram();
294
295 assertTrue(colorBefore.contains(fBackground));
296 assertTrue(colorBefore.contains(fForeground));
297 assertFalse(colorBefore.contains(fHighlight));
298 assertFalse(colorBefore.contains(GREEN));
299
300 assertTrue(colorAfter.contains(fBackground));
301 assertTrue(colorAfter.contains(fForeground));
302 assertFalse(colorAfter.contains(fHighlight));
303 assertTrue(colorAfter.contains(GREEN));
304
305 /*
306 * Check that some background became green.
307 */
308 assertTrue(colorAfter.count(fBackground) < colorBefore.count(fBackground));
309 assertTrue(colorAfter.count(GREEN) > colorBefore.count(GREEN));
310
311 // reset the highlight color preference
312 colorRegistry.put(HIGHLIGHT_COLOR_DEFINITION_ID, fHighlight);
313 }
328e5fe4 314}
This page took 0.04905 seconds and 5 git commands to generate.