swtbot: Add Control Flow view tests
authorPatrick Tasse <patrick.tasse@gmail.com>
Fri, 22 May 2015 21:24:43 +0000 (17:24 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Thu, 28 May 2015 17:09:44 +0000 (13:09 -0400)
Tests involving shift-clicking a tool bar button are commented out until
this is supported by the SWTBot framework.

Change-Id: I82071d50828db282a0f5f8afa4b8974b9daf83c1
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/48502
Reviewed-by: Hudson CI
org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/AllTests.java
org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/ControlFlowViewTest.java [new file with mode: 0644]
org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/ImportAndReadKernelSmokeTest.java
org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/KernelTest.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.ui.swtbot.tests/build.properties
org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/ConditionHelpers.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java

index 26c37091c64844cc68f85a331bf5ecdcd94263f7..8a78de8bc728b6dbd6c5b501a0ab0291518094ae 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2013, 2014 Ericsson
+ * Copyright (c) 2013, 2015 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -20,8 +20,9 @@ import org.junit.runners.Suite;
  */
 @RunWith(Suite.class)
 @Suite.SuiteClasses({
-    ImportAndReadKernelSmokeTest.class,
     KernelPerspectiveChecker.class,
+    ImportAndReadKernelSmokeTest.class,
+    ControlFlowViewTest.class,
     OpenTraceStressTest.class
 })
 public class AllTests {
diff --git a/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/ControlFlowViewTest.java b/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/ControlFlowViewTest.java
new file mode 100644 (file)
index 0000000..a0a56e9
--- /dev/null
@@ -0,0 +1,385 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
+import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
+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.VoidResult;
+import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
+import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
+import org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal;
+import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
+import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
+import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent;
+import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * SWTBot tests for Control Flow view
+ *
+ * @author Patrick Tasse
+ */
+public class ControlFlowViewTest extends KernelTest {
+
+    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";
+    private static final String SELECT_NEXT_EVENT = "Select Next Event";
+    private static final Keyboard KEYBOARD = KeyboardFactory.getSWTKeyboard();
+    private static final @NonNull ITmfTimestamp START_TIME = new TmfNanoTimestamp(1368000272650993664L);
+    private static final @NonNull ITmfTimestamp TID1_TIME1 = new TmfNanoTimestamp(1368000272651208412L);
+    private static final @NonNull ITmfTimestamp TID1_TIME2 = new TmfNanoTimestamp(1368000272656147616L);
+    private static final @NonNull ITmfTimestamp TID1_TIME3 = new TmfNanoTimestamp(1368000272656362364L);
+    private static final @NonNull ITmfTimestamp TID1_TIME4 = new TmfNanoTimestamp(1368000272663234300L);
+    private static final @NonNull ITmfTimestamp TID1_TIME5 = new TmfNanoTimestamp(1368000272663449048L);
+    private static final @NonNull ITmfTimestamp TID1_TIME6 = new TmfNanoTimestamp(1368000272665596528L);
+    private static final @NonNull ITmfTimestamp TID2_TIME1 = new TmfNanoTimestamp(1368000272651852656L);
+    private static final @NonNull ITmfTimestamp TID2_TIME2 = new TmfNanoTimestamp(1368000272652067404L);
+    private static final @NonNull ITmfTimestamp TID2_TIME3 = new TmfNanoTimestamp(1368000272652282152L);
+    private static final @NonNull ITmfTimestamp TID2_TIME4 = new TmfNanoTimestamp(1368000272652496900L);
+    private static final @NonNull ITmfTimestamp TID5_TIME1 = new TmfNanoTimestamp(1368000272652496900L);
+
+    private SWTBotView fViewBot;
+
+    /**
+     * Before Test
+     */
+    @Override
+    @Before
+    public void before() {
+        super.before();
+        fViewBot = fBot.viewByTitle("Control Flow");
+    }
+
+    /**
+     * Test keyboard navigation using ARROW_RIGHT and ARROW_LEFT
+     */
+    @Test
+    public void testKeyboardLeftRight() {
+        /* change window range to 10 ms */
+        TmfTimeRange range = new TmfTimeRange(START_TIME, START_TIME.normalize(10000000L, ITmfTimestamp.NANOSECOND_SCALE));
+        TmfSignalManager.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, range));
+        fBot.waitUntil(ConditionHelpers.windowRange(range));
+
+        /* set selection to trace start time */
+        TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, START_TIME));
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(START_TIME, START_TIME)));
+
+        /* select first item */
+        final SWTBotTree tree = fViewBot.bot().tree();
+        tree.pressShortcut(Keystrokes.HOME);
+
+        /* set focus on time graph */
+        final TimeGraphControl timegraph = fViewBot.bot().widget(WidgetOfType.widgetOfType(TimeGraphControl.class));
+        UIThreadRunnable.syncExec(new VoidResult() {
+            @Override
+            public void run() {
+                timegraph.setFocus();
+            }
+        });
+
+        /* press ARROW_RIGHT 3 times */
+        KEYBOARD.pressShortcut(Keystrokes.RIGHT);
+        KEYBOARD.pressShortcut(Keystrokes.RIGHT);
+        KEYBOARD.pressShortcut(Keystrokes.RIGHT);
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME3, TID1_TIME3)));
+        assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME3));
+
+        /* press Shift-ARROW_RIGHT 3 times */
+        KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.RIGHT);
+        KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.RIGHT);
+        KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.RIGHT);
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME3, TID1_TIME6)));
+        assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME6));
+
+        /* press Shift-ARROW_LEFT 4 times */
+        KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.LEFT);
+        KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.LEFT);
+        KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.LEFT);
+        KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.LEFT);
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME3, TID1_TIME2)));
+        assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME2));
+
+        /* press ARROW_RIGHT 2 times */
+        KEYBOARD.pressShortcut(Keystrokes.RIGHT);
+        KEYBOARD.pressShortcut(Keystrokes.RIGHT);
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME4, TID1_TIME4)));
+        assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME4));
+
+        /* press Shift-ARROW_LEFT 3 times */
+        KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.LEFT);
+        KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.LEFT);
+        KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.LEFT);
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME4, TID1_TIME1)));
+        assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME1));
+
+        /* press Shift-ARROW_RIGHT 4 times */
+        KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.RIGHT);
+        KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.RIGHT);
+        KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.RIGHT);
+        KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.RIGHT);
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME4, TID1_TIME5)));
+        assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME5));
+
+        /* press ARROW_LEFT 5 times */
+        KEYBOARD.pressShortcut(Keystrokes.LEFT);
+        KEYBOARD.pressShortcut(Keystrokes.LEFT);
+        KEYBOARD.pressShortcut(Keystrokes.LEFT);
+        KEYBOARD.pressShortcut(Keystrokes.LEFT);
+        KEYBOARD.pressShortcut(Keystrokes.LEFT);
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(START_TIME, START_TIME)));
+        assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(START_TIME));
+    }
+
+    /**
+     * Test tool bar buttons "Select Next Event" and "Select Previous Event"
+     */
+    @Test
+    public void testToolBarSelectNextPreviousEvent() {
+        /* change window range to 10 ms */
+        TmfTimeRange range = new TmfTimeRange(START_TIME, START_TIME.normalize(10000000L, ITmfTimestamp.NANOSECOND_SCALE));
+        TmfSignalManager.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, range));
+        fBot.waitUntil(ConditionHelpers.windowRange(range));
+
+        /* set selection to trace start time */
+        TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, START_TIME));
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(START_TIME, START_TIME)));
+
+        /* select first item */
+        final SWTBotTree tree = fViewBot.bot().tree();
+        tree.pressShortcut(Keystrokes.HOME);
+
+        /* set focus on time graph */
+        final TimeGraphControl timegraph = fViewBot.bot().widget(WidgetOfType.widgetOfType(TimeGraphControl.class));
+        UIThreadRunnable.syncExec(new VoidResult() {
+            @Override
+            public void run() {
+                timegraph.setFocus();
+            }
+        });
+
+        /* click "Select Next Event" 3 times */
+        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
+        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
+        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME3, TID1_TIME3)));
+        assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME3));
+
+//        /* shift-click "Select Next Event" 3 times */
+//        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
+//        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
+//        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
+//        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME3, TID1_TIME6)));
+        /* click "Select Next Event" 3 times */
+        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
+        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
+        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME6, TID1_TIME6)));
+        assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME6));
+
+//        /* shift-click "Select Previous Event" 4 times */
+//        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
+//        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
+//        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
+//        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
+//        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME3, TID1_TIME2)));
+        /* click "Select Previous Event" 4 times */
+        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
+        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
+        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
+        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME2, TID1_TIME2)));
+        assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME2));
+
+        /* click "Select Next Event" 2 times */
+        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
+        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME4, TID1_TIME4)));
+        assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME4));
+
+//        /* shift-click "Select Previous Event" 3 times */
+//        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
+//        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
+//        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
+//        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME4, TID1_TIME1)));
+        /* click "Select Previous Event" 3 times */
+        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
+        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
+        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME1, TID1_TIME1)));
+        assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME1));
+
+//        /* shift-click "Select Next Event" 4 times */
+//        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
+//        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
+//        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
+//        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
+//        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME4, TID1_TIME5)));
+        /* click "Select Next Event" 4 times */
+        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
+        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
+        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
+        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME5, TID1_TIME5)));
+        assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME5));
+
+        /* click "Select Previous Event" 5 times */
+        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
+        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
+        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
+        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
+        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(START_TIME, START_TIME)));
+        assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(START_TIME));
+    }
+
+    /**
+     * Test tool bar buttons "Follow CPU Forward" and "Follow CPU Backward"
+     */
+    @Test
+    public void testToolBarFollowCPUForwardBackward() {
+        /* change window range to 10 ms */
+        TmfTimeRange range = new TmfTimeRange(START_TIME, START_TIME.normalize(10000000L, ITmfTimestamp.NANOSECOND_SCALE));
+        TmfSignalManager.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, range));
+        fBot.waitUntil(ConditionHelpers.windowRange(range));
+
+        /* set selection to trace start time */
+        TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, START_TIME));
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(START_TIME, START_TIME)));
+
+        /* select first item */
+        final SWTBotTree tree = fViewBot.bot().tree();
+        tree.pressShortcut(Keystrokes.HOME);
+
+        /* set focus on time graph */
+        final TimeGraphControl timegraph = fViewBot.bot().widget(WidgetOfType.widgetOfType(TimeGraphControl.class));
+        UIThreadRunnable.syncExec(new VoidResult() {
+            @Override
+            public void run() {
+                timegraph.setFocus();
+            }
+        });
+
+        /* make sure arrows have been computed */
+        fBot.waitUntil(new DefaultCondition() {
+            @Override
+            public boolean test() throws Exception {
+                List<ILinkEvent> arrows = timegraph.getArrows();
+                return arrows.size() >= 3 &&
+                        arrows.get(0).getTime() == TID1_TIME1.getValue() &&
+                        arrows.get(1).getTime() == TID2_TIME2.getValue() &&
+                        arrows.get(2).getTime() == TID2_TIME4.getValue();
+            }
+            @Override
+            public String getFailureMessage() {
+                return "Arrows not found";
+            }
+        });
+
+        /* click "Follow CPU Forward" 3 times */
+        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
+        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
+        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME2, TID2_TIME2)));
+        assertEquals("2", tree.selection().get(0, 1));
+        assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID2_TIME2));
+
+//        /* shift-click "Follow CPU Forward" 3 times */
+//        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
+//        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
+//        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
+//        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME2, TID5_TIME1)));
+        /* click "Follow CPU Forward" 3 times */
+        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
+        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
+        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID5_TIME1, TID5_TIME1)));
+        assertEquals("5", tree.selection().get(0, 1));
+        assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID5_TIME1));
+
+//        /* shift-click "Follow CPU Backward" 4 times */
+//        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
+//        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
+//        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
+//        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
+//        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME2, TID2_TIME1)));
+        /* click "Follow CPU Backward" 4 times */
+        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
+        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
+        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
+        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME1, TID2_TIME1)));
+        assertEquals("2", tree.selection().get(0, 1));
+        assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID2_TIME1));
+
+        /* click "Follow CPU Forward" 2 times */
+        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
+        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME3, TID2_TIME3)));
+        assertEquals("2", tree.selection().get(0, 1));
+        assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID2_TIME3));
+
+//        /* shift-click "Follow CPU Backward" 3 times */
+//        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
+//        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
+//        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
+//        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME3, TID1_TIME1)));
+        /* click "Follow CPU Backward" 3 times */
+        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
+        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
+        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME1, TID1_TIME1)));
+        assertEquals("1", tree.selection().get(0, 1));
+        assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME1));
+
+//        /* shift-click "Follow CPU Forward" 4 times */
+//        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
+//        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
+//        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
+//        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
+//        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME3, TID2_TIME4)));
+        /* click "Follow CPU Forward" 4 times */
+        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
+        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
+        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
+        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME4, TID2_TIME4)));
+        assertEquals("2", tree.selection().get(0, 1));
+        assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID2_TIME4));
+
+        /* click "Follow CPU Backward" 5 times */
+        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
+        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
+        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
+        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
+        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(START_TIME, START_TIME)));
+        assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(START_TIME));
+    }
+}
index 7650be9c9142e5afab9e058b1ea6b36c7ca2ea7c..c71f7a0f5719dced19bee2f7385d9fc22d36eac2 100644 (file)
@@ -9,19 +9,15 @@
  * Contributors:
  *   Matthew Khouzam - Initial API and implementation
  *   Marc-Andre Laperle
