1 # -*- coding: windows-31j -*-
2 $:.unshift File.join(File.dirname(__FILE__), "..")
3 $topdir = File.expand_path File.dirname(__FILE__)
4 require "test/baseclient"
7 class TestClientAtmark < BaseClient
17 result, result2 = handshake do
21 assert(/#LOSE/ =~ result)
22 assert(/#WIN/ =~ result2)
25 year = now.strftime("%Y")
26 month = now.strftime("%m")
27 day = now.strftime("%d")
28 path = File.join( File.dirname(__FILE__), "..", year, month, day, "*atmark-1500-0*")
29 log_files = Dir.glob(path)
30 assert(!log_files.empty?)
32 log_content = File.read(log_files.sort.last)
34 # "$EVENT", "$START_TIME" and "'$END_TIME" are removed since they vary dinamically.
40 'Least_Time_Per_Move:0
41 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
42 P2 * -HI * * * * * -KA *
43 P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
47 P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
48 P8 * +KA * * * * * +HI *
49 P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
51 'rating:atmark_B@p1+275876e34cf609db118f3d84b799a790:atmark_W@p2+275876e34cf609db118f3d84b799a790
57 'P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
58 'P2 * -HI * * * * * -KA *
59 'P3-FU-FU-FU-FU-FU-FU * -FU-FU
60 'P4 * * * * * * -FU * *
62 'P6 * * * * * * * +FU *
63 'P7+FU+FU+FU+FU+FU+FU+FU * +FU
64 'P8 * +KA * * * * * +HI *
65 'P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
67 'summary:toryo:atmark_B@p1 lose:atmark_W@p2 win
70 log_content.gsub!(/^\$.*?\n/m, "")
71 log_content.gsub!(/^'\$.*?\n/m, "")
72 assert_equal(should_be, log_content)
76 class TestHandicappedGame < BaseClient
80 @game_name = "hc2p_hoge"
86 result, result2 = handshake do
90 assert(/#LOSE/ =~ result)
91 assert(/#WIN/ =~ result2)
94 year = now.strftime("%Y")
95 month = now.strftime("%m")
96 day = now.strftime("%d")
97 path = File.join( File.dirname(__FILE__), "..", year, month, day, "*hc2p_hoge-1500-0*")
98 log_files = Dir.glob(path)
99 assert(!log_files.empty?)
101 log_content = File.read(log_files.sort.last)
103 # "$EVENT", "$START_TIME" and "'$END_TIME" are removed since they vary dinamically.
109 'Least_Time_Per_Move:0
110 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
111 P2 * -HI * * * * * -KA *
112 P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
116 P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
118 P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
120 'rating:hc2p_hoge_B+275876e34cf609db118f3d84b799a790:hc2p_hoge_W+275876e34cf609db118f3d84b799a790
126 'P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
127 'P2 * -HI * * * * * -KA *
128 'P3-FU-FU-FU-FU-FU-FU * -FU-FU
129 'P4 * * * * * * -FU * *
130 'P5 * * * * * * * * *
131 'P6 * * * * * * * +FU *
132 'P7+FU+FU+FU+FU+FU+FU+FU * +FU
133 'P8 * * * * * * * * *
134 'P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
136 'summary:toryo:hc2p_hoge_B lose:hc2p_hoge_W win
139 log_content.gsub!(/^\$.*?\n/m, "")
140 log_content.gsub!(/^'\$.*?\n/m, "")
141 assert_equal(should_be, log_content)
146 class TestComment < BaseClient
148 result, result2 = handshake do
152 assert(/#LOSE/ =~ result)
153 assert(/#WIN/ =~ result2)
156 def test_inline_comment
157 result, result2 = handshake do
158 move "+2625FU,'comment"
163 assert(/#LOSE/ =~ result)
164 assert(/#WIN/ =~ result2)
167 def test_inline_comment_ja_euc
168 result, result2 = handshake do
169 move "+2625FU,'
\93ú
\96{
\8cêEUC"
174 assert(/#LOSE/ =~ result)
175 assert(/#WIN/ =~ result2)
178 def test_inline_comment_ja_utf8
179 result, result2 = handshake do
180 move "+2625FU,'
\93ú
\96{
\8cêUTF8".toutf8
185 assert(/#LOSE/ =~ result)
186 assert(/#WIN/ =~ result2)
191 class TestWhiteMovesBlack < BaseClient
192 def test_white_moves_black
193 result, result2 = handshake do
198 assert(/#ILLEGAL_MOVE/ =~ result)
199 assert(/#WIN/ =~ result)
200 assert(/#ILLEGAL_MOVE/ =~ result2)
201 assert(/#LOSE/ =~ result2)
210 class TestLoginCSAWithoutTripGoodGamename < CSABaseClient
213 @game_name = "csawotrip"
219 result, result2 = handshake do
224 assert(/#LOSE/ =~ result)
225 assert(/#WIN/ =~ result2)
229 class TestLoginCSAWithTripGoodGamename < CSABaseClient
232 @game_name = "csawtrip"
239 @p1.login_command += ",atrip"
240 @p2.login_command += ",anothertrip"
244 result, result2 = handshake do
249 assert(/#LOSE/ =~ result)
250 assert(/#WIN/ =~ result2)
254 class TestChallenge < CSABaseClient
257 @game_name = "challenge"
264 @p1.login_command += ",atrip"
265 @p2.login_command += ",anothertrip"
269 result, result2 = handshake do
271 @p1.wait(/CHALLENGE ACCEPTED/)
273 @p2.wait(/CHALLENGE ACCEPTED/)
283 class TestFloodgateGame < BaseClient
286 @game_name = "floodgate"
290 @p1 = SocketPlayer.new @game_name, @p1_name, "*"
291 @p2 = SocketPlayer.new @game_name, @p2_name, "*"
306 class TestFloodgateGameWrongTebam < BaseClient
309 @game_name = "floodgate"
318 @p1.wait %r!##\[ERROR\] You are not allowed!
327 class TestDuplicatedMoves < BaseClient
329 result, result2 = handshake do
331 @p1.puts "+8786FU" # defer
332 @p1.puts "+9796FU" # defer
338 assert(/#WIN/ =~ result)
339 assert(/#LOSE/ =~ result2)
343 result, result2 = handshake do
345 @p1.puts "+8786FU" # defer
346 @p1.puts "%TORYO" # defer
351 assert(/#LOSE/ =~ result)
352 assert(/#WIN/ =~ result2)
356 result, result2 = handshake do
358 @p1.puts "+8786FU" # defer
364 assert(/#LOSE/ =~ result)
365 assert(/#WIN/ =~ result2)
369 class TestFunctionalChatCommand < BaseClient
371 result, result2 = handshake do
372 @p1.puts"%%CHAT Hello"
373 @p1.wait %r!##\[CHAT\].*Hello!
374 @p2.wait %r!##\[CHAT\].*Hello!
383 class TestTwoSameMoves < CSABaseClient
386 @game_name = "2moves"
391 def test_two_same_moves
392 result, result2 = handshake do
395 @p2.puts "-8384FU" # ignored
396 sleep 0.1 # wait for finish of the command above
399 assert(/#ILLEGAL_MOVE/ !~ result)
400 assert(/#ILLEGAL_MOVE/ !~ result2)