X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=analysis%2Forg.eclipse.tracecompass.analysis.os.linux.ui.swtbot.tests%2Fsrc%2Forg%2Feclipse%2Ftracecompass%2Fanalysis%2Fos%2Flinux%2Fui%2Fswtbot%2Ftests%2Flatency%2FSystemCallLatencyTableAnalysisTest.java;h=a5b312f3280fdc70476eb41ec15756fd3e23285c;hb=37b7faba6f4b597d03a6fd982bfc49dd1b199080;hp=9a0ab4c5c1ce08452422c7ff2c60af9888775d04;hpb=660d4ed9bd22ac357b49953bad1f11f5893747de;p=deliverable%2Ftracecompass.git 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 9a0ab4c5c1..a5b312f328 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,10 +12,12 @@ package org.eclipse.tracecompass.analysis.os.linux.ui.swtbot.tests.latency; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; +import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import java.util.Random; @@ -33,7 +35,9 @@ 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.swtbot.swt.finder.widgets.SWTBotMenu; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable; +import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.table.AbstractSegmentStoreTableView; import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.table.AbstractSegmentStoreTableViewer; import org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency.SystemCallLatencyView; import org.eclipse.tracecompass.segmentstore.core.BasicSegment; @@ -232,7 +236,7 @@ public class SystemCallLatencyTableAnalysisTest { tableBot.header("Duration").click(); bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "0", 0, 2)); tableBot.header("Duration").click(); - bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "999999", 0, 2)); + bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "999,999", 0, 2)); } /** @@ -253,11 +257,11 @@ public class SystemCallLatencyTableAnalysisTest { fTable.updateModel(fixture); SWTBotTable tableBot = new SWTBotTable(fTable.getTableViewer().getTable()); SWTBot bot = new SWTBot(); - bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "894633", 0, 2)); + bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "894,633", 0, 2)); tableBot.header("Duration").click(); bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "0", 0, 2)); tableBot.header("Duration").click(); - bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "999999", 0, 2)); + bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "999,999", 0, 2)); } /** @@ -278,11 +282,63 @@ public class SystemCallLatencyTableAnalysisTest { fTable.updateModel(fixture); SWTBotTable tableBot = new SWTBotTable(fTable.getTableViewer().getTable()); SWTBot bot = new SWTBot(); - bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "400689", 0, 2)); + bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "400,689", 0, 2)); tableBot.header("Duration").click(); bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "0", 0, 2)); tableBot.header("Duration").click(); - bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "998001", 0, 2)); + bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "998,001", 0, 2)); + } + + /** + * Test creating a tsv + * + * @throws NoSuchMethodException + * Error creating the tsv + */ + @Test + public void testWriteToTsv() throws NoSuchMethodException { + List<@NonNull BasicSegment> fixture = new ArrayList<>(); + for (int i = 1; i <= 20; i++) { + int start = i; + final int delta = i; + int end = start + delta * delta; + fixture.add(new BasicSegment(start, end)); + } + assertNotNull(fTable); + fTable.updateModel(fixture); + SWTBotTable tableBot = new SWTBotTable(fTable.getTableViewer().getTable()); + SWTBot bot = new SWTBot(); + bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "1", 0, 2)); + SWTWorkbenchBot swtWorkbenchBot = new SWTWorkbenchBot(); + SWTBotView viewBot = swtWorkbenchBot.viewById(VIEW_ID); + testToTsv(viewBot); + SWTBotMenu menuBot = viewBot.viewMenu().menu("Export to TSV"); + assertTrue(menuBot.isEnabled()); + assertTrue(menuBot.isVisible()); + } + + private void testToTsv(SWTBotView view) throws NoSuchMethodException { + ByteArrayOutputStream os = new ByteArrayOutputStream(); + assertNotNull(os); + Class<@NonNull AbstractSegmentStoreTableView> clazz = AbstractSegmentStoreTableView.class; + Method method = clazz.getDeclaredMethod("exportToTsv", java.io.OutputStream.class); + method.setAccessible(true); + final Exception[] except = new Exception[1]; + UIThreadRunnable.syncExec(() -> { + try { + method.invoke(fLatencyView, os); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + except[0] = e; + } + }); + assertNull(except[0]); + @SuppressWarnings("null") + String[] lines = String.valueOf(os).split(System.getProperty("line.separator")); + 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. + assertTrue("line 1", lines[1].matches("\\d\\d:\\d\\d:00\\.000\\s000\\s001\\t\\d\\d:\\d\\d:00.000 000 002\\t1")); } /** @@ -308,11 +364,11 @@ public class SystemCallLatencyTableAnalysisTest { createTable(); SWTBotUtils.waitForJobs(); SWTBotTable tableBot = new SWTBotTable(fTable.getTableViewer().getTable()); - bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "24100", 0, 2)); + bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "24,100", 0, 2)); tableBot.header("Duration").click(); - bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "1000", 0, 2)); + bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "1,000", 0, 2)); tableBot.header("Duration").click(); - bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "5904091700", 0, 2)); + bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "5,904,091,700", 0, 2)); bot.closeAllEditors(); SWTBotUtils.deleteProject(PROJECT_NAME, bot); }