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.fail; | |
16 | ||
17 | import org.eclipse.titan.executorapi.JniExecutor; | |
18 | import org.eclipse.titan.executorapi.exception.JniExecutorIllegalArgumentException; | |
19 | import org.eclipse.titan.executorapi.exception.JniExecutorWrongStateException; | |
20 | import org.junit.Test; | |
21 | ||
22 | /** | |
23 | * Testing all the JniExecutor methods in all the stable states with illegal arguments. | |
24 | * If method is callable in the given state and 1 or more arguments are illegal (null, empty string, filename for a non-existent file, ...), | |
25 | * JniExecutorIllegalArgException is expected. | |
26 | */ | |
27 | public class JniExecutorAsyncErrorIllegalArgTest extends JniExecutorAsyncErrorTest { | |
28 | ||
29 | private void testIllegalArgAddHostController( final JniExecutor je ) { | |
30 | try { | |
31 | je.addHostController( null ); | |
32 | fail("JniExecutorIllegalArgumentException expected"); | |
33 | } catch (JniExecutorIllegalArgumentException e) { | |
34 | //expected | |
35 | } catch (JniExecutorWrongStateException e) { | |
36 | fail(); | |
37 | } | |
38 | } | |
39 | ||
40 | private void testIllegalArgSetConfigFileName( final JniExecutor je ) { | |
41 | try { | |
42 | je.setConfigFileName( null ); | |
43 | fail("JniExecutorIllegalArgumentException expected"); | |
44 | } catch (JniExecutorIllegalArgumentException e) { | |
45 | //expected | |
46 | } catch (JniExecutorWrongStateException e) { | |
47 | fail(); | |
48 | } | |
49 | ||
50 | try { | |
51 | je.setConfigFileName( "" ); | |
52 | fail("JniExecutorIllegalArgumentException expected"); | |
53 | } catch (JniExecutorIllegalArgumentException e) { | |
54 | //expected | |
55 | } catch (JniExecutorWrongStateException e) { | |
56 | fail(); | |
57 | } | |
58 | } | |
59 | ||
60 | private void testIllegalArgSetObserver( final JniExecutor je, final TestData td ) { | |
61 | try { | |
62 | je.setObserver(td.mObserver); | |
63 | je.setObserver(null); | |
64 | // any observer including null is a valid argument | |
65 | } catch (JniExecutorWrongStateException e) { | |
66 | fail(); | |
67 | } | |
68 | } | |
69 | ||
70 | private void testIllegalArgExecuteControl( final JniExecutor je ) { | |
71 | try { | |
72 | je.executeControl(null); | |
73 | fail("JniExecutorIllegalArgumentException expected"); | |
74 | } catch (JniExecutorIllegalArgumentException e) { | |
75 | //expected | |
76 | } catch (JniExecutorWrongStateException e) { | |
77 | fail(); | |
78 | } | |
79 | ||
80 | try { | |
81 | je.executeControl(""); | |
82 | fail("JniExecutorIllegalArgumentException expected"); | |
83 | } catch (JniExecutorIllegalArgumentException e) { | |
84 | //expected | |
85 | } catch (JniExecutorWrongStateException e) { | |
86 | fail(); | |
87 | } | |
88 | } | |
89 | ||
90 | private void testIllegalArgExecuteTestcase( final JniExecutor je, final TestData td ) { | |
91 | try { | |
92 | je.executeTestcase( null, td.mTestcases.get(0)); | |
93 | fail("JniExecutorIllegalArgumentException expected"); | |
94 | } catch (JniExecutorIllegalArgumentException e) { | |
95 | //expected | |
96 | } catch (JniExecutorWrongStateException e) { | |
97 | fail(); | |
98 | } | |
99 | try { | |
100 | je.executeTestcase( "", td.mTestcases.get(0)); | |
101 | fail("JniExecutorIllegalArgumentException expected"); | |
102 | } catch (JniExecutorIllegalArgumentException e) { | |
103 | //expected | |
104 | } catch (JniExecutorWrongStateException e) { | |
105 | fail(); | |
106 | } | |
107 | try { | |
108 | je.executeTestcase( td.mModule, null); | |
109 | fail("JniExecutorIllegalArgumentException expected"); | |
110 | } catch (JniExecutorIllegalArgumentException e) { | |
111 | //expected | |
112 | } catch (JniExecutorWrongStateException e) { | |
113 | fail(); | |
114 | } | |
115 | try { | |
116 | je.executeTestcase( td.mModule, ""); | |
117 | fail("JniExecutorIllegalArgumentException expected"); | |
118 | } catch (JniExecutorIllegalArgumentException e) { | |
119 | //expected | |
120 | } catch (JniExecutorWrongStateException e) { | |
121 | fail(); | |
122 | } | |
123 | } | |
124 | ||
125 | private void testIllegalArgExecuteCfg( final JniExecutor je ) { | |
126 | try { | |
127 | je.executeCfg( -1 ); | |
128 | fail("JniExecutorIllegalArgumentException expected"); | |
129 | } catch (JniExecutorIllegalArgumentException e) { | |
130 | //expected | |
131 | } catch (JniExecutorWrongStateException e) { | |
132 | fail(); | |
133 | } | |
134 | ||
135 | try { | |
136 | final int executeCfgLen = je.getExecuteCfgLen(); | |
137 | je.executeCfg( executeCfgLen ); | |
138 | fail("JniExecutorIllegalArgumentException expected"); | |
139 | } catch (JniExecutorIllegalArgumentException e) { | |
140 | //expected | |
141 | } catch (JniExecutorWrongStateException e) { | |
142 | fail(); | |
143 | } | |
144 | } | |
145 | ||
146 | /** | |
147 | * disconnected (before init()) | |
148 | */ | |
149 | @Test | |
150 | public void testExecutorIllegalArgDisconnected() { | |
151 | //nothing to test in disconnected state | |
152 | } | |
153 | ||
154 | /** | |
155 | * connected MC_INACTIVE state (after init()) | |
156 | */ | |
157 | @Test | |
158 | public void testExecutorIllegalArgInactive() { | |
159 | final TestData td = createTestData1(); | |
160 | final JniExecutor je = JniExecutor.getInstance(); | |
161 | ||
162 | gotoInactive(je, td); | |
163 | ||
164 | // we are now in connected MC_INACTIVE, test all the functions, which has argument | |
165 | testIllegalArgAddHostController(je); | |
166 | testIllegalArgSetConfigFileName(je); | |
167 | testIllegalArgSetObserver(je, td); | |
168 | ||
169 | // -------------- | |
170 | je.shutdownSession(); | |
171 | je.waitForCompletion(); | |
172 | } | |
173 | ||
174 | /** | |
175 | * MC_LISTENING state (after startSession()) | |
176 | */ | |
177 | @Test | |
178 | public void testExecutorIllegalArgListening() { | |
179 | final TestData td = createTestData1(); | |
180 | final JniExecutor je = JniExecutor.getInstance(); | |
181 | ||
182 | gotoListening(je, td); | |
183 | ||
184 | // we are now in MC_LISTENING, test all the functions, which has argument | |
185 | testIllegalArgAddHostController(je); | |
186 | testIllegalArgSetObserver(je, td); | |
187 | ||
188 | // -------------- | |
189 | je.shutdownSession(); | |
190 | je.waitForCompletion(); | |
191 | } | |
192 | ||
193 | /** | |
194 | * MC_HC_CONNECTED after startHostControllers() | |
195 | */ | |
196 | @Test | |
197 | public void testExecutorIllegalArgHcConnected() { | |
198 | final TestData td = createTestData1(); | |
199 | final JniExecutor je = JniExecutor.getInstance(); | |
200 | ||
201 | gotoHcConnected(je, td); | |
202 | ||
203 | // we are now in MC_HC_CONNECTED, test all the functions, which has argument | |
204 | testIllegalArgSetObserver(je, td); | |
205 | ||
206 | // -------------- | |
207 | je.shutdownSession(); | |
208 | je.waitForCompletion(); | |
209 | } | |
210 | ||
211 | /** | |
212 | * MC_LISTENING_CONFIGURED state (after configure()) | |
213 | */ | |
214 | @Test | |
215 | public void testExecutorIllegalArgListeningConfigured() { | |
216 | final TestData td = createTestData1(); | |
217 | final JniExecutor je = JniExecutor.getInstance(); | |
218 | ||
219 | gotoListeningConfigured(je, td); | |
220 | ||
221 | // we are now in MC_LISTENING_CONFIGURED, test all the functions, which has argument | |
222 | testIllegalArgAddHostController(je); | |
223 | testIllegalArgSetObserver(je, td); | |
224 | ||
225 | // -------------- | |
226 | je.shutdownSession(); | |
227 | je.waitForCompletion(); | |
228 | } | |
229 | ||
230 | /** | |
231 | * MC_ACTIVE after configure() | |
232 | */ | |
233 | @Test | |
234 | public void testExecutorIllegalArgActive() { | |
235 | final TestData td = createTestData1(); | |
236 | final JniExecutor je = JniExecutor.getInstance(); | |
237 | ||
238 | gotoActive(je, td); | |
239 | ||
240 | // we are now in MC_ACTIVE, test all the functions, which has argument | |
241 | testIllegalArgSetObserver(je, td); | |
242 | ||
243 | // -------------- | |
244 | je.shutdownSession(); | |
245 | je.waitForCompletion(); | |
246 | } | |
247 | ||
248 | /** | |
249 | * MC_READY after createMTC() | |
250 | */ | |
251 | @Test | |
252 | public void testExecutorIllegalArgReady() { | |
253 | final TestData td = createTestData1(); | |
254 | final JniExecutor je = JniExecutor.getInstance(); | |
255 | ||
256 | gotoReady(je, td); | |
257 | ||
258 | // we are now in MC_READY, test all the functions, which has argument | |
259 | testIllegalArgSetObserver(je, td); | |
260 | testIllegalArgExecuteControl(je); | |
261 | testIllegalArgExecuteTestcase(je, td); | |
262 | testIllegalArgExecuteCfg(je); | |
263 | ||
264 | // -------------- | |
265 | je.shutdownSession(); | |
266 | je.waitForCompletion(); | |
267 | } | |
268 | } |