1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
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
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.viewers
.events
;
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
;
21 import java
.io
.IOException
;
23 import java
.net
.URISyntaxException
;
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
.eclipse
.tracecompass
.tmf
.ui
.tests
.shared
.WaitUtils
;
47 import org
.junit
.AfterClass
;
48 import org
.junit
.BeforeClass
;
49 import org
.junit
.Test
;
50 import org
.junit
.runner
.RunWith
;
53 * SWTBot test for testing movable column feature.
55 @RunWith(SWTBotJunit4ClassRunner
.class)
56 public class FontEventEditorTest
{
58 private static final String TRACE_PROJECT_NAME
= "test";
59 private static final String COLUMN_TRACE
= "syslog_collapse";
60 private static final String COLUMN_TRACE_PATH
= "testfiles/" + COLUMN_TRACE
;
61 private static final String COLUMN_TRACE_TYPE
= "org.eclipse.linuxtools.tmf.tests.stubs.trace.text.testsyslog";
63 private static File fTestFile
= null;
65 private static SWTWorkbenchBot fBot
;
67 /** The Log4j logger instance. */
68 private static final Logger fLogger
= Logger
.getRootLogger();
74 public static void init() {
75 SWTBotUtils
.initialize();
77 /* set up test trace */
78 URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(COLUMN_TRACE_PATH
), null);
81 uri
= FileLocator
.toFileURL(location
).toURI();
82 fTestFile
= new File(uri
);
83 } catch (URISyntaxException
| IOException e
) {
87 assumeTrue(fTestFile
.exists());
89 /* Set up for swtbot */
90 SWTBotPreferences
.TIMEOUT
= 20000; /* 20 second timeout */
91 fLogger
.removeAllAppenders();
92 fLogger
.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender
.SYSTEM_OUT
));
93 fBot
= new SWTWorkbenchBot();
95 /* Close welcome view */
96 SWTBotUtils
.closeView("Welcome", fBot
);
98 /* Switch perspectives */
99 SWTBotUtils
.switchToTracingPerspective();
101 /* Finish waiting for eclipse to load */
102 WaitUtils
.waitForJobs();
106 * Test class tear down method.
109 public static void tearDown() {
110 fLogger
.removeAllAppenders();
114 * Switch the font to system then back to default.
117 public void testChangeFont() {
118 SWTBotUtils
.createProject(TRACE_PROJECT_NAME
);
120 // Open the actual trace
121 SWTBotUtils
.openTrace(TRACE_PROJECT_NAME
, fTestFile
.getAbsolutePath(), COLUMN_TRACE_TYPE
);
122 SWTBotEditor editorBot
= SWTBotUtils
.activateEditor(fBot
, fTestFile
.getName());
124 SWTBotTable tableBot
= editorBot
.bot().table();
126 // Maximize editor area
127 SWTBotUtils
.maximizeTable(tableBot
);
128 tableBot
.contextMenu("Show Raw").click();
130 tableBot
.click(4, 1);
133 SWTBotStyledText rawText
= editorBot
.bot().styledText();
135 FontData font
= getFont(rawText
);
137 SWTBotShell preferencesShell
= SWTBotUtils
.openPreferences(fBot
);
139 SWTBot bot
= preferencesShell
.bot();
140 preferencesShell
.activate();
141 bot
.text().setText("color");
143 SWTBotTreeItem generalItem
= bot
.tree().getTreeItem("General");
145 generalItem
.select();
146 bot
.waitUntil(ConditionHelpers
.IsTreeChildNodeAvailable("Appearance", generalItem
));
147 SWTBotTreeItem appearanceNode
= generalItem
.getNode("Appearance");
148 appearanceNode
.click();
149 appearanceNode
.select();
150 bot
.waitUntil(ConditionHelpers
.IsTreeChildNodeAvailable("Colors and Fonts", appearanceNode
));
151 SWTBotTreeItem colorAndFontNode
= appearanceNode
.getNode("Colors and Fonts");
152 colorAndFontNode
.click();
153 colorAndFontNode
.select();
154 SWTBotTreeItem tracingItem
= bot
.tree(1).getTreeItem("Tracing");
156 tracingItem
.select();
157 tracingItem
.expand();
158 // Get the raw viewer default which is "Text Font" and change it to "System Font"
159 SWTBotTreeItem traceEventTableFont
= tracingItem
.getNode("Trace event raw text font (set to default: Text Font)");
160 traceEventTableFont
.click();
161 traceEventTableFont
.select();
162 bot
.button("Use System Font").click();
163 bot
.button("Apply").click();
164 FontData font2
= getFont(rawText
);
165 assertFalse(font2
.equals(font
));
166 // Reset the raw viewer to the "Text Font"
167 bot
.button("Reset").click();
168 bot
.button("OK").click();
169 assertEquals(getFont(rawText
), font
);
170 fBot
.closeAllEditors();
171 SWTBotUtils
.deleteProject(TRACE_PROJECT_NAME
, fBot
);
174 private static FontData
getFont(final SWTBotStyledText rawText
) {
175 return UIThreadRunnable
.syncExec(new Result
<FontData
>() {
177 public FontData
run() {
178 return rawText
.widget
.getFont().getFontData()[0];