tmf : Fix the xml condition multiple problem
authorJean-Christian Kouame <jean-christian.kouame@ericsson.com>
Thu, 10 Dec 2015 20:34:16 +0000 (15:34 -0500)
committerBernd Hufmann <bernd.hufmann@ericsson.com>
Mon, 14 Dec 2015 20:25:04 +0000 (15:25 -0500)
This patch initiates the number of state values involved in a comparison
only when the xml element is <condition>. Without this fix, conditions
like OR or AND with more than two operands fail because we were
validating that the maximum number of state values was actually two.
Since the XSD validates that already the condition is removed in this
patch and the allocation of the state value list is done only when the
element is <condition>. In other cases, the list is instantiated to an
empty list.
This patch also add a test with a condition with three operands in
TmfXmlConditionTest to validate this case.

Change-Id: I6e99f770b35f3359a5617bc01b8a53bc77df637e
Signed-off-by: Jean-Christian Kouame <jean-christian.kouame@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/62425
Reviewed-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tested-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stateprovider/TmfXmlConditionTest.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/test_xml_files/test_valid/test_conditions.xml
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlCondition.java

index 33b16769a1c67aabc0045ea8cf63f8f8b91871c0..8d4d0fe6611b1dda9bf073197e1bafd7b71bdb52 100644 (file)
@@ -55,7 +55,7 @@ public class TmfXmlConditionTest {
             assertNotNull(ss);
 
             List<Integer> quarks = ss.getQuarks("*");
-            assertEquals(3, quarks.size());
+            assertEquals(4, quarks.size());
 
             for (Integer quark : quarks) {
                 String name = ss.getAttributeName(quark);
@@ -78,6 +78,12 @@ public class TmfXmlConditionTest {
                     XmlUtilsTest.verifyStateIntervals("checkpoint", ss, quark, expectedStarts, expectedValues);
                 }
                     break;
+                case "or_three_operands": {
+                    final int[] expectedStarts = { 1, 5, 7, 7 };
+                    ITmfStateValue[] expectedValues = { TmfStateValue.newValueLong(1), TmfStateValue.newValueLong(0), TmfStateValue.newValueLong(1) };
+                    XmlUtilsTest.verifyStateIntervals("or_three_operands", ss, quark, expectedStarts, expectedValues);
+                }
+                    break;
                 default:
                     fail("Wrong attribute name " + name);
                     break;
index 3f5a6f73279ec2be6deaddc35ae300eb02472176..5747c5f0edf86059973b273b2bf84fbfb5c857c6 100644 (file)
                                </else>
                        </stateChange>
                </eventHandler>
+               <eventHandler eventName="*">
+                       <stateChange>
+                               <if>
+                                       <and>
+                                               <condition>
+                                                       <stateAttribute type="constant" value="test" />
+                                                       <stateValue type="long" value="0" />
+                                               </condition>
+                                               <condition>
+                                                       <stateAttribute type="constant" value="test1" />
+                                                       <stateValue type="long" value="0" />
+                                               </condition>
+                                               <condition>
+                                                       <stateAttribute type="constant" value="checkpoint" />
+                                                       <stateValue type="long" value="1" />
+                                               </condition>
+                                       </and>
+                               </if>
+                               <then>
+                                       <stateAttribute type="constant" value="or_three_operands" />
+                                       <stateValue type="long" value="0" />
+                               </then>
+                               <else>
+                                       <stateAttribute type="constant" value="or_three_operands" />
+                                       <stateValue type="long" value="1" />
+                               </else>
+                       </stateChange>
+               </eventHandler>
        </stateProvider>
 </tmfxml>
\ No newline at end of file
index 8b97c6c7f50559af3dd915c43375d1813f49e50d..81c687f8fab7bc99527777ff2bc4b2f7631c313b 100644 (file)
@@ -104,14 +104,11 @@ public class TmfXmlCondition {
             rootNode = firstElement;
             childElements = XmlUtils.getChildElements(rootNode);
         }
-        int size = rootNode.getElementsByTagName(TmfXmlStrings.STATE_VALUE).getLength();
-        fStateValues = new ArrayList<>(size);
-        if (size > 2 || size == 0) {
-            throw new IllegalArgumentException("TmfXmlCondition: a condition should have 1 or 2 state values at most"); //$NON-NLS-1$
-        }
 
         switch (rootNode.getNodeName()) {
         case TmfXmlStrings.CONDITION:
+            int size = rootNode.getElementsByTagName(TmfXmlStrings.STATE_VALUE).getLength();
+            fStateValues = new ArrayList<>(size);
             fOperator = LogicalOperator.NONE;
             if (size == 1) {
                 fConditionOperator = getConditionOperator(rootNode);
@@ -123,12 +120,14 @@ public class TmfXmlCondition {
             }
             break;
         case TmfXmlStrings.NOT:
+            fStateValues = new ArrayList<>();
             fOperator = LogicalOperator.NOT;
             fConditionOperator = ConditionOperator.NONE;
             Element element = firstElement;
             fConditions.add(modelFactory.createCondition(element, fContainer));
             break;
         case TmfXmlStrings.AND:
+            fStateValues = new ArrayList<>();
             fOperator = LogicalOperator.AND;
             fConditionOperator = ConditionOperator.NONE;
             for (Element condition : childElements) {
@@ -139,6 +138,7 @@ public class TmfXmlCondition {
             }
             break;
         case TmfXmlStrings.OR:
+            fStateValues = new ArrayList<>();
             fOperator = LogicalOperator.OR;
             fConditionOperator = ConditionOperator.NONE;
             for (Element condition : childElements) {
This page took 0.026799 seconds and 5 git commands to generate.