package org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
+import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.keyboard.Keyboard;
import org.eclipse.swtbot.swt.finder.keyboard.KeyboardFactory;
import org.eclipse.swtbot.swt.finder.keyboard.Keystrokes;
import org.eclipse.swtbot.swt.finder.matchers.WidgetOfType;
+import org.eclipse.swtbot.swt.finder.results.Result;
import org.eclipse.swtbot.swt.finder.results.VoidResult;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotLabel;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
@RunWith(SWTBotJunit4ClassRunner.class)
public class ControlFlowViewTest extends KernelTestBase {
+ private static final String CHECK_SELECTED = "Check selected";
+ private static final String CHECK_ALL = "Check all";
+ private static final String CHECK_SUBTREE = "Check subtree";
+ private static final String CHECK_ACTIVE = "Check Active";
+ private static final String UNCHECK_SELECTED = "Uncheck selected";
+ private static final String UNCHECK_ALL = "Uncheck all";
+ private static final String UNCHECK_SUBTREE = "Uncheck subtree";
+ private static final String UNCHECK_INACTIVE = "Uncheck Inactive";
+
+ private static final class TreeCheckedCounter implements Result<Integer> {
+ private final SWTBotTree fTreeBot;
+
+ private TreeCheckedCounter(SWTBotTree treeBot) {
+ fTreeBot = treeBot;
+ }
+
+ @Override
+ public Integer run() {
+ int checked = 0;
+ for (TreeItem item : fTreeBot.widget.getItems()) {
+ checked += getChecked(item);
+ }
+ return checked;
+ }
+
+ private int getChecked(TreeItem item) {
+ int total = 0;
+ if (item.getChecked()) {
+ total++;
+ }
+ for (TreeItem child : item.getItems()) {
+ total += getChecked(child);
+ }
+ return total;
+ }
+ }
+
private static final String FOLLOW_CPU_BACKWARD = "Follow CPU Backward";
private static final String FOLLOW_CPU_FORWARD = "Follow CPU Forward";
private static final String SELECT_PREVIOUS_EVENT = "Select Previous Event";
assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(START_TIME));
}
+ /**
+ * Test the legend content
+ */
+ @Test
+ public void testLegend() {
+ String[] labelValues = { "UNKNOWN", "WAIT_UNKNOWN", "WAIT_BLOCKED", "WAIT_FOR_CPU", "USERMODE", "SYSCALL", "INTERRUPTED" };
+ SWTBotToolbarButton legendButton = fViewBot.toolbarButton("Show Legend");
+ legendButton.click();
+ fBot.waitUntil(org.eclipse.swtbot.swt.finder.waits.Conditions.shellIsActive("States Transition Visualizer"));
+ SWTBot bot = fBot.activeShell().bot();
+ for (int i = 1; i < 8; i++) {
+ SWTBotLabel label = bot.label(i);
+ assertNotNull(label);
+ assertEquals(labelValues[i - 1], label.getText());
+ }
+ bot.button("OK").click();
+ }
+
+ /**
+ * Test the filter
+ */
+ @Test
+ public void testFilter() {
+ /* change window range to 1 ms */
+ TmfTimeRange range = new TmfTimeRange(START_TIME, START_TIME.normalize(1000000L, ITmfTimestamp.NANOSECOND_SCALE));
+ TmfSignalManager.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, range));
+ fBot.waitUntil(ConditionHelpers.windowRange(range));
+
+ SWTBotToolbarButton filterButton = fViewBot.toolbarButton("Show View Filters");
+ filterButton.click();
+ fBot.waitUntil(org.eclipse.swtbot.swt.finder.waits.Conditions.shellIsActive("Filter"));
+ SWTBot bot = fBot.activeShell().bot();
+ SWTBotTree treeBot = bot.tree();
+ TreeCheckedCounter treeCheckCounter = new TreeCheckedCounter(treeBot);
+ // get how many items there are
+ Integer checked = UIThreadRunnable.syncExec(treeCheckCounter);
+ assertEquals("default", 200, checked.intValue());
+ // test "uncheck all button"
+ bot.button(UNCHECK_ALL).click();
+ checked = UIThreadRunnable.syncExec(treeCheckCounter);
+ assertEquals(0, checked.intValue());
+ // test check active
+ bot.button(CHECK_ACTIVE).click();
+ checked = UIThreadRunnable.syncExec(treeCheckCounter);
+ assertEquals(CHECK_ACTIVE, 43, checked.intValue());
+ // test check all
+ bot.button(CHECK_ALL).click();
+ checked = UIThreadRunnable.syncExec(treeCheckCounter);
+ assertEquals(CHECK_ALL, 200, checked.intValue());
+ // test uncheck inactive
+ bot.button(UNCHECK_INACTIVE).click();
+ checked = UIThreadRunnable.syncExec(treeCheckCounter);
+ assertEquals(UNCHECK_INACTIVE, 43, checked.intValue());
+ // test check selected
+ treeBot.select(1);
+ bot.button(UNCHECK_ALL).click();
+ bot.button(CHECK_SELECTED).click();
+ checked = UIThreadRunnable.syncExec(treeCheckCounter);
+ assertEquals(CHECK_SELECTED, 1, checked.intValue());
+ // test check subtree
+ bot.button(UNCHECK_ALL).click();
+ bot.button(CHECK_SUBTREE).click();
+ checked = UIThreadRunnable.syncExec(treeCheckCounter);
+ assertEquals(CHECK_SUBTREE, 1, checked.intValue());
+ // test uncheck selected
+ bot.button(CHECK_ALL).click();
+ bot.button(UNCHECK_SELECTED).click();
+ checked = UIThreadRunnable.syncExec(treeCheckCounter);
+ assertEquals(UNCHECK_SELECTED, 199, checked.intValue());
+ // test uncheck subtree
+ bot.button(CHECK_ALL).click();
+ bot.button(UNCHECK_SUBTREE).click();
+ checked = UIThreadRunnable.syncExec(treeCheckCounter);
+ assertEquals(UNCHECK_SELECTED, 199, checked.intValue());
+ // test filter
+ bot.button(UNCHECK_ALL).click();
+ checked = UIThreadRunnable.syncExec(treeCheckCounter);
+ assertEquals(0, checked.intValue());
+ bot.text().setText("half-life 3");
+ fBot.waitUntil(org.eclipse.swtbot.swt.finder.waits.Conditions.treeHasRows(treeBot, 25));
+ bot.button(CHECK_ALL).click();
+ checked = UIThreadRunnable.syncExec(treeCheckCounter);
+ assertEquals("Filtered", 25, checked.intValue());
+ bot.button("OK").click();
+ treeBot = fViewBot.bot().tree();
+ for (int i = 0; i < 25; i++) {
+ assertEquals("Filtered Control flow view", "Half-life 3", treeBot.cell(i, 0));
+ }
+ }
+
/**
* Test tool bar buttons "Follow CPU Forward" and "Follow CPU Backward"
*/