Commit | Line | Data |
---|---|---|
970ed795 | 1 | /****************************************************************************** |
d44e3c4f | 2 | * Copyright (c) 2000-2016 Ericsson Telecom AB |
970ed795 EL |
3 | * All rights reserved. This program and the accompanying materials |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
d44e3c4f | 7 | * |
8 | * Contributors: | |
9 | * Balasko, Jeno | |
10 | * Lovassy, Arpad | |
11 | * | |
970ed795 EL |
12 | ******************************************************************************/ |
13 | package org.eclipse.titan.executorapi.test; | |
14 | ||
15 | import static org.junit.Assert.assertTrue; | |
16 | import static org.junit.Assert.fail; | |
17 | ||
18 | import org.eclipse.titan.executor.jni.ComponentStruct; | |
19 | import org.eclipse.titan.executor.jni.HostStruct; | |
20 | import org.eclipse.titan.executor.jni.McStateEnum; | |
21 | import org.eclipse.titan.executorapi.JniExecutor; | |
22 | import org.eclipse.titan.executorapi.exception.JniExecutorIllegalArgumentException; | |
23 | import org.eclipse.titan.executorapi.exception.JniExecutorJniLoadException; | |
24 | import org.eclipse.titan.executorapi.exception.JniExecutorStartSessionException; | |
25 | import org.eclipse.titan.executorapi.exception.JniExecutorWrongStateException; | |
26 | import org.eclipse.titan.executorapi.util.Log; | |
27 | import org.junit.Test; | |
28 | ||
29 | /** | |
30 | * Testing all the JniExecutor methods in all the stable states if they can be called. | |
31 | * If method is not callable in the given state, JniExecutorWrongStateException is expected. | |
32 | */ | |
33 | public class JniExecutorAsyncErrorWrongStateTest extends JniExecutorAsyncErrorTest { | |
34 | ||
35 | // Method testers. Each method is tested in 2 ways: | |
36 | // 1. true: If it's callable in the given state, we expect NOT to throw JniExecutorWrongStateException and to get to the next state (if any). | |
37 | // in this case it is recommended to check the state before and after this function using assertState | |
38 | // 2. false: If it's NOT callable in the given state, we expect to throw JniExecutorWrongStateException | |
39 | // final boolean aCallable determines the expected behaviour for each testWrongState...() method | |
40 | ||
41 | // there is no separate method tester for the following methods, as they are called many times in the other method testers in all of the states: | |
42 | // shutdownSession | |
43 | // getState | |
44 | // isConnected | |
45 | ||
46 | private void testWrongStateInit( final boolean aCallable, final JniExecutor je ) { | |
47 | if ( aCallable ) { | |
48 | try { | |
49 | je.init(); | |
50 | } catch (JniExecutorWrongStateException | JniExecutorJniLoadException e) { | |
51 | fail(); | |
52 | } | |
53 | } else { | |
54 | try { | |
55 | je.init(); | |
56 | fail("JniExecutorWrongStateException expected"); | |
57 | } catch (JniExecutorWrongStateException e) { | |
58 | //expected | |
59 | } catch (JniExecutorJniLoadException e) { | |
60 | fail(); | |
61 | } | |
62 | } | |
63 | } | |
64 | ||
65 | private void testWrongStateAddHostControllers( final boolean aCallable, final JniExecutor je, final TestData td ) { | |
66 | if ( aCallable ) { | |
67 | try { | |
68 | je.addHostController( td.mHc ); | |
69 | } catch (JniExecutorIllegalArgumentException | JniExecutorWrongStateException e) { | |
70 | fail(); | |
71 | } | |
72 | } else { | |
73 | try { | |
74 | je.addHostController(td.mHc); | |
75 | fail("JniExecutorWrongStateException expected"); | |
76 | } catch (JniExecutorIllegalArgumentException e) { | |
77 | fail(); | |
78 | } catch (JniExecutorWrongStateException e) { | |
79 | //expected | |
80 | } | |
81 | } | |
82 | } | |
83 | ||
84 | private void testWrongStateSetConfigFileName( final boolean aCallable, final JniExecutor je, final TestData td ) { | |
85 | if ( aCallable ) { | |
86 | try { | |
87 | je.setConfigFileName( td.mCfgFileName ); | |
88 | } catch (JniExecutorIllegalArgumentException | JniExecutorWrongStateException e) { | |
89 | fail(); | |
90 | } | |
91 | } else { | |
92 | try { | |
93 | je.setConfigFileName(td.mCfgFileName); | |
94 | fail("JniExecutorWrongStateException expected"); | |
95 | } catch (JniExecutorIllegalArgumentException e) { | |
96 | fail(); | |
97 | } catch (JniExecutorWrongStateException e) { | |
98 | //expected | |
99 | } | |
100 | } | |
101 | } | |
102 | ||
103 | private void testWrongStateSetObserver( final boolean aCallable, final JniExecutor je, final TestData td ) { | |
104 | if ( aCallable ) { | |
105 | try { | |
106 | je.setObserver(null); | |
107 | } catch (JniExecutorWrongStateException e) { | |
108 | fail(); | |
109 | } | |
110 | } else { | |
111 | try { | |
112 | je.setObserver(td.mObserver); | |
113 | fail("JniExecutorWrongStateException expected"); | |
114 | } catch (JniExecutorWrongStateException e) { | |
115 | //expected | |
116 | } | |
117 | } | |
118 | } | |
119 | ||
120 | private void testWrongStateStartSession( final boolean aCallable, final JniExecutor je ) { | |
121 | if ( aCallable ) { | |
122 | try { | |
123 | je.startSession(); | |
124 | } catch (JniExecutorWrongStateException | JniExecutorStartSessionException e) { | |
125 | fail(); | |
126 | } | |
127 | } else { | |
128 | try { | |
129 | je.startSession(); | |
130 | fail("JniExecutorWrongStateException expected"); | |
131 | } catch (JniExecutorWrongStateException e) { | |
132 | //expected | |
133 | } catch (JniExecutorStartSessionException e) { | |
134 | fail(); | |
135 | } | |
136 | } | |
137 | } | |
138 | ||
139 | private void testWrongStateStartHostControllers( final boolean aCallable, final JniExecutor je ) { | |
140 | if ( aCallable ) { | |
141 | try { | |
142 | je.startHostControllers(); | |
143 | } catch (JniExecutorWrongStateException e) { | |
144 | fail(); | |
145 | } | |
146 | } else { | |
147 | try { | |
148 | je.startHostControllers(); | |
149 | fail("JniExecutorWrongStateException expected"); | |
150 | } catch (JniExecutorWrongStateException e) { | |
151 | //expected | |
152 | } | |
153 | } | |
154 | } | |
155 | ||
156 | private void testWrongStateConfigure( final boolean aCallable, final JniExecutor je ) { | |
157 | if ( aCallable ) { | |
158 | try { | |
159 | je.configure(); | |
160 | } catch (JniExecutorWrongStateException e) { | |
161 | fail(); | |
162 | } | |
163 | } else { | |
164 | try { | |
165 | je.configure(); | |
166 | fail("JniExecutorWrongStateException expected"); | |
167 | } catch (JniExecutorWrongStateException e) { | |
168 | //expected | |
169 | } | |
170 | } | |
171 | } | |
172 | ||
173 | private void testWrongStateCreateMTC( final boolean aCallable, final JniExecutor je ) { | |
174 | if ( aCallable ) { | |
175 | try { | |
176 | je.createMTC(); | |
177 | } catch (JniExecutorWrongStateException e) { | |
178 | fail(); | |
179 | } | |
180 | } else { | |
181 | try { | |
182 | je.createMTC(); | |
183 | fail("JniExecutorWrongStateException expected"); | |
184 | } catch (JniExecutorWrongStateException e) { | |
185 | //expected | |
186 | } | |
187 | } | |
188 | } | |
189 | ||
190 | private void testWrongStateExecuteControl( final boolean aCallable, final JniExecutor je, final TestData td ) { | |
191 | if ( aCallable ) { | |
192 | try { | |
193 | je.executeControl(td.mModule); | |
194 | } catch (JniExecutorWrongStateException | JniExecutorIllegalArgumentException e) { | |
195 | fail(); | |
196 | } | |
197 | } else { | |
198 | try { | |
199 | je.executeControl(td.mModule); | |
200 | fail("JniExecutorWrongStateException expected"); | |
201 | } catch (JniExecutorIllegalArgumentException e) { | |
202 | fail(); | |
203 | } catch (JniExecutorWrongStateException e) { | |
204 | //expected | |
205 | } | |
206 | } | |
207 | } | |
208 | ||
209 | private void testWrongStateExecuteTextcase( final boolean aCallable, final JniExecutor je, final TestData td ) { | |
210 | if ( aCallable ) { | |
211 | try { | |
212 | je.executeTestcase(td.mModule, td.mTestcases.get(0)); | |
213 | } catch (JniExecutorWrongStateException | JniExecutorIllegalArgumentException e) { | |
214 | fail(); | |
215 | } | |
216 | } else { | |
217 | try { | |
218 | je.executeTestcase(td.mModule, td.mTestcases.get(0)); | |
219 | fail("JniExecutorWrongStateException expected"); | |
220 | } catch (JniExecutorIllegalArgumentException e) { | |
221 | fail(); | |
222 | } catch (JniExecutorWrongStateException e) { | |
223 | //expected | |
224 | } | |
225 | } | |
226 | } | |
227 | ||
228 | private void testWrongStateGetExecuteCfglen( final boolean aCallable, final JniExecutor je ) { | |
229 | if ( aCallable ) { | |
230 | try { | |
231 | assertTrue(je.getExecuteCfgLen() > 0); | |
232 | } catch (JniExecutorWrongStateException e) { | |
233 | fail(); | |
234 | } | |
235 | } else { | |
236 | try { | |
237 | je.getExecuteCfgLen(); | |
238 | fail("JniExecutorWrongStateException expected"); | |
239 | } catch (JniExecutorWrongStateException e) { | |
240 | //expected | |
241 | } | |
242 | } | |
243 | } | |
244 | ||
245 | private void testWrongStateExecuteCfg( final boolean aCallable, final JniExecutor je ) { | |
246 | if ( aCallable ) { | |
247 | try { | |
248 | je.executeCfg(0); | |
249 | } catch (JniExecutorWrongStateException | JniExecutorIllegalArgumentException e) { | |
250 | fail(); | |
251 | } | |
252 | } else { | |
253 | try { | |
254 | je.executeCfg(0); | |
255 | fail("JniExecutorWrongStateException expected"); | |
256 | } catch (JniExecutorWrongStateException e) { | |
257 | //expected | |
258 | } catch (JniExecutorIllegalArgumentException e) { | |
259 | fail(); | |
260 | } | |
261 | } | |
262 | } | |
263 | ||
264 | private void testWrongStatePauseExecutionAndIsPaused( final boolean aCallable, final JniExecutor je ) { | |
265 | if ( aCallable ) { | |
266 | try { | |
267 | je.pauseExecution(true); | |
268 | assertTrue(je.isPaused()); | |
269 | je.pauseExecution(false); | |
270 | assertTrue(!je.isPaused()); | |
271 | } catch (JniExecutorWrongStateException e) { | |
272 | fail(); | |
273 | } | |
274 | } else { | |
275 | try { | |
276 | je.pauseExecution(false); | |
277 | fail("JniExecutorWrongStateException expected"); | |
278 | } catch (JniExecutorWrongStateException e) { | |
279 | //expected | |
280 | } | |
281 | ||
282 | try { | |
283 | je.isPaused(); | |
284 | fail("JniExecutorWrongStateException expected"); | |
285 | } catch (JniExecutorWrongStateException e) { | |
286 | //expected | |
287 | } | |
288 | } | |
289 | } | |
290 | ||
291 | private void testWrongStateContinueExecution( final boolean aCallable, final JniExecutor je ) { | |
292 | if ( aCallable ) { | |
293 | try { | |
294 | je.continueExecution(); | |
295 | } catch (JniExecutorWrongStateException e) { | |
296 | fail(); | |
297 | } | |
298 | } else { | |
299 | try { | |
300 | je.continueExecution(); | |
301 | fail("JniExecutorWrongStateException expected"); | |
302 | } catch (JniExecutorWrongStateException e) { | |
303 | //expected | |
304 | } | |
305 | } | |
306 | } | |
307 | ||
308 | private void testWrongStateStopExecution( final boolean aCallable, final JniExecutor je ) { | |
309 | if ( aCallable ) { | |
310 | try { | |
311 | je.stopExecution(); | |
312 | } catch (JniExecutorWrongStateException e) { | |
313 | fail(); | |
314 | } | |
315 | } else { | |
316 | try { | |
317 | je.stopExecution(); | |
318 | fail("JniExecutorWrongStateException expected"); | |
319 | } catch (JniExecutorWrongStateException e) { | |
320 | //expected | |
321 | } | |
322 | } | |
323 | } | |
324 | ||
325 | private void testWrongStateExitMTC( final boolean aCallable, final JniExecutor je ) { | |
326 | if ( aCallable ) { | |
327 | try { | |
328 | je.exitMTC(); | |
329 | } catch (JniExecutorWrongStateException e) { | |
330 | fail(); | |
331 | } | |
332 | } else { | |
333 | try { | |
334 | je.exitMTC(); | |
335 | fail("JniExecutorWrongStateException expected"); | |
336 | } catch (JniExecutorWrongStateException e) { | |
337 | //expected | |
338 | } | |
339 | } | |
340 | } | |
341 | ||
342 | /** | |
343 | * Method tester for getNumberOfHosts(), getHostData() and getComponentData() | |
344 | * @param aCallable true, if getNumberOfHosts() and getHostData() are callable | |
345 | * @param aCallable2 true, if getComponentData() is callable | |
346 | * @param je JniExecutor instance | |
347 | */ | |
348 | private void testWrongStateHostAndComponentData( final boolean aCallable, final boolean aCallable2, final JniExecutor je ) { | |
349 | if ( aCallable ) { | |
350 | try { | |
351 | Log.i("---------------------------------------------------"); | |
352 | Log.i("state == " + je.getState() + ", " + ( je.isConnected() ? "connected" : "NOT connected")); | |
353 | final int nofHosts = je.getNumberOfHosts(); | |
354 | Log.i("nofHosts == " + nofHosts); | |
355 | for ( int i = 0; i < nofHosts; i++ ) { | |
356 | final HostStruct host = je.getHostData( i ); | |
357 | Log.i("host[ " + i + " ] == " + host); | |
358 | ||
359 | if ( aCallable2 ) { | |
360 | // number of compontents | |
361 | final int nofComponents = host.n_active_components; | |
362 | final int[] components = host.components; | |
363 | for (int componentIndex = 0; componentIndex < nofComponents; componentIndex++) { | |
364 | Log.i( "host.components[ " + i + " ] == " + components[ componentIndex ] ); | |
365 | final ComponentStruct comp = je.getComponentData( components[ componentIndex ] ); | |
366 | Log.i( "comp == " + comp ); | |
367 | } | |
368 | } else { | |
369 | try { | |
370 | je.getComponentData(0); | |
371 | fail("JniExecutorWrongStateException expected"); | |
372 | } catch ( JniExecutorWrongStateException e ) { | |
373 | //expected | |
374 | } | |
375 | } | |
376 | } | |
377 | } catch ( JniExecutorWrongStateException e ) { | |
378 | fail(); | |
379 | } | |
380 | } else { | |
381 | try { | |
382 | je.getNumberOfHosts(); | |
383 | fail("JniExecutorWrongStateException expected"); | |
384 | } catch ( JniExecutorWrongStateException e ) { | |
385 | //expected | |
386 | } | |
387 | ||
388 | try { | |
389 | je.getHostData(0); | |
390 | fail("JniExecutorWrongStateException expected"); | |
391 | } catch ( JniExecutorWrongStateException e ) { | |
392 | //expected | |
393 | } | |
394 | ||
395 | try { | |
396 | je.getComponentData(0); | |
397 | fail("JniExecutorWrongStateException expected"); | |
398 | } catch ( JniExecutorWrongStateException e ) { | |
399 | //expected | |
400 | } | |
401 | } | |
402 | } | |
403 | ||
404 | /** | |
405 | * disconnected (before init()) | |
406 | */ | |
407 | @Test | |
408 | public void testExecutorWrongStateDisconnected() { | |
409 | Log.fi(); | |
410 | final TestData td = createTestData1(); | |
411 | final JniExecutor je = JniExecutor.getInstance(); | |
412 | ||
413 | testWrongStateHostAndComponentData(false, false, je); | |
414 | ||
415 | testWrongStateAddHostControllers(false, je, td); | |
416 | testWrongStateSetConfigFileName(false, je, td); | |
417 | testWrongStateSetObserver(false, je, td); | |
418 | testWrongStateStartSession(false, je); | |
419 | testWrongStateStartHostControllers(false, je); | |
420 | testWrongStateConfigure(false, je); | |
421 | testWrongStateCreateMTC(false, je); | |
422 | testWrongStateExecuteControl(false, je, td); | |
423 | testWrongStateExecuteTextcase(false, je, td); | |
424 | testWrongStateGetExecuteCfglen(false, je); | |
425 | testWrongStateExecuteCfg(false, je); | |
426 | testWrongStatePauseExecutionAndIsPaused(false, je); | |
427 | testWrongStateContinueExecution(false, je); | |
428 | testWrongStateStopExecution(false, je); | |
429 | testWrongStateExitMTC(false, je); | |
430 | ||
431 | assertTrue( !je.isConnected() ); | |
432 | assertTrue( je.getState() == McStateEnum.MC_INACTIVE ); | |
433 | ||
434 | // it can be called in any state, it has no effect if we are in disconnected state | |
435 | je.shutdownSession(); | |
436 | ||
437 | assertTrue( !je.isConnected() ); | |
438 | assertTrue( je.getState() == McStateEnum.MC_INACTIVE ); | |
439 | ||
440 | testWrongStateInit(true, je); | |
441 | ||
442 | TestUtil.assertState( McStateEnum.MC_INACTIVE ); | |
443 | ||
444 | // in this case shutdownSession() is synchronous | |
445 | je.shutdownSession(); | |
446 | assertTrue( !je.isConnected() ); | |
447 | assertTrue( je.getState() == McStateEnum.MC_INACTIVE ); | |
448 | Log.fo(); | |
449 | } | |
450 | ||
451 | /** | |
452 | * connected MC_INACTIVE state (after init()) | |
453 | */ | |
454 | @Test | |
455 | public void testExecutorWrongStateInactive() { | |
456 | Log.fi(); | |
457 | final TestData td = createTestData1(); | |
458 | final JniExecutor je = JniExecutor.getInstance(); | |
459 | ||
460 | gotoInactive(je, td); | |
461 | ||
462 | // we are now in connected MC_INACTIVE, test all the functions, first the ones, that throw exception | |
463 | testWrongStateHostAndComponentData(false, false, je); | |
464 | ||
465 | testWrongStateInit(false, je); | |
466 | testWrongStateStartHostControllers(false, je); | |
467 | testWrongStateConfigure(false, je); | |
468 | testWrongStateCreateMTC(false, je); | |
469 | testWrongStateExecuteControl(false, je, td); | |
470 | testWrongStateExecuteTextcase(false, je, td); | |
471 | testWrongStateGetExecuteCfglen(false, je); | |
472 | testWrongStateExecuteCfg(false, je); | |
473 | testWrongStatePauseExecutionAndIsPaused(true, je); | |
474 | testWrongStateContinueExecution(false, je); | |
475 | testWrongStateStopExecution(false, je); | |
476 | testWrongStateExitMTC(false, je); | |
477 | ||
478 | TestUtil.assertState( McStateEnum.MC_INACTIVE ); | |
479 | testWrongStateAddHostControllers(true, je, td); | |
480 | TestUtil.assertState( McStateEnum.MC_INACTIVE ); | |
481 | testWrongStateSetConfigFileName(true, je, td); | |
482 | TestUtil.assertState( McStateEnum.MC_INACTIVE ); | |
483 | testWrongStateSetObserver(true, je, td); | |
484 | TestUtil.assertState( McStateEnum.MC_INACTIVE ); | |
485 | testWrongStateStartSession(true, je); | |
486 | TestUtil.assertState( McStateEnum.MC_LISTENING ); | |
487 | ||
488 | // -------------- | |
489 | je.shutdownSession(); | |
490 | je.waitForCompletion(); | |
491 | Log.fo(); | |
492 | } | |
493 | ||
494 | /** | |
495 | * MC_LISTENING state (after startSession()) | |
496 | */ | |
497 | @Test | |
498 | public void testExecutorWrongStateListening() { | |
499 | Log.fi(); | |
500 | final TestData td = createTestData1(); | |
501 | final JniExecutor je = JniExecutor.getInstance(); | |
502 | ||
503 | gotoListening(je, td); | |
504 | ||
505 | // we are now in MC_LISTENING, test all the functions, first the ones, that throw exception | |
506 | ||
507 | testWrongStateHostAndComponentData(false, false, je); | |
508 | ||
509 | testWrongStateInit(false, je); | |
510 | testWrongStateSetConfigFileName(false, je, td); | |
511 | testWrongStateSetObserver(true, je, td); | |
512 | testWrongStateStartSession(false, je); | |
513 | testWrongStateCreateMTC(false, je); | |
514 | testWrongStateExecuteControl(false, je, td); | |
515 | testWrongStateExecuteTextcase(false, je, td); | |
516 | testWrongStateGetExecuteCfglen(false, je); | |
517 | testWrongStateExecuteCfg(false, je); | |
518 | testWrongStatePauseExecutionAndIsPaused(true, je); | |
519 | testWrongStateContinueExecution(false, je); | |
520 | testWrongStateStopExecution(false, je); | |
521 | testWrongStateExitMTC(false, je); | |
522 | ||
523 | TestUtil.assertState( McStateEnum.MC_LISTENING ); | |
524 | final Object lock = new Object(); | |
525 | synchronized (lock) { | |
526 | waitBefore(lock, McStateEnum.MC_HC_CONNECTED ); | |
527 | testWrongStateStartHostControllers(true, je); | |
528 | waitAfter(lock); | |
529 | } | |
530 | TestUtil.assertState( McStateEnum.MC_HC_CONNECTED ); | |
531 | ||
532 | // -------------- | |
533 | je.shutdownSession(); | |
534 | je.waitForCompletion(); | |
535 | Log.fo(); | |
536 | } | |
537 | ||
538 | /** | |
539 | * MC_HC_CONNECTED after startHostControllers() | |
540 | */ | |
541 | @Test | |
542 | public void testExecutorWrongStateHcConnected() { | |
543 | Log.fi(); | |
544 | final TestData td = createTestData1(); | |
545 | final JniExecutor je = JniExecutor.getInstance(); | |
546 | ||
547 | gotoHcConnected(je, td); | |
548 | ||
549 | // we are now in MC_HC_CONNECTED, test all the functions, first the ones, that throw exception | |
550 | ||
551 | testWrongStateHostAndComponentData(true, false, je); | |
552 | ||
553 | testWrongStateInit(false, je); | |
554 | testWrongStateAddHostControllers(false, je, td); | |
555 | testWrongStateSetConfigFileName(false, je, td); | |
556 | testWrongStateSetObserver(true, je, td); | |
557 | testWrongStateStartSession(false, je); | |
558 | testWrongStateStartHostControllers(false, je); | |
559 | testWrongStateCreateMTC(false, je); | |
560 | testWrongStateExecuteControl(false, je, td); | |
561 | testWrongStateExecuteTextcase(false, je, td); | |
562 | testWrongStateGetExecuteCfglen(false, je); | |
563 | testWrongStateExecuteCfg(false, je); | |
564 | testWrongStatePauseExecutionAndIsPaused(true, je); | |
565 | testWrongStateContinueExecution(false, je); | |
566 | testWrongStateStopExecution(false, je); | |
567 | testWrongStateExitMTC(false, je); | |
568 | ||
569 | TestUtil.assertState( McStateEnum.MC_HC_CONNECTED ); | |
570 | final Object lock = new Object(); | |
571 | synchronized (lock) { | |
572 | waitBefore(lock, McStateEnum.MC_ACTIVE ); | |
573 | testWrongStateConfigure(true, je); | |
574 | waitAfter(lock); | |
575 | } | |
576 | TestUtil.assertState( McStateEnum.MC_ACTIVE ); | |
577 | ||
578 | // -------------- | |
579 | je.shutdownSession(); | |
580 | je.waitForCompletion(); | |
581 | Log.fo(); | |
582 | } | |
583 | ||
584 | /** | |
585 | * MC_LISTENING state (after startSession()), addHostController() is called | |
586 | */ | |
587 | @Test | |
588 | public void testExecutorWrongStateListening2() { | |
589 | Log.fi(); | |
590 | final TestData td = createTestData1(); | |
591 | final JniExecutor je = JniExecutor.getInstance(); | |
592 | ||
593 | // get to MC_LISTENING without calling addHostController() | |
594 | gotoListeningWithoutAddHostController(je, td); | |
595 | ||
596 | testWrongStateHostAndComponentData(false, false, je); | |
597 | ||
598 | TestUtil.assertState( McStateEnum.MC_LISTENING ); | |
599 | testWrongStateAddHostControllers(true, je, td); | |
600 | TestUtil.assertState( McStateEnum.MC_LISTENING ); | |
601 | ||
602 | // -------------- | |
603 | je.shutdownSession(); | |
604 | je.waitForCompletion(); | |
605 | Log.fo(); | |
606 | } | |
607 | ||
608 | /** | |
609 | * MC_LISTENING_CONFIGURED state (after configure()) | |
610 | */ | |
611 | @Test | |
612 | public void testExecutorWrongStateListeningConfigured() { | |
613 | Log.fi(); | |
614 | final TestData td = createTestData1(); | |
615 | final JniExecutor je = JniExecutor.getInstance(); | |
616 | ||
617 | gotoListeningConfigured(je, td); | |
618 | ||
619 | // we are now in MC_LISTENING_CONFIGURED, test all the functions, first the ones, that throw exception | |
620 | ||
621 | testWrongStateHostAndComponentData(false, false, je); | |
622 | ||
623 | testWrongStateInit(false, je); | |
624 | testWrongStateSetConfigFileName(false, je, td); | |
625 | testWrongStateSetObserver(true, je, td); | |
626 | testWrongStateStartSession(false, je); | |
627 | testWrongStateCreateMTC(false, je); | |
628 | testWrongStateExecuteControl(false, je, td); | |
629 | testWrongStateExecuteTextcase(false, je, td); | |
630 | testWrongStateGetExecuteCfglen(false, je); | |
631 | testWrongStateExecuteCfg(false, je); | |
632 | testWrongStatePauseExecutionAndIsPaused(true, je); | |
633 | testWrongStateContinueExecution(false, je); | |
634 | testWrongStateStopExecution(false, je); | |
635 | testWrongStateExitMTC(false, je); | |
636 | ||
637 | TestUtil.assertState( McStateEnum.MC_LISTENING_CONFIGURED ); | |
638 | final Object lock = new Object(); | |
639 | synchronized (lock) { | |
640 | waitBefore(lock, McStateEnum.MC_ACTIVE ); | |
641 | testWrongStateStartHostControllers(true, je); | |
642 | waitAfter(lock); | |
643 | } | |
644 | TestUtil.assertState( McStateEnum.MC_ACTIVE ); | |
645 | ||
646 | // -------------- | |
647 | je.shutdownSession(); | |
648 | je.waitForCompletion(); | |
649 | Log.fo(); | |
650 | } | |
651 | ||
652 | /** | |
653 | * MC_LISTENING_CONFIGURED state (after configure()) to call addHostController() | |
654 | */ | |
655 | @Test | |
656 | public void testExecutorWrongStateListeningConfigured2() { | |
657 | Log.fi(); | |
658 | final TestData td = createTestData1(); | |
659 | final JniExecutor je = JniExecutor.getInstance(); | |
660 | ||
661 | gotoListeningConfiguredWithoutAddHostController(je, td); | |
662 | ||
663 | // we are now in MC_LISTENING_CONFIGURED, test all the functions, first the ones, that throw exception | |
664 | ||
665 | testWrongStateHostAndComponentData(false, false, je); | |
666 | ||
667 | testWrongStateInit(false, je); | |
668 | testWrongStateAddHostControllers(true, je, td); | |
669 | testWrongStateSetConfigFileName(false, je, td); | |
670 | testWrongStateSetObserver(true, je, td); | |
671 | testWrongStateStartSession(false, je); | |
672 | testWrongStateCreateMTC(false, je); | |
673 | testWrongStateExecuteControl(false, je, td); | |
674 | testWrongStateExecuteTextcase(false, je, td); | |
675 | testWrongStateGetExecuteCfglen(false, je); | |
676 | testWrongStateExecuteCfg(false, je); | |
677 | testWrongStatePauseExecutionAndIsPaused(true, je); | |
678 | testWrongStateContinueExecution(false, je); | |
679 | testWrongStateStopExecution(false, je); | |
680 | testWrongStateExitMTC(false, je); | |
681 | ||
682 | TestUtil.assertState( McStateEnum.MC_LISTENING_CONFIGURED ); | |
683 | final Object lock = new Object(); | |
684 | synchronized (lock) { | |
685 | waitBefore(lock, McStateEnum.MC_ACTIVE ); | |
686 | testWrongStateStartHostControllers(true, je); | |
687 | waitAfter(lock); | |
688 | } | |
689 | TestUtil.assertState( McStateEnum.MC_ACTIVE ); | |
690 | ||
691 | // -------------- | |
692 | je.shutdownSession(); | |
693 | je.waitForCompletion(); | |
694 | Log.fo(); | |
695 | } | |
696 | ||
697 | /** | |
698 | * MC_ACTIVE after configure() | |
699 | */ | |
700 | @Test | |
701 | public void testExecutorWrongStateActive() { | |
702 | Log.fi(); | |
703 | final TestData td = createTestData1(); | |
704 | final JniExecutor je = JniExecutor.getInstance(); | |
705 | ||
706 | gotoActive(je, td); | |
707 | ||
708 | // we are now in MC_ACTIVE, test all the functions, first the ones, that throw exception | |
709 | ||
710 | testWrongStateHostAndComponentData(true, false, je); | |
711 | ||
712 | testWrongStateInit(false, je); | |
713 | testWrongStateAddHostControllers(false, je, td); | |
714 | testWrongStateSetConfigFileName(false, je, td); | |
715 | testWrongStateSetObserver(true, je, td); | |
716 | testWrongStateStartSession(false, je); | |
717 | testWrongStateStartHostControllers(false, je); | |
718 | testWrongStateConfigure(false, je); | |
719 | testWrongStateExecuteControl(false, je, td); | |
720 | testWrongStateExecuteTextcase(false, je, td); | |
721 | testWrongStateGetExecuteCfglen(false, je); | |
722 | testWrongStateExecuteCfg(false, je); | |
723 | testWrongStatePauseExecutionAndIsPaused(true, je); | |
724 | testWrongStateContinueExecution(false, je); | |
725 | testWrongStateStopExecution(false, je); | |
726 | testWrongStateExitMTC(false, je); | |
727 | ||
728 | TestUtil.assertState( McStateEnum.MC_ACTIVE ); | |
729 | final Object lock = new Object(); | |
730 | synchronized (lock) { | |
731 | waitBefore(lock, McStateEnum.MC_READY ); | |
732 | testWrongStateCreateMTC(true, je); | |
733 | waitAfter(lock); | |
734 | } | |
735 | TestUtil.assertState( McStateEnum.MC_READY ); | |
736 | ||
737 | // -------------- | |
738 | je.shutdownSession(); | |
739 | je.waitForCompletion(); | |
740 | Log.fo(); | |
741 | } | |
742 | ||
743 | /** | |
744 | * MC_READY after createMTC() | |
745 | */ | |
746 | @Test | |
747 | public void testExecutorWrongStateReady() { | |
748 | Log.fi(); | |
749 | final TestData td = createTestData1(); | |
750 | final JniExecutor je = JniExecutor.getInstance(); | |
751 | ||
752 | gotoReady(je, td); | |
753 | ||
754 | // we are now in MC_READY, test all the functions, first the ones, that throw exception | |
755 | ||
756 | testWrongStateHostAndComponentData(true, true, je); | |
757 | ||
758 | testWrongStateInit(false, je); | |
759 | testWrongStateAddHostControllers(false, je, td); | |
760 | testWrongStateSetConfigFileName(false, je, td); | |
761 | testWrongStateSetObserver(true, je, td); | |
762 | testWrongStateStartSession(false, je); | |
763 | testWrongStateStartHostControllers(false, je); | |
764 | testWrongStateConfigure(false, je); | |
765 | testWrongStateCreateMTC(false, je); | |
766 | testWrongStatePauseExecutionAndIsPaused(true, je); | |
767 | testWrongStateContinueExecution(false, je); | |
768 | testWrongStateStopExecution(true, je); // do nothing | |
769 | ||
770 | TestUtil.assertState( McStateEnum.MC_READY ); | |
771 | final Object lock1 = new Object(); | |
772 | synchronized (lock1) { | |
773 | waitBefore(lock1, McStateEnum.MC_READY ); | |
774 | testWrongStateExecuteControl(true, je, td); | |
775 | waitAfter(lock1); | |
776 | } | |
777 | TestUtil.assertState( McStateEnum.MC_READY ); | |
778 | ||
779 | final Object lock2 = new Object(); | |
780 | synchronized (lock2) { | |
781 | waitBefore(lock2, McStateEnum.MC_READY ); | |
782 | testWrongStateExecuteTextcase(true, je, td); | |
783 | waitAfter(lock2); | |
784 | } | |
785 | TestUtil.assertState( McStateEnum.MC_READY ); | |
786 | ||
787 | testWrongStateGetExecuteCfglen(true, je); | |
788 | TestUtil.assertState( McStateEnum.MC_READY ); | |
789 | ||
790 | final Object lock3 = new Object(); | |
791 | synchronized (lock3) { | |
792 | waitBefore(lock3, McStateEnum.MC_READY ); | |
793 | testWrongStateExecuteCfg(true, je); | |
794 | waitAfter(lock3); | |
795 | } | |
796 | TestUtil.assertState( McStateEnum.MC_READY ); | |
797 | ||
798 | testWrongStateHostAndComponentData( true, true, je ); | |
799 | ||
800 | // -------------- | |
801 | je.shutdownSession(); | |
802 | je.waitForCompletion(); | |
803 | Log.fo(); | |
804 | } | |
805 | ||
806 | /** | |
807 | * MC_READY after createMTC() to call exitMTC() | |
808 | */ | |
809 | @Test | |
810 | public void testExecutorWrongStateReady2() { | |
811 | Log.fi(); | |
812 | final TestData td = createTestData1(); | |
813 | final JniExecutor je = JniExecutor.getInstance(); | |
814 | ||
815 | gotoReady(je, td); | |
816 | ||
817 | TestUtil.assertState( McStateEnum.MC_READY ); | |
818 | final Object lock = new Object(); | |
819 | synchronized (lock) { | |
820 | waitBefore(lock, McStateEnum.MC_ACTIVE ); | |
821 | testWrongStateExitMTC(true, je); | |
822 | waitAfter(lock); | |
823 | } | |
824 | TestUtil.assertState( McStateEnum.MC_ACTIVE ); | |
825 | ||
826 | // -------------- | |
827 | je.shutdownSession(); | |
828 | je.waitForCompletion(); | |
829 | Log.fo(); | |
830 | } | |
831 | ||
832 | /** | |
833 | * MC_READY after createMTC() to call stopExecution() | |
834 | */ | |
835 | @Test | |
836 | public void testExecutorWrongStateReady3() { | |
837 | Log.fi(); | |
838 | final TestData td = createTestData1(); | |
839 | final JniExecutor je = JniExecutor.getInstance(); | |
840 | ||
841 | gotoReady(je, td); | |
842 | ||
843 | TestUtil.assertState( McStateEnum.MC_READY ); | |
844 | final Object lock = new Object(); | |
845 | synchronized (lock) { | |
846 | waitBefore(lock, McStateEnum.MC_READY ); | |
847 | try { | |
848 | je.executeTestcase(td.mModule, td.mTestcases.get(1)); // long running testcase | |
849 | // Immediately after the method call we are in MC_EXECUTING_CONTROL state until the testcase finishes, | |
850 | // when it gets to MC_READY. | |
851 | // So we could write this: | |
852 | //TestUtil.assertState( McStateEnum.MC_EXECUTING_CONTROL ); | |
853 | // But MC_EXECUTING_CONTROL is an unstable state, and if the system is slow and the thread in MC runs | |
854 | // the testcase faster, than we get here or java side MC lock is blocked (JniExecutor.getState() is synchronized), | |
855 | // we are already in MC_READY, so the testcase fails. | |
856 | // It really happened sometimes during the automatic tests, so assert was removed. | |
857 | ||
858 | // If executeTestcase() is called and then stopExecution() is also called without any delay, | |
859 | // the behaviour of MainController is unpredictable: | |
860 | // Sometimes "Dynamic test case error" sent by MainController to the JniExecutor through the pipe. | |
861 | try { | |
862 | Thread.sleep(100); // in milliseconds | |
863 | } catch(InterruptedException ex) { | |
864 | Thread.currentThread().interrupt(); | |
865 | } | |
866 | ||
867 | je.stopExecution(); | |
868 | } catch (JniExecutorWrongStateException | JniExecutorIllegalArgumentException e ) { | |
869 | fail(); | |
870 | } | |
871 | waitAfter(lock); | |
872 | } | |
873 | TestUtil.assertState( McStateEnum.MC_READY ); | |
874 | ||
875 | // -------------- | |
876 | je.shutdownSession(); | |
877 | je.waitForCompletion(); | |
878 | Log.fo(); | |
879 | } | |
880 | ||
881 | /** | |
882 | * MC_PAUSED, call continueExecution | |
883 | */ | |
884 | @Test | |
885 | public void testExecutorWrongStatePaused() { | |
886 | Log.fi(); | |
887 | final TestData td = createTestData1(); | |
888 | final JniExecutor je = JniExecutor.getInstance(); | |
889 | ||
890 | gotoPaused(je, td); | |
891 | ||
892 | // we are now in MC_PAUSED, test all the functions, first the ones, that throw exception | |
893 | ||
894 | testWrongStateHostAndComponentData(false, false, je); | |
895 | ||
896 | testWrongStateInit(false, je); | |
897 | testWrongStateAddHostControllers(false, je, td); | |
898 | testWrongStateSetConfigFileName(false, je, td); | |
899 | testWrongStateSetObserver(true, je, td); | |
900 | testWrongStateStartSession(false, je); | |
901 | testWrongStateStartHostControllers(false, je); | |
902 | testWrongStateConfigure(false, je); | |
903 | testWrongStateCreateMTC(false, je); | |
904 | testWrongStateExecuteControl(false, je, td); | |
905 | testWrongStateExecuteTextcase(false, je, td); | |
906 | testWrongStateGetExecuteCfglen(false, je); | |
907 | testWrongStateExecuteCfg(false, je); | |
908 | ||
909 | TestUtil.assertState( McStateEnum.MC_PAUSED ); | |
910 | ||
911 | final Object lock = new Object(); | |
912 | synchronized (lock) { | |
913 | waitBefore(lock, McStateEnum.MC_PAUSED ); | |
914 | testWrongStateContinueExecution(true, je); | |
915 | waitAfter(lock); | |
916 | } | |
917 | TestUtil.assertState( McStateEnum.MC_PAUSED ); | |
918 | ||
919 | // -------------- | |
920 | je.shutdownSession(); | |
921 | je.waitForCompletion(); | |
922 | Log.fo(); | |
923 | } | |
924 | ||
925 | /** | |
926 | * MC_PAUSED, call stopExecution | |
927 | */ | |
928 | @Test | |
929 | public void testExecutorWrongStatePaused2() { | |
930 | Log.fi(); | |
931 | final TestData td = createTestData1(); | |
932 | final JniExecutor je = JniExecutor.getInstance(); | |
933 | ||
934 | gotoPaused(je, td); | |
935 | ||
936 | TestUtil.assertState( McStateEnum.MC_PAUSED ); | |
937 | ||
938 | final Object lock = new Object(); | |
939 | synchronized (lock) { | |
940 | waitBefore(lock, McStateEnum.MC_READY ); | |
941 | testWrongStateStopExecution(true, je); | |
942 | waitAfter(lock); | |
943 | } | |
944 | TestUtil.assertState( McStateEnum.MC_READY ); | |
945 | ||
946 | // -------------- | |
947 | je.shutdownSession(); | |
948 | je.waitForCompletion(); | |
949 | Log.fo(); | |
950 | } | |
951 | ||
952 | /** | |
953 | * MC_PAUSED switch paused state to false -> test control continues | |
954 | */ | |
955 | @Test | |
956 | public void testExecutorWrongStatePaused3() { | |
957 | Log.fi(); | |
958 | final TestData td = createTestData1(); | |
959 | final JniExecutor je = JniExecutor.getInstance(); | |
960 | ||
961 | gotoPaused(je, td); | |
962 | ||
963 | TestUtil.assertState( McStateEnum.MC_PAUSED ); | |
964 | final Object lock = new Object(); | |
965 | synchronized (lock) { | |
966 | waitBefore(lock, McStateEnum.MC_READY ); | |
967 | //If we switch paused from on to off in MC_PAUSED state, execution of the next testcase will be automatically continued. | |
968 | try { | |
969 | assertTrue(je.isPaused()); | |
970 | je.pauseExecution(false); | |
971 | } catch( JniExecutorWrongStateException e ) { | |
972 | fail(); | |
973 | } | |
974 | waitAfter(lock); | |
975 | } | |
976 | TestUtil.assertState( McStateEnum.MC_READY ); | |
977 | ||
978 | // -------------- | |
979 | je.shutdownSession(); | |
980 | je.waitForCompletion(); | |
981 | Log.fo(); | |
982 | } | |
983 | ||
984 | } |