- *   Patrick Tasse - Add support for folder elements
+ *   Patrick Tasse - Extract base class from ImportAndReadKernelSmokeTest
  *******************************************************************************/
 
 package org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests;
 
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
 
 import java.util.List;
 
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Logger;
-import org.apache.log4j.SimpleLayout;
 import org.eclipse.jface.viewers.SelectionChangedEvent;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
@@ -29,9 +25,7 @@ import org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory;
 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
 import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
 import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
-import org.eclipse.swtbot.swt.finder.results.BoolResult;
 import org.eclipse.swtbot.swt.finder.results.VoidResult;
-import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton;
 import org.eclipse.tracecompass.analysis.os.linux.ui.views.controlflow.ControlFlowView;
 import org.eclipse.tracecompass.analysis.os.linux.ui.views.resources.ResourcesView;
@@ -42,7 +36,6 @@ import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
 import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
 import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor;
-import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
 import org.eclipse.tracecompass.tmf.ui.views.histogram.HistogramView;
 import org.eclipse.ui.IEditorPart;
@@ -50,10 +43,7 @@ import org.eclipse.ui.IEditorReference;
 import org.eclipse.ui.IViewPart;
 import org.eclipse.ui.IViewReference;
 import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.WorkbenchException;
 import org.hamcrest.Matcher;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -63,96 +53,23 @@ import org.junit.runner.RunWith;
  * @author Matthew Khouzam
  */
 @RunWith(SWTBotJunit4ClassRunner.class)
