Commit | Line | Data |
---|---|---|
7b583932 BH |
1 | /******************************************************************************* |
2 | * Copyright (c) 2015 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | *******************************************************************************/ | |
9 | ||
10 | package org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests; | |
11 | ||
12 | import static org.junit.Assert.assertEquals; | |
13 | import static org.junit.Assert.assertNotNull; | |
14 | import static org.junit.Assert.assertTrue; | |
15 | ||
16 | import java.io.File; | |
17 | ||
18 | import org.apache.log4j.ConsoleAppender; | |
19 | import org.apache.log4j.Logger; | |
20 | import org.apache.log4j.SimpleLayout; | |
21 | import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; | |
22 | import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; | |
23 | import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; | |
24 | import org.eclipse.swtbot.swt.finder.matchers.WidgetOfType; | |
25 | import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; | |
26 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; | |
27 | import org.eclipse.tracecompass.internal.lttng2.ust.ui.views.memusage.MemoryUsageView; | |
28 | import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace; | |
29 | import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils; | |
30 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils; | |
31 | import org.hamcrest.Matcher; | |
32 | import org.junit.After; | |
33 | import org.junit.Before; | |
34 | import org.junit.BeforeClass; | |
35 | import org.junit.Test; | |
36 | import org.junit.runner.RunWith; | |
37 | import org.swtchart.Chart; | |
38 | import org.swtchart.ILineSeries; | |
39 | import org.swtchart.ISeries; | |
40 | import org.swtchart.ISeriesSet; | |
41 | ||
42 | /** | |
43 | * Test for the Memory Usage view in trace compass | |
44 | */ | |
45 | @RunWith(SWTBotJunit4ClassRunner.class) | |
46 | public class MemoryUsageViewTest { | |
47 | ||
48 | private static final String UST_ID = "org.eclipse.linuxtools.lttng2.ust.tracetype"; | |
49 | ||
50 | private static final String PROJECT_NAME = "TestForMemory"; | |
51 | ||
52 | /** The Log4j logger instance. */ | |
53 | private static final Logger fLogger = Logger.getRootLogger(); | |
54 | private static SWTWorkbenchBot fBot; | |
55 | ||
56 | /** | |
57 | * Initialization | |
58 | */ | |
59 | @BeforeClass | |
60 | public static void init() { | |
61 | SWTBotUtils.initialize(); | |
62 | ||
63 | Thread.currentThread().setName("SWTBot Thread"); // for the debugger | |
64 | /* set up for swtbot */ | |
65 | SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */ | |
66 | fLogger.addAppender(new ConsoleAppender(new SimpleLayout())); | |
67 | fBot = new SWTWorkbenchBot(); | |
68 | ||
69 | SWTBotUtils.closeView("welcome", fBot); | |
70 | ||
71 | SWTBotUtils.switchToTracingPerspective(); | |
72 | ||
73 | /* finish waiting for eclipse to load */ | |
74 | SWTBotUtils.waitForJobs(); | |
75 | } | |
76 | ||
77 | /** | |
78 | * Open a trace in an editor | |
79 | */ | |
80 | @Before | |
81 | public void beforeTest() { | |
82 | SWTBotUtils.createProject(PROJECT_NAME); | |
83 | SWTBotTreeItem treeItem = SWTBotUtils.selectTracesFolder(fBot, PROJECT_NAME); | |
84 | assertNotNull(treeItem); | |
85 | final CtfTestTrace cygProfile = CtfTestTrace.MEMORY_ANALYSIS; | |
86 | final File file = new File(CtfTmfTestTraceUtils.getTrace(cygProfile).getPath()); | |
87 | SWTBotUtils.openTrace(PROJECT_NAME, file.getAbsolutePath(), UST_ID); | |
88 | SWTBotUtils.openView(MemoryUsageView.ID); | |
89 | SWTBotUtils.waitForJobs(); | |
90 | } | |
91 | ||
92 | /** | |
93 | * Close the editor | |
94 | */ | |
95 | @After | |
96 | public void tearDown() { | |
97 | fBot.closeAllEditors(); | |
98 | SWTBotUtils.deleteProject(PROJECT_NAME, fBot); | |
99 | } | |
100 | ||
101 | /** | |
102 | * Test if Memory Usage is populated | |
103 | */ | |
104 | @Test | |
105 | public void testOpenMemoryUsage() { | |
106 | SWTBotView viewBot = fBot.viewById(MemoryUsageView.ID); | |
107 | viewBot.setFocus(); | |
108 | ||
109 | // Do some basic validation | |
110 | Matcher<Chart> matcher = WidgetOfType.widgetOfType(Chart.class); | |
111 | Chart chart = viewBot.bot().widget(matcher); | |
112 | ISeriesSet seriesSet = chart.getSeriesSet(); | |
113 | assertNotNull(seriesSet); | |
114 | ISeries[] series = seriesSet.getSeries(); | |
115 | assertNotNull(series); | |
116 | ||
117 | // Verify that the chart has 4 series | |
118 | assertEquals(4, series.length); | |
119 | // Verify that each series is a ILineSeries | |
120 | for (int i = 0; i < series.length; i++) { | |
121 | assertTrue(series[i] instanceof ILineSeries); | |
122 | } | |
123 | } | |
124 | ||
125 | } |