Commit | Line | Data |
---|---|---|
ebc1e992 PT |
1 | /******************************************************************************* |
2 | * Copyright (c) 2015 Ericsson | |
3 | * | |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Patrick Tasse - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.tracecompass.tmf.core.tests.filter; | |
14 | ||
15 | import static org.junit.Assert.assertEquals; | |
16 | import static org.junit.Assert.assertFalse; | |
17 | import static org.junit.Assert.assertNull; | |
18 | ||
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; | |
30 | ||
31 | /** | |
b0d2c558 | 32 | * Test suite for the {@link TmfFilterTreeNodeTestBase} class. |
ebc1e992 PT |
33 | * |
34 | * @author Patrick Tasse | |
35 | */ | |
36 | @SuppressWarnings("javadoc") | |
b0d2c558 | 37 | public abstract class TmfFilterTreeNodeTestBase { |
ebc1e992 PT |
38 | |
39 | // ------------------------------------------------------------------------ | |
40 | // Variables | |
41 | // ------------------------------------------------------------------------ | |
42 | ||
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) { | |
46 | @Override | |
47 | public boolean matches(ITmfEvent event) { | |
48 | return true; | |
49 | } | |
50 | }; | |
51 | protected static final ITmfFilterTreeNode FALSE_NODE = new TmfFilterNode(null) { | |
52 | @Override | |
53 | public boolean matches(ITmfEvent event) { | |
54 | return false; | |
55 | } | |
56 | }; | |
57 | protected static final ITmfEventType EVENT_TYPE = new TmfEventType("Type", TmfEventField.makeRoot(new String[] { FIELD })); | |
58 | protected ITmfFilterTreeNode fFilterNode; | |
59 | ||
60 | @AfterClass | |
61 | public static void disposeTrace() { | |
62 | TRACE.dispose(); | |
63 | } | |
64 | ||
65 | // ------------------------------------------------------------------------ | |
66 | // Tests | |
67 | // ------------------------------------------------------------------------ | |
68 | ||
69 | @Test | |
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); | |
75 | } | |
76 | ||
77 | @Test | |
78 | public void testClone() { | |
ec4e56da PT |
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()); | |
ebc1e992 PT |
84 | } |
85 | ||
86 | @Test | |
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)); | |
92 | } | |
93 | ||
94 | @Test(expected = IndexOutOfBoundsException.class) | |
95 | public void testGetChild() { | |
96 | fFilterNode.getChild(0); | |
97 | } | |
98 | ||
99 | @Test | |
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()); | |
105 | } | |
106 | ||
107 | @Test | |
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()); | |
113 | } | |
114 | ||
115 | @Test | |
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)); | |
126 | } | |
127 | } |