tmf.ui: add test for Control Flow view dialogs
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Tue, 12 Jan 2016 12:40:02 +0000 (07:40 -0500)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 27 Jan 2016 21:14:15 +0000 (16:14 -0500)
Change-Id: I433af57a2a2e713bc1c74a712d7d1b927c48c838
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/64119
Reviewed-by: Hudson CI
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tested-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
lttng/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/ControlFlowViewTest.java

index 76ec140cd7451629a4ecbb6d35a817133728b17c..f78c30b5270d42861f417afa8c4cb6b2ad7123f9 100644 (file)
 
 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;
@@ -48,6 +55,43 @@ import org.junit.runner.RunWith;
 @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";
@@ -202,6 +246,96 @@ public class ControlFlowViewTest extends KernelTestBase {
         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"
      */
This page took 0.042449 seconds and 5 git commands to generate.