Crossfire JXClient, Trunk
AbstractScriptProcessTest.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff
19  * Copyright (C) 2006-2017,2019-2023 Andreas Kirschbaum
20  * Copyright (C) 2010-2012,2014-2018,2020-2023 Nicolas Weeger
21  */
22 
23 package com.realtime.crossfire.jxclient.scripts;
24 
27 import org.junit.Assert;
28 import org.junit.Ignore;
29 import org.junit.Test;
30 
34 @SuppressWarnings("JavaDoc")
36 
37  @Test
40  "request map pos\n"+//
41  "@map_scroll 1 -1\n"+//
42  "request map pos\n"+//
43  "@map_scroll -2 3\n"+//
44  "request map pos\n"+//
45  "@map_new\n"+//
46  "request map pos\n"+//
47  "");
48  try {
49  final Thread thread = new Thread(process, "ScriptProcess");
50  try {
51  thread.start();
52  try {
53  thread.join();
54  } catch (final InterruptedException ignored) {
55  Assert.fail();
56  }
57  } finally {
58  thread.interrupt();
59  }
60  } finally {
61  process.killScript();
62  }
63 
64  Assert.assertEquals(""+//
65  "readFromScript: request map pos\n"+//
66  "writeToScript: request map pos 0 0\n"+//
67  "readFromScript: @map_scroll 1 -1\n"+//
68  "readFromScript: request map pos\n"+//
69  "writeToScript: request map pos 1 -1\n"+//
70  "readFromScript: @map_scroll -2 3\n"+//
71  "readFromScript: request map pos\n"+//
72  "writeToScript: request map pos -1 2\n"+//
73  "readFromScript: @map_new\n"+//
74  "readFromScript: request map pos\n"+//
75  "writeToScript: request map pos 0 0\n"+//
76  "readFromScript: EOF\n"+//
77  "killScript\n"+//
78  "", process.getAndClearEvents());
79  }
80 
81  @Test
83  final CrossfireServerConnection crossfireServerConnection = new TestCrossfireServerConnection();
85  "issue mark 123\n"+//
86  "", crossfireServerConnection);
87  try {
88  final Thread thread = new Thread(process, "ScriptProcess");
89  try {
90  thread.start();
91  try {
92  thread.join();
93  } catch (final InterruptedException ignored) {
94  Assert.fail();
95  }
96  } finally {
97  thread.interrupt();
98  }
99  } finally {
100  process.killScript();
101  }
102 
103  Assert.assertEquals(""+//
104  "readFromScript: issue mark 123\n"+//
105  "readFromScript: EOF\n"+//
106  "killScript\n"+//
107  "", process.getAndClearEvents());
108  Assert.assertEquals("mark 123\n", crossfireServerConnection.toString());
109  }
110 
111  @Test
113  final CrossfireServerConnection crossfireServerConnection = new TestCrossfireServerConnection();
115  "issue lock 1 123\n"+//
116  "", crossfireServerConnection);
117  try {
118  final Thread thread = new Thread(process, "ScriptProcess");
119  try {
120  thread.start();
121  try {
122  thread.join();
123  } catch (final InterruptedException ignored) {
124  Assert.fail();
125  }
126  } finally {
127  thread.interrupt();
128  }
129  } finally {
130  process.killScript();
131  }
132 
133  Assert.assertEquals(""+//
134  "readFromScript: issue lock 1 123\n"+//
135  "readFromScript: EOF\n"+//
136  "killScript\n"+//
137  "", process.getAndClearEvents());
138  Assert.assertEquals("lock true 123\n", crossfireServerConnection.toString());
139  }
140 
141  @Ignore("player tag is not known")
142  @Test
144  final CrossfireServerConnection crossfireServerConnection = new TestCrossfireServerConnection();
146  "issue take 123\n"+//
147  "", crossfireServerConnection);
148  try {
149  final Thread thread = new Thread(process, "ScriptProcess");
150  try {
151  thread.start();
152  try {
153  thread.join();
154  } catch (final InterruptedException ignored) {
155  Assert.fail();
156  }
157  } finally {
158  thread.interrupt();
159  }
160  } finally {
161  process.killScript();
162  }
163 
164  Assert.assertEquals(""+//
165  "readFromScript: issue take 123\n"+//
166  "readFromScript: EOF\n"+//
167  "killScript\n"+//
168  "", process.getAndClearEvents());
169  Assert.assertEquals("move 123 0\n", crossfireServerConnection.toString());
170  }
171 
172  @Ignore("player tag is not known")
173  @Test
175  final CrossfireServerConnection crossfireServerConnection = new TestCrossfireServerConnection();
177  "issue take 123 45\n"+//
178  "", crossfireServerConnection);
179  try {
180  final Thread thread = new Thread(process, "ScriptProcess");
181  try {
182  thread.start();
183  try {
184  thread.join();
185  } catch (final InterruptedException ignored) {
186  Assert.fail();
187  }
188  } finally {
189  thread.interrupt();
190  }
191  } finally {
192  process.killScript();
193  }
194 
195  Assert.assertEquals(""+//
196  "readFromScript: issue take 123 45\n"+//
197  "readFromScript: EOF\n"+//
198  "killScript\n"+//
199  "", process.getAndClearEvents());
200  Assert.assertEquals("move 123 45\n", crossfireServerConnection.toString());
201  }
202 
203  @Test
205  final CrossfireServerConnection crossfireServerConnection = new TestCrossfireServerConnection();
207  "issue drop 123\n"+//
208  "", crossfireServerConnection);
209  try {
210  final Thread thread = new Thread(process, "ScriptProcess");
211  try {
212  thread.start();
213  try {
214  thread.join();
215  } catch (final InterruptedException ignored) {
216  Assert.fail();
217  }
218  } finally {
219  thread.interrupt();
220  }
221  } finally {
222  process.killScript();
223  }
224 
225  Assert.assertEquals(""+//
226  "readFromScript: issue drop 123\n"+//
227  "readFromScript: EOF\n"+//
228  "killScript\n"+//
229  "", process.getAndClearEvents());
230  Assert.assertEquals("move 0 123 0\n", crossfireServerConnection.toString());
231  }
232 
233  @Test
235  final CrossfireServerConnection crossfireServerConnection = new TestCrossfireServerConnection();
237  "issue drop 123 45\n"+//
238  "", crossfireServerConnection);
239  try {
240  final Thread thread = new Thread(process, "ScriptProcess");
241  try {
242  thread.start();
243  try {
244  thread.join();
245  } catch (final InterruptedException ignored) {
246  Assert.fail();
247  }
248  } finally {
249  thread.interrupt();
250  }
251  } finally {
252  process.killScript();
253  }
254 
255  Assert.assertEquals(""+//
256  "readFromScript: issue drop 123 45\n"+//
257  "readFromScript: EOF\n"+//
258  "killScript\n"+//
259  "", process.getAndClearEvents());
260  Assert.assertEquals("move 0 123 45\n", crossfireServerConnection.toString());
261  }
262 
263  @Test
265  final CrossfireServerConnection crossfireServerConnection = new TestCrossfireServerConnection();
267  "issue apply 123\n"+//
268  "", crossfireServerConnection);
269  try {
270  final Thread thread = new Thread(process, "ScriptProcess");
271  try {
272  thread.start();
273  try {
274  thread.join();
275  } catch (final InterruptedException ignored) {
276  Assert.fail();
277  }
278  } finally {
279  thread.interrupt();
280  }
281  } finally {
282  process.killScript();
283  }
284 
285  Assert.assertEquals(""+//
286  "readFromScript: issue apply 123\n"+//
287  "readFromScript: EOF\n"+//
288  "killScript\n"+//
289  "", process.getAndClearEvents());
290  Assert.assertEquals("apply 123\n", crossfireServerConnection.toString());
291  }
292 
293  @Test
295  final CrossfireServerConnection crossfireServerConnection = new TestCrossfireServerConnection();
297  "issue 3 0 north\n"+//
298  "", crossfireServerConnection);
299  try {
300  final Thread thread = new Thread(process, "ScriptProcess");
301  try {
302  thread.start();
303  try {
304  thread.join();
305  } catch (final InterruptedException ignored) {
306  Assert.fail();
307  }
308  } finally {
309  thread.interrupt();
310  }
311  } finally {
312  process.killScript();
313  }
314 
315  Assert.assertEquals(""+//
316  "readFromScript: issue 3 0 north\n"+//
317  "readFromScript: EOF\n"+//
318  "killScript\n"+//
319  "", process.getAndClearEvents());
320  Assert.assertEquals("ncom 3 north\n", crossfireServerConnection.toString());
321  }
322 
323  @Test
325  final CrossfireServerConnection crossfireServerConnection = new TestCrossfireServerConnection();
327  "issue xyz\n"+//
328  "", crossfireServerConnection);
329  try {
330  final Thread thread = new Thread(process, "ScriptProcess");
331  try {
332  thread.start();
333  try {
334  thread.join();
335  } catch (final InterruptedException ignored) {
336  Assert.fail();
337  }
338  } finally {
339  thread.interrupt();
340  }
341  } finally {
342  process.killScript();
343  }
344 
345  Assert.assertEquals(""+//
346  "readFromScript: issue xyz\n"+//
347  "readFromScript: EOF\n"+//
348  "killScript\n"+//
349  "", process.getAndClearEvents());
350  Assert.assertEquals("raw xyz\n", crossfireServerConnection.toString());
351  }
352 
353 }
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.scripts.AbstractScriptProcessTest.requestMap_issueApply_sendsCommand
void requestMap_issueApply_sendsCommand()
Definition: AbstractScriptProcessTest.java:264
com.realtime.crossfire.jxclient.scripts.AbstractScriptProcessTest.requestMap_issueNcom_sendsCommand
void requestMap_issueNcom_sendsCommand()
Definition: AbstractScriptProcessTest.java:294
com.realtime.crossfire.jxclient.server
com.realtime.crossfire.jxclient.scripts.AbstractScriptProcessTest.requestMap_issueDropTagCount_sendsCommand
void requestMap_issueDropTagCount_sendsCommand()
Definition: AbstractScriptProcessTest.java:234
com.realtime.crossfire.jxclient.scripts.TestScriptProcess.newTestScriptProcess
static TestScriptProcess newTestScriptProcess(@NotNull final String scriptCommands)
Definition: TestScriptProcess.java:103
com.realtime.crossfire.jxclient.scripts.TestScriptProcess.killScript
void killScript()
Definition: TestScriptProcess.java:159
com.realtime.crossfire.jxclient.scripts.AbstractScriptProcessTest.requestMap_issueTakeTag_sendsCommand
void requestMap_issueTakeTag_sendsCommand()
Definition: AbstractScriptProcessTest.java:143
com.realtime.crossfire.jxclient.scripts.AbstractScriptProcessTest.requestMap_issueMark_sendsCommand
void requestMap_issueMark_sendsCommand()
Definition: AbstractScriptProcessTest.java:82
com.realtime.crossfire.jxclient.scripts.AbstractScriptProcessTest.requestMap_issueLock_sendsCommand
void requestMap_issueLock_sendsCommand()
Definition: AbstractScriptProcessTest.java:112
com.realtime.crossfire.jxclient.scripts.TestScriptProcess
Definition: TestScriptProcess.java:65
com.realtime.crossfire.jxclient.server.crossfire.CrossfireServerConnection
Definition: CrossfireServerConnection.java:37
com.realtime.crossfire.jxclient.scripts.AbstractScriptProcessTest.requestMap_issueDropTag_sendsCommand
void requestMap_issueDropTag_sendsCommand()
Definition: AbstractScriptProcessTest.java:204
com.realtime.crossfire.jxclient.scripts.AbstractScriptProcessTest.requestMap_issueRawString_sendsCommand
void requestMap_issueRawString_sendsCommand()
Definition: AbstractScriptProcessTest.java:324
com.realtime.crossfire.jxclient.scripts.AbstractScriptProcessTest.requestMap_issueTakeTagCount_sendsCommand
void requestMap_issueTakeTagCount_sendsCommand()
Definition: AbstractScriptProcessTest.java:174
com.realtime.crossfire.jxclient.server.crossfire
Definition: AbstractCrossfireServerConnection.java:23
com.realtime.crossfire.jxclient.server.crossfire.TestCrossfireServerConnection
Definition: TestCrossfireServerConnection.java:39
com.realtime.crossfire
com.realtime.crossfire.jxclient.scripts.AbstractScriptProcessTest
Definition: AbstractScriptProcessTest.java:35
com.realtime
com
com.realtime.crossfire.jxclient.scripts.TestScriptProcess.getAndClearEvents
String getAndClearEvents()
Definition: TestScriptProcess.java:223
com.realtime.crossfire.jxclient.scripts.AbstractScriptProcessTest.requestMap_commands_returnsResults
void requestMap_commands_returnsResults()
Definition: AbstractScriptProcessTest.java:38