tmf: Update unit tests for custom event type by text line or XML element
authorPatrick Tasse <patrick.tasse@gmail.com>
Mon, 25 Jul 2016 17:22:27 +0000 (13:22 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Wed, 27 Jul 2016 18:57:27 +0000 (14:57 -0400)
Change-Id: Ie97c63b72dcc5b9483b9f25faa1c5a51c54400e7
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/77859
Reviewed-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
tmf/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/parsers/custom/CustomTxtTraceDataTest.java
tmf/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/parsers/custom/CustomXmlTraceDataTest.java
tmf/org.eclipse.tracecompass.tmf.core.tests/testfiles/txt/testTxtDefinition.xml
tmf/org.eclipse.tracecompass.tmf.core.tests/testfiles/xml/testDefinition.xml

index e4148110b9810e5e7eb9b565a35ad4b534c97917..ea6b90d5147c327e7b58bf989ec62f7c035ca089 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2016 École Polytechnique de Montréal
+ * Copyright (c) 2016 École Polytechnique de Montréal and others
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -96,6 +96,7 @@ public class CustomTxtTraceDataTest extends AbstractCustomTraceDataTest {
     private static final ICustomTestData CUSTOM_TXT_EVENT_NAME = new ICustomTestData() {
 
         private static final int NB_EVENTS = 10;
+        private static final String DEFAULT_EVENT = "DefaultName";
         private static final String ODD_EVENT = "OddName";
         private static final String EVEN_EVENT = "EvenName";
         private CustomTxtTraceDefinition fDefinition;
@@ -106,7 +107,7 @@ public class CustomTxtTraceDataTest extends AbstractCustomTraceDataTest {
             final File file = new File(TRACE_PATH);
             try (BufferedWriter writer = new BufferedWriter(new FileWriter(file));) {
                 for (int i = 1; i <= NB_EVENTS; ++i) {
-                    String evName = ((i % 2) == 0) ? EVEN_EVENT : ODD_EVENT;
+                    String evName = (i % 5) == 0 ? DEFAULT_EVENT : ((i % 2) == 0) ? EVEN_EVENT : ODD_EVENT;
                     String eventStr = i + " " + evName + "\n";
                     writer.write(eventStr);
                     int extra = i % 3;
@@ -122,7 +123,9 @@ public class CustomTxtTraceDataTest extends AbstractCustomTraceDataTest {
         public void validateEvent(ITmfEvent event) {
             assertTrue(event instanceof CustomTxtEvent);
             long ts = event.getTimestamp().getValue();
-            if (ts % 2 == 0) {
+            if (ts % 5 == 0) {
+                assertEquals("Event name", DEFAULT_EVENT, event.getName());
+            } else if (ts % 2 == 0) {
                 assertEquals("Event name", EVEN_EVENT, event.getName());
             } else {
                 assertEquals("Event name", ODD_EVENT, event.getName());
index 2eb5b7b63046eda978c7937ea2babbad0db31e07..48b811cb81cb5c4ad423290a77618c04ceacea58 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2016 École Polytechnique de Montréal
+ * Copyright (c) 2016 École Polytechnique de Montréal and others
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -98,8 +98,9 @@ public class CustomXmlTraceDataTest extends AbstractCustomTraceDataTest {
     private static final ICustomTestData CUSTOM_XML_EVENT_NAME = new ICustomTestData() {
 
         private static final int NB_EVENTS = 10;
-        private static final String ODD_EVENT = "OddName";
-        private static final String EVEN_EVENT = "EvenName";
+        private static final String DEFAULT_EVENT = "DefaultName";
+        private static final String ATTRIBUTE_EVENT = "AttributeName";
+        private static final String ELEMENT_EVENT = "ElementName";
         private CustomXmlTraceDefinition fDefinition;
 
         @Override
@@ -109,8 +110,9 @@ public class CustomXmlTraceDataTest extends AbstractCustomTraceDataTest {
             try (BufferedWriter writer = new BufferedWriter(new FileWriter(file));) {
                 writer.write("<trace>");
                 for (int i = 0; i < NB_EVENTS; ++i) {
-                    String msg = (i % 2 == 0) ? EVEN_EVENT : ODD_EVENT;
-                    String eventStr = "<element time=\"" + i + "\">" + msg + "</element>\n";
+                    String attribute = (i % 5) != 0 ? String.format(" type=\"%s\"", ATTRIBUTE_EVENT) : "";
+                    String element = (i % 5) != 0 && i % 2 != 0 ? String.format("<type>%s</type>", ELEMENT_EVENT) : "";
+                    String eventStr = String.format("<element time=\"" + i + "\"%s>%s</element>\n", attribute, element);
                     writer.write(eventStr);
                 }
                 writer.write("</trace>");
@@ -122,10 +124,12 @@ public class CustomXmlTraceDataTest extends AbstractCustomTraceDataTest {
         public void validateEvent(ITmfEvent event) {
             assertTrue(event instanceof CustomXmlEvent);
             long ts = event.getTimestamp().getValue();
-            if (ts % 2 == 0) {
-                assertEquals("Event name", EVEN_EVENT, event.getName());
+            if (ts % 5 == 0) {
+                assertEquals("Event name", DEFAULT_EVENT, event.getName());
+            } else if (ts % 2 == 0) {
+                assertEquals("Event name", ATTRIBUTE_EVENT, event.getName());
             } else {
-                assertEquals("Event name", ODD_EVENT, event.getName());
+                assertEquals("Event name", ELEMENT_EVENT, event.getName());
             }
             assertEquals("Event name and type", event.getType().getName(), event.getName());
         }
index c21f6da13e567b26f0ddedc5165747e584a7d93e..da479bf6ee6b676cb25a25f699f12e24b911e29d 100644 (file)
@@ -20,7 +20,8 @@
 <TimeStampOutputFormat>dd/MM/yyyy HH:mm:ss:SSS</TimeStampOutputFormat>
 <InputLine>
 <Cardinality max="2147483647" min="0"/>
-<RegEx>(\d*) (.*\S)</RegEx>
+<RegEx>(\d*) (.*\S)?</RegEx>
+<EventType>DefaultName</EventType>
 <InputData action="0" format="Tn" name="Timestamp" tag="TIMESTAMP"/>
 <InputData action="0" name="Event type" tag="EVENT_TYPE"/>
 <InputLine>
index 3eddce1677299f1f5f3d08d525e540fd531d46f0..ccdc4adbca59c70693b4f602470e8f074bf19632 100644 (file)
 <Definition name="xmlevname">
 <TimeStampOutputFormat>HH:mm:ss:SSS</TimeStampOutputFormat>
 <InputElement name="trace">
-<InputElement logentry="true" name="element">
-<InputData action="0" name="Event type" tag="EVENT_TYPE"/>
+<InputElement eventtype="DefaultName" logentry="true" name="element">
+<InputData action="0" name="Ignore" tag="IGNORE"/>
 <Attribute name="time">
 <InputData action="0" format="Tn" name="Timestamp" tag="TIMESTAMP"/>
 </Attribute>
+<Attribute name="type">
+<InputData action="0" name="Event type" tag="EVENT_TYPE"/>
+</Attribute>
+<InputElement name="type">
+<InputData action="0" name="Event type" tag="EVENT_TYPE"/>
+</InputElement>
 </InputElement>
 </InputElement>
 <OutputColumn name="Timestamp" tag="TIMESTAMP"/>
This page took 0.02741 seconds and 5 git commands to generate.