1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 École Polytechnique de Montréal
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 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.tests
.stubs
.analysis
;
15 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
16 import org
.eclipse
.jdt
.annotation
.NonNull
;
17 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.TmfAbstractAnalysisModule
;
18 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
21 * Simple analysis type for test
23 public class TestAnalysis
extends TmfAbstractAnalysisModule
{
26 * Test parameter. If set, simulate cancellation
28 public static final @NonNull String PARAM_TEST
= "test";
30 private int fOutput
= 0;
35 public TestAnalysis() {
40 public boolean canExecute(ITmfTrace trace
) {
45 protected boolean executeAnalysis(final IProgressMonitor monitor
) {
46 if (getParameter(PARAM_TEST
) == null) {
47 throw new RuntimeException("The parameter should be set");
49 /* If PARAM_TEST is set to 0, simulate cancellation */
50 if ((Integer
) getParameter(PARAM_TEST
) == 0) {
53 } else if ((Integer
) getParameter(PARAM_TEST
) == 999) {
54 /* just stay in an infinite loop until cancellation */
55 while (!monitor
.isCanceled()) {
58 return !monitor
.isCanceled();
60 Object obj
= getParameter(PARAM_TEST
);
62 throw new IllegalStateException();
64 fOutput
= (Integer
) obj
;
69 protected void canceling() {
74 public Object
getParameter(String name
) {
75 Object value
= super.getParameter(name
);
76 if ((value
!= null) && name
.equals(PARAM_TEST
) && (value
instanceof String
)) {
77 return Integer
.decode((String
) value
);
83 protected void parameterChanged(String name
) {
88 * Get the analysis output value
90 * @return The analysis output
92 public int getAnalysisOutput() {