1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
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
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.viewers
.events
;
14 import static org
.junit
.Assert
.assertArrayEquals
;
15 import static org
.junit
.Assert
.assertEquals
;
16 import static org
.junit
.Assert
.assertNotNull
;
19 import java
.io
.IOException
;
20 import java
.util
.ArrayList
;
21 import java
.util
.List
;
23 import org
.apache
.log4j
.ConsoleAppender
;
24 import org
.apache
.log4j
.Logger
;
25 import org
.apache
.log4j
.SimpleLayout
;
26 import org
.eclipse
.core
.runtime
.Platform
;
27 import org
.eclipse
.swtbot
.eclipse
.finder
.SWTWorkbenchBot
;
28 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotView
;
29 import org
.eclipse
.swtbot
.swt
.finder
.junit
.SWTBotJunit4ClassRunner
;
30 import org
.eclipse
.swtbot
.swt
.finder
.utils
.SWTBotPreferences
;
31 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotToolbarButton
;
32 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTreeItem
;
33 import org
.eclipse
.tracecompass
.tmf
.core
.io
.BufferedRandomAccessFile
;
34 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.SWTBotUtils
;
35 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.SDView
;
36 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.core
.Frame
;
37 import org
.junit
.After
;
38 import org
.junit
.AfterClass
;
39 import org
.junit
.Before
;
40 import org
.junit
.BeforeClass
;
41 import org
.junit
.Test
;
42 import org
.junit
.runner
.RunWith
;
45 * Test for Sequence Diagram view in trace compass
47 @RunWith(SWTBotJunit4ClassRunner
.class)
48 public class SDViewTest
{
50 private static final String UML2DVIEW_ID
= "org.eclipse.linuxtools.tmf.ui.tmfUml2SDSyncView";
52 private static final String XMLSTUB_ID
= "org.eclipse.linuxtools.tmf.core.tests.xmlstub";
54 private static final String TRACE_START
= "<trace>";
55 private static final String EVENT_BEGIN
= "<event timestamp=\"";
56 private static final String EVENT_MIDDLE1
= " \" name=\"";
57 private static final String EVENT_MIDDLE2
= "\">";
58 private static final String FIELD_SENDER
= "<field name=\"sender\" value=\"";
59 private static final String FIELD_RECEIVER
= "<field name=\"receiver\" value=\"";
60 private static final String FIELD_SIGNAL
= "<field name=\"signal\" value=\"";
61 private static final String FIELD_END
= "\" type=\"string\" />";
62 private static final String EVENT_END
= "</event>";
63 private static final String TRACE_END
= "</trace>";
65 private static final String PROJECT_NAME
= "TestForFiltering";
67 /** The Log4j logger instance. */
68 private static final Logger fLogger
= Logger
.getRootLogger();
69 private static SWTWorkbenchBot fBot
;
71 private static String
makeEvent(int ts
, String eventName
, String send
, String recv
, String signal
) {
72 return EVENT_BEGIN
+ Integer
.toString(ts
) + EVENT_MIDDLE1
+ eventName
+ EVENT_MIDDLE2
+ FIELD_SENDER
+ send
+ FIELD_END
+ FIELD_RECEIVER
+ recv
+ FIELD_END
+ FIELD_SIGNAL
+ signal
+ FIELD_END
+ EVENT_END
+ "\n";
75 private static File fFileLocation
;
78 * Initialization, creates a temp trace
84 public static void init() throws IOException
{
85 SWTBotUtils
.initialize();
86 Thread
.currentThread().setName("SWTBot Thread"); // for the debugger
87 /* set up for swtbot */
88 SWTBotPreferences
.TIMEOUT
= 20000; /* 20 second timeout */
89 fLogger
.removeAllAppenders();
90 fLogger
.addAppender(new ConsoleAppender(new SimpleLayout()));
91 fBot
= new SWTWorkbenchBot();
93 SWTBotUtils
.closeView("welcome", fBot
);
95 SWTBotUtils
.switchToTracingPerspective();
96 /* finish waiting for eclipse to load */
97 SWTBotUtils
.waitForJobs();
98 fFileLocation
= File
.createTempFile("sample", ".xml");
99 String eventNames
[] = { "test:SEND", "test:RECEIVE" };
100 String targets
[] = { "peer1", "peer2" };
102 try (BufferedRandomAccessFile braf
= new BufferedRandomAccessFile(fFileLocation
, "rw")) {
103 braf
.writeBytes(TRACE_START
);
104 for (int i
= 0; i
< 100; i
++) {
105 braf
.writeBytes(makeEvent(i
* i
* 100, eventNames
[i
% 2], targets
[i
% 2], targets
[(i
+ 1) % 2], Integer
.toString(i
% 2 + 1000)));
107 braf
.writeBytes(TRACE_END
);
112 * Open a trace in an editor
115 public void beforeTest() {
116 SWTBotUtils
.createProject(PROJECT_NAME
);
117 SWTBotTreeItem treeItem
= SWTBotUtils
.selectTracesFolder(fBot
, PROJECT_NAME
);
118 assertNotNull(treeItem
);
119 SWTBotUtils
.openTrace(PROJECT_NAME
, fFileLocation
.getAbsolutePath(), XMLSTUB_ID
);
120 SWTBotUtils
.openView(UML2DVIEW_ID
);
127 public static void cleanUp() {
128 SWTBotUtils
.closeViewById(UML2DVIEW_ID
, fBot
);
129 fFileLocation
.delete();
130 fLogger
.removeAllAppenders();
137 public void tearDown() {
138 fBot
.closeAllEditors();
139 SWTBotUtils
.deleteProject(PROJECT_NAME
, fBot
);
143 * Test Sequence diagram view, counting the columns
146 public void testSDView() {
147 SWTBotView viewBot
= fBot
.viewById(UML2DVIEW_ID
);
149 assertNotNull(viewBot
);
151 SWTBotUtils
.waitForJobs();
152 List
<SWTBotToolbarButton
> viewButtons
= viewBot
.getToolbarButtons();
153 List
<String
> titles
= new ArrayList
<>();
154 for (SWTBotToolbarButton buttonBot
: viewButtons
) {
155 titles
.add(buttonBot
.getToolTipText());
158 final char commandKeyChar
= (char) 0x2318;
159 final String findShortcut
= (Platform
.getOS().equals(Platform
.OS_MACOSX
) ? commandKeyChar
: "Ctrl+") + "F";
160 String
[] expected
= { "Reset zoom factor", "Select",
161 "Zoom in the diagram", "Zoom out the diagram",
162 "Go to next page", "Go to previous page",
163 "Go to first page", "Go to last page",
164 "Find... (" + findShortcut
+ ")"
166 assertArrayEquals("Buttons", expected
, titles
.toArray(new String
[0]));
167 SDView view
= (SDView
) viewBot
.getViewReference().getPart(false);
168 Frame frame
= view
.getFrame();
169 assertEquals(2, frame
.lifeLinesCount());