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
.analysis
.xml
.core
.tests
.stateprovider
;
15 import static org
.junit
.Assert
.assertFalse
;
16 import static org
.junit
.Assert
.assertNotNull
;
17 import static org
.junit
.Assert
.assertTrue
;
18 import static org
.junit
.Assert
.fail
;
19 import static org
.junit
.Assume
.assumeTrue
;
21 import java
.util
.List
;
23 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
24 import org
.eclipse
.core
.runtime
.Path
;
25 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystem
;
26 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.stateprovider
.TmfXmlStrings
;
27 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.stateprovider
.XmlStateSystemModule
;
28 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.tests
.common
.TmfXmlTestFiles
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfAnalysisException
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
31 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTrace
;
32 import org
.junit
.After
;
33 import org
.junit
.Before
;
34 import org
.junit
.Test
;
35 import org
.w3c
.dom
.Document
;
36 import org
.w3c
.dom
.Element
;
37 import org
.w3c
.dom
.NodeList
;
40 * Test suite for the xml state providers
42 * TODO: instead of using one of the test traces, we should make a custom trace
43 * to make sure it covers the different possibilities of the state provider
45 * @author Geneviève Bastien
47 public class StateProviderTest
{
49 private ITmfTrace fTrace
;
50 private XmlStateSystemModule fModule
;
53 * Setup the test fields
56 public void setupTest() {
57 /* Initialize the trace */
58 assumeTrue(CtfTmfTestTrace
.KERNEL
.exists());
59 ITmfTrace trace
= CtfTmfTestTrace
.KERNEL
.getTrace();
62 /* Initialize the state provider module */
63 Document doc
= TmfXmlTestFiles
.VALID_FILE
.getXmlDocument();
66 /* get State Providers modules */
67 NodeList stateproviderNodes
= doc
.getElementsByTagName(TmfXmlStrings
.STATE_PROVIDER
);
69 Element node
= (Element
) stateproviderNodes
.item(0);
70 fModule
= new XmlStateSystemModule();
71 String moduleId
= node
.getAttribute(TmfXmlStrings
.ID
);
72 assertNotNull(moduleId
);
73 fModule
.setId(moduleId
);
75 fModule
.setXmlFile(new Path(TmfXmlTestFiles
.VALID_FILE
.getFile().getAbsolutePath()));
78 fModule
.setTrace(trace
);
80 } catch (TmfAnalysisException e
) {
81 fail("Cannot set trace " + e
.getMessage());
86 * Cleanup after the test
89 public void cleanupTest() {
94 * Test the building of the state system
97 public void testStateSystem() {
98 assertTrue(fModule
.waitForCompletion(new NullProgressMonitor()));
99 ITmfStateSystem ss
= fModule
.getStateSystem();
102 List
<Integer
> quarks
= ss
.getQuarks("*");
103 assertFalse(quarks
.isEmpty());