control.test: SWTBot test for enabling specific event type by name
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.control.ui.swtbot.tests / src / org / eclipse / tracecompass / lttng2 / control / ui / swtbot / tests / ControlViewSwtBotUtil.java
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.control.ui.swtbot.tests;
11
12 import java.util.Arrays;
13
14 import org.eclipse.swtbot.swt.finder.waits.ICondition;
15 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TargetNodeState;
16 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceSessionState;
17 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent;
18 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent;
19 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent;
20 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers.SWTBotTestCondition;
21
22 /**
23 * SWTBot utilities for ControlView test
24 *
25 * @author Bernd Hufmann
26 */
27 class ControlViewSwtBotUtil {
28
29 public static final String USER_HOME = System.getProperty("user.home");
30 public static final String DEFAULT_CHANNEL_NAME = "channel0";
31 public static final String KERNEL_DOMAIN_NAME = "Kernel";
32 public static final String UST_DOMAIN_NAME = "UST global";
33 public static final String SESSION_GROUP_NAME = "Sessions";
34 public static final String PROVIDER_GROUP_NAME = "Provider";
35 public static final String ALL_EVENTS_NAME = "*";
36 public static final String SCHED_SWITCH_EVENT_NAME = "sched_switch";
37 public static final String SCHED_WAKEUP_EVENT_NAME = "sched_wakeup";
38 public static final String SCHED_PROCESSWAIT_EVENT_NAME = "sched_process_wait";
39 public static final String SCHED_PROCESSFORK_EVENT_NAME = "sched_process_fork";
40 public static final String SCHED_PROCESSEXEC_EVENT_NAME = "sched_process_exec";
41 public static final String PROFILE_SUFFIX = ".lttng";
42 public static final String KERNEL_TRACE_NAME = "kernel";
43
44 // Menu strings
45 public static final String CONNECT_MENU_ITEM = "Connect";
46 public static final String CREATE_SESSION_MENU_ITEM = "Create Session...";
47 public static final String ENABLE_EVENT_DEFAULT_CHANNEL_MENU_ITEM = "Enable Event (default channel)...";
48 public static final String ENABLE_CHANNEL_MENU_ITEM = "Enable Channel...";
49 public static final String ENABLE_EVENT_MENU_ITEM = "Enable Event...";
50 public static final String START_MENU_ITEM = "Start";
51 public static final String STOP_MENU_ITEM = "Stop";
52 public static final String IMPORT_MENU_ITEM = "Import...";
53 public static final String DESTROY_MENU_ITEM = "Destroy Session...";
54 public static final String DISCONNECT_MENU_ITEM = "Disconnect";
55 public static final String SAVE_MENU_ITEM = "Save...";
56 public static final String LOAD_MENU_ITEM = "Load...";
57
58 // Dialog strings
59 public static final String CREATE_SESSION_DIALOG_TITLE = "Create Session";
60 public static final String SESSION_NAME_LABEL = "Session Name";
61 public static final String DIALOG_OK_BUTTON = "Ok";
62 public static final String CONFIRM_DIALOG_OK_BUTTON = "OK";
63 public static final String ENABLE_EVENT_DIALOG_TITLE = "Enable Events";
64 public static final String ALL_TREE_NODE = "All";
65 public static final String ALL_EVENT_GROUP_NAME = "All Tracepoint Events and Syscalls";
66 public static final String SPECIFIC_EVENT_GROUP_NAME = "Specific event";
67 public static final String TRACEPOINTS_GROUP_NAME = "Tracepoint Events";
68 public static final String SYSCALL_GROUP_NAME = "All Syscalls";
69 public static final String GROUP_SELECT_NAME = "Select";
70 public static final String ENABLE_CHANNEL_DIALOG_TITLE = "Enable Channel";
71 public static final String DOMAIN_GROUP_NAME = "Domain";
72 public static final String UST_GROUP_NAME = "UST";
73 public static final String BUFFERTYPE_GROUP_NAME = "Buffer Type";
74 public static final String BUFFERTYPE_PER_UID = "Per UID buffers";
75 public static final String FILTER_EXPRESSION_LABEL = "Filter Expression";
76 public static final String SESSION_LIST_GROUP_NAME = "Session List";
77
78 public static final String DESTROY_CONFIRM_DIALOG_TITLE = "Destroy Confirmation";
79 public static final String CHANNEL_NAME_LABEL = "Channel Name";
80
81 public static final String SAVE_DIALOG_TITLE = "Save Sessions";
82 public static final String LOAD_DIALOG_TITLE = "Load Sessions";
83 public static final String REMOTE_RADIO_BUTTON_LABEL = "Remote";
84
85 // Remote import strings
86 public static final String IMPORT_WIZARD_TITLE = "Fetch Remote Traces";
87 public static final String DEFAULT_REMOTE_PROJECT = "Remote";
88 public static final String FINISH_BUTTON = "Finish";
89 public static final String CANCEL_BUTTON = "Cancel";
90 public static final String OPTION_GROUP_NAME = "Options";
91
92 private ControlViewSwtBotUtil() { }
93
94 /**
95 * Tests for Target node state
96 *
97 * @param node
98 * target node component
99 * @param state
100 * the state to wait
101 * @return the condition instance
102 */
103 public static ICondition isStateChanged(final TargetNodeComponent node, final TargetNodeState state) {
104 return new SWTBotTestCondition() {
105 @Override
106 public boolean test() throws Exception {
107 if (node.getTargetNodeState() != state) {
108 return false;
109 }
110 return true;
111 }
112 };
113 }
114
115 /**
116 * Tests for session state
117 *
118 * @param session
119 * the session component
120 * @param state
121 * the state to wait
122 * @return the condition instance
123 */
124 public static ICondition isSessionStateChanged(final TraceSessionComponent session, final TraceSessionState state) {
125 return new SWTBotTestCondition() {
126 @Override
127 public boolean test() throws Exception {
128 if (session.getSessionState() != state) {
129 return false;
130 }
131 return true;
132 }
133 };
134 }
135
136 /**
137 * Finds a session for given node
138 *
139 * @param target
140 * target node component
141 * @param sessionName
142 * session name to find
143 * @return the session component or null
144 */
145 public static TraceSessionComponent getSessionComponent(TargetNodeComponent target, String sessionName) {
146 final TraceSessionComponent[] sessions = target.getSessions();
147 if (sessions != null) {
148 for (int i = 0; i < sessions.length; i++) {
149 if (sessionName.equals(sessions[i].getName())) {
150 return sessions[i];
151 }
152 }
153 }
154 return null;
155 }
156
157 /**
158 * Finds a {@link ITraceControlComponent} in a tree for given path.
159 *
160 * @param root
161 * root component
162 * @param path
163 * path to element
164 * @return the matched component or null
165 */
166 public static ITraceControlComponent getComponent(ITraceControlComponent root, String... path) {
167 ITraceControlComponent newRoot = root;
168 for (String segment : path) {
169 newRoot = Arrays.asList(newRoot.getChildren()).stream()
170 .filter(child -> (child.getName().equals(segment)))
171 .findFirst()
172 .orElse(null);
173 if (newRoot == null) {
174 return null;
175 }
176 }
177 return newRoot;
178 }
179
180 }
This page took 0.035956 seconds and 5 git commands to generate.