-public class ImportAndReadKernelSmokeTest {
+public class ImportAndReadKernelSmokeTest extends KernelTest {
 
-    private static final String TRACE_TYPE = "org.eclipse.linuxtools.lttng2.kernel.tracetype";
-    private static final String KERNEL_PERSPECTIVE_ID = "org.eclipse.linuxtools.lttng2.kernel.ui.perspective";
-    private static final String TRACE_PROJECT_NAME = "test";
     private static final CtfTmfTestTrace CTT = CtfTmfTestTrace.SYNTHETIC_TRACE;
 
-    private static SWTWorkbenchBot fBot;
     private ITmfEvent fDesired1;
     private ITmfEvent fDesired2;
 
-    /** The Log4j logger instance. */
-    private static final Logger fLogger = Logger.getRootLogger();
-
-    /**
-     * Test Class setup
-     */
-    @BeforeClass
-    public static void init() {
-        SWTBotUtils.failIfUIThread();
-
-        /* set up for swtbot */
-        SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
-        fLogger.removeAllAppenders();
-        fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
-        fBot = new SWTWorkbenchBot();
-
-        final List<SWTBotView> openViews = fBot.views();
-        for (SWTBotView view : openViews) {
-            if (view.getTitle().equals("Welcome")) {
-                view.close();
-                fBot.waitUntil(ConditionHelpers.ViewIsClosed(view));
-            }
-        }
-        /* Switch perspectives */
-        switchKernelPerspective();
-        /* Finish waiting for eclipse to load */
-        SWTBotUtils.waitForJobs();
-    }
-
-    /**
-     * Test Class teardown
-     */
-    @AfterClass
-    public static void terminate() {
-        fLogger.removeAllAppenders();
-    }
-
-    private static void switchKernelPerspective() {
-        final Exception retE[] = new Exception[1];
-        if (!UIThreadRunnable.syncExec(new BoolResult() {
-            @Override
-            public Boolean run() {
-                try {
-                    PlatformUI.getWorkbench().showPerspective(KERNEL_PERSPECTIVE_ID,
-                            PlatformUI.getWorkbench().getActiveWorkbenchWindow());
-                } catch (WorkbenchException e) {
-                    retE[0] = e;
-                    return false;
-                }
-                return true;
-            }
-        })) {
-            fail(retE[0].getMessage());
-        }
-
-    }
-
     /**
      * Main test case
      */
     @Test
     public void test() {
-        SWTBotUtils.createProject(TRACE_PROJECT_NAME);
-        SWTBotUtils.openTrace(TRACE_PROJECT_NAME, CTT.getPath(), TRACE_TYPE);
-        openEditor();
-        testHV(getViewPart("Histogram"));
-        testCFV((ControlFlowView) getViewPart("Control Flow"));
-        testRV((ResourcesView) getViewPart("Resources"));
-
-        fBot.closeAllEditors();
-        SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot);
-    }
-
-    private void openEditor() {
         Matcher<IEditorReference> matcher = WidgetMatcherFactory.withPartName(CTT.getTrace().getName());
         IEditorPart iep = fBot.editor(matcher).getReference().getEditor(true);
+        final TmfEventsEditor tmfEd = (TmfEventsEditor) iep;
         fDesired1 = getEvent(100);
         fDesired2 = getEvent(10000);
-        final TmfEventsEditor tmfEd = (TmfEventsEditor) iep;
         UIThreadRunnable.syncExec(new VoidResult() {
             @Override
             public void run() {
@@ -160,10 +77,9 @@ public class ImportAndReadKernelSmokeTest {
                 tmfEd.selectionChanged(new SelectionChangedEvent(tmfEd, new StructuredSelection(fDesired1)));
             }
         });
-
-        SWTBotUtils.waitForJobs();
-        SWTBotUtils.delay(1000);
-        assertNotNull(tmfEd);
+        testHV(getViewPart("Histogram"));
+        testCFV((ControlFlowView) getViewPart("Control Flow"));
+        testRV((ResourcesView) getViewPart("Resources"));
     }
 
     private static void testCFV(ControlFlowView vp) {
diff --git a/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/KernelTest.java b/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/KernelTest.java
new file mode 100644 (file)
index 0000000..ef19434
--- /dev/null
@@ -0,0 +1,132 @@
+/*******************************************************************************
+ * Copyright (c) 2013, 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Matthew Khouzam - Initial API and implementation
+ *   Marc-Andre Laperle
+ *   Patrick Tasse - Extract base class from ImportAndReadKernelSmokeTest
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests;
+
+import static org.junit.Assert.fail;
+
+import java.util.List;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Logger;
+import org.apache.log4j.SimpleLayout;
+import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
+import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.results.BoolResult;
+import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
+import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
+import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
+import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.WorkbenchException;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.runner.RunWith;
+
+/**
+ * Base SWTBot test for LTTng Kernel UI.
+ *
+ * @author Matthew Khouzam
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class KernelTest {
+
+    private static final String TRACE_TYPE = "org.eclipse.linuxtools.lttng2.kernel.tracetype";
+    private static final String KERNEL_PERSPECTIVE_ID = "org.eclipse.linuxtools.lttng2.kernel.ui.perspective";
+    private static final String TRACE_PROJECT_NAME = "test";
+    private static final CtfTmfTestTrace CTT = CtfTmfTestTrace.SYNTHETIC_TRACE;
+
+    /** The workbench bot */
+    protected static SWTWorkbenchBot fBot;
+
+    /** The Log4j logger instance. */
+    private static final Logger fLogger = Logger.getRootLogger();
+
+    /**
+     * Before Class
+     */
+    @BeforeClass
+    public static void beforeClass() {
+        SWTBotUtils.failIfUIThread();
+
+        /* set up for swtbot */
+        SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
+        fLogger.removeAllAppenders();
+        fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
+        fBot = new SWTWorkbenchBot();
+
+        final List<SWTBotView> openViews = fBot.views();
+        for (SWTBotView view : openViews) {
+            if (view.getTitle().equals("Welcome")) {
+                view.close();
+                fBot.waitUntil(ConditionHelpers.ViewIsClosed(view));
+            }
+        }
+        /* Switch perspectives */
+        switchKernelPerspective();
+        /* Finish waiting for eclipse to load */
+        SWTBotUtils.waitForJobs();
+        SWTBotUtils.createProject(TRACE_PROJECT_NAME);
+    }
+
+    /**
+     * After Class
+     */
+    @AfterClass
+    public static void afterClass() {
+        SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot);
+        fLogger.removeAllAppenders();
+    }
+
+    private static void switchKernelPerspective() {
+        final Exception retE[] = new Exception[1];
+        if (!UIThreadRunnable.syncExec(new BoolResult() {
+            @Override
+            public Boolean run() {
+                try {
+                    PlatformUI.getWorkbench().showPerspective(KERNEL_PERSPECTIVE_ID,
+                            PlatformUI.getWorkbench().getActiveWorkbenchWindow());
+                } catch (WorkbenchException e) {
+                    retE[0] = e;
+                    return false;
+                }
+                return true;
+            }
+        })) {
+            fail(retE[0].getMessage());
+        }
+
+    }
+
+    /**
+     * Before Test
+     */
+    @Before
+    public void before() {
+        SWTBotUtils.openTrace(TRACE_PROJECT_NAME, CTT.getPath(), TRACE_TYPE);
+        SWTBotUtils.activateEditor(fBot, CTT.getTrace().getName());
+    }
+
+    /**
+     * After Test
+     */
+    @After
+    public void after() {
+        fBot.closeAllEditors();
+    }
+}
index 90c4c80cb6d830fe490af5f012e1c7f7f74aecd0..ca5450db7ba990e5acbeea22b9efeab199a66866 100644 (file)
@@ -19,3 +19,5 @@ bin.includes = META-INF/,\
                about.html,\
                plugin.xml
 src.includes = about.html
+additional.bundles = org.eclipse.jdt.annotation
+jars.extra.classpath = platform:/plugin/org.eclipse.jdt.annotation
index 5923be38e792179e1accf5748562e180fd18801a..ef7d191334d253b9bc696e7f92af4c0b5df38e38 100644 (file)
@@ -29,6 +29,8 @@ import org.eclipse.swtbot.swt.finder.waits.ICondition;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
 import org.eclipse.ui.IEditorReference;
 import org.hamcrest.Matcher;
 
@@ -54,7 +56,7 @@ public final class ConditionHelpers {
         }
 
         @Override
-        public final String getFailureMessage() {
+        public String getFailureMessage() {
             return null;
         }
     }
@@ -295,4 +297,48 @@ public final class ConditionHelpers {
             }
         };
     }
