e9a53fae5df16616abc2e2c1cf2020febb8a0349
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.analysis.xml.core.tests / src / org / eclipse / tracecompass / tmf / analysis / xml / core / tests / model / TmfStateValueTest.java
1 /*******************************************************************************
2 * Copyright (c) 2016 É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
10 package org.eclipse.tracecompass.tmf.analysis.xml.core.tests.model;
11
12 import static org.junit.Assert.assertNotNull;
13
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
16 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
17 import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
18 import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
19 import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
20 import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
21 import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles;
22 import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.module.XmlUtilsTest;
23 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
24 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
25 import org.junit.After;
26 import org.junit.Before;
27 import org.junit.Test;
28
29 /**
30 * Test the various cases for the state value changes. To add new test cases,
31 * the trace test file and the state value test files can be modified to cover
32 * extra cases.
33 *
34 * @author Geneviève Bastien
35 */
36 public class TmfStateValueTest {
37
38 private static final @NonNull String TEST_TRACE = "test_traces/testTrace4.xml";
39
40 ITmfTrace fTrace;
41 XmlStateSystemModule fModule;
42
43 /**
44 * Initializes the trace and the module for the tests
45 *
46 * @throws TmfAnalysisException
47 * Any exception thrown during module initialization
48 */
49 @Before
50 public void setUp() throws TmfAnalysisException {
51 ITmfTrace trace = XmlUtilsTest.initializeTrace(TEST_TRACE);
52 XmlStateSystemModule module = XmlUtilsTest.initializeModule(TmfXmlTestFiles.STATE_VALUE_FILE);
53
54 module.setTrace(trace);
55
56 module.schedule();
57 module.waitForCompletion();
58
59 fTrace = trace;
60 fModule = module;
61 }
62
63 /**
64 * Dispose the module and the trace
65 */
66 @After
67 public void cleanUp() {
68 fTrace.dispose();
69 fModule.dispose();
70 }
71
72 /**
73 * Test that the ongoing state is updated instead of creating a new state
74 *
75 * @throws StateSystemDisposedException
76 * Exceptions thrown during state system verification
77 * @throws AttributeNotFoundException
78 * Exceptions thrown during state system verification
79 */
80 @Test
81 public void testStateValueUpdate() throws AttributeNotFoundException, StateSystemDisposedException {
82 XmlStateSystemModule module = fModule;
83 assertNotNull(module);
84
85 ITmfStateSystem ss = module.getStateSystem();
86 assertNotNull(ss);
87
88 int quark = ss.getQuarkAbsolute("update", "0");
89
90 final int[] expectedStarts = { 1, 3, 5, 7, 7 };
91 ITmfStateValue[] expectedValues = { TmfStateValue.newValueString("GOOD"), TmfStateValue.nullValue(), TmfStateValue.newValueString("BAD"), TmfStateValue.nullValue() };
92 XmlUtilsTest.verifyStateIntervals("testStateValueUpdate", ss, quark, expectedStarts, expectedValues);
93
94 }
95
96 /**
97 * Test that a state change with no update causes the modification of the
98 * state value at the time of the event
99 *
100 * @throws StateSystemDisposedException
101 * Exceptions thrown during state system verification
102 * @throws AttributeNotFoundException
103 * Exceptions thrown during state system verification
104 */
105 @Test
106 public void testStateValueModify() throws AttributeNotFoundException, StateSystemDisposedException {
107 XmlStateSystemModule module = fModule;
108 assertNotNull(module);
109
110 ITmfStateSystem ss = module.getStateSystem();
111 assertNotNull(ss);
112
113 int quark = ss.getQuarkAbsolute("modify", "0");
114
115 final int[] expectedStarts = { 1, 3, 5, 7, 7 };
116 ITmfStateValue[] expectedValues = { TmfStateValue.newValueString("UNKNOWN"), TmfStateValue.newValueString("GOOD"), TmfStateValue.newValueString("UNKNOWN"), TmfStateValue.newValueString("BAD") };
117 XmlUtilsTest.verifyStateIntervals("testStateValueModify", ss, quark, expectedStarts, expectedValues);
118
119 }
120
121 /**
122 *
123 * it tests that a state change on stack, with a peek() condition. This test
124 * verifies the value on the top of the stack and verifies that the peek
125 * operation do not remove the value on the top of the stack.
126 *
127 * @throws StateSystemDisposedException
128 * Exceptions thrown during state system verification
129 * @throws AttributeNotFoundException
130 * Exceptions thrown during state system verification
131 */
132 @Test
133 public void testStateValuePeek() throws AttributeNotFoundException, StateSystemDisposedException {
134 XmlStateSystemModule module = fModule;
135 assertNotNull(module);
136
137 ITmfStateSystem ss = module.getStateSystem();
138 assertNotNull(ss);
139
140 int quark = ss.getQuarkAbsolute("stack");
141
142 final int[] expectedStarts = { 1, 5, 7, 7 };
143 ITmfStateValue[] expectedValues = { TmfStateValue.newValueLong(1l), TmfStateValue.newValueLong(5l), TmfStateValue.newValueLong(1l) };
144 XmlUtilsTest.verifyStackStateIntervals("testStateValueModify", ss, quark, expectedStarts, expectedValues);
145 }
146 }
This page took 0.050375 seconds and 4 git commands to generate.