From b6fddb839ef7b61c5a418a5e05091c52b3d25c67 Mon Sep 17 00:00:00 2001 From: Matthew Khouzam Date: Wed, 5 Oct 2016 13:51:38 -0400 Subject: [PATCH] analysis.ui: add Export to TSV action test Change-Id: I4852f270b5af4d1e957285690f271f3f94ad9d5e Signed-off-by: Matthew Khouzam Reviewed-on: https://git.eclipse.org/r/82552 Reviewed-by: Hudson CI Reviewed-by: Genevieve Bastien Tested-by: Genevieve Bastien --- .../SystemCallLatencyTableAnalysisTest.java | 43 ++++++++++++++++--- .../ui/swtbot/tests/shared/SWTBotUtils.java | 19 +++++--- 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui.swtbot.tests/src/org/eclipse/tracecompass/analysis/os/linux/ui/swtbot/tests/latency/SystemCallLatencyTableAnalysisTest.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui.swtbot.tests/src/org/eclipse/tracecompass/analysis/os/linux/ui/swtbot/tests/latency/SystemCallLatencyTableAnalysisTest.java index d755726d66..269834b1d9 100644 --- a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui.swtbot.tests/src/org/eclipse/tracecompass/analysis/os/linux/ui/swtbot/tests/latency/SystemCallLatencyTableAnalysisTest.java +++ b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui.swtbot.tests/src/org/eclipse/tracecompass/analysis/os/linux/ui/swtbot/tests/latency/SystemCallLatencyTableAnalysisTest.java @@ -12,15 +12,24 @@ package org.eclipse.tracecompass.analysis.os.linux.ui.swtbot.tests.latency; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import java.io.BufferedReader; import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileReader; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Random; +import java.util.stream.Collectors; import org.apache.log4j.ConsoleAppender; import org.apache.log4j.Logger; @@ -42,6 +51,8 @@ import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.table.Abst import org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency.SystemCallLatencyView; import org.eclipse.tracecompass.segmentstore.core.BasicSegment; import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace; +import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager; +import org.eclipse.tracecompass.tmf.ui.dialog.TmfFileDialogFactory; 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.tests.shared.WaitUtils; @@ -295,9 +306,12 @@ public class SystemCallLatencyTableAnalysisTest { * * @throws NoSuchMethodException * Error creating the tsv + * @throws IOException + * no such file or the file is locked. */ @Test - public void testWriteToTsv() throws NoSuchMethodException { + public void testWriteToTsv() throws NoSuchMethodException, IOException { + List<@NonNull BasicSegment> fixture = new ArrayList<>(); for (int i = 1; i <= 20; i++) { int start = i; @@ -312,13 +326,26 @@ public class SystemCallLatencyTableAnalysisTest { bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "1", 0, 2)); SWTWorkbenchBot swtWorkbenchBot = new SWTWorkbenchBot(); SWTBotView viewBot = swtWorkbenchBot.viewById(VIEW_ID); - testToTsv(viewBot); + List actionResult = Arrays.asList(testToTsv(viewBot)); + String absolutePath = TmfTraceManager.getTemporaryDirPath() + File.separator + "syscallLatencyTest.testWriteToTsv.tsv"; + TmfFileDialogFactory.setOverrideFiles(absolutePath); SWTBotMenu menuBot = viewBot.viewMenu().menu("Export to TSV"); - assertTrue(menuBot.isEnabled()); - assertTrue(menuBot.isVisible()); + try { + assertTrue(menuBot.isEnabled()); + assertTrue(menuBot.isVisible()); + menuBot.click(); + + try (BufferedReader br = new BufferedReader(new FileReader(absolutePath))) { + List lines = br.lines().collect(Collectors.toList()); + assertEquals("Both reads", actionResult, lines); + } + } finally { + new File(absolutePath).delete(); + } + } - private void testToTsv(SWTBotView view) throws NoSuchMethodException { + private String[] testToTsv(SWTBotView view) throws NoSuchMethodException { ByteArrayOutputStream os = new ByteArrayOutputStream(); assertNotNull(os); Class<@NonNull AbstractSegmentStoreTableView> clazz = AbstractSegmentStoreTableView.class; @@ -338,8 +365,10 @@ public class SystemCallLatencyTableAnalysisTest { assertNotNull(lines); assertEquals("number of lines", 21, lines.length); assertEquals("header", "Start Time\tEnd Time\tDuration", lines[0]); - // not a straight up string compare due to time zones. Kathmandu and Eucla have 15 minute time zones. + // not a straight up string compare due to time zones. Kathmandu and + // Eucla have 15 minute time zones. assertTrue("line 1", lines[1].matches("\\d\\d:\\d\\d:00\\.000\\s000\\s001\\t\\d\\d:\\d\\d:00.000 000 002\\t1")); + return lines; } /** diff --git a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/SWTBotUtils.java b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/SWTBotUtils.java index 00a4b329fa..dc2189419a 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/SWTBotUtils.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/SWTBotUtils.java @@ -247,7 +247,6 @@ public final class SWTBotUtils { }); } - /** * Focus on the main window * @@ -316,7 +315,8 @@ public final class SWTBotUtils { * Close a view with an id * * @param viewId - * the view id, like "org.eclipse.linuxtools.tmf.ui.views.histogram" + * the view id, like + * "org.eclipse.linuxtools.tmf.ui.views.histogram" * @param bot * the workbench bot */ @@ -364,7 +364,8 @@ public final class SWTBotUtils { printEnvironment(); // There seems to be problems on some system where the main shell is - // not in focus initially. This was seen using Xvfb and Xephyr on some occasions. + // not in focus initially. This was seen using Xvfb and Xephyr on + // some occasions. focusMainWindow(bot.shells()); Shell shell = bot.activeShell().widget; @@ -381,7 +382,8 @@ public final class SWTBotUtils { return; } - // Print some information about the environment that could affect test outcome + // Print some information about the environment that could affect test + // outcome Rectangle bounds = Display.getDefault().getBounds(); System.out.println("Display size: " + bounds.width + "x" + bounds.height); @@ -392,7 +394,8 @@ public final class SWTBotUtils { String gtkVersion = System.getProperty("org.eclipse.swt.internal.gtk.version"); if (gtkVersion != null) { System.out.println("GTK version=" + gtkVersion); - // Try to print the GTK theme information as behavior can change depending on the theme + // Try to print the GTK theme information as behavior can change + // depending on the theme String gtkTheme = System.getProperty("org.eclipse.swt.internal.gtk.theme"); System.out.println("GTK theme=" + (gtkTheme == null ? "unknown" : gtkTheme)); @@ -734,7 +737,8 @@ public final class SWTBotUtils { * @param bot * a given workbench bot * @param projectName - * the name of the project (it needs to exist or else it would time out) + * the name of the project (it needs to exist or else it would + * time out) * @return a {@link SWTBotTreeItem} of the project */ public static SWTBotTreeItem selectProject(SWTWorkbenchBot bot, String projectName) { @@ -885,7 +889,8 @@ public final class SWTBotUtils { try { bot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(nodeName, currentNode)); } catch (TimeoutException e) { - //FIXME: Sometimes in a JFace TreeViewer, it expands to nothing. Need to find out why. + // FIXME: Sometimes in a JFace TreeViewer, it expands to + // nothing. Need to find out why. currentNode.collapse(); currentNode.expand(); bot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(nodeName, currentNode)); -- 2.34.1