tmf.core: Introduce TmfTimestamp factory methods
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core.tests / src / org / eclipse / tracecompass / tmf / core / tests / filter / TmfCollapseFilterTest.java
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
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.assertNotEquals;
18 import static org.junit.Assert.assertNull;
19 import static org.junit.Assert.assertTrue;
20
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;
38
39 /**
40 * Test suite for the {@link TmfCollpaseFilter} class.
41 *
42 * @author Bernd Hufmann
43 */
44 @SuppressWarnings("javadoc")
45 public class TmfCollapseFilterTest {
46
47 private static final TmfTestTrace STUB_TRACE = TmfTestTrace.A_TEST_10K;
48
49 // ------------------------------------------------------------------------
50 // Variables
51 // ------------------------------------------------------------------------
52
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();
59
60 // ------------------------------------------------------------------------
61 // matches
62 // ------------------------------------------------------------------------
63
64 @After
65 public void disposeTrace() {
66 fTrace.dispose();
67 }
68
69 @Test
70 public void testMatches() {
71
72 TmfCollapseFilter filter = new TmfCollapseFilter();
73
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));
83 }
84
85 @Test
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);
92 }
93
94 @Test
95 public void testClone() {
96 assertNotEquals("clone()", fFilter, fFilter.clone());
97 }
98
99 @Test(expected = UnsupportedOperationException.class)
100 public void testGetChild() {
101 fFilter.getChild(0);
102 }
103
104 @Test(expected = UnsupportedOperationException.class)
105 public void testRemove() {
106 fFilter.remove();
107 }
108
109 @Test(expected = UnsupportedOperationException.class)
110 public void testRemoveChild() {
111 fFilter.removeChild(null);
112 }
113
114 @Test(expected = UnsupportedOperationException.class)
115 public void testAddChild() {
116 fFilter.addChild(null);
117 }
118
119 @Test(expected = UnsupportedOperationException.class)
120 public void testReplaceChild() {
121 fFilter.replaceChild(0, null);
122 }
123
124 @Test(expected = UnsupportedOperationException.class)
125 public void testGetValidChildren() {
126 fFilter.getValidChildren();
127 }
128
129 // ------------------------------------------------------------------------
130 // Helper Classes
131 // ------------------------------------------------------------------------
132
133 private class CollapsibleEvent extends TmfEvent implements ITmfCollapsibleEvent {
134
135 private final boolean fIsCollapsible;
136
137 CollapsibleEvent(boolean isCollapsible) {
138 super(fTrace, ITmfContext.UNKNOWN_RANK, null, null, null);
139 fIsCollapsible = isCollapsible;
140 }
141
142 @Override
143 public boolean isCollapsibleWith(ITmfEvent otherEvent) {
144 return ((CollapsibleEvent) otherEvent).fIsCollapsible;
145 }
146 }
147
148 private class NonCollapsibleEvent extends PlatformObject implements ITmfEvent {
149
150 @Override
151 public ITmfTrace getTrace() {
152 return fTrace;
153 }
154
155 @Override
156 public long getRank() {
157 return 0;
158 }
159
160 @Override
161 public ITmfTimestamp getTimestamp() {
162 return TmfTimestamp.fromNanos(100);
163 }
164
165 @Override
166 public ITmfEventType getType() {
167 return new TmfEventType();
168 }
169
170 @Override
171 public String getName() {
172 return "";
173 }
174
175 @Override
176 public ITmfEventField getContent() {
177 return new TmfEventField("testField", "test", null);
178 }
179 }
180 }
This page took 0.034669 seconds and 5 git commands to generate.