1 /******************************************************************************
2 * Copyright (c) 2000-2014 Ericsson Telecom AB
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
7 ******************************************************************************/
8 package org
.eclipse
.titan
.executorapi
.test
;
10 import java
.util
.List
;
13 import org
.eclipse
.titan
.executor
.jni
.McStateEnum
;
14 import org
.eclipse
.titan
.executor
.jni
.Timeval
;
15 import org
.eclipse
.titan
.executor
.jni
.VerdictTypeEnum
;
16 import org
.eclipse
.titan
.executorapi
.IJniExecutorObserver
;
17 import org
.eclipse
.titan
.executorapi
.JniExecutor
;
18 import org
.eclipse
.titan
.executorapi
.exception
.JniExecutorException
;
19 import org
.eclipse
.titan
.executorapi
.test
.JniExecutorAsyncHappyTest
.ExecutionMethod
;
20 import org
.eclipse
.titan
.executorapi
.test
.JniExecutorAsyncHappyTest
.McRoute
;
21 import org
.eclipse
.titan
.executorapi
.util
.Log
;
23 abstract class TestObserverBase
implements IJniExecutorObserver
{
25 /** Executor instance, NOT OWNED */
26 protected final JniExecutor mJe
;
28 /** TTCN-3 module name of the test control or test case(s), it can be null (it means execution list from cfg file is used) */
29 protected String mModule
= null;
31 /** List of test cases, it can be null (it means test control is executed) */
32 protected List
<String
> mTestcases
= null;
34 protected final McRoute mRoute
;
35 protected final ExecutionMethod mExecMethod
;
38 * Lock object for waiting completion. NOT OWNED
40 private Object mLockCompletion
= null;
44 * verdict in the observer
45 * true: PASS -> it can still be FAIL in the testcase!
48 private volatile boolean mVerdict
= true;
50 public void setLock( final Object aLockObject
) {
51 mLockCompletion
= aLockObject
;
54 public boolean getVerdict() {
58 public void setModule( final String aModule
) {
62 public void setTestcases( final List
<String
> aTestcases
) {
63 mTestcases
= aTestcases
;
66 protected TestObserverBase( final JniExecutor aJe
, final McRoute aRoute
, final ExecutionMethod aExecMethod
) {
69 mExecMethod
= aExecMethod
;
73 public void statusChanged(McStateEnum aNewState
) {
75 if ( aNewState
== McStateEnum
.MC_INACTIVE
) {
76 // session is shut down
77 // (It cannot be the initial MC_INACTIVE state, because we are at least
78 // in MC_LISTENING state when the 1st asynchronous request is sent.)
82 statusChanged2( aNewState
);
83 } catch (JniExecutorException e
) {
84 Log
.f( e
.toString() );
91 public void error(int aSeverity
, String aMsg
) {
92 Log
.fi( aSeverity
, aMsg
);
98 public void notify(Timeval aTime
, String aSource
, int aSeverity
, String aMsg
) {
99 Log
.fi( aTime
, aSource
, aSeverity
, aMsg
);
104 public void verdict(String aTestcase
, VerdictTypeEnum aVerdictType
) {
105 Log
.fi( aTestcase
, aVerdictType
);
110 public void verdictStats(Map
<VerdictTypeEnum
, Integer
> aVerdictStats
) {
111 Log
.fi( aVerdictStats
);
116 * Exception proof function instead of statusChanged(), exception is handled in statusChanged()
118 * @throws JniExecutorException
119 * @see #statusChanged(McStateEnum)
121 abstract protected void statusChanged2( final McStateEnum aNewState
) throws JniExecutorException
;
124 * releases the lock of the test client
126 private void releaseLock() {
127 if (mLockCompletion
!= null) {
128 synchronized (mLockCompletion
) {
129 if (mLockCompletion
!= null) {
130 mLockCompletion
.notifyAll();
137 * Set verdict to FAIL on the observer, so to can be read by the test method
139 private void fail() {
145 * sets lock, waits until lock is released
147 public void waitForCompletion() {
148 if (mLockCompletion
!= null) {
149 synchronized (mLockCompletion
) {
150 if (mLockCompletion
!= null) {
152 mLockCompletion
.wait();
153 } catch (InterruptedException e
) {