Commit | Line | Data |
---|---|---|
8584dc20 FC |
1 | /******************************************************************************* |
2 | * Copyright (c) 2012 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 | * Francois Chouinard - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.core.tests.request; | |
14 | ||
15 | import junit.framework.TestCase; | |
16 | ||
17 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; | |
18 | import org.eclipse.linuxtools.tmf.core.event.TmfEvent; | |
19 | import org.eclipse.linuxtools.tmf.core.request.TmfEventTypeFilter; | |
20 | import org.junit.Test; | |
21 | ||
22 | /** | |
23 | * <b><u>TmfEventTypeFilterTest</u></b> | |
24 | * <p> | |
25 | * Test suite for the TmfEventTypeFilter class. | |
26 | */ | |
27 | @SuppressWarnings({"nls","javadoc"}) | |
28 | public class TmfEventTypeFilterTest extends TestCase { | |
29 | ||
30 | // ------------------------------------------------------------------------ | |
31 | // Constants | |
32 | // ------------------------------------------------------------------------ | |
33 | ||
34 | private static final TmfEventTypeFilter ALL_EVENTS = TmfEventTypeFilter.ALL_EVENTS; | |
35 | ||
36 | // ------------------------------------------------------------------------ | |
37 | // Housekeeping | |
38 | // ------------------------------------------------------------------------ | |
39 | ||
40 | /** | |
41 | * @param name the test name | |
42 | */ | |
43 | public TmfEventTypeFilterTest(String name) { | |
44 | super(name); | |
45 | } | |
46 | ||
47 | @Override | |
48 | protected void setUp() throws Exception { | |
49 | super.setUp(); | |
50 | } | |
51 | ||
52 | @Override | |
53 | protected void tearDown() throws Exception { | |
54 | super.tearDown(); | |
55 | } | |
56 | ||
57 | // ------------------------------------------------------------------------ | |
58 | // Constructors | |
59 | // ------------------------------------------------------------------------ | |
60 | ||
61 | @Test | |
62 | public void testTmfBlockFilter() { | |
63 | TmfEventTypeFilter filter = ALL_EVENTS; | |
64 | assertEquals("getEventType", ITmfEvent.class, filter.getEventType()); | |
65 | ||
66 | filter = new TmfEventTypeFilter(ITmfEvent.class); | |
67 | assertEquals("getEventType", ITmfEvent.class, filter.getEventType()); | |
68 | ||
69 | filter = new TmfEventTypeFilter(TmfEvent.class); | |
70 | assertEquals("getEventType", TmfEvent.class, filter.getEventType()); | |
71 | ||
72 | } | |
73 | ||
74 | @Test | |
75 | public void testTmfBlockFilterCopy() { | |
76 | TmfEventTypeFilter filter1 = new TmfEventTypeFilter(TmfEvent.class); | |
77 | TmfEventTypeFilter filter2 = new TmfEventTypeFilter(filter1); | |
78 | ||
79 | assertEquals("getEventType", filter1.getEventType(), filter2.getEventType()); | |
80 | assertEquals("getEventType", TmfEvent.class, filter2.getEventType()); | |
81 | } | |
82 | ||
83 | // ------------------------------------------------------------------------ | |
84 | // equals | |
85 | // ------------------------------------------------------------------------ | |
86 | ||
87 | @Test | |
88 | public void testEqualsReflexivity() { | |
89 | TmfEventTypeFilter filter1 = new TmfEventTypeFilter(ITmfEvent.class); | |
90 | TmfEventTypeFilter filter2 = new TmfEventTypeFilter(TmfEvent.class); | |
91 | ||
92 | assertEquals("equals", filter1, filter1); | |
93 | assertEquals("equals", filter2, filter2); | |
94 | ||
95 | assertFalse("equals", filter1.equals(filter2)); | |
96 | assertFalse("equals", filter2.equals(filter1)); | |
97 | } | |
98 | ||
99 | @Test | |
100 | public void testEqualsSymmetry() { | |
101 | TmfEventTypeFilter filter1 = new TmfEventTypeFilter(ITmfEvent.class); | |
102 | TmfEventTypeFilter filter2 = new TmfEventTypeFilter(ITmfEvent.class); | |
103 | TmfEventTypeFilter filter3 = new TmfEventTypeFilter(TmfEvent.class); | |
104 | ||
105 | assertEquals("equals", filter1, filter2); | |
106 | assertEquals("equals", filter2, filter1); | |
107 | ||
108 | assertFalse("equals", filter1.equals(filter3)); | |
109 | assertFalse("equals", filter3.equals(filter1)); | |
110 | } | |
111 | ||
112 | @Test | |
113 | public void testEqualsTransivity() { | |
114 | TmfEventTypeFilter filter1 = new TmfEventTypeFilter(TmfEvent.class); | |
115 | TmfEventTypeFilter filter2 = new TmfEventTypeFilter(TmfEvent.class); | |
116 | TmfEventTypeFilter filter3 = new TmfEventTypeFilter(TmfEvent.class); | |
117 | ||
118 | assertEquals("equals", filter1, filter2); | |
119 | assertEquals("equals", filter2, filter3); | |
120 | assertEquals("equals", filter3, filter1); | |
121 | } | |
122 | ||
123 | @Test | |
124 | public void testEqualsNull() { | |
125 | TmfEventTypeFilter filter1 = new TmfEventTypeFilter(ITmfEvent.class); | |
126 | TmfEventTypeFilter filter2 = new TmfEventTypeFilter(TmfEvent.class); | |
127 | ||
128 | assertFalse("equals", filter1.equals(null)); | |
129 | assertFalse("equals", filter2.equals(null)); | |
130 | } | |
131 | ||
132 | // ------------------------------------------------------------------------ | |
133 | // hashCode | |
134 | // ------------------------------------------------------------------------ | |
135 | ||
136 | @Test | |
137 | public void testHashCode() { | |
138 | TmfEventTypeFilter filter1 = new TmfEventTypeFilter(ITmfEvent.class); | |
139 | TmfEventTypeFilter filter2 = new TmfEventTypeFilter(TmfEvent.class); | |
140 | ||
8584dc20 FC |
141 | assertFalse("hashCode", filter1.hashCode() == filter2.hashCode()); |
142 | } | |
143 | ||
144 | // ------------------------------------------------------------------------ | |
145 | // toString | |
146 | // ------------------------------------------------------------------------ | |
147 | ||
148 | @Test | |
149 | public void testToString() { | |
150 | TmfEventTypeFilter filter1 = new TmfEventTypeFilter(ITmfEvent.class); | |
151 | TmfEventTypeFilter filter2 = new TmfEventTypeFilter(TmfEvent.class); | |
152 | ||
153 | String expected0 = "TmfEventTypeFilter [fEventType=ITmfEvent]"; | |
154 | String expected1 = "TmfEventTypeFilter [fEventType=ITmfEvent]"; | |
155 | String expected2 = "TmfEventTypeFilter [fEventType=TmfEvent]"; | |
156 | ||
157 | assertEquals("toString", expected0, ALL_EVENTS.toString()); | |
158 | assertEquals("toString", expected1, filter1.toString()); | |
159 | assertEquals("toString", expected2, filter2.toString()); | |
160 | } | |
161 | ||
162 | // ------------------------------------------------------------------------ | |
163 | // matches | |
164 | // ------------------------------------------------------------------------ | |
165 | ||
166 | private class TmfEvent1 extends TmfEvent { | |
167 | public TmfEvent1(final ITmfEvent event) { | |
168 | super(event); | |
169 | } | |
170 | } | |
171 | ||
172 | private class TmfEvent2 extends TmfEvent { | |
173 | public TmfEvent2(final ITmfEvent event) { | |
174 | super(event); | |
175 | } | |
176 | } | |
177 | ||
178 | /** | |
179 | * The only test that really matters... | |
180 | */ | |
181 | @Test | |
182 | public void testMatches() { | |
183 | ||
184 | TmfEventTypeFilter filter1 = new TmfEventTypeFilter(TmfEvent1.class); | |
185 | TmfEventTypeFilter filter2 = new TmfEventTypeFilter(TmfEvent2.class); | |
186 | ||
187 | TmfEvent event0 = new TmfEvent(null, 0, null, null, null, null, null); | |
188 | TmfEvent1 event1 = new TmfEvent1(event0); | |
189 | TmfEvent2 event2 = new TmfEvent2(event0); | |
190 | ||
191 | assertFalse("matches", filter1.matches(event0)); | |
192 | assertFalse("matches", filter2.matches(event0)); | |
193 | ||
194 | assertTrue ("matches", filter1.matches(event1)); | |
195 | assertFalse("matches", filter2.matches(event1)); | |
196 | ||
197 | assertFalse("matches", filter2.matches(event1)); | |
198 | assertTrue ("matches", filter2.matches(event2)); | |
199 | ||
200 | assertTrue("matches", ALL_EVENTS.matches(event1)); | |
201 | assertTrue("matches", ALL_EVENTS.matches(event2)); | |
202 | assertTrue("matches", ALL_EVENTS.matches(event0)); | |
203 | } | |
204 | ||
205 | } |