tmf : Add test suite for the XML conditions
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.analysis.xml.core.tests / src / org / eclipse / tracecompass / tmf / analysis / xml / core / tests / stateprovider / StateProviderModelTest.java
1 /*******************************************************************************
2 * Copyright (c) 2014 École Polytechnique de Montréal
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
13 package org.eclipse.tracecompass.tmf.analysis.xml.core.tests.stateprovider;
14
15 import static org.junit.Assert.assertEquals;
16 import static org.junit.Assert.assertNotNull;
17 import static org.junit.Assert.fail;
18
19 import java.util.List;
20
21 import org.eclipse.jdt.annotation.NonNull;
22 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
23 import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
24 import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
25 import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
26 import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
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.analysis.xml.core.tests.module.XmlUtilsTest;
30 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
31 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
32 import org.junit.Test;
33
34 /**
35 * Test the XML model for state providers
36 *
37 * @author Geneviève Bastien
38 */
39 public class StateProviderModelTest {
40
41 private static final @NonNull String testTrace1 = "test_traces/testTrace1.xml";
42
43 /**
44 * Test an increment of one, for an event name attribute
45 */
46 @Test
47 public void testEventName() {
48 ITmfTrace trace = XmlUtilsTest.initializeTrace(testTrace1);
49 XmlStateSystemModule module = XmlUtilsTest.initializeModule(TmfXmlTestFiles.ATTRIBUTE_FILE);
50 try {
51
52 module.setTrace(trace);
53
54 module.schedule();
55 module.waitForCompletion();
56
57 ITmfStateSystem ss = module.getStateSystem();
58 assertNotNull(ss);
59
60 List<Integer> quarks = ss.getQuarks("*");
61 assertEquals(2, quarks.size());
62
63 for (Integer quark : quarks) {
64 String name = ss.getAttributeName(quark);
65 switch (name) {
66 case "test":
67 {
68 final int[] expectedStarts = { 1, 5, 7 };
69 ITmfStateValue[] expectedValues = { TmfStateValue.newValueInt(1), TmfStateValue.newValueInt(2) };
70 XmlUtilsTest.verifyStateIntervals("test", ss, quark, expectedStarts, expectedValues);
71 }
72 break;
73 case "test1":
74 {
75 final int[] expectedStarts = { 1, 3, 7, 7 };
76 ITmfStateValue[] expectedValues = { TmfStateValue.nullValue(), TmfStateValue.newValueInt(1), TmfStateValue.newValueInt(2) };
77 XmlUtilsTest.verifyStateIntervals("test1", ss, quark, expectedStarts, expectedValues);
78 }
79 break;
80 default:
81 fail("Wrong attribute name " + name);
82 break;
83 }
84 }
85
86 } catch (TmfAnalysisException | AttributeNotFoundException | StateSystemDisposedException e) {
87 fail(e.getMessage());
88 } finally {
89 module.dispose();
90 trace.dispose();
91 }
92
93 }
94
95 }
This page took 0.033259 seconds and 5 git commands to generate.