1 /*******************************************************************************
2 * Copyright (c) 2014 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 * Bernd Hufmann - 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
.assertNotEquals
;
18 import static org
.junit
.Assert
.assertNull
;
19 import static org
.junit
.Assert
.assertTrue
;
21 import org
.eclipse
.core
.runtime
.PlatformObject
;
22 import org
.eclipse
.jdt
.annotation
.NonNull
;
23 import org
.eclipse
.tracecompass
.internal
.tmf
.core
.filter
.TmfCollapseFilter
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventType
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEvent
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEventField
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEventType
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.event
.collapse
.ITmfCollapsibleEvent
;
31 import org
.eclipse
.tracecompass
.tmf
.core
.tests
.shared
.TmfTestTrace
;
32 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
33 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
34 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
35 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
36 import org
.junit
.After
;
37 import org
.junit
.Test
;
40 * Test suite for the {@link TmfCollpaseFilter} class.
42 * @author Bernd Hufmann
44 @SuppressWarnings("javadoc")
45 public class TmfCollapseFilterTest
{
47 private static final TmfTestTrace STUB_TRACE
= TmfTestTrace
.A_TEST_10K
;
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
53 private CollapsibleEvent fCollapsibleEvent1
= new CollapsibleEvent(true);
54 private CollapsibleEvent fCollapsibleEvent2
= new CollapsibleEvent(true);
55 private CollapsibleEvent fCollapsibleEvent3
= new CollapsibleEvent(false);
56 private NonCollapsibleEvent fNonCollapsibleEvent1
= new NonCollapsibleEvent();
57 private TmfCollapseFilter fFilter
= new TmfCollapseFilter();
58 private @NonNull ITmfTrace fTrace
= STUB_TRACE
.getTrace();
60 // ------------------------------------------------------------------------
62 // ------------------------------------------------------------------------
65 public void disposeTrace() {
70 public void testMatches() {
72 TmfCollapseFilter filter
= new TmfCollapseFilter();
74 assertTrue(filter
.matches(fCollapsibleEvent1
));
75 assertFalse(filter
.matches(fCollapsibleEvent2
));
76 assertFalse(filter
.matches(fCollapsibleEvent1
));
77 assertFalse(filter
.matches(fCollapsibleEvent2
));
78 assertTrue(filter
.matches(fNonCollapsibleEvent1
));
79 assertTrue(filter
.matches(fNonCollapsibleEvent1
));
80 assertTrue(filter
.matches(fCollapsibleEvent1
));
81 assertFalse(filter
.matches(fCollapsibleEvent2
));
82 assertTrue(filter
.matches(fCollapsibleEvent3
));
86 public void testInterfaces() {
87 assertNull("getParent()", fFilter
.getParent());
88 assertEquals("getName()", "Collapse", fFilter
.getNodeName());
89 assertEquals("hasChildren()", false, fFilter
.hasChildren());
90 assertEquals("getChildrenCount()", 0, fFilter
.getChildrenCount());
91 assertEquals("getChildren()", 0, fFilter
.getChildren().length
);
95 public void testClone() {
96 assertNotEquals("clone()", fFilter
, fFilter
.clone());
99 @Test(expected
= UnsupportedOperationException
.class)
100 public void testGetChild() {
104 @Test(expected
= UnsupportedOperationException
.class)
105 public void testRemove() {
109 @Test(expected
= UnsupportedOperationException
.class)
110 public void testRemoveChild() {
111 fFilter
.removeChild(null);
114 @Test(expected
= UnsupportedOperationException
.class)
115 public void testAddChild() {
116 fFilter
.addChild(null);
119 @Test(expected
= UnsupportedOperationException
.class)
120 public void testReplaceChild() {
121 fFilter
.replaceChild(0, null);
124 @Test(expected
= UnsupportedOperationException
.class)
125 public void testGetValidChildren() {
126 fFilter
.getValidChildren();
129 // ------------------------------------------------------------------------
131 // ------------------------------------------------------------------------
133 private class CollapsibleEvent
extends TmfEvent
implements ITmfCollapsibleEvent
{
135 private final boolean fIsCollapsible
;
137 CollapsibleEvent(boolean isCollapsible
) {
138 super(fTrace
, ITmfContext
.UNKNOWN_RANK
, null, null, null);
139 fIsCollapsible
= isCollapsible
;
143 public boolean isCollapsibleWith(ITmfEvent otherEvent
) {
144 return ((CollapsibleEvent
) otherEvent
).fIsCollapsible
;
148 private class NonCollapsibleEvent
extends PlatformObject
implements ITmfEvent
{
151 public ITmfTrace
getTrace() {
156 public long getRank() {
161 public ITmfTimestamp
getTimestamp() {
162 return TmfTimestamp
.fromNanos(100);
166 public ITmfEventType
getType() {
167 return new TmfEventType();
171 public String
getName() {
176 public ITmfEventField
getContent() {
177 return new TmfEventField("testField", "test", null);