ee9b033ec78bdb407cffa71aed037184f112a1bf
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / ui / swtbot / tests / viewers / events / FontEventEditorTest.java
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
13 package org.eclipse.tracecompass.tmf.ui.swtbot.tests.viewers.events;
14
15 import static org.junit.Assert.assertEquals;
16 import static org.junit.Assert.assertFalse;
17 import static org.junit.Assert.fail;
18 import static org.junit.Assume.assumeTrue;
19
20 import java.io.File;
21 import java.io.IOException;
22 import java.net.URI;
23 import java.net.URISyntaxException;
24 import java.net.URL;
25
26 import org.apache.log4j.ConsoleAppender;
27 import org.apache.log4j.Logger;
28 import org.apache.log4j.SimpleLayout;
29 import org.eclipse.core.runtime.FileLocator;
30 import org.eclipse.core.runtime.Path;
31 import org.eclipse.swt.graphics.FontData;
32 import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
33 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
34 import org.eclipse.swtbot.swt.finder.SWTBot;
35 import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
36 import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
37 import org.eclipse.swtbot.swt.finder.results.Result;
38 import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
39 import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
40 import org.eclipse.swtbot.swt.finder.widgets.SWTBotStyledText;
41 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
42 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
43 import org.eclipse.tracecompass.tmf.core.tests.TmfCoreTestPlugin;
44 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
45 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
46 import org.junit.AfterClass;
47 import org.junit.BeforeClass;
48 import org.junit.Test;
49 import org.junit.runner.RunWith;
50
51 /**
52 * SWTBot test for testing movable column feature.
53 */
54 @RunWith(SWTBotJunit4ClassRunner.class)
55 public class FontEventEditorTest {
56
57 private static final String TRACE_PROJECT_NAME = "test";
58 private static final String COLUMN_TRACE = "syslog_collapse";
59 private static final String COLUMN_TRACE_PATH = "testfiles/" + COLUMN_TRACE;
60 private static final String COLUMN_TRACE_TYPE = "org.eclipse.linuxtools.tmf.tests.stubs.trace.text.testsyslog";
61
62 private static File fTestFile = null;
63
64 private static SWTWorkbenchBot fBot;
65
66 /** The Log4j logger instance. */
67 private static final Logger fLogger = Logger.getRootLogger();
68
69 /**
70 * Test Class setup
71 */
72 @BeforeClass
73 public static void init() {
74 SWTBotUtils.initialize();
75
76 /* set up test trace */
77 URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(COLUMN_TRACE_PATH), null);
78 URI uri;
79 try {
80 uri = FileLocator.toFileURL(location).toURI();
81 fTestFile = new File(uri);
82 } catch (URISyntaxException | IOException e) {
83 fail(e.getMessage());
84 }
85
86 assumeTrue(fTestFile.exists());
87
88 /* Set up for swtbot */
89 SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
90 fLogger.removeAllAppenders();
91 fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
92 fBot = new SWTWorkbenchBot();
93
94 /* Close welcome view */
95 SWTBotUtils.closeView("Welcome", fBot);
96
97 /* Switch perspectives */
98 SWTBotUtils.switchToTracingPerspective();
99
100 /* Finish waiting for eclipse to load */
101 SWTBotUtils.waitForJobs();
102 }
103
104 /**
105 * Test class tear down method.
106 */
107 @AfterClass
108 public static void tearDown() {
109 fLogger.removeAllAppenders();
110 }
111
112 /**
113 * Switch the font to system then back to default.
114 */
115 @Test
116 public void testChangeFont() {
117 SWTBotUtils.createProject(TRACE_PROJECT_NAME);
118
119 // Open the actual trace
120 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), COLUMN_TRACE_TYPE);
121 SWTBotEditor editorBot = SWTBotUtils.activateEditor(fBot, fTestFile.getName());
122
123 SWTBotTable tableBot = editorBot.bot().table();
124
125 // Maximize editor area
126 SWTBotUtils.maximizeTable(tableBot);
127 tableBot.contextMenu("Show Raw").click();
128 tableBot.setFocus();
129 tableBot.click(4, 1);
130 tableBot.select(4);
131
132 SWTBotStyledText rawText = editorBot.bot().styledText();
133
134 FontData font = getFont(rawText);
135
136 SWTBotShell preferencesShell = SWTBotUtils.openPreferences(fBot);
137
138 SWTBot bot = preferencesShell.bot();
139 preferencesShell.activate();
140 bot.text().setText("color");
141
142 SWTBotTreeItem generalItem = bot.tree().getTreeItem("General");
143 generalItem.click();
144 generalItem.select();
145 bot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable("Appearance", generalItem));
146 SWTBotTreeItem appearanceNode = generalItem.getNode("Appearance");
147 appearanceNode.click();
148 appearanceNode.select();
149 bot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable("Colors and Fonts", appearanceNode));
150 SWTBotTreeItem colorAndFontNode = appearanceNode.getNode("Colors and Fonts");
151 colorAndFontNode.click();
152 colorAndFontNode.select();
153 SWTBotTreeItem tracingItem = bot.tree(1).getTreeItem("Tracing");
154 tracingItem.click();
155 tracingItem.select();
156 tracingItem.expand();
157 // Get the raw viewer default which is "Text Font" and change it to "System Font"
158 SWTBotTreeItem traceEventTableFont = tracingItem.getNode("Trace event raw text font (set to default: Text Font)");
159 traceEventTableFont.click();
160 traceEventTableFont.select();
161 bot.button("Use System Font").click();
162 bot.button("Apply").click();
163 FontData font2 = getFont(rawText);
164 assertFalse(font2.equals(font));
165 // Reset the raw viewer to the "Text Font"
166 bot.button("Reset").click();
167 bot.button("OK").click();
168 assertEquals(getFont(rawText), font);
169 fBot.closeAllEditors();
170 SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot);
171 }
172
173 private static FontData getFont(final SWTBotStyledText rawText) {
174 return UIThreadRunnable.syncExec(new Result<FontData>() {
175 @Override
176 public FontData run() {
177 return rawText.widget.getFont().getFontData()[0];
178 }
179 });
180 }
181 }
This page took 0.039542 seconds and 4 git commands to generate.