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