Commit | Line | Data |
---|---|---|
976af99f MK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2016 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 | ||
10 | package org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests; | |
11 | ||
12 | import static org.junit.Assert.assertEquals; | |
13 | import static org.junit.Assert.assertNotNull; | |
14 | import static org.junit.Assert.assertTrue; | |
15 | ||
16 | import java.util.ArrayList; | |
17 | import java.util.List; | |
18 | ||
19 | import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; | |
20 | import org.eclipse.swtbot.swt.finder.SWTBot; | |
21 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotLabel; | |
22 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton; | |
23 | import org.junit.Test; | |
24 | ||
25 | /** | |
26 | * Kernel based time graph view test base. Used to test time graph views using | |
27 | * kernel traces | |
28 | * | |
29 | * @author Matthew Khouzam | |
30 | * | |
31 | */ | |
32 | public abstract class KernelTimeGraphViewTestBase extends KernelTestBase { | |
33 | ||
34 | /** | |
35 | * Tooltip used for separator toolbar items | |
36 | */ | |
37 | protected static final String SEPARATOR = ""; | |
38 | ||
39 | /** | |
40 | * Get an SWTBotView of the view being tested | |
41 | * | |
42 | * @return a bot of the view being tested | |
43 | */ | |
44 | protected abstract SWTBotView getViewBot(); | |
45 | ||
46 | /** | |
47 | * Get the tool bar tool tip text values in order | |
48 | * | |
49 | * @return the tool bar tool tip text values in order | |
50 | */ | |
51 | protected abstract List<String> getToolbarTooltips(); | |
52 | ||
53 | /** | |
54 | * Get the legend text values in order | |
55 | * | |
56 | * @return the legend text values in order | |
57 | */ | |
58 | protected abstract List<String> getLegendValues(); | |
59 | ||
60 | /** | |
61 | * Test toolbar button order and that all buttons are enabled and visible | |
62 | */ | |
63 | @Test | |
64 | public void testToolbar() { | |
65 | List<SWTBotToolbarButton> buttons = getViewBot().getToolbarButtons(); | |
66 | List<String> tooltipsExpected = getToolbarTooltips(); | |
67 | List<String> tooltips = new ArrayList<>(); | |
68 | for (SWTBotToolbarButton button : buttons) { | |
69 | tooltips.add(button.getToolTipText()); | |
70 | assertTrue(button.getText() + " enabled", button.isEnabled()); | |
71 | assertTrue(button.getText() + " visible", button.isVisible()); | |
72 | } | |
73 | assertEquals(tooltipsExpected, tooltips); | |
74 | } | |
75 | ||
76 | /** | |
77 | * Test the legend content | |
78 | */ | |
79 | @Test | |
80 | public void testLegend() { | |
81 | List<String> labelValues = getLegendValues(); | |
82 | SWTBotToolbarButton legendButton = getViewBot().toolbarButton("Show Legend"); | |
83 | legendButton.click(); | |
84 | fBot.waitUntil(org.eclipse.swtbot.swt.finder.waits.Conditions.shellIsActive("States Transition Visualizer")); | |
85 | SWTBot bot = fBot.activeShell().bot(); | |
86 | for (int i = 1; i <= labelValues.size(); i++) { | |
87 | SWTBotLabel label = bot.label(i); | |
88 | assertNotNull(label); | |
89 | assertEquals(labelValues.get(i - 1), label.getText()); | |
90 | } | |
91 | bot.button("OK").click(); | |
92 | } | |
93 | ||
94 | } |