tmf: Bug 457502: Filter node elements should not implement equals()
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / ui / swtbot / tests / viewers / events / ColorsViewTest.java
CommitLineData
d87a9633
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 *******************************************************************************/
12package org.eclipse.tracecompass.tmf.ui.swtbot.tests.viewers.events;
13
14import static org.junit.Assert.assertEquals;
15import static org.junit.Assert.assertNotNull;
16
17import java.io.File;
18import java.io.IOException;
19import java.util.Collections;
20import java.util.List;
21
22import org.apache.log4j.ConsoleAppender;
23import org.apache.log4j.Logger;
24import org.apache.log4j.SimpleLayout;
25import org.eclipse.swt.graphics.RGB;
26import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
27import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
28import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
29import org.eclipse.swtbot.swt.finder.results.Result;
30import org.eclipse.swtbot.swt.finder.results.VoidResult;
31import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
32import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
33import org.eclipse.swtbot.swt.finder.widgets.SWTBotTableItem;
34import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
35import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
36import org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode;
37import org.eclipse.tracecompass.tmf.core.io.BufferedRandomAccessFile;
38import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
39import org.eclipse.tracecompass.tmf.ui.views.colors.ColorSetting;
40import org.eclipse.tracecompass.tmf.ui.views.colors.ColorSettingsManager;
41import org.eclipse.tracecompass.tmf.ui.views.colors.ColorsView;
42import org.junit.After;
43import org.junit.AfterClass;
44import org.junit.Before;
45import org.junit.BeforeClass;
46import org.junit.Test;
47
48/**
49 * Test for Colors views in trace compass
50 */
51public class ColorsViewTest {
52
53 private static final class PassAll implements ITmfFilterTreeNode {
54 @Override
55 public boolean matches(ITmfEvent event) {
56 return true;
57 }
58
d87a9633
MK
59 @Override
60 public void setParent(ITmfFilterTreeNode parent) {
61
62 }
63
64 @Override
65 public ITmfFilterTreeNode replaceChild(int index, ITmfFilterTreeNode node) {
66 return null;
67 }
68
69 @Override
70 public ITmfFilterTreeNode removeChild(ITmfFilterTreeNode node) {
71 return null;
72 }
73
74 @Override
75 public ITmfFilterTreeNode remove() {
76 return null;
77 }
78
79 @Override
80 public boolean hasChildren() {
81 return false;
82 }
83
84 @Override
85 public List<String> getValidChildren() {
86 return Collections.EMPTY_LIST;
87 }
88
89 @Override
90 public ITmfFilterTreeNode getParent() {
91 return null;
92 }
93
94 @Override
95 public String getNodeName() {
96 return "YES";
97 }
98
99 @Override
100 public int getChildrenCount() {
101 return 0;
102 }
103
104 @Override
105 public ITmfFilterTreeNode[] getChildren() {
106 return null;
107 }
108
109 @Override
110 public ITmfFilterTreeNode getChild(int index) {
111 return null;
112 }
113
114 @Override
115 public int addChild(ITmfFilterTreeNode node) {
116 return 0;
117 }
118
119 @Override
120 public ITmfFilterTreeNode clone() {
121 return null;
122 }
123 }
124
125 private static final String XMLSTUB_ID = "org.eclipse.linuxtools.tmf.core.tests.xmlstub";
126
127 private static final String TRACE_START = "<trace>";
128 private static final String EVENT_BEGIN = "<event timestamp=\"";
129 private static final String EVENT_MIDDLE = " \" name=\"event\"><field name=\"field\" value=\"";
130 private static final String EVENT_END = "\" type=\"int\" />" + "</event>";
131 private static final String TRACE_END = "</trace>";
132
133 private static final String PROJECT_NAME = "TestForFiltering";
134
135 /** The Log4j logger instance. */
136 private static final Logger fLogger = Logger.getRootLogger();
137 private static SWTWorkbenchBot fBot;
138
139 private static String makeEvent(int ts, int val) {
140 return EVENT_BEGIN + Integer.toString(ts) + EVENT_MIDDLE + Integer.toString(val) + EVENT_END + "\n";
141 }
142
143 private static File fFileLocation;
144
145 /**
146 * Initialization, creates a temp trace
147 *
148 * @throws IOException
149 * should not happen
150 */
151 @BeforeClass
152 public static void init() throws IOException {
153 SWTBotUtils.failIfUIThread();
154 Thread.currentThread().setName("SWTBot Thread"); // for the debugger
155 /* set up for swtbot */
156 SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
157 fLogger.addAppender(new ConsoleAppender(new SimpleLayout()));
158 fBot = new SWTWorkbenchBot();
159
160 SWTBotUtils.closeView("welcome", fBot);
161
162 SWTBotUtils.switchToTracingPerspective();
163 /* finish waiting for eclipse to load */
164 SWTBotUtils.waitForJobs();
165 fFileLocation = File.createTempFile("sample", ".xml");
166 try (BufferedRandomAccessFile braf = new BufferedRandomAccessFile(fFileLocation, "rw")) {
167 braf.writeBytes(TRACE_START);
168 for (int i = 0; i < 100; i++) {
169 braf.writeBytes(makeEvent(i * 100, i % 4));
170 }
171 braf.writeBytes(TRACE_END);
172 }
173 }
174
175 /**
176 * Open a trace in an editor
177 */
178 @Before
179 public void beforeTest() {
180 SWTBotUtils.createProject(PROJECT_NAME);
181 SWTBotTreeItem treeItem = SWTBotUtils.selectTracesFolder(fBot, PROJECT_NAME);
182 assertNotNull(treeItem);
183 SWTBotUtils.openTrace(PROJECT_NAME, fFileLocation.getAbsolutePath(), XMLSTUB_ID);
184 SWTBotUtils.openView(ColorsView.ID);
185 }
186
187 /**
188 * Delete the file
189 */
190 @AfterClass
191 public static void cleanUp() {
192 fFileLocation.delete();
193 }
194
195 /**
196 * Close the editor
197 */
198 @After
199 public void tearDown() {
200 fBot.closeAllEditors();
201 SWTBotUtils.deleteProject(PROJECT_NAME, fBot);
202 }
203
204 /**
205 * Test color by making all events yellow
206 */
207 @Test
208 public void testYellow() {
209 SWTBotView viewBot = fBot.viewById(ColorsView.ID);
210 viewBot.setFocus();
211 final String insert = "Insert new color setting";
212 final String increasePriority = "Increase priority";
213 final String decreasePriority = "Decrease priority";
214 final String delete = "Delete color setting";
215 viewBot.toolbarButton(insert).click();
216 viewBot.toolbarButton(insert).click();
217 viewBot.toolbarButton(insert).click();
218 viewBot.toolbarButton(insert).click();
219 viewBot.toolbarButton(increasePriority).click();
220 viewBot.toolbarButton(decreasePriority).click();
221 viewBot.toolbarButton(delete).click();
222 viewBot.bot().label(0).setFocus();
223 viewBot.toolbarButton(delete).click();
224 viewBot.bot().label(0).setFocus();
225 viewBot.toolbarButton(delete).click();
226 final RGB foreground = new RGB(0, 0, 0);
227 final RGB background = new RGB(255, 255, 0);
228 // Simulate the site effects of picking a color because we cannot
229 // control native Color picker dialog in SWTBot.
230 final ColorSetting[] cs = new ColorSetting[1];
231 UIThreadRunnable.syncExec(new VoidResult() {
232 @Override
233 public void run() {
234 cs[0] = new ColorSetting(foreground, background, foreground, new PassAll());
235 ColorSettingsManager.setColorSettings(cs);
236 }
237 });
238 final SWTBotTable eventsEditor = fBot.activeEditor().bot().table();
239 eventsEditor.select(2);
240 final SWTBotTableItem tableItem = eventsEditor.getTableItem(2);
241 RGB fgc = UIThreadRunnable.syncExec(new Result<RGB>() {
242 @Override
243 public RGB run() {
244 return tableItem.widget.getForeground().getRGB();
245 }
246 });
247 RGB bgc = UIThreadRunnable.syncExec(new Result<RGB>() {
248 @Override
249 public RGB run() {
250 return tableItem.widget.getBackground().getRGB();
251 }
252 });
253 assertEquals("Fg", foreground, fgc);
254 assertEquals("Bg", background, bgc);
255 }
256}
This page took 0.033159 seconds and 5 git commands to generate.