Commit | Line | Data |
---|---|---|
d18dd09b ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009, 2010 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 | ||
6c13869b | 13 | package org.eclipse.linuxtools.tmf.core.tests.component; |
d18dd09b ASL |
14 | |
15 | import junit.framework.TestCase; | |
16 | ||
8fd82db5 | 17 | import org.eclipse.linuxtools.internal.tmf.core.component.TmfProviderManager; |
6c13869b | 18 | import org.eclipse.linuxtools.tmf.core.component.TmfDataProvider; |
6c13869b FC |
19 | import org.eclipse.linuxtools.tmf.core.event.TmfEvent; |
20 | import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest; | |
21 | import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; | |
d18dd09b ASL |
22 | |
23 | /** | |
24 | * <b><u>TmfProviderManagerTest</u></b> | |
25 | * <p> | |
ff4ed569 | 26 | * Test suite for the TmfProviderManager class. |
d18dd09b | 27 | */ |
2d223a34 | 28 | @SuppressWarnings({ "nls" }) |
d18dd09b ASL |
29 | public class TmfProviderManagerTest extends TestCase { |
30 | ||
fc6ccf6f FC |
31 | public TmfProviderManagerTest(String name) { |
32 | super(name); | |
33 | } | |
34 | ||
d18dd09b ASL |
35 | @Override |
36 | protected void setUp() throws Exception { | |
37 | super.setUp(); | |
38 | } | |
39 | ||
40 | @Override | |
41 | protected void tearDown() throws Exception { | |
42 | super.tearDown(); | |
43 | } | |
44 | ||
45 | // ------------------------------------------------------------------------ | |
46 | // Dummy Providers | |
47 | // ------------------------------------------------------------------------ | |
48 | ||
fc6ccf6f | 49 | public class TestProvider1 extends TmfDataProvider<TmfEvent> { |
d18dd09b | 50 | public TestProvider1(Class<TmfEvent> type) { |
fc6ccf6f | 51 | super("TestProvider1", type); |
d18dd09b ASL |
52 | } |
53 | @Override | |
2fb2eb37 | 54 | public ITmfContext armRequest(ITmfDataRequest<TmfEvent> request) { |
d18dd09b ASL |
55 | return null; |
56 | } | |
57 | @Override | |
58 | public TmfEvent getNext(ITmfContext context) { | |
59 | return null; | |
60 | } | |
61 | @Override | |
2fb2eb37 | 62 | public boolean isCompleted(ITmfDataRequest<TmfEvent> request, TmfEvent data, int nbRead) { |
d18dd09b ASL |
63 | return false; |
64 | } | |
65 | } | |
66 | ||
fc6ccf6f | 67 | public class TestProvider2 extends TmfDataProvider<TmfEvent> { |
d18dd09b | 68 | public TestProvider2(Class<TmfEvent> type) { |
fc6ccf6f | 69 | super("TestProvider2", type); |
d18dd09b ASL |
70 | } |
71 | @Override | |
2fb2eb37 | 72 | public ITmfContext armRequest(ITmfDataRequest<TmfEvent> request) { |
d18dd09b ASL |
73 | return null; |
74 | } | |
75 | @Override | |
76 | public TmfEvent getNext(ITmfContext context) { | |
77 | return null; | |
78 | } | |
79 | @Override | |
2fb2eb37 | 80 | public boolean isCompleted(ITmfDataRequest<TmfEvent> request, TmfEvent data, int nbRead) { |
d18dd09b ASL |
81 | return false; |
82 | } | |
83 | } | |
84 | ||
85 | public class TmfEvent3 extends TmfEvent { | |
86 | public TmfEvent3(TmfEvent3 other) { | |
87 | super(other); | |
88 | } | |
89 | } | |
90 | ||
fc6ccf6f | 91 | public class TestProvider3 extends TmfDataProvider<TmfEvent3> { |
d18dd09b | 92 | public TestProvider3(Class<TmfEvent3> type) { |
fc6ccf6f | 93 | super("TestProvider3", type); |
d18dd09b ASL |
94 | } |
95 | @Override | |
2fb2eb37 | 96 | public ITmfContext armRequest(ITmfDataRequest<TmfEvent3> request) { |
d18dd09b ASL |
97 | return null; |
98 | } | |
99 | @Override | |
100 | public TmfEvent3 getNext(ITmfContext context) { | |
101 | return null; | |
102 | } | |
103 | @Override | |
2fb2eb37 | 104 | public boolean isCompleted(ITmfDataRequest<TmfEvent3> request, TmfEvent3 data, int nbRead) { |
d18dd09b ASL |
105 | return false; |
106 | } | |
107 | } | |
108 | ||
109 | // ------------------------------------------------------------------------ | |
ff4ed569 | 110 | // register/dispose |
d18dd09b ASL |
111 | // ------------------------------------------------------------------------ |
112 | ||
113 | @SuppressWarnings("unchecked") | |
114 | public void testRegister_0() { | |
fc6ccf6f | 115 | TmfDataProvider<TmfEvent>[] providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class); |
ff4ed569 | 116 | assertEquals("getProviders", 0, providers.length); |
d18dd09b | 117 | |
fc6ccf6f | 118 | providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TestProvider1.class); |
ff4ed569 | 119 | assertEquals("getProviders", 0, providers.length); |
d18dd09b ASL |
120 | } |
121 | ||
122 | @SuppressWarnings("unchecked") | |
123 | public void testRegister_Unregister_1() { | |
124 | ||
125 | // Register a single provider | |
126 | TestProvider1 testProvider1 = new TestProvider1(TmfEvent.class); | |
127 | ||
fc6ccf6f | 128 | TmfDataProvider<TmfEvent>[] providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class); |
ff4ed569 FC |
129 | assertEquals("getProviders", 1, providers.length); |
130 | assertEquals("getProviders", testProvider1, providers[0]); | |
d18dd09b | 131 | |
fc6ccf6f | 132 | providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TestProvider1.class); |
ff4ed569 FC |
133 | assertEquals("getProviders", 1, providers.length); |
134 | assertEquals("getProviders", testProvider1, providers[0]); | |
d18dd09b ASL |
135 | |
136 | // Unregister it | |
2fb2eb37 | 137 | testProvider1.dispose(); |
d18dd09b | 138 | |
fc6ccf6f | 139 | providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class); |
ff4ed569 | 140 | assertEquals("getProviders", 0, providers.length); |
d18dd09b | 141 | |
fc6ccf6f | 142 | providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TestProvider1.class); |
ff4ed569 | 143 | assertEquals("getProviders", 0, providers.length); |
d18dd09b ASL |
144 | } |
145 | ||
146 | @SuppressWarnings("unchecked") | |
147 | public void testRegister_Unregister_2() { | |
148 | ||
149 | // Register 2 providers, same data type | |
150 | TestProvider1 testProvider1 = new TestProvider1(TmfEvent.class); | |
151 | TestProvider2 testProvider2 = new TestProvider2(TmfEvent.class); | |
152 | ||
fc6ccf6f | 153 | TmfDataProvider<TmfEvent>[] providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class); |
ff4ed569 | 154 | assertEquals("getProviders", 2, providers.length); |
d18dd09b ASL |
155 | assertTrue(providers.length == 2); |
156 | if (providers[0] == testProvider1) { | |
ff4ed569 | 157 | assertEquals("getProviders", testProvider2, providers[1]); |
d18dd09b ASL |
158 | } |
159 | else { | |
ff4ed569 FC |
160 | assertEquals("getProviders", testProvider2, providers[0]); |
161 | assertEquals("getProviders", testProvider1, providers[1]); | |
d18dd09b ASL |
162 | } |
163 | ||
fc6ccf6f | 164 | providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TestProvider1.class); |
ff4ed569 FC |
165 | assertEquals("getProviders", 1, providers.length); |
166 | assertEquals("getProviders", testProvider1, providers[0]); | |
d18dd09b | 167 | |
fc6ccf6f | 168 | providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TestProvider2.class); |
ff4ed569 FC |
169 | assertEquals("getProviders", 1, providers.length); |
170 | assertEquals("getProviders", testProvider2, providers[0]); | |
d18dd09b ASL |
171 | |
172 | // Remove one | |
2fb2eb37 | 173 | testProvider1.dispose(); |
d18dd09b | 174 | |
fc6ccf6f | 175 | providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class); |
ff4ed569 FC |
176 | assertEquals("getProviders", 1, providers.length); |
177 | assertEquals("getProviders", testProvider2, providers[0]); | |
d18dd09b | 178 | |
fc6ccf6f | 179 | providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TestProvider1.class); |
ff4ed569 | 180 | assertEquals("getProviders", 0, providers.length); |
d18dd09b | 181 | |
fc6ccf6f | 182 | providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TestProvider2.class); |
ff4ed569 FC |
183 | assertEquals("getProviders", 1, providers.length); |
184 | assertEquals("getProviders", testProvider2, providers[0]); | |
d18dd09b ASL |
185 | |
186 | // Remove the other | |
2fb2eb37 | 187 | testProvider2.dispose(); |
d18dd09b | 188 | |
fc6ccf6f | 189 | providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class); |
ff4ed569 | 190 | assertEquals("getProviders", 0, providers.length); |
d18dd09b | 191 | |
fc6ccf6f | 192 | providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TestProvider1.class); |
ff4ed569 | 193 | assertEquals("getProviders", 0, providers.length); |
d18dd09b | 194 | |
fc6ccf6f | 195 | providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TestProvider2.class); |
ff4ed569 | 196 | assertEquals("getProviders", 0, providers.length); |
d18dd09b ASL |
197 | } |
198 | ||
199 | @SuppressWarnings("unchecked") | |
200 | public void testRegister_Unregister_3() { | |
201 | ||
202 | // Register 3 providers, mixed data types | |
203 | TestProvider1 testProvider1 = new TestProvider1(TmfEvent.class); | |
204 | TestProvider2 testProvider2 = new TestProvider2(TmfEvent.class); | |
205 | TestProvider3 testProvider3 = new TestProvider3(TmfEvent3.class); | |
206 | ||
fc6ccf6f | 207 | TmfDataProvider<TmfEvent>[] providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class); |
ff4ed569 | 208 | assertEquals("getProviders", 2, providers.length); |
d18dd09b | 209 | if (providers[0] == testProvider1) { |
ff4ed569 | 210 | assertEquals("getProviders", testProvider2, providers[1]); |
d18dd09b ASL |
211 | } |
212 | else { | |
ff4ed569 FC |
213 | assertEquals("getProviders", testProvider2, providers[0]); |
214 | assertEquals("getProviders", testProvider1, providers[1]); | |
d18dd09b ASL |
215 | } |
216 | ||
fc6ccf6f | 217 | TmfDataProvider<TmfEvent3>[] providers3 = (TmfDataProvider<TmfEvent3>[]) TmfProviderManager.getProviders(TmfEvent3.class); |
ff4ed569 FC |
218 | assertEquals("getProviders", 1, providers3.length); |
219 | assertEquals("getProviders", testProvider3, providers3[0]); | |
d18dd09b | 220 | |
fc6ccf6f | 221 | providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TestProvider1.class); |
ff4ed569 FC |
222 | assertEquals("getProviders", 1, providers.length); |
223 | assertEquals("getProviders", testProvider1, providers[0]); | |
d18dd09b | 224 | |
fc6ccf6f | 225 | providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TestProvider2.class); |
ff4ed569 FC |
226 | assertEquals("getProviders", 1, providers.length); |
227 | assertEquals("getProviders", testProvider2, providers[0]); | |
d18dd09b | 228 | |
fc6ccf6f | 229 | providers3 = (TmfDataProvider<TmfEvent3>[]) TmfProviderManager.getProviders(TmfEvent3.class, TestProvider3.class); |
ff4ed569 FC |
230 | assertEquals("getProviders", 1, providers3.length); |
231 | assertEquals("getProviders", testProvider3, providers3[0]); | |
d18dd09b ASL |
232 | |
233 | // Remove one | |
2fb2eb37 | 234 | testProvider1.dispose(); |
d18dd09b | 235 | |
fc6ccf6f | 236 | providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class); |
ff4ed569 FC |
237 | assertEquals("getProviders", 1, providers.length); |
238 | assertEquals("getProviders", testProvider2, providers[0]); | |
d18dd09b | 239 | |
fc6ccf6f | 240 | providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TestProvider1.class); |
ff4ed569 | 241 | assertEquals("getProviders", 0, providers.length); |
d18dd09b | 242 | |
fc6ccf6f | 243 | providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TestProvider2.class); |
ff4ed569 FC |
244 | assertEquals("getProviders", 1, providers.length); |
245 | assertEquals("getProviders", testProvider2, providers[0]); | |
d18dd09b | 246 | |
fc6ccf6f | 247 | providers3 = (TmfDataProvider<TmfEvent3>[]) TmfProviderManager.getProviders(TmfEvent3.class); |
ff4ed569 FC |
248 | assertEquals("getProviders", 1, providers3.length); |
249 | assertEquals("getProviders", testProvider3, providers3[0]); | |
d18dd09b | 250 | |
fc6ccf6f | 251 | providers3 = (TmfDataProvider<TmfEvent3>[]) TmfProviderManager.getProviders(TmfEvent3.class, TestProvider3.class); |
ff4ed569 FC |
252 | assertEquals("getProviders", 1, providers3.length); |
253 | assertEquals("getProviders", testProvider3, providers3[0]); | |
d18dd09b ASL |
254 | |
255 | // Remove another one | |
2fb2eb37 | 256 | testProvider2.dispose(); |
d18dd09b | 257 | |
fc6ccf6f | 258 | providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class); |
ff4ed569 | 259 | assertEquals("getProviders", 0, providers.length); |
d18dd09b | 260 | |
fc6ccf6f | 261 | providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TestProvider1.class); |
ff4ed569 | 262 | assertEquals("getProviders", 0, providers.length); |
d18dd09b | 263 | |
fc6ccf6f | 264 | providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TestProvider2.class); |
ff4ed569 | 265 | assertEquals("getProviders", 0, providers.length); |
d18dd09b | 266 | |
fc6ccf6f | 267 | providers3 = (TmfDataProvider<TmfEvent3>[]) TmfProviderManager.getProviders(TmfEvent3.class); |
d18dd09b ASL |
268 | assertTrue(providers3.length == 1); |
269 | assertTrue(providers3[0] == testProvider3); | |
270 | ||
fc6ccf6f | 271 | providers3 = (TmfDataProvider<TmfEvent3>[]) TmfProviderManager.getProviders(TmfEvent3.class, TestProvider3.class); |
ff4ed569 FC |
272 | assertEquals("getProviders", 1, providers3.length); |
273 | assertEquals("getProviders", testProvider3, providers3[0]); | |
d18dd09b ASL |
274 | |
275 | // Remove the last one | |
2fb2eb37 | 276 | testProvider3.dispose(); |
d18dd09b | 277 | |
fc6ccf6f | 278 | providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class); |
ff4ed569 | 279 | assertEquals("getProviders", 0, providers.length); |
d18dd09b | 280 | |
fc6ccf6f | 281 | providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TestProvider1.class); |
ff4ed569 | 282 | assertEquals("getProviders", 0, providers.length); |
d18dd09b | 283 | |
fc6ccf6f | 284 | providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TestProvider2.class); |
ff4ed569 | 285 | assertEquals("getProviders", 0, providers.length); |
d18dd09b | 286 | |
fc6ccf6f | 287 | providers3 = (TmfDataProvider<TmfEvent3>[]) TmfProviderManager.getProviders(TmfEvent3.class); |
ff4ed569 | 288 | assertEquals("getProviders", 0, providers.length); |
d18dd09b | 289 | |
fc6ccf6f | 290 | providers3 = (TmfDataProvider<TmfEvent3>[]) TmfProviderManager.getProviders(TmfEvent3.class, TestProvider3.class); |
ff4ed569 FC |
291 | assertEquals("getProviders", 0, providers.length); |
292 | } | |
293 | ||
294 | @SuppressWarnings("unchecked") | |
295 | public void testGetProvider() { | |
296 | ||
297 | // Register 3 providers, mixed data types | |
298 | TestProvider1 testProvider1 = new TestProvider1(TmfEvent.class); | |
299 | TestProvider2 testProvider2 = new TestProvider2(TmfEvent.class); | |
300 | TestProvider3 testProvider3 = new TestProvider3(TmfEvent3.class); | |
301 | ||
302 | TmfDataProvider<TmfEvent>[] providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, null); | |
303 | assertEquals("getProviders", 2, providers.length); | |
304 | if (providers[0] == testProvider1) { | |
305 | assertEquals("getProviders", testProvider2, providers[1]); | |
306 | } | |
307 | else { | |
308 | assertEquals("getProviders", testProvider2, providers[0]); | |
309 | assertEquals("getProviders", testProvider1, providers[1]); | |
310 | } | |
311 | ||
312 | providers = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent3.class, null); | |
313 | assertEquals("getProviders", 1, providers.length); | |
314 | assertEquals("getProviders", testProvider3, providers[0]); | |
315 | ||
316 | // Remove the providers | |
317 | testProvider1.dispose(); | |
318 | testProvider2.dispose(); | |
319 | testProvider3.dispose(); | |
d18dd09b ASL |
320 | } |
321 | ||
322 | } |