1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
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
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.core
.tests
.filter
;
15 import static org
.junit
.Assert
.assertEquals
;
16 import static org
.junit
.Assert
.assertFalse
;
17 import static org
.junit
.Assert
.assertNull
;
19 import org
.eclipse
.jdt
.annotation
.NonNull
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventType
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEventField
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEventType
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.ITmfFilterTreeNode
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterNode
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
27 import org
.eclipse
.tracecompass
.tmf
.tests
.stubs
.trace
.TmfTraceStub
;
28 import org
.junit
.AfterClass
;
29 import org
.junit
.Test
;
32 * Test suite for the {@link TmfFilterTreeNodeTest} class.
34 * @author Patrick Tasse
36 @SuppressWarnings("javadoc")
37 public class TmfFilterTreeNodeTest
{
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
43 protected static final @NonNull ITmfTrace TRACE
= new TmfTraceStub();
44 protected static final @NonNull String FIELD
= "field";
45 protected static final ITmfFilterTreeNode TRUE_NODE
= new TmfFilterNode(null) {
47 public boolean matches(ITmfEvent event
) {
51 protected static final ITmfFilterTreeNode FALSE_NODE
= new TmfFilterNode(null) {
53 public boolean matches(ITmfEvent event
) {
57 protected static final ITmfEventType EVENT_TYPE
= new TmfEventType("Type", TmfEventField
.makeRoot(new String
[] { FIELD
}));
58 protected ITmfFilterTreeNode fFilterNode
;
61 public static void disposeTrace() {
65 // ------------------------------------------------------------------------
67 // ------------------------------------------------------------------------
70 public void testDefaults() {
71 assertNull("getParent()", fFilterNode
.getParent());
72 assertEquals("hasChildren()", false, fFilterNode
.hasChildren());
73 assertEquals("getChildrenCount()", 0, fFilterNode
.getChildrenCount());
74 assertEquals("getChildren()", 0, fFilterNode
.getChildren().length
);
78 public void testClone() {
79 ITmfFilterTreeNode clone
= fFilterNode
.clone();
80 assertFalse("clone().equals()", fFilterNode
.equals(clone
));
81 assertFalse("clone() ==", fFilterNode
== clone
);
82 assertEquals("clone().toString.equals()", fFilterNode
.toString(), clone
.toString());
83 assertNull("clone().getParent()", clone
.getParent());
87 public void testAddChild() {
88 ITmfFilterTreeNode child
= fFilterNode
.clone();
89 assertEquals("addChild()", 0, fFilterNode
.addChild(child
));
90 assertEquals("hasChildren()", true, fFilterNode
.hasChildren());
91 assertEquals("removeChild()", child
, fFilterNode
.removeChild(child
));
94 @Test(expected
= IndexOutOfBoundsException
.class)
95 public void testGetChild() {
96 fFilterNode
.getChild(0);
100 public void testRemove() {
101 ITmfFilterTreeNode child
= fFilterNode
.clone();
102 assertEquals("addChild()", 0, fFilterNode
.addChild(child
));
103 assertEquals("remove()", child
, child
.remove());
104 assertEquals("hasChildren()", false, fFilterNode
.hasChildren());
108 public void testRemoveChild() {
109 ITmfFilterTreeNode child
= fFilterNode
.clone();
110 assertEquals("addChild()", 0, fFilterNode
.addChild(child
));
111 assertEquals("removeChild()", child
, fFilterNode
.removeChild(child
));
112 assertEquals("hasChildren()", false, fFilterNode
.hasChildren());
116 public void testReplaceChild() {
117 ITmfFilterTreeNode child1
= fFilterNode
.clone();
118 ITmfFilterTreeNode child2
= fFilterNode
.clone();
119 child1
.addChild(child1
.clone());
120 assertEquals("addChild()", 0, fFilterNode
.addChild(child1
));
121 assertEquals("getChild()", child1
, fFilterNode
.getChild(0));
122 assertEquals("replaceChild()", child1
, fFilterNode
.replaceChild(0, child2
));
123 assertEquals("getChildrenCount()", 1, fFilterNode
.getChildrenCount());
124 assertEquals("getChild()", child2
, fFilterNode
.getChild(0));
125 assertEquals("removeChild()", child2
, fFilterNode
.removeChild(child2
));