OSDN Git Service

Merge branch 'master' of git.sourceforge.jp:/gitroot/shogi-server/shogi-server
[shogi-server/shogi-server.git] / test / TC_functional.rb
1 require "baseclient"
2 require "kconv"
3
4 class TestClientAtmark < BaseClient
5   # login with trip
6   def set_name
7     super
8     @game_name = "atmark"
9     @p1_name = "B@p1"
10     @p2_name = "W@p2"
11   end
12
13   def test_toryo
14     result, result2 = handshake do
15       @p1.toryo
16       wait_finish
17     end
18     assert(/#LOSE/ =~ result)
19     assert(/#WIN/  =~ result2)
20
21     now = Time.now
22     year  = now.strftime("%Y")
23     month = now.strftime("%m")
24     day   = now.strftime("%d")
25     path = File.join( File.dirname(__FILE__), "..", year, month, day, "*atmark-1500-0*")
26     log_files = Dir.glob(path)
27     assert(!log_files.empty?) 
28     sleep 0.1
29     log_content = File.read(log_files.sort.last)
30
31     # "$EVENT", "$START_TIME" and "'$END_TIME" are removed since they vary dinamically.
32     should_be = <<-EOF
33 V2
34 N+atmark_B@p1
35 N-atmark_W@p2
36 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
37 P2 * -HI *  *  *  *  * -KA * 
38 P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
39 P4 *  *  *  *  *  *  *  *  * 
40 P5 *  *  *  *  *  *  *  *  * 
41 P6 *  *  *  *  *  *  *  *  * 
42 P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
43 P8 * +KA *  *  *  *  * +HI * 
44 P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
45 +
46 'rating:atmark_B@p1+275876e34cf609db118f3d84b799a790:atmark_W@p2+275876e34cf609db118f3d84b799a790
47 +2726FU
48 T1
49 -3334FU
50 T1
51 %TORYO
52 'P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
53 'P2 * -HI *  *  *  *  * -KA * 
54 'P3-FU-FU-FU-FU-FU-FU * -FU-FU
55 'P4 *  *  *  *  *  * -FU *  * 
56 'P5 *  *  *  *  *  *  *  *  * 
57 'P6 *  *  *  *  *  *  * +FU * 
58 'P7+FU+FU+FU+FU+FU+FU+FU * +FU
59 'P8 * +KA *  *  *  *  * +HI * 
60 'P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
61 '+
62 'summary:toryo:atmark_B@p1 lose:atmark_W@p2 win
63 EOF
64
65     log_content.gsub!(/^\$.*?\n/m, "")
66     log_content.gsub!(/^'\$.*?\n/m, "")
67     assert_equal(should_be, log_content)
68   end
69 end
70
71
72 class TestComment < BaseClient
73   def test_toryo
74     result, result2 = handshake do
75       @p1.toryo
76       wait_finish
77     end
78     assert(/#LOSE/ =~ result)
79     assert(/#WIN/  =~ result2)
80   end
81
82   def test_inline_comment
83     result, result2 = handshake do
84       move "+2625FU,'comment"
85       move "-2233KA"
86       @p1.toryo
87       wait_finish
88     end
89     assert(/#LOSE/ =~ result)
90     assert(/#WIN/  =~ result2)
91   end
92
93   def test_inline_comment_ja_euc
94     result, result2 = handshake do
95       move "+2625FU,'\93ú\96{\8cêEUC"
96       move "-2233KA"
97       @p1.toryo
98       wait_finish
99     end
100     assert(/#LOSE/ =~ result)
101     assert(/#WIN/  =~ result2)
102   end
103
104   def test_inline_comment_ja_utf8
105     result, result2 = handshake do
106       move "+2625FU,'\93ú\96{\8cêUTF8".toutf8
107       move "-2233KA"
108       @p1.toryo
109       wait_finish
110     end
111     assert(/#LOSE/ =~ result)
112     assert(/#WIN/  =~ result2)
113   end
114 end
115
116
117 class TestWhiteMovesBlack < BaseClient
118   def test_white_moves_black
119     result, result2 = handshake do
120       move "+9796FU"
121       @p2.move "+1716FU"
122       wait_finish
123     end
124     assert(/#ILLEGAL_MOVE/ =~ result)
125     assert(/#WIN/  =~ result)
126     assert(/#ILLEGAL_MOVE/ =~ result2)
127     assert(/#LOSE/ =~ result2)
128   end
129 end
130
131
132 #
133 # CSA test
134 #
135
136 class TestLoginCSAWithoutTripGoodGamename < CSABaseClient
137   def set_name
138     super
139     @game_name = "csawotrip"
140     @p1_name   = "p1"
141     @p2_name   = "p2"
142   end
143
144   def test_toryo
145     result, result2 = handshake do
146       @p1.toryo
147       @p1.wait_finish
148       @p2.wait_finish
149     end
150     assert(/#LOSE/ =~ result)
151     assert(/#WIN/  =~ result2)
152   end
153 end
154
155 class TestLoginCSAWithTripGoodGamename < CSABaseClient
156   def set_name
157     super
158     @game_name = "csawtrip"
159     @p1_name   = "p1"
160     @p2_name   = "p2"
161   end
162
163   def set_player
164     super
165     @p1.login_command += ",atrip"
166     @p2.login_command += ",anothertrip"
167   end
168
169   def test_toryo
170     result, result2 = handshake do
171       @p1.toryo
172       @p1.wait_finish
173       @p2.wait_finish
174     end
175     assert(/#LOSE/ =~ result)
176     assert(/#WIN/  =~ result2)
177   end
178 end
179
180 class TestChallenge < CSABaseClient
181   def set_name
182     super
183     @game_name = "challenge"
184     @p1_name   = "p1"
185     @p2_name   = "p2"
186   end
187
188   def set_player
189     super
190     @p1.login_command += ",atrip"
191     @p2.login_command += ",anothertrip"
192   end
193
194   def test_toryo
195     result, result2 = handshake do
196       @p1.puts "CHALLENGE"
197       @p1.wait(/CHALLENGE ACCEPTED/)
198       @p2.puts "CHALLENGE"
199       @p2.wait(/CHALLENGE ACCEPTED/)
200     end
201     assert(true)
202   end
203 end
204
205 #
206 # Test Floodgate
207 #
208
209 class TestFloodgateGame < BaseClient
210   def set_name
211     super
212     @game_name = "floodgate"
213   end
214
215   def set_player
216     @p1 = SocketPlayer.new @game_name, @p1_name, "*"
217     @p2 = SocketPlayer.new @game_name, @p2_name, "*"
218   end
219
220   def test_game_wait
221     @p1.connect
222     @p2.connect
223     @p1.login
224     @p2.login
225     @p1.game
226     @p2.game
227     assert(true)
228     logout12
229   end
230 end
231
232 class TestFloodgateGameWrongTebam < BaseClient
233   def set_name
234     super
235     @game_name = "floodgate"
236   end
237
238   def test_game_wait
239     @p1.connect
240     @p2.connect
241     @p1.login
242     @p2.login
243     @p1.game
244     @p1.wait %r!##\[ERROR\] You are not allowed!
245     assert true
246     logout12
247   end
248 end
249
250
251
252
253 class TestDuplicatedMoves < BaseClient
254   def test_defer
255     result, result2 = handshake do
256       @p1.puts "+7776FU"
257       @p1.puts "+8786FU" # defer
258       @p1.puts "+9796FU" # defer
259       @p2.puts "-7374FU"
260       @p2.puts "-8384FU"
261       @p2.toryo
262       wait_finish
263     end
264     assert(/#WIN/  =~ result)
265     assert(/#LOSE/ =~ result2)
266   end
267
268   def test_defer2
269     result, result2 = handshake do
270       @p1.puts "+7776FU"
271       @p1.puts "+8786FU" # defer
272       @p1.puts "%TORYO" # defer
273       @p2.puts "-7374FU"
274       @p2.puts "-8384FU"
275       wait_finish
276     end
277     assert(/#LOSE/  =~ result)
278     assert(/#WIN/ =~ result2)
279   end
280
281   def test_defer3
282     result, result2 = handshake do
283       @p1.puts "+7776FU"
284       @p1.puts "+8786FU" # defer
285       @p2.puts "-7374FU"
286       @p2.puts "-8384FU"
287       @p1.toryo
288       wait_finish
289     end
290     assert(/#LOSE/  =~ result)
291     assert(/#WIN/ =~ result2)
292   end
293 end
294
295 class TestFunctionalChatCommand < BaseClient
296   def test_chat
297     result, result2 = handshake do
298       @p1.puts"%%CHAT Hello"
299       @p1.wait %r!##\[CHAT\].*Hello!
300       @p2.wait %r!##\[CHAT\].*Hello!
301     end
302     assert true
303   end
304 end
305
306
307
308
309 class TestTwoSameMoves < CSABaseClient
310   def set_name
311     super
312     @game_name = "2moves"
313     @p1_name   = "p1"
314     @p2_name   = "p2"
315   end
316
317   def test_two_same_moves
318     result, result2 = handshake do
319       move  "+2726FU"
320       move "-8384FU"
321       @p2.puts "-8384FU" # ignored
322       sleep 0.1 # wait for finish of the command above
323       move "+2625FU"
324     end
325     assert(/#ILLEGAL_MOVE/ !~ result)
326     assert(/#ILLEGAL_MOVE/ !~ result2)
327   end
328 end
329