Commit | Line | Data |
---|---|---|
8945f67f | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2013, 2014 École Polytechnique de Montréal |
8945f67f GB |
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 | * Contributors: | |
10 | * Geneviève Bastien - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.analysis.xml.core.tests.stateprovider; |
8945f67f GB |
14 | |
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; | |
20 | ||
8945f67f GB |
21 | import java.util.List; |
22 | ||
8945f67f GB |
23 | import org.eclipse.core.runtime.NullProgressMonitor; |
24 | import org.eclipse.core.runtime.Path; | |
e894a508 | 25 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem; |
2bdf0193 AM |
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; | |
8945f67f GB |
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; | |
8945f67f GB |
38 | |
39 | /** | |
40 | * Test suite for the xml state providers | |
41 | * | |
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 | |
44 | * | |
45 | * @author Geneviève Bastien | |
46 | */ | |
47 | public class StateProviderTest { | |
48 | ||
49 | private ITmfTrace fTrace; | |
50 | private XmlStateSystemModule fModule; | |
51 | ||
52 | /** | |
53 | * Setup the test fields | |
54 | */ | |
55 | @Before | |
56 | public void setupTest() { | |
57 | /* Initialize the trace */ | |
58 | assumeTrue(CtfTmfTestTrace.KERNEL.exists()); | |
ba27dd38 GB |
59 | ITmfTrace trace = CtfTmfTestTrace.KERNEL.getTrace(); |
60 | fTrace = trace; | |
8945f67f GB |
61 | |
62 | /* Initialize the state provider module */ | |
9a0aa59e | 63 | Document doc = TmfXmlTestFiles.VALID_FILE.getXmlDocument(); |
8945f67f GB |
64 | assertNotNull(doc); |
65 | ||
66 | /* get State Providers modules */ | |
67 | NodeList stateproviderNodes = doc.getElementsByTagName(TmfXmlStrings.STATE_PROVIDER); | |
68 | ||
69 | Element node = (Element) stateproviderNodes.item(0); | |
70 | fModule = new XmlStateSystemModule(); | |
f47f1bbe | 71 | String moduleId = node.getAttribute(TmfXmlStrings.ID); |
ba27dd38 | 72 | assertNotNull(moduleId); |
8945f67f GB |
73 | fModule.setId(moduleId); |
74 | ||
75 | fModule.setXmlFile(new Path(TmfXmlTestFiles.VALID_FILE.getFile().getAbsolutePath())); | |
aa89118c | 76 | |
8945f67f | 77 | try { |
ba27dd38 | 78 | fModule.setTrace(trace); |
8945f67f GB |
79 | fModule.schedule(); |
80 | } catch (TmfAnalysisException e) { | |
81 | fail("Cannot set trace " + e.getMessage()); | |
82 | } | |
83 | } | |
84 | ||
85 | /** | |
86 | * Cleanup after the test | |
87 | */ | |
88 | @After | |
89 | public void cleanupTest() { | |
ba27dd38 | 90 | fTrace.dispose(); |
8945f67f GB |
91 | } |
92 | ||
93 | /** | |
94 | * Test the building of the state system | |
95 | */ | |
96 | @Test | |
97 | public void testStateSystem() { | |
98 | assertTrue(fModule.waitForCompletion(new NullProgressMonitor())); | |
99 | ITmfStateSystem ss = fModule.getStateSystem(); | |
100 | assertNotNull(ss); | |
101 | ||
102 | List<Integer> quarks = ss.getQuarks("*"); | |
103 | assertFalse(quarks.isEmpty()); | |
104 | } | |
105 | ||
106 | } |