Add utility method to close secondary shells after tests
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests / src / org / eclipse / tracecompass / lttng2 / kernel / ui / swtbot / tests / KernelTestBase.java
index f049bce62d714eed132f7a173e66ccd16b2bd0fb..2c826f782894e87b8aca62d88567314c930fd39a 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2013, 2015 Ericsson
+ * Copyright (c) 2013, 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
@@ -21,13 +21,16 @@ import java.util.List;
 import org.apache.log4j.ConsoleAppender;
 import org.apache.log4j.Logger;
 import org.apache.log4j.SimpleLayout;
+import org.eclipse.swt.widgets.TreeItem;
 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.results.Result;
 import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
-import org.eclipse.tracecompass.ctf.core.tests.shared.LttngKernelTraceGenerator;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.tracecompass.ctf.core.tests.shared.LttngTraceGenerator;
 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;
@@ -46,9 +49,12 @@ import org.junit.runner.RunWith;
 @RunWith(SWTBotJunit4ClassRunner.class)
 public abstract class KernelTestBase {
 
-    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";
+    /** LTTng kernel trace type */
+    protected static final String KERNEL_TRACE_TYPE = "org.eclipse.linuxtools.lttng2.kernel.tracetype";
+    /** LTTng kernel perspective */
+    protected static final String KERNEL_PERSPECTIVE_ID = "org.eclipse.linuxtools.lttng2.kernel.ui.perspective";
+    /** Default project name */
+    protected static final String TRACE_PROJECT_NAME = "test";
 
     /** The workbench bot */
     protected static SWTWorkbenchBot fBot;
@@ -119,8 +125,8 @@ public abstract class KernelTestBase {
      */
     @Before
     public void before() {
-        SWTBotUtils.openTrace(TRACE_PROJECT_NAME, LttngKernelTraceGenerator.getPath(), TRACE_TYPE);
-        SWTBotUtils.activateEditor(fBot, LttngKernelTraceGenerator.getName());
+        SWTBotUtils.openTrace(TRACE_PROJECT_NAME, LttngTraceGenerator.getPath(), KERNEL_TRACE_TYPE);
+        SWTBotUtils.activateEditor(fBot, LttngTraceGenerator.getName());
     }
 
     /**
@@ -129,5 +135,37 @@ public abstract class KernelTestBase {
     @After
     public void after() {
         fBot.closeAllEditors();
+        SWTBotUtils.closeSecondaryShells(fBot);
+    }
+
+    /**
+     * Class to check number of checked items
+     */
+    static final class TreeCheckedCounter implements Result<Integer> {
+        private final SWTBotTree fTreeBot;
+
+        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;
+        }
     }
 }
This page took 0.029406 seconds and 5 git commands to generate.