tmf : fix the 'Not' condition in TmfXmlCondition
authorJean-Christian Kouame <jean-christian.kouame@ericsson.com>
Wed, 13 Jan 2016 22:47:09 +0000 (17:47 -0500)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Tue, 19 Jan 2016 21:10:19 +0000 (16:10 -0500)
Now, a 'Not' condition "Not X" will create a subcondition using its
first children instead of itself; which was actually creating the
condition "X".
Also, this patch update TmfXmlConditionTest to validate the fix.

Change-Id: I5b14d345c652a8eb553728c56ba6933b87a56ddd
Signed-off-by: Jean-Christian Kouame <jean-christian.kouame@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/64309
Reviewed-by: Hudson CI
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-by: Matthew Khouzam <matthew.khouzam@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 8d4d0fe6611b1dda9bf073197e1bafd7b71bdb52..762afcc3b38bcbae28b3580d9dad42814a2d9823 100644 (file)
@@ -55,7 +55,7 @@ public class TmfXmlConditionTest {
             assertNotNull(ss);
 
             List<Integer> quarks = ss.getQuarks("*");
-            assertEquals(4, quarks.size());
+            assertEquals(5, quarks.size());
 
             for (Integer quark : quarks) {
                 String name = ss.getAttributeName(quark);
@@ -78,10 +78,16 @@ public class TmfXmlConditionTest {
                     XmlUtilsTest.verifyStateIntervals("checkpoint", ss, quark, expectedStarts, expectedValues);
                 }
                     break;
-                case "or_three_operands": {
+                case "and_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);
+                    XmlUtilsTest.verifyStateIntervals("and_three_operands", ss, quark, expectedStarts, expectedValues);
+                }
+                    break;
+                case "not_operand": {
+                    final int[] expectedStarts = { 1, 5, 7, 7 };
+                    ITmfStateValue[] expectedValues = { TmfStateValue.newValueLong(0), TmfStateValue.newValueLong(1), TmfStateValue.newValueLong(0) };
+                    XmlUtilsTest.verifyStateIntervals("not_operand", ss, quark, expectedStarts, expectedValues);
                 }
                     break;
                 default:
index 5747c5f0edf86059973b273b2bf84fbfb5c857c6..afe39b88bc7c495e0562095d8c1106349ad3b167 100644 (file)
 <tmfxml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="xmlDefinition.xsd">
 
+<!-- ***************************************************************************
+* The following represents the state of the attributes in the system after the
+* analysis.
+*
+* n corresponds to a null state value
+*
+* Timestamp                    |       1       |       3       |       5       |       7       |
+* -events and field value-
+* ev.test                      |       10                              20
+* ev.test1                     |                       100                             200
+* -states-
+* test                         |       1                               0
+* test1                                |       n               0                               1
+* checkpoint           |       0                               1               0
+* or_three_operands    |       1                               0               1
+* not_operand          |       0                               1               0
+*
+*************************************************************************** -->
+
        <stateProvider id="test.xml.conditions" version="1">
                <eventHandler eventName="test">
                        <stateChange>
                                        </and>
                                </if>
                                <then>
-                                       <stateAttribute type="constant" value="or_three_operands" />
+                                       <stateAttribute type="constant" value="and_three_operands" />
                                        <stateValue type="long" value="0" />
                                </then>
                                <else>
-                                       <stateAttribute type="constant" value="or_three_operands" />
+                                       <stateAttribute type="constant" value="and_three_operands" />
                                        <stateValue type="long" value="1" />
                                </else>
                        </stateChange>
                </eventHandler>
+               <eventHandler eventName="*">
+                       <stateChange>
+                               <if>
+                                       <not>
+                                               <condition>
+                                                       <stateAttribute type="constant" value="and_three_operands" />
+                                                       <stateValue type="long" value="1" />
+                                               </condition>
+                                       </not>
+                               </if>
+                               <then>
+                                       <stateAttribute type="constant" value="not_operand" />
+                                       <stateValue type="long" value="1" />
+                               </then>
+                               <else>
+                                       <stateAttribute type="constant" value="not_operand" />
+                                       <stateValue type="long" value="0" />
+                               </else>
+                       </stateChange>
+               </eventHandler>
        </stateProvider>
 </tmfxml>
\ No newline at end of file
index 81c687f8fab7bc99527777ff2bc4b2f7631c313b..e9705e743e08fa0ea2c98a68fe04fb30324c1a84 100644 (file)
@@ -90,7 +90,6 @@ public class TmfXmlCondition {
         Element rootNode = node;
         /* Process the conditions: in each case, only process Element nodes */
         List<@Nullable Element> childElements = XmlUtils.getChildElements(rootNode);
-        final Element firstElement = NonNullUtils.checkNotNull(childElements.get(0));
 
         /*
          * If the node is an if, take the child as the root condition
@@ -101,7 +100,7 @@ public class TmfXmlCondition {
             if (childElements.isEmpty()) {
                 throw new IllegalArgumentException("TmfXmlCondition constructor: IF node with no child element"); //$NON-NLS-1$
             }
-            rootNode = firstElement;
+            rootNode = NonNullUtils.checkNotNull(childElements.get(0));
             childElements = XmlUtils.getChildElements(rootNode);
         }
 
@@ -123,7 +122,7 @@ public class TmfXmlCondition {
             fStateValues = new ArrayList<>();
             fOperator = LogicalOperator.NOT;
             fConditionOperator = ConditionOperator.NONE;
-            Element element = firstElement;
+            Element element = NonNullUtils.checkNotNull(childElements.get(0));
             fConditions.add(modelFactory.createCondition(element, fContainer));
             break;
         case TmfXmlStrings.AND:
This page took 0.029768 seconds and 5 git commands to generate.