tmf: Add filter node unit tests
authorPatrick Tasse <patrick.tasse@gmail.com>
Mon, 12 Jan 2015 16:39:17 +0000 (11:39 -0500)
committerPatrick Tasse <patrick.tasse@gmail.com>
Wed, 4 Feb 2015 17:49:07 +0000 (12:49 -0500)
Change-Id: I7dbc6f641fa57c83ccbf5ee7783fa2b658bf195c
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/39432
Reviewed-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/AllTests.java
org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterAndNodeTest.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterCompareNodeTest.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterContainsNodeTest.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterEqualsNodeTest.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterMatchesNodeTest.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterNodeTest.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterOrNodeTest.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterRootNodeTest.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterTraceTypeNodeTest.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterTreeNodeTest.java [new file with mode: 0644]

index d63bb2d71e6f8c2625ece5a2b2800a2f9f946ab2..f5b0b9d4293d8e29b42482905359cbb4a573a12a 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014 Ericsson
+ * Copyright (c) 2014, 2015 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -8,6 +8,7 @@
  *
  * Contributors:
  *   Bernd Hufmann - Initial API and implementation
+ *   Patrick Tasse - Added filter node tests
  *******************************************************************************/
 
 package org.eclipse.tracecompass.tmf.core.tests.filter;
