Commit | Line | Data |
---|---|---|
203f982e BH |
1 | /******************************************************************************* |
2 | * Copyright (c) 2014 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 | * Bernd Hufmann - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.core.tests.filter; |
203f982e BH |
14 | |
15 | import static org.junit.Assert.assertEquals; | |
16 | import static org.junit.Assert.assertFalse; | |
17 | import static org.junit.Assert.assertNotEquals; | |
18 | import static org.junit.Assert.assertNull; | |
19 | import static org.junit.Assert.assertTrue; | |
20 | ||
ca5b04ad | 21 | import org.eclipse.jdt.annotation.NonNull; |
2bdf0193 AM |
22 | import org.eclipse.tracecompass.internal.tmf.core.filter.TmfCollapseFilter; |
23 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; | |
24 | import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; | |
25 | import org.eclipse.tracecompass.tmf.core.event.ITmfEventType; | |
26 | import org.eclipse.tracecompass.tmf.core.event.TmfEvent; | |
27 | import org.eclipse.tracecompass.tmf.core.event.TmfEventField; | |
28 | import org.eclipse.tracecompass.tmf.core.event.TmfEventType; | |
29 | import org.eclipse.tracecompass.tmf.core.event.collapse.ITmfCollapsibleEvent; | |
ca5b04ad | 30 | import org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestTrace; |
2bdf0193 AM |
31 | import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; |
32 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp; | |
33 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
ca5b04ad | 34 | import org.junit.After; |
203f982e BH |
35 | import org.junit.Test; |
36 | ||
37 | /** | |
38 | * Test suite for the {@link TmfCollpaseFilter} class. | |
39 | * | |
40 | * @author Bernd Hufmann | |
41 | */ | |
42 | @SuppressWarnings("javadoc") | |
43 | public class TmfCollapseFilterTest { | |
44 | ||
ca5b04ad GB |
45 | private static final TmfTestTrace STUB_TRACE = TmfTestTrace.A_TEST_10K; |
46 | ||
203f982e BH |
47 | // ------------------------------------------------------------------------ |
48 | // Variables | |
49 | // ------------------------------------------------------------------------ | |
50 | ||
51 | private CollapsibleEvent fCollapsibleEvent1 = new CollapsibleEvent(true); | |
52 | private CollapsibleEvent fCollapsibleEvent2 = new CollapsibleEvent(true); | |
53 | private CollapsibleEvent fCollapsibleEvent3 = new CollapsibleEvent(false); | |
54 | private NonCollapsibleEvent fNonCollapsibleEvent1 = new NonCollapsibleEvent(); | |
55 | private TmfCollapseFilter fFilter = new TmfCollapseFilter(); | |
ca5b04ad | 56 | private @NonNull ITmfTrace fTrace = STUB_TRACE.getTrace(); |
203f982e BH |
57 | |
58 | // ------------------------------------------------------------------------ | |
59 | // matches | |
60 | // ------------------------------------------------------------------------ | |
61 | ||
ca5b04ad GB |
62 | @After |
63 | public void disposeTrace() { | |
64 | fTrace.dispose(); | |
65 | } | |
66 | ||
203f982e BH |
67 | @Test |
68 | public void testMatches() { | |
69 | ||
70 | TmfCollapseFilter filter = new TmfCollapseFilter(); | |
71 | ||
72 | assertTrue(filter.matches(fCollapsibleEvent1)); | |
73 | assertFalse(filter.matches(fCollapsibleEvent2)); | |
74 | assertFalse(filter.matches(fCollapsibleEvent1)); | |
75 | assertFalse(filter.matches(fCollapsibleEvent2)); | |
76 | assertTrue(filter.matches(fNonCollapsibleEvent1)); | |
77 | assertTrue(filter.matches(fNonCollapsibleEvent1)); | |
78 | assertTrue(filter.matches(fCollapsibleEvent1)); | |
79 | assertFalse(filter.matches(fCollapsibleEvent2)); | |
80 | assertTrue(filter.matches(fCollapsibleEvent3)); | |
81 | } | |
82 | ||
83 | @Test | |
84 | public void testInterfaces() { | |
85 | assertNull("getParent()", fFilter.getParent()); | |
86 | assertEquals("getName()", "Collapse", fFilter.getNodeName()); | |
87 | assertEquals("hasChildren()", false, fFilter.hasChildren()); | |
88 | assertEquals("getChildrenCount()", 0, fFilter.getChildrenCount()); | |
89 | assertEquals("getChildren()", 0, fFilter.getChildren().length); | |
90 | } | |
91 | ||
92 | @Test | |
93 | public void testClone() { | |
94 | assertNotEquals("clone()", fFilter, fFilter.clone()); | |
95 | } | |
96 | ||
ca5b04ad | 97 | @Test(expected = UnsupportedOperationException.class) |
203f982e BH |
98 | public void testGetChild() { |
99 | fFilter.getChild(0); | |
100 | } | |
101 | ||
ca5b04ad | 102 | @Test(expected = UnsupportedOperationException.class) |
203f982e BH |
103 | public void testRemove() { |
104 | fFilter.remove(); | |
105 | } | |
106 | ||
ca5b04ad | 107 | @Test(expected = UnsupportedOperationException.class) |
203f982e BH |
108 | public void testRemoveChild() { |
109 | fFilter.removeChild(null); | |
110 | } | |
111 | ||
ca5b04ad | 112 | @Test(expected = UnsupportedOperationException.class) |
203f982e BH |
113 | public void testAddChild() { |
114 | fFilter.addChild(null); | |
115 | } | |
116 | ||
ca5b04ad | 117 | @Test(expected = UnsupportedOperationException.class) |
203f982e BH |
118 | public void testReplaceChild() { |
119 | fFilter.replaceChild(0, null); | |
120 | } | |
121 | ||
ca5b04ad | 122 | @Test(expected = UnsupportedOperationException.class) |
203f982e BH |
123 | public void testGetValidChildren() { |
124 | fFilter.getValidChildren(); | |
125 | } | |
126 | ||
127 | // ------------------------------------------------------------------------ | |
128 | // Helper Classes | |
129 | // ------------------------------------------------------------------------ | |
130 | ||
131 | private class CollapsibleEvent extends TmfEvent implements ITmfCollapsibleEvent { | |
132 | ||
133 | private final boolean fIsCollapsible; | |
ca5b04ad | 134 | |
203f982e | 135 | CollapsibleEvent(boolean isCollapsible) { |
ca5b04ad | 136 | super(fTrace); |
203f982e BH |
137 | fIsCollapsible = isCollapsible; |
138 | } | |
ca5b04ad | 139 | |
203f982e BH |
140 | @Override |
141 | public boolean isCollapsibleWith(ITmfEvent otherEvent) { | |
ca5b04ad | 142 | return ((CollapsibleEvent) otherEvent).fIsCollapsible; |
203f982e BH |
143 | } |
144 | } | |
145 | ||
146 | private class NonCollapsibleEvent implements ITmfEvent { | |
147 | ||
148 | @Override | |
149 | public Object getAdapter(Class adapter) { | |
150 | return null; | |
151 | } | |
ca5b04ad | 152 | |
203f982e BH |
153 | @Override |
154 | public ITmfTrace getTrace() { | |
ca5b04ad | 155 | return fTrace; |
203f982e | 156 | } |
ca5b04ad | 157 | |
203f982e BH |
158 | @Override |
159 | public long getRank() { | |
160 | return 0; | |
161 | } | |
ca5b04ad | 162 | |
203f982e BH |
163 | @Override |
164 | public ITmfTimestamp getTimestamp() { | |
165 | return new TmfNanoTimestamp(100); | |
166 | } | |
ca5b04ad | 167 | |
203f982e BH |
168 | @Override |
169 | public String getSource() { | |
170 | return ""; | |
171 | } | |
ca5b04ad | 172 | |
203f982e BH |
173 | @Override |
174 | public ITmfEventType getType() { | |
175 | return new TmfEventType(); | |
176 | } | |
ca5b04ad | 177 | |
203f982e BH |
178 | @Override |
179 | public ITmfEventField getContent() { | |
180 | return new TmfEventField("testField", "test", null); | |
181 | } | |
ca5b04ad | 182 | |
203f982e BH |
183 | @Override |
184 | public String getReference() { | |
185 | return "remote"; | |
186 | } | |
187 | } | |
188 | } |