+
+    /**
+     * Condition to check if the selection range equals the specified range.
+     *
+     * @param range
+     *            the selection range
+     * @return ICondition for verification
+     */
+    public static ICondition selectionRange(final TmfTimeRange range) {
+        return new SWTBotTestCondition() {
+            @Override
+            public boolean test() throws Exception {
+                return TmfTraceManager.getInstance().getCurrentTraceContext().getSelectionRange().equals(range);
+            }
+
+            @Override
+            public String getFailureMessage() {
+                return NLS.bind("Selection range: {0} expected: {1}",
+                        TmfTraceManager.getInstance().getCurrentTraceContext().getSelectionRange(), range);
+            }
+        };
+    }
+
+    /**
+     * Condition to check if the window range equals the specified range.
+     *
+     * @param range
+     *            the window range
+     * @return ICondition for verification
+     */
+    public static ICondition windowRange(final TmfTimeRange range) {
+        return new SWTBotTestCondition() {
+            @Override
+            public boolean test() throws Exception {
+                return TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().equals(range);
+            }
+
+            @Override
+            public String getFailureMessage() {
+                return NLS.bind("Window range: {0} expected: {1}",
+                        TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange(), range);
+            }
+        };
+    }
 }
index f7ea5e3fc55f2c1c4af58393e577c91147e4a477..256327c04ec75ec6805d6578d12eed4518b380e4 100644 (file)
@@ -22,6 +22,7 @@ package org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -407,12 +408,23 @@ public class TimeGraphControl extends TimeGraphBaseControl
     /**
      * Refresh the links (arrows) of this widget
      *
-     * @param events The link events to refresh
+     * @param events The link event list
      */
     public void refreshArrows(List<ILinkEvent> events) {
         fItemData.refreshArrows(events);
     }
 
+    /**
+     * Get the links (arrows) of this widget
+     *
+     * @return The unmodifiable link event list
+     *
+     * @since 1.0
+     */
+    public List<ILinkEvent> getArrows() {
+        return Collections.unmodifiableList(fItemData.fLinks);
+    }
+
     boolean ensureVisibleItem(int idx, boolean redraw) {
         boolean changed = false;
         int index = idx;
This page took 0.036313 seconds and 5 git commands to generate.