@@ -20,6 +21,15 @@ import org.junit.runners.Suite;
  */
 @RunWith(Suite.class)
 @Suite.SuiteClasses({
+    TmfFilterAndNodeTest.class,
+    TmfFilterCompareNodeTest.class,
+    TmfFilterContainsNodeTest.class,
+    TmfFilterEqualsNodeTest.class,
+    TmfFilterMatchesNodeTest.class,
+    TmfFilterNodeTest.class,
+    TmfFilterOrNodeTest.class,
+    TmfFilterRootNodeTest.class,
+    TmfFilterTraceTypeNodeTest.class,
     TmfCollapseFilterTest.class,
 })
 public class AllTests {
diff --git a/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterAndNodeTest.java b/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterAndNodeTest.java
new file mode 100644 (file)
index 0000000..5aace92
--- /dev/null
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.core.tests.filter;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
+import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
+import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test suite for the {@link TmfFilterAndNode} class.
+ *
+ * @author Patrick Tasse
+ */
+@SuppressWarnings("javadoc")
+public class TmfFilterAndNodeTest extends TmfFilterTreeNodeTest {
+
+    // ------------------------------------------------------------------------
+    // Variables
+    // ------------------------------------------------------------------------
+
+    private ITmfEventField fContent = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, null);
+    private TmfEvent fEvent = new TmfEvent(TRACE, 0, new TmfNanoTimestamp(1), EVENT_TYPE, fContent);
+    private TmfFilterAndNode fFilter;
+
+    // ------------------------------------------------------------------------
+    // Tests
+    // ------------------------------------------------------------------------
+
+    @Before
+    public void createFilter() {
+        fFilter = new TmfFilterAndNode(null);
+        fFilterNode = fFilter;
+    }
+
+    @Test
+    public void testMatches() {
+        fFilter.addChild(TRUE_NODE);
+        fFilter.addChild(TRUE_NODE);
+        assertTrue(fFilter.matches(fEvent));
+
+        fFilter.replaceChild(0, FALSE_NODE);
+        assertFalse(fFilter.matches(fEvent));
+
+        fFilter.setNot(true);
+        assertTrue(fFilter.matches(fEvent));
+    }
+
+    @Test
+    public void testGetName() {
+        assertEquals("getName()", "AND", fFilter.getNodeName());
+    }
+
+    @Test
+    public void testGetValidChildren() {
+        Set<String> validChildren = new HashSet<>(Arrays.asList(
+                TmfFilterTraceTypeNode.NODE_NAME,
+                TmfFilterAndNode.NODE_NAME,
+                TmfFilterOrNode.NODE_NAME,
+                TmfFilterContainsNode.NODE_NAME,
+                TmfFilterEqualsNode.NODE_NAME,
+                TmfFilterMatchesNode.NODE_NAME,
+                TmfFilterCompareNode.NODE_NAME));
+        assertEquals("getValidChildren()", validChildren, new HashSet<>(fFilter.getValidChildren()));
+    }
+}
diff --git a/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterCompareNodeTest.java b/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterCompareNodeTest.java
new file mode 100644 (file)
index 0000000..b344f20
--- /dev/null
@@ -0,0 +1,154 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.core.tests.filter;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
+import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
+import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
+import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
+import org.eclipse.tracecompass.tmf.core.event.aspect.TmfEventFieldAspect;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode.Type;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test suite for the {@link TmfFilterCompareNode} class.
+ *
+ * @author Patrick Tasse
+ */
+@SuppressWarnings("javadoc")
+public class TmfFilterCompareNodeTest extends TmfFilterTreeNodeTest {
+
+    // ------------------------------------------------------------------------
+    // Variables
+    // ------------------------------------------------------------------------
+
+    private ITmfEventField[] fFields1 = new ITmfEventField[] { new TmfEventField(FIELD, "1", null) };
+    private ITmfEventField[] fFields2 = new ITmfEventField[] { new TmfEventField(FIELD, "5", null) };
+    private ITmfEventField[] fFields3 = new ITmfEventField[] { new TmfEventField(FIELD, "11", null) };
+    private ITmfEventField fContent1 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, fFields1);
+    private ITmfEventField fContent2 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, fFields2);
+    private ITmfEventField fContent3 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, fFields3);
+    private TmfEvent fEvent1 = new TmfEvent(TRACE, 0, new TmfNanoTimestamp(1), EVENT_TYPE, fContent1);
+    private TmfEvent fEvent2 = new TmfEvent(TRACE, 1, new TmfNanoTimestamp(2), EVENT_TYPE, fContent2);
+    private TmfEvent fEvent3 = new TmfEvent(TRACE, 2, new TmfNanoTimestamp(3), EVENT_TYPE, fContent3);
+    private TmfFilterCompareNode fFilter;
+
+    // ------------------------------------------------------------------------
+    // Tests
+    // ------------------------------------------------------------------------
+
+    @Before
+    public void createFilter() {
+        fFilter = new TmfFilterCompareNode(null);
+        fFilterNode = fFilter;
+    }
+
+    @Test
+    public void testMatchesNum() {
+        fFilter.setEventAspect(new TmfEventFieldAspect(FIELD, FIELD));
+        fFilter.setType(Type.NUM);
+        fFilter.setValue("5");
+
+        fFilter.setResult(-1);
+        assertTrue(fFilter.matches(fEvent1));
+        assertFalse(fFilter.matches(fEvent2));
+        assertFalse(fFilter.matches(fEvent3));
+
+        fFilter.setResult(0);
+        assertFalse(fFilter.matches(fEvent1));
+        assertTrue(fFilter.matches(fEvent2));
+        assertFalse(fFilter.matches(fEvent3));
+
+        fFilter.setResult(1);
+        assertFalse(fFilter.matches(fEvent1));
+        assertFalse(fFilter.matches(fEvent2));
+        assertTrue(fFilter.matches(fEvent3));
+
+        fFilter.setNot(true);
+        assertTrue(fFilter.matches(fEvent1));
+        assertTrue(fFilter.matches(fEvent2));
+        assertFalse(fFilter.matches(fEvent3));
+    }
+
+    @Test
+    public void testMatchesAlpha() {
+        fFilter.setEventAspect(new TmfEventFieldAspect(FIELD, FIELD));
+        fFilter.setType(Type.ALPHA);
+        fFilter.setValue("5");
+
+        fFilter.setResult(-1);
+        assertTrue(fFilter.matches(fEvent1));
+        assertFalse(fFilter.matches(fEvent2));
+        assertTrue(fFilter.matches(fEvent3));
+
+        fFilter.setResult(0);
+        assertFalse(fFilter.matches(fEvent1));
+        assertTrue(fFilter.matches(fEvent2));
+        assertFalse(fFilter.matches(fEvent3));
+
+        fFilter.setResult(1);
+        assertFalse(fFilter.matches(fEvent1));
+        assertFalse(fFilter.matches(fEvent2));
+        assertFalse(fFilter.matches(fEvent3));
+
+        fFilter.setNot(true);
+        assertTrue(fFilter.matches(fEvent1));
+        assertTrue(fFilter.matches(fEvent2));
+        assertTrue(fFilter.matches(fEvent3));
+    }
+
+    @Test
+    public void testMatchesTimestamp() {
+        fFilter.setEventAspect(ITmfEventAspect.BaseAspects.TIMESTAMP);
+        fFilter.setType(Type.TIMESTAMP);
+        fFilter.setValue("0.000000002");
+
+        fFilter.setResult(-1);
+        assertTrue(fFilter.matches(fEvent1));
+        assertFalse(fFilter.matches(fEvent2));
+        assertFalse(fFilter.matches(fEvent3));
+
+        fFilter.setResult(0);
+        assertFalse(fFilter.matches(fEvent1));
+        assertTrue(fFilter.matches(fEvent2));
+        assertFalse(fFilter.matches(fEvent3));
+
+        fFilter.setResult(1);
+        assertFalse(fFilter.matches(fEvent1));
+        assertFalse(fFilter.matches(fEvent2));
+        assertTrue(fFilter.matches(fEvent3));
+
+        fFilter.setNot(true);
+        assertTrue(fFilter.matches(fEvent1));
+        assertTrue(fFilter.matches(fEvent2));
+        assertFalse(fFilter.matches(fEvent3));
+    }
+
+    @Test
+    public void testGetName() {
+        assertEquals("getName()", "COMPARE", fFilter.getNodeName());
+    }
+
+    @Test
+    public void testGetValidChildren() {
+        assertArrayEquals("getValidChildren()", new String[] {}, fFilter.getValidChildren().toArray());
+    }
+}
diff --git a/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterContainsNodeTest.java b/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterContainsNodeTest.java
new file mode 100644 (file)
index 0000000..59bf203
--- /dev/null
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.core.tests.filter;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
+import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
+import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
+import org.eclipse.tracecompass.tmf.core.event.aspect.TmfEventFieldAspect;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test suite for the {@link TmfFilterContainsNode} class.
+ *
+ * @author Patrick Tasse
+ */
+@SuppressWarnings("javadoc")
+public class TmfFilterContainsNodeTest extends TmfFilterTreeNodeTest {
+
+    // ------------------------------------------------------------------------
+    // Variables
+    // ------------------------------------------------------------------------
+
+    private ITmfEventField[] fFields1 = new ITmfEventField[] { new TmfEventField(FIELD, "value 1", null) };
+    private ITmfEventField[] fFields2 = new ITmfEventField[] { new TmfEventField(FIELD, "value 2", null) };
+    private ITmfEventField fContent1 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, fFields1);
+    private ITmfEventField fContent2 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, fFields2);
+    private TmfEvent fEvent1 = new TmfEvent(TRACE, 0, new TmfNanoTimestamp(1), EVENT_TYPE, fContent1);
+    private TmfEvent fEvent2 = new TmfEvent(TRACE, 1, new TmfNanoTimestamp(2), EVENT_TYPE, fContent2);
+    private TmfFilterContainsNode fFilter;
+
+    // ------------------------------------------------------------------------
+    // Tests
+    // ------------------------------------------------------------------------
+
+    @Before
+    public void createFilter() {
+        fFilter = new TmfFilterContainsNode(null);
+        fFilterNode = fFilter;
+    }
+
+    @Test
+    public void testMatches() {
+        fFilter.setEventAspect(new TmfEventFieldAspect(FIELD, FIELD));
+
+        fFilter.setValue("1");
+        assertTrue(fFilter.matches(fEvent1));
+        assertFalse(fFilter.matches(fEvent2));
+
+        fFilter.setValue("value");
+        assertTrue(fFilter.matches(fEvent1));
+        assertTrue(fFilter.matches(fEvent2));
+
+        fFilter.setValue("VALUE");
+        assertFalse(fFilter.matches(fEvent1));
+        assertFalse(fFilter.matches(fEvent2));
+
+        fFilter.setIgnoreCase(true);
+        assertTrue(fFilter.matches(fEvent1));
+        assertTrue(fFilter.matches(fEvent2));
+
+        fFilter.setNot(true);
+        assertFalse(fFilter.matches(fEvent1));
+        assertFalse(fFilter.matches(fEvent2));
+    }
+
+    @Test
+    public void testGetName() {
+        assertEquals("getName()", "CONTAINS", fFilter.getNodeName());
+    }
+
+    @Test
+    public void testGetValidChildren() {
+        assertArrayEquals("getValidChildren()", new String[] {}, fFilter.getValidChildren().toArray());
+    }
+}
diff --git a/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterEqualsNodeTest.java b/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterEqualsNodeTest.java
new file mode 100644 (file)
index 0000000..0501de1
--- /dev/null
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.core.tests.filter;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
+import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
+import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
+import org.eclipse.tracecompass.tmf.core.event.aspect.TmfEventFieldAspect;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test suite for the {@link TmfFilterEqualsNode} class.
+ *
+ * @author Patrick Tasse
+ */
+@SuppressWarnings("javadoc")
+public class TmfFilterEqualsNodeTest extends TmfFilterTreeNodeTest {
+
+    // ------------------------------------------------------------------------
+    // Variables
+    // ------------------------------------------------------------------------
+
+    private ITmfEventField[] fFields1 = new ITmfEventField[] { new TmfEventField(FIELD, "value 1", null) };
+    private ITmfEventField[] fFields2 = new ITmfEventField[] { new TmfEventField(FIELD, "value 2", null) };
+    private ITmfEventField fContent1 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, fFields1);
+    private ITmfEventField fContent2 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, fFields2);
+    private TmfEvent fEvent1 = new TmfEvent(TRACE, 0, new TmfNanoTimestamp(1), EVENT_TYPE, fContent1);
+    private TmfEvent fEvent2 = new TmfEvent(TRACE, 1, new TmfNanoTimestamp(2), EVENT_TYPE, fContent2);
+    private TmfFilterEqualsNode fFilter;
+
+    // ------------------------------------------------------------------------
+    // Tests
+    // ------------------------------------------------------------------------
+
+    @Before
+    public void createFilter() {
+        fFilter = new TmfFilterEqualsNode(null);
+        fFilterNode = fFilter;
+    }
+
+    @Test
+    public void testMatches() {
+        fFilter.setEventAspect(new TmfEventFieldAspect(FIELD, FIELD));
+
+        fFilter.setValue("value");
+        assertFalse(fFilter.matches(fEvent1));
+        assertFalse(fFilter.matches(fEvent2));
+
+        fFilter.setValue("value 1");
+        assertTrue(fFilter.matches(fEvent1));
+        assertFalse(fFilter.matches(fEvent2));
+
+        fFilter.setValue("VALUE 1");
+        assertFalse(fFilter.matches(fEvent1));
+        assertFalse(fFilter.matches(fEvent2));
+
+        fFilter.setIgnoreCase(true);
+        assertTrue(fFilter.matches(fEvent1));
+        assertFalse(fFilter.matches(fEvent2));
+
+        fFilter.setNot(true);
+        assertFalse(fFilter.matches(fEvent1));
+        assertTrue(fFilter.matches(fEvent2));
+    }
+
+    @Test
+    public void testGetName() {
+        assertEquals("getName()", "EQUALS", fFilter.getNodeName());
+    }
+
+    @Test
+    public void testGetValidChildren() {
+        assertArrayEquals("getValidChildren()", new String[] {}, fFilter.getValidChildren().toArray());
+    }
+}
diff --git a/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterMatchesNodeTest.java b/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterMatchesNodeTest.java
new file mode 100644 (file)
index 0000000..2f1d07d
--- /dev/null
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.core.tests.filter;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
+import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
+import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
+import org.eclipse.tracecompass.tmf.core.event.aspect.TmfEventFieldAspect;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test suite for the {@link TmfFilterMatchesNode} class.
+ *
+ * @author Patrick Tasse
+ */
+@SuppressWarnings("javadoc")
+public class TmfFilterMatchesNodeTest extends TmfFilterTreeNodeTest {
+
+    // ------------------------------------------------------------------------
+    // Variables
+    // ------------------------------------------------------------------------
+
+    private ITmfEventField[] fFields1 = new ITmfEventField[] { new TmfEventField(FIELD, "value 1", null) };
+    private ITmfEventField[] fFields2 = new ITmfEventField[] { new TmfEventField(FIELD, "value 2", null) };
+    private ITmfEventField fContent1 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, fFields1);
+    private ITmfEventField fContent2 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, fFields2);
+    private TmfEvent fEvent1 = new TmfEvent(TRACE, 0, new TmfNanoTimestamp(1), EVENT_TYPE, fContent1);
+    private TmfEvent fEvent2 = new TmfEvent(TRACE, 1, new TmfNanoTimestamp(2), EVENT_TYPE, fContent2);
+    private TmfFilterMatchesNode fFilter;
+
+    // ------------------------------------------------------------------------
+    // Tests
+    // ------------------------------------------------------------------------
+
+    @Before
+    public void createFilter() {
+        fFilter = new TmfFilterMatchesNode(null);
+        fFilterNode = fFilter;
+    }
+
+    @Test
+    public void testMatches() {
+        fFilter.setEventAspect(new TmfEventFieldAspect(FIELD, FIELD));
+
+        fFilter.setRegex("value");
+        assertFalse(fFilter.matches(fEvent1));
+        assertFalse(fFilter.matches(fEvent2));
+
+        fFilter.setRegex(".* 1");
+        assertTrue(fFilter.matches(fEvent1));
+        assertFalse(fFilter.matches(fEvent2));
+
+        fFilter.setNot(true);
+        assertFalse(fFilter.matches(fEvent1));
+        assertTrue(fFilter.matches(fEvent2));
+    }
+
+    @Test
+    public void testGetName() {
+        assertEquals("getName()", "MATCHES", fFilter.getNodeName());
+    }
+
+    @Test
+    public void testGetValidChildren() {
+        assertArrayEquals("getValidChildren()", new String[] {}, fFilter.getValidChildren().toArray());
+    }
+}
diff --git a/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterNodeTest.java b/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterNodeTest.java
new file mode 100644 (file)
index 0000000..14f953f
--- /dev/null
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.core.tests.filter;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
+import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
+import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test suite for the {@link TmfFilterNode} class.
+ *
+ * @author Patrick Tasse
+ */
+@SuppressWarnings("javadoc")
+public class TmfFilterNodeTest extends TmfFilterTreeNodeTest {
+
+    // ------------------------------------------------------------------------
+    // Variables
+    // ------------------------------------------------------------------------
+
+    private static final String FILTER = "filter";
+    private ITmfEventField fContent = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, null);
+    private TmfEvent fEvent = new TmfEvent(TRACE, 0, new TmfNanoTimestamp(1), EVENT_TYPE, fContent);
+    private TmfFilterNode fFilter;
+
+    // ------------------------------------------------------------------------
+    // Tests
+    // ------------------------------------------------------------------------
+
+    @Before
+    public void createFilter() {
+        fFilter = new TmfFilterNode(null, FILTER);
+        fFilterNode = fFilter;
+    }
+
+    @Test
+    public void testMatches() {
+        fFilter.addChild(TRUE_NODE);
+        assertTrue(fFilter.matches(fEvent));
+
+        fFilter.replaceChild(0, FALSE_NODE);
+        assertFalse(fFilter.matches(fEvent));
+    }
+
+    @Test
+    public void testGetFilterName() {
+        assertEquals("getFilterName()", FILTER, fFilter.getFilterName());
+    }
+
+    @Test
+    public void testGetName() {
+        assertEquals("getName()", "FILTER", fFilter.getNodeName());
+    }
+
+    @Test
+    public void testGetValidChildren() {
+        Set<String> validChildren = new HashSet<>(Arrays.asList(
+                TmfFilterTraceTypeNode.NODE_NAME,
+                TmfFilterAndNode.NODE_NAME,
+                TmfFilterOrNode.NODE_NAME,
+                TmfFilterContainsNode.NODE_NAME,
+                TmfFilterEqualsNode.NODE_NAME,
+                TmfFilterMatchesNode.NODE_NAME,
+                TmfFilterCompareNode.NODE_NAME));
+        assertEquals("getValidChildren()", validChildren, new HashSet<>(fFilter.getValidChildren()));
+    }
+}
diff --git a/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterOrNodeTest.java b/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterOrNodeTest.java
new file mode 100644 (file)
index 0000000..0357c72
--- /dev/null
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.core.tests.filter;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
+import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
+import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test suite for the {@link TmfFilterOrNode} class.
+ *
+ * @author Patrick Tasse
+ */
+@SuppressWarnings("javadoc")
+public class TmfFilterOrNodeTest extends TmfFilterTreeNodeTest {
+
+    // ------------------------------------------------------------------------
+    // Variables
+    // ------------------------------------------------------------------------
+
+    private ITmfEventField fContent = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, null);
+    private TmfEvent fEvent = new TmfEvent(TRACE, 0, new TmfNanoTimestamp(1), EVENT_TYPE, fContent);
+    private TmfFilterOrNode fFilter;
+
+    // ------------------------------------------------------------------------
+    // Tests
+    // ------------------------------------------------------------------------
+
+    @Before
+    public void createFilter() {
+        fFilter = new TmfFilterOrNode(null);
+        fFilterNode = fFilter;
+    }
+
+    @Test
+    public void testMatches() {
+        fFilter.addChild(TRUE_NODE);
+        fFilter.addChild(TRUE_NODE);
+        assertTrue(fFilter.matches(fEvent));
+
+        fFilter.replaceChild(0, FALSE_NODE);
+        assertTrue(fFilter.matches(fEvent));
+
+        fFilter.setNot(true);
+        assertFalse(fFilter.matches(fEvent));
+    }
+
+    @Test
+    public void testGetName() {
+        assertEquals("getName()", "OR", fFilter.getNodeName());
+    }
+
+    @Test
+    public void testGetValidChildren() {
+        Set<String> validChildren = new HashSet<>(Arrays.asList(
+                TmfFilterTraceTypeNode.NODE_NAME,
+                TmfFilterAndNode.NODE_NAME,
+                TmfFilterOrNode.NODE_NAME,
+                TmfFilterContainsNode.NODE_NAME,
+                TmfFilterEqualsNode.NODE_NAME,
+                TmfFilterMatchesNode.NODE_NAME,
+                TmfFilterCompareNode.NODE_NAME));
+        assertEquals("getValidChildren()", validChildren, new HashSet<>(fFilter.getValidChildren()));
+    }
+}
diff --git a/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterRootNodeTest.java b/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterRootNodeTest.java
new file mode 100644 (file)
index 0000000..01317ba
--- /dev/null
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.core.tests.filter;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
+import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
+import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test suite for the {@link TmfFilterRootNode} class.
+ *
+ * @author Patrick Tasse
+ */
+@SuppressWarnings("javadoc")
+public class TmfFilterRootNodeTest extends TmfFilterTreeNodeTest {
+
+    // ------------------------------------------------------------------------
+    // Variables
+    // ------------------------------------------------------------------------
+
+    private ITmfEventField fContent = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, null);
+    private TmfEvent fEvent = new TmfEvent(TRACE, 0, new TmfNanoTimestamp(1), EVENT_TYPE, fContent);
+    private TmfFilterRootNode fFilter;
+
+    // ------------------------------------------------------------------------
+    // Tests
+    // ------------------------------------------------------------------------
+
+    @Before
+    public void createFilter() {
+        fFilter = new TmfFilterRootNode();
+        fFilterNode = fFilter;
+    }
+
+    @Test
+    public void testMatches() {
+        fFilter.addChild(TRUE_NODE);
+        fFilter.addChild(TRUE_NODE);
+        assertTrue(fFilter.matches(fEvent));
+
+        fFilter.replaceChild(0, FALSE_NODE);
+        assertFalse(fFilter.matches(fEvent));
+    }
+
+    @Test
+    public void testGetName() {
+        assertEquals("getName()", "ROOT", fFilter.getNodeName());
+    }
+
+    @Test
+    public void testGetValidChildren() {
+        assertArrayEquals("getValidChildren()", new String[] { TmfFilterNode.NODE_NAME }, fFilter.getValidChildren().toArray());
+    }
+}
diff --git a/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterTraceTypeNodeTest.java b/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterTraceTypeNodeTest.java
new file mode 100644 (file)
index 0000000..d6e65b0
--- /dev/null
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.core.tests.filter;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
+import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
+import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
+import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtEvent;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtEventType;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTrace;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlEvent;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlEventType;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlInputElement;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTrace;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
+import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test suite for the {@link TmfFilterTraceTypeNode} class.
+ *
+ * @author Patrick Tasse
+ */
+@SuppressWarnings("javadoc")
+public class TmfFilterTraceTypeNodeTest extends TmfFilterTreeNodeTest {
+
+    // ------------------------------------------------------------------------
+    // Variables
+    // ------------------------------------------------------------------------
+
+    private static final String CATEGORY_TXT = "txt";
+    private static final String CATEGORY_XML = "xml";
+    private static final String DEFINITION_NAME_TXT = "name txt";
+    private static final String DEFINITION_NAME_XML = "name xml";
+    private static final String SEP = ":";
+    private static CustomTxtTraceDefinition fCustomTxtDefinition = new CustomTxtTraceDefinition();
+    private static CustomXmlTraceDefinition fCustomXmlDefinition = new CustomXmlTraceDefinition();
+    static {
+        fCustomTxtDefinition.categoryName = CATEGORY_TXT;
+        fCustomTxtDefinition.definitionName = DEFINITION_NAME_TXT;
+        fCustomXmlDefinition.categoryName = CATEGORY_XML;
+        fCustomXmlDefinition.definitionName = DEFINITION_NAME_XML;
+        fCustomXmlDefinition.rootInputElement = new CustomXmlInputElement();
+    }
+    private static CustomTxtTrace fCustomTxtTrace = new CustomTxtTrace(fCustomTxtDefinition);
+    private static CustomXmlTrace fCustomXmlTrace = new CustomXmlTrace(fCustomXmlDefinition);
+    private static TmfEventType fCustomTxtEventType = new CustomTxtEventType(fCustomTxtDefinition);
+    private static TmfEventType fCustomXmlEventType = new CustomXmlEventType(fCustomXmlDefinition);
+    private ITmfEventField fContent = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, null);
+    private TmfEvent fEvent1 = new TmfEvent(TRACE, 0, new TmfNanoTimestamp(1), EVENT_TYPE, fContent);
+    private TmfEvent fEvent2 = new CustomTxtEvent(fCustomTxtDefinition, fCustomTxtTrace, new TmfNanoTimestamp(2), fCustomTxtEventType);
+    private TmfEvent fEvent3 = new CustomXmlEvent(fCustomXmlDefinition, fCustomXmlTrace, new TmfNanoTimestamp(3), fCustomXmlEventType);
+    private TmfFilterTraceTypeNode fFilter;
+
+    @AfterClass
+    public static void disposeCustomTraces() {
+        fCustomTxtTrace.dispose();
+        fCustomXmlTrace.dispose();
+    }
+
+    // ------------------------------------------------------------------------
+    // Tests
+    // ------------------------------------------------------------------------
+
+    @Before
+    public void createFilter() {
+        fFilter = new TmfFilterTraceTypeNode(null);
+        fFilterNode = fFilter;
+    }
+
+    @Test
+    public void testMatches() {
+        fFilter.setTraceClass(TmfTraceStub.class);
+        assertTrue(fFilter.matches(fEvent1));
+        assertFalse(fFilter.matches(fEvent2));
+        assertFalse(fFilter.matches(fEvent3));
+
+        fFilter.setTraceClass(CustomTxtTrace.class);
+        fFilter.setTraceTypeId(CustomTxtTrace.class.getCanonicalName() + SEP + CATEGORY_TXT + SEP + DEFINITION_NAME_TXT);
+        assertFalse(fFilter.matches(fEvent1));
+        assertTrue(fFilter.matches(fEvent2));
+        assertFalse(fFilter.matches(fEvent3));
+
+        fFilter.setTraceClass(CustomXmlTrace.class);
+        fFilter.setTraceTypeId(CustomXmlTrace.class.getCanonicalName() + SEP + CATEGORY_XML + SEP + DEFINITION_NAME_XML);
+        assertFalse(fFilter.matches(fEvent1));
+        assertFalse(fFilter.matches(fEvent2));
+        assertTrue(fFilter.matches(fEvent3));
+
+        fFilter.setTraceClass(CustomTxtTrace.class);
+        fFilter.setTraceTypeId(CustomTxtTrace.class.getCanonicalName() + SEP + CATEGORY_XML + SEP + DEFINITION_NAME_XML);
+        assertFalse(fFilter.matches(fEvent1));
+        assertFalse(fFilter.matches(fEvent2));
+        assertFalse(fFilter.matches(fEvent3));
+    }
+
+    @Test
+    public void testGetName() {
+        assertEquals("getName()", "TRACETYPE", fFilter.getNodeName());
+    }
+
+    @Test
+    public void testGetValidChildren() {
+        Set<String> validChildren = new HashSet<>(Arrays.asList(
+                TmfFilterTraceTypeNode.NODE_NAME,
+                TmfFilterAndNode.NODE_NAME,
+                TmfFilterOrNode.NODE_NAME,
+                TmfFilterContainsNode.NODE_NAME,
+                TmfFilterEqualsNode.NODE_NAME,
+                TmfFilterMatchesNode.NODE_NAME,
+                TmfFilterCompareNode.NODE_NAME));
+        assertEquals("getValidChildren()", validChildren, new HashSet<>(fFilter.getValidChildren()));
+    }
+}
diff --git a/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterTreeNodeTest.java b/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterTreeNodeTest.java
new file mode 100644 (file)
index 0000000..7ed66c1
--- /dev/null
@@ -0,0 +1,124 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.core.tests.filter;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEventType;
+import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
+import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
+import org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+/**
+ * Test suite for the {@link TmfFilterTreeNodeTest} class.
+ *
+ * @author Patrick Tasse
+ */
+@SuppressWarnings("javadoc")
+public class TmfFilterTreeNodeTest {
+
+    // ------------------------------------------------------------------------
+    // Variables
+    // ------------------------------------------------------------------------
+
+    protected static final @NonNull ITmfTrace TRACE = new TmfTraceStub();
+    protected static final @NonNull String FIELD = "field";
+    protected static final ITmfFilterTreeNode TRUE_NODE = new TmfFilterNode(null) {
+        @Override
+        public boolean matches(ITmfEvent event) {
+            return true;
+        }
+    };
+    protected static final ITmfFilterTreeNode FALSE_NODE = new TmfFilterNode(null) {
+        @Override
+        public boolean matches(ITmfEvent event) {
+            return false;
+        }
+    };
+    protected static final ITmfEventType EVENT_TYPE = new TmfEventType("Type", TmfEventField.makeRoot(new String[] { FIELD }));
+    protected ITmfFilterTreeNode fFilterNode;
+
+    @AfterClass
+    public static void disposeTrace() {
+        TRACE.dispose();
+    }
+
+    // ------------------------------------------------------------------------
+    // Tests
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testDefaults() {
+        assertNull("getParent()", fFilterNode.getParent());
+        assertEquals("hasChildren()", false, fFilterNode.hasChildren());
+        assertEquals("getChildrenCount()", 0, fFilterNode.getChildrenCount());
+        assertEquals("getChildren()", 0, fFilterNode.getChildren().length);
+    }
+
+    @Test
+    public void testClone() {
+        assertEquals("clone()", fFilterNode, fFilterNode.clone());
+        assertFalse(fFilterNode == fFilterNode.clone());
+    }
+
+    @Test
+    public void testAddChild() {
+        ITmfFilterTreeNode child = fFilterNode.clone();
+        assertEquals("addChild()", 0, fFilterNode.addChild(child));
+        assertEquals("hasChildren()", true, fFilterNode.hasChildren());
+        assertEquals("removeChild()", child, fFilterNode.removeChild(child));
+    }
+
+    @Test(expected = IndexOutOfBoundsException.class)
+    public void testGetChild() {
+        fFilterNode.getChild(0);
+    }
+
+    @Test
+    public void testRemove() {
+        ITmfFilterTreeNode child = fFilterNode.clone();
+        assertEquals("addChild()", 0, fFilterNode.addChild(child));
+        assertEquals("remove()", child, child.remove());
+        assertEquals("hasChildren()", false, fFilterNode.hasChildren());
+    }
+
+    @Test
+    public void testRemoveChild() {
+        ITmfFilterTreeNode child = fFilterNode.clone();
+        assertEquals("addChild()", 0, fFilterNode.addChild(child));
+        assertEquals("removeChild()", child, fFilterNode.removeChild(child));
+        assertEquals("hasChildren()", false, fFilterNode.hasChildren());
+    }
+
+    @Test
+    public void testReplaceChild() {
+        ITmfFilterTreeNode child1 = fFilterNode.clone();
+        ITmfFilterTreeNode child2 = fFilterNode.clone();
+        child1.addChild(child1.clone());
+        assertEquals("addChild()", 0, fFilterNode.addChild(child1));
+        assertEquals("getChild()", child1, fFilterNode.getChild(0));
+        assertEquals("replaceChild()", child1, fFilterNode.replaceChild(0, child2));
+        assertEquals("getChildrenCount()", 1, fFilterNode.getChildrenCount());
+        assertEquals("getChild()", child2, fFilterNode.getChild(0));
+        assertEquals("removeChild()", child2, fFilterNode.removeChild(child2));
+    }
+}
This page took 0.039313 seconds and 5 git commands to generate.