timing.core/ui/tests: add function density test
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Mon, 24 Oct 2016 15:39:25 +0000 (11:39 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Tue, 15 Nov 2016 14:39:17 +0000 (09:39 -0500)
This is a unit test for the function density view.

Change-Id: I296d6f33fd4b81b99363cf3de5a280fb9ef04c68
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/83794
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
analysis/org.eclipse.tracecompass.analysis.timing.core.tests/src/org/eclipse/tracecompass/analysis/timing/core/tests/flamegraph/AggregationTreeTest.java
analysis/org.eclipse.tracecompass.analysis.timing.ui.swtbot.tests/META-INF/MANIFEST.MF
analysis/org.eclipse.tracecompass.analysis.timing.ui.swtbot.tests/src/org/eclipse/tracecompass/analysis/timing/ui/swtbot/tests/callgraph/CallGraphDensityViewTest.java [new file with mode: 0644]
analysis/org.eclipse.tracecompass.analysis.timing.ui.swtbot.tests/src/org/eclipse/tracecompass/analysis/timing/ui/swtbot/tests/flamegraph/FlameGraphTest.java
analysis/org.eclipse.tracecompass.analysis.timing.ui/META-INF/MANIFEST.MF
analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/density/AbstractSegmentStoreDensityView.java
analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/density/AbstractSegmentStoreDensityViewer.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/SWTBotUtils.java

index 4554c32158461d6bf8561ede1d0bb36ca225b45d..bea1d1ca7bd5a633b3cf16b7e91928712d51d492 100644 (file)
@@ -13,7 +13,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
-import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -24,6 +24,7 @@ import org.eclipse.tracecompass.common.core.NonNullUtils;
 import org.eclipse.tracecompass.internal.analysis.timing.core.callgraph.AggregatedCalledFunction;
 import org.eclipse.tracecompass.internal.analysis.timing.core.callgraph.CallGraphAnalysis;
 import org.eclipse.tracecompass.internal.analysis.timing.core.callgraph.ThreadNode;
+import org.eclipse.tracecompass.segmentstore.core.ISegment;
 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
 import org.eclipse.tracecompass.statesystem.core.StateSystemFactory;
@@ -33,6 +34,8 @@ import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
 import org.eclipse.tracecompass.tmf.core.segment.ISegmentAspect;
 import org.junit.Test;
 
+import com.google.common.collect.ImmutableList;
+
 /**
  * Test the CallGraphAnalysis.This creates a virtual state system in each test
  * and tests the aggregation tree returned by the CallGraphAnalysis.
@@ -61,6 +64,28 @@ public class AggregationTreeTest {
      */
     private class CGAnalysis extends CallGraphAnalysis {
 
+        private final class HelloAspect implements ISegmentAspect {
+            @Override
+            public @NonNull String getName() {
+                return "aspect name";
+            }
+
+            @Override
+            public @NonNull String getHelpText() {
+                return "aspect help";
+            }
+
+            @Override
+            public @Nullable Comparator<?> getComparator() {
+                return null;
+            }
+
+            @Override
+            public @Nullable Object resolve(@NonNull ISegment segment) {
+                return "Hello";
+            }
+        }
+
         @Override
         protected boolean iterateOverStateSystem(@Nullable ITmfStateSystem ss, String[] threadsPattern, String[] processesPattern, String[] callStackPath, IProgressMonitor monitor) {
             return super.iterateOverStateSystem(ss, threadsPattern, processesPattern, callStackPath, monitor);
@@ -68,7 +93,9 @@ public class AggregationTreeTest {
 
         @Override
         public @NonNull Iterable<@NonNull ISegmentAspect> getSegmentAspects() {
-            return Collections.EMPTY_LIST;
+            ImmutableList<@NonNull ISegmentAspect> aspectList = ImmutableList.of(new HelloAspect());
+            assertNotNull(aspectList);
+            return aspectList;
         }
 
     }
index 605890831440bd2e75004a3eefd7d2b25c613d9a..f9946adf715c4ec3371e9ebc6be962bb50959ff4 100644 (file)
@@ -7,7 +7,8 @@ Bundle-Localization: plugin
 Bundle-SymbolicName: org.eclipse.tracecompass.analysis.timing.ui.swtbot.tests;singleton:=true
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
-Export-Package: org.eclipse.tracecompass.analysis.timing.ui.swtbot.tests.flamegraph;x-internal:=true,
+Export-Package: org.eclipse.tracecompass.analysis.timing.ui.swtbot.tests.callgraph;x-internal:=true,
+ org.eclipse.tracecompass.analysis.timing.ui.swtbot.tests.flamegraph;x-internal:=true,
  org.eclipse.tracecompass.analysis.timing.ui.swtbot.tests.table
 Require-Bundle: org.apache.log4j,
  org.eclipse.core.resources,
diff --git a/analysis/org.eclipse.tracecompass.analysis.timing.ui.swtbot.tests/src/org/eclipse/tracecompass/analysis/timing/ui/swtbot/tests/callgraph/CallGraphDensityViewTest.java b/analysis/org.eclipse.tracecompass.analysis.timing.ui.swtbot.tests/src/org/eclipse/tracecompass/analysis/timing/ui/swtbot/tests/callgraph/CallGraphDensityViewTest.java
new file mode 100644 (file)
index 0000000..6c8cfe4
--- /dev/null
@@ -0,0 +1,287 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.analysis.timing.ui.swtbot.tests.callgraph;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Logger;
+import org.apache.log4j.SimpleLayout;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+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.results.Result;
+import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotCanvas;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
+import org.eclipse.tracecompass.analysis.timing.core.segmentstore.ISegmentStoreProvider;
+import org.eclipse.tracecompass.analysis.timing.core.segmentstore.statistics.SegmentStoreStatistics;
+import org.eclipse.tracecompass.analysis.timing.core.tests.flamegraph.AggregationTreeTest;
+import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.density.AbstractSegmentStoreDensityViewer;
+import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.density.ISegmentStoreDensityViewerDataListener;
+import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.table.AbstractSegmentStoreTableViewer;
+import org.eclipse.tracecompass.internal.analysis.timing.ui.callgraph.CallGraphDensityView;
+import org.eclipse.tracecompass.segmentstore.core.BasicSegment;
+import org.eclipse.tracecompass.segmentstore.core.ISegment;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
+import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
+import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
+import org.eclipse.ui.IViewPart;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.swtchart.ISeries;
+
+/**
+ * Test the call graph density view, known as the Function Density view. The
+ * density view can change its data with respect to screen resolution, so
+ * descriptive statistics are used to check validity. This is one of the rare
+ * occasions that the error in the
+ * {@link Assert#assertEquals(double, double, double)} is actually quite useful
+ *
+ * @author Matthew Khouzam
+ */
+public class CallGraphDensityViewTest extends AggregationTreeTest {
+
+    private static final String CALLGRAPHDENSITY_ID = CallGraphDensityView.ID;
+
+    private final @NonNull ISegmentStoreDensityViewerDataListener fSyncListener = new ISegmentStoreDensityViewerDataListener() {
+        @Override
+        public void dataChanged(List<ISegment> newData) {
+            fLatch.countDown();
+        }
+
+        @Override
+        public void dataSelectionChanged(@Nullable List<@NonNull ISegment> newSelectionData) {
+            // do nothing
+        }
+
+    };
+    private SWTWorkbenchBot fBot;
+    private SWTBotView fView;
+    private CallGraphDensityView fFuncDensityView;
+    private SWTBotTable fTableBot;
+    private SWTBotCanvas fDensityBot;
+    private AbstractSegmentStoreDensityViewer fDensityViewer;
+    private AbstractSegmentStoreTableViewer fTableViewer;
+    private CountDownLatch fLatch;
+
+    /** The Log4j logger instance. */
+    private static final Logger fLogger = Logger.getRootLogger();
+
+    /**
+     * Initialization
+     */
+    @BeforeClass
+    public static void beforeClass() {
+
+        SWTBotUtils.initialize();
+        Thread.currentThread().setName("SWTBotTest");
+        /* set up for swtbot */
+        SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
+        SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
+        fLogger.removeAllAppenders();
+        fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
+        SWTWorkbenchBot bot = new SWTWorkbenchBot();
+        SWTBotUtils.closeView("welcome", bot);
+        /* Switch perspectives */
+        SWTBotUtils.switchToTracingPerspective();
+        /* Finish waiting for eclipse to load */
+        WaitUtils.waitForJobs();
+    }
+
+    /**
+     * Setup for the test
+     */
+    @Before
+    public void before() {
+        fBot = new SWTWorkbenchBot();
+        SWTBotUtils.openView(CALLGRAPHDENSITY_ID);
+        SWTBotView view = fBot.viewById(CALLGRAPHDENSITY_ID);
+        assertNotNull(view);
+        fView = view;
+        CallGraphDensityView funcDensityView = UIThreadRunnable.syncExec((Result<CallGraphDensityView>) () -> {
+            IViewPart viewRef = fView.getViewReference().getView(true);
+            return (viewRef instanceof CallGraphDensityView) ? (CallGraphDensityView) viewRef : null;
+        });
+        assertNotNull(funcDensityView);
+        fTableBot = fView.bot().table();
+        assertNotNull(fTableBot);
+        fDensityBot = fView.bot().canvas();
+        assertNotNull(fDensityBot);
+        fDensityViewer = funcDensityView.getDensityViewer();
+        assertNotNull(fDensityViewer);
+        fLatch = new CountDownLatch(1);
+        fDensityViewer.removeDataListener(fSyncListener);
+        fDensityViewer.addDataListener(fSyncListener);
+        fTableViewer = funcDensityView.getTableViewer();
+        assertNotNull(fTableViewer);
+        SWTBotUtils.maximize(funcDensityView);
+        fFuncDensityView = funcDensityView;
+    }
+
+    /**
+     * Reset
+     */
+    @After
+    public void after() {
+        CallGraphDensityView funcDensityView = fFuncDensityView;
+        assertNotNull(funcDensityView);
+        SWTBotUtils.maximize(funcDensityView);
+
+    }
+
+    @Override
+    public void emptyStateSystemTest() {
+        super.emptyStateSystemTest();
+        loadData();
+        assertEquals(0, fTableBot.rowCount());
+        ISeries series = getSeries();
+        assertNotNull(series);
+    }
+
+    @Override
+    public void cascadeTest() {
+        super.cascadeTest();
+        loadData();
+        assertEquals(3, fTableBot.rowCount());
+        ISeries series = getSeries();
+        SegmentStoreStatistics sss = getDescriptiveStatistics(series);
+        assertEquals(3.0, sss.getTotal(), 0.0);
+        assertEquals(0.02, sss.getAverage(), 0.02); // low mean
+    }
+
+    @Override
+    public void mergeFirstLevelCalleesTest() {
+        super.mergeFirstLevelCalleesTest();
+        loadData();
+        assertEquals(5, fTableBot.rowCount());
+        ISeries series = getSeries();
+        SegmentStoreStatistics sss = getDescriptiveStatistics(series);
+        assertEquals(5.0, sss.getTotal(), 0.0);
+        assertEquals(0.02, sss.getAverage(), 0.03); // low mean
+    }
+
+    @Override
+    public void multiFunctionRootsSecondTest() {
+        super.multiFunctionRootsSecondTest();
+        loadData();
+        assertEquals(4, fTableBot.rowCount());
+        ISeries series = getSeries();
+        SegmentStoreStatistics sss = getDescriptiveStatistics(series);
+        assertEquals(4.0, sss.getTotal(), 0.0);
+        assertEquals(0.02, sss.getAverage(), 0.02); // low mean
+    }
+
+    @Override
+    public void mergeSecondLevelCalleesTest() {
+        super.mergeSecondLevelCalleesTest();
+        loadData();
+        assertEquals(8, fTableBot.rowCount());
+        ISeries series = getSeries();
+        double[] ySeries = series.getYSeries();
+        assertNotNull(ySeries);
+        SegmentStoreStatistics sss = getDescriptiveStatistics(series);
+        assertEquals(8.0, sss.getTotal(), 0.0);
+        assertEquals(0.06, sss.getAverage(), 0.02); // average mean
+    }
+
+    @Override
+    public void multiFunctionRootsTest() {
+        super.multiFunctionRootsTest();
+        loadData();
+        assertEquals(4, fTableBot.rowCount());
+        ISeries series = getSeries();
+        double[] ySeries = series.getYSeries();
+        assertNotNull(ySeries);
+        SegmentStoreStatistics sss = getDescriptiveStatistics(series);
+        assertEquals(4.0, sss.getTotal(), 0.0);
+        assertEquals(0.02, sss.getAverage(), 0.02); // low mean
+    }
+
+    @Override
+    public void treeTest() {
+        super.treeTest();
+        loadData();
+        assertEquals(4, fTableBot.rowCount());
+        ISeries series = getSeries();
+        double[] ySeries = series.getYSeries();
+        assertNotNull(ySeries);
+        SegmentStoreStatistics sss = getDescriptiveStatistics(series);
+        assertEquals(4.0, sss.getTotal(), 0.0);
+        assertEquals(0.02, sss.getAverage(), 0.02); // low mean
+    }
+
+    @Override
+    public void largeTest() {
+        super.largeTest();
+        loadData();
+        assertEquals(1000, fTableBot.rowCount());
+        ISeries series = getSeries();
+        double[] ySeries = series.getYSeries();
+        assertNotNull(ySeries);
+        SegmentStoreStatistics sss = getDescriptiveStatistics(series);
+        assertEquals(1000.0, sss.getTotal(), 0.0);
+        assertEquals(8, sss.getAverage(), 1); // high mean
+    }
+
+    private ISeries getSeries() {
+        AbstractSegmentStoreDensityViewer densityViewer = fDensityViewer;
+        assertNotNull(densityViewer);
+        ISeries[] serieses = densityViewer.getControl().getSeriesSet().getSeries();
+        assertNotNull(serieses);
+        assertTrue(serieses.length > 0);
+        ISeries series = serieses[0];
+        assertNotNull(series);
+        return series;
+    }
+
+    private void loadData() {
+        final ISegmentStoreProvider cga = getCga();
+        UIThreadRunnable.syncExec(() -> {
+            fTableViewer.setData(cga);
+            fDensityViewer.setSegmentProvider(cga);
+            fDensityViewer.updateWithRange(TmfTimeRange.ETERNITY);
+            fDensityViewer.refresh();
+        });
+        if (cga != null) {
+            try {
+                /*
+                 * timeout of the test
+                 */
+                assertTrue(fLatch.await(20, TimeUnit.SECONDS));
+            } catch (InterruptedException e) {
+                fail(e.getMessage());
+            }
+        }
+
+    }
+
+    private static SegmentStoreStatistics getDescriptiveStatistics(ISeries series) {
+        double[] ySeries = series.getYSeries();
+        assertNotNull(ySeries);
+        SegmentStoreStatistics sss = new SegmentStoreStatistics();
+        for (double item : ySeries) {
+            sss.update(new BasicSegment(0, (long) (item - 1.0)));
+        }
+        return sss;
+    }
+
+}
index 1198574e68bcf8d06fa33d382171b31c2bf4e1b5..130a5a23b43f689c319c05b007398c3d3d667f62 100644 (file)
@@ -24,12 +24,7 @@ import java.util.stream.StreamSupport;
 import org.apache.log4j.ConsoleAppender;
 import org.apache.log4j.Logger;
 import org.apache.log4j.SimpleLayout;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.NotEnabledException;
-import org.eclipse.core.commands.NotHandledException;
-import org.eclipse.core.commands.common.NotDefinedException;
 import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
 import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
@@ -46,9 +41,6 @@ import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.NullTimeEvent;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeEvent;
 import org.eclipse.ui.IViewPart;
-import org.eclipse.ui.IWorkbenchCommandConstants;
-import org.eclipse.ui.IWorkbenchPartSite;
-import org.eclipse.ui.handlers.IHandlerService;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
@@ -106,33 +98,10 @@ public class FlameGraphTest extends AggregationTreeTest {
         assertNotNull(flamegraph);
         fTimeGraphViewer = flamegraph.getTimeGraphViewer();
         assertNotNull(fTimeGraphViewer);
-        maximize(flamegraph);
+        SWTBotUtils.maximize(flamegraph);
         fFg = flamegraph;
     }
 
-    /**
-     * Maximize a view by reference
-     * <p>
-     * TODO: if this is useful, maybe uplift to SWTViewBot
-     *
-     * @param view
-     *            the view reference
-     */
-    private static void maximize(@NonNull IViewPart view) {
-        assertNotNull(view);
-        IWorkbenchPartSite site = view.getSite();
-        assertNotNull(site);
-        // The annotation is to make the compiler not complain.
-        @Nullable Object handlerServiceObject = site.getService(IHandlerService.class);
-        assertTrue(handlerServiceObject instanceof IHandlerService);
-        IHandlerService handlerService = (IHandlerService) handlerServiceObject;
-        try {
-            handlerService.executeCommand(IWorkbenchCommandConstants.WINDOW_MAXIMIZE_ACTIVE_VIEW_OR_EDITOR, null);
-        } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) {
-            fail(e.getMessage());
-        }
-    }
-
     private void loadFlameGraph() {
         UIThreadRunnable.syncExec(() -> fFg.buildFlameGraph(getCga()));
         try {
index 276f1fde034214c533e87ad8dfac1628074d6e6a..33c9d084cb6f8966e1d713575bb172dfcfa03c1c 100644 (file)
@@ -25,7 +25,7 @@ Export-Package: org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore,
  org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.statistics,
  org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.table,
  org.eclipse.tracecompass.internal.analysis.timing.ui,
- org.eclipse.tracecompass.internal.analysis.timing.ui.callgraph;x-internal:=true,
+ org.eclipse.tracecompass.internal.analysis.timing.ui.callgraph;x-friends:="org.eclipse.tracecompass.analysis.timing.ui.swtbot.tests",
  org.eclipse.tracecompass.internal.analysis.timing.ui.flamegraph;x-friends:="org.eclipse.tracecompass.analysis.timing.ui.swtbot.tests",
  org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore;x-internal:=true,
  org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.density;x-internal:=true,
index b92e254676407dba55917491c774a86304564eda..dfb4df0e85d93f96cfe62b8d188d67ea31b1ae77 100644 (file)
@@ -24,6 +24,8 @@ import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
 import org.eclipse.tracecompass.tmf.ui.views.TmfView;
 
+import com.google.common.annotations.VisibleForTesting;
+
 /**
  * Displays the segment store analysis data in a density chart and a table
  * corresponding to the selected latencies.
@@ -139,9 +141,25 @@ public abstract class AbstractSegmentStoreDensityView extends TmfView {
         super.dispose();
     }
 
-    // Package-visible on purpose for ZoomOutAction
-    @Nullable
-    AbstractSegmentStoreDensityViewer getDensityViewer() {
+    /**
+     * Get the density viewer
+     *
+     * @return the density viewer
+     * @since 1.2
+     */
+    @VisibleForTesting
+    public @Nullable AbstractSegmentStoreDensityViewer getDensityViewer() {
         return fDensityViewer;
     }
+
+    /**
+     * Get the table viewer
+     *
+     * @return the table viewer
+     * @since 1.2
+     */
+    @VisibleForTesting
+    public @Nullable AbstractSegmentStoreTableViewer getTableViewer() {
+        return fTableViewer;
+    }
 }
\ No newline at end of file
index 4e003ec0a28d09361562b47eba202135a98fc1ab..559cb2109ea3fcd5fbeee5508cbd1bf4987df83f 100644 (file)
@@ -55,6 +55,7 @@ import org.swtchart.ISeriesSet;
 import org.swtchart.LineStyle;
 import org.swtchart.Range;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Predicate;
 import com.google.common.collect.Iterators;
 import com.google.common.collect.Lists;
@@ -245,6 +246,19 @@ public abstract class AbstractSegmentStoreDensityViewer extends TmfViewer {
         }
     }
 
+    /**
+     * Sets the segment store provider
+     *
+     * @param ssp
+     *            The segment store provider to give to this view
+     *
+     * @since 1.2
+     */
+    @VisibleForTesting
+    public void setSegmentProvider(@Nullable ISegmentStoreProvider ssp) {
+        fSegmentStoreProvider = ssp;
+    }
+
     /**
      * Signal handler for handling of the window range signal.
      *
@@ -265,7 +279,15 @@ public abstract class AbstractSegmentStoreDensityViewer extends TmfViewer {
         updateWithRange(fCurrentTimeRange);
     }
 
-    private void updateWithRange(final TmfTimeRange range) {
+    /**
+     * Update the display range
+     *
+     * @param range
+     *            the range
+     * @since 1.2
+     */
+    @VisibleForTesting
+    public void updateWithRange(final TmfTimeRange range) {
         computeDataAsync(range, new Range(Double.MIN_VALUE, Double.MAX_VALUE)).thenAccept((data) -> applyData(data));
     }
 
@@ -352,7 +374,7 @@ public abstract class AbstractSegmentStoreDensityViewer extends TmfViewer {
             if (provider != null) {
                 fListener = (segmentProvider, data) -> updateWithRange(windowRange);
                 provider.addListener(fListener);
-                ifprovider instanceof IAnalysisModule) {
+                if (provider instanceof IAnalysisModule) {
                     ((IAnalysisModule) provider).schedule();
                 }
             }
index 3809a3f3ff279e9d995afc48a47600e06628dad2..ca730a4dd476d7fdae611f8f981e32a81df54611 100644 (file)
@@ -22,6 +22,10 @@ import java.util.TimeZone;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.log4j.Logger;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.NotEnabledException;
+import org.eclipse.core.commands.NotHandledException;
+import org.eclipse.core.commands.common.NotDefinedException;
 import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
@@ -81,10 +85,14 @@ import org.eclipse.tracecompass.tmf.ui.views.TracingPerspectiveFactory;
 import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IEditorReference;
 import org.eclipse.ui.IPageLayout;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchCommandConstants;
 import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPartSite;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.WorkbenchException;
+import org.eclipse.ui.handlers.IHandlerService;
 import org.hamcrest.Matcher;
 
 /**
@@ -991,4 +999,28 @@ public final class SWTBotUtils {
         bot.waitUntil(Conditions.shellIsActive(PREFERENCES_MENU_ITEM));
         return bot.activeShell();
     }
+
+    /**
+     * Maximize a view by reference. Calling this a second time will "un-maximize" a view.
+     * <p>
+     * TODO: if this is useful, maybe uplift to SWTViewBot
+     *
+     * @param view
+     *            the view reference
+     */
+    public static void maximize(@NonNull IViewPart view) {
+        assertNotNull(view);
+        IWorkbenchPartSite site = view.getSite();
+        assertNotNull(site);
+        // The annotation is to make the compiler not complain.
+        @Nullable
+        Object handlerServiceObject = site.getService(IHandlerService.class);
+        assertTrue(handlerServiceObject instanceof IHandlerService);
+        IHandlerService handlerService = (IHandlerService) handlerServiceObject;
+        try {
+            handlerService.executeCommand(IWorkbenchCommandConstants.WINDOW_MAXIMIZE_ACTIVE_VIEW_OR_EDITOR, null);
+        } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) {
+            fail(e.getMessage());
+        }
+    }
 }
This page took 0.032231 seconds and 5 git commands to generate.