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