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.
39 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
40 P2 * -HI * * * * * -KA *
41 P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
45 P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
46 P8 * +KA * * * * * +HI *
47 P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
49 'rating:atmark_B@p1+275876e34cf609db118f3d84b799a790:atmark_W@p2+275876e34cf609db118f3d84b799a790
55 'P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
56 'P2 * -HI * * * * * -KA *
57 'P3-FU-FU-FU-FU-FU-FU * -FU-FU
58 'P4 * * * * * * -FU * *
60 'P6 * * * * * * * +FU *
61 'P7+FU+FU+FU+FU+FU+FU+FU * +FU
62 'P8 * +KA * * * * * +HI *
63 'P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
65 'summary:toryo:atmark_B@p1 lose:atmark_W@p2 win
68 log_content.gsub!(/^\$.*?\n/m, "")
69 log_content.gsub!(/^'\$.*?\n/m, "")
70 assert_equal(should_be, log_content)
74 class TestHandicappedGame < BaseClient
78 @game_name = "hc2p_hoge"
84 result, result2 = handshake do
88 assert(/#LOSE/ =~ result)
89 assert(/#WIN/ =~ result2)
92 year = now.strftime("%Y")
93 month = now.strftime("%m")
94 day = now.strftime("%d")
95 path = File.join( File.dirname(__FILE__), "..", year, month, day, "*hc2p_hoge-1500-0*")
96 log_files = Dir.glob(path)
97 assert(!log_files.empty?)
99 log_content = File.read(log_files.sort.last)
101 # "$EVENT", "$START_TIME" and "'$END_TIME" are removed since they vary dinamically.
106 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
107 P2 * -HI * * * * * -KA *
108 P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
112 P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
114 P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
116 'rating:hc2p_hoge_B+275876e34cf609db118f3d84b799a790:hc2p_hoge_W+275876e34cf609db118f3d84b799a790
122 'P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
123 'P2 * -HI * * * * * -KA *
124 'P3-FU-FU-FU-FU-FU-FU * -FU-FU
125 'P4 * * * * * * -FU * *
126 'P5 * * * * * * * * *
127 'P6 * * * * * * * +FU *
128 'P7+FU+FU+FU+FU+FU+FU+FU * +FU
129 'P8 * * * * * * * * *
130 'P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
132 'summary:toryo:hc2p_hoge_B lose:hc2p_hoge_W win
135 log_content.gsub!(/^\$.*?\n/m, "")
136 log_content.gsub!(/^'\$.*?\n/m, "")
137 assert_equal(should_be, log_content)
142 class TestComment < BaseClient
144 result, result2 = handshake do
148 assert(/#LOSE/ =~ result)
149 assert(/#WIN/ =~ result2)
152 def test_inline_comment
153 result, result2 = handshake do
154 move "+2625FU,'comment"
159 assert(/#LOSE/ =~ result)
160 assert(/#WIN/ =~ result2)
163 def test_inline_comment_ja_euc
164 result, result2 = handshake do
165 move "+2625FU,'
\93ú
\96{
\8cêEUC"
170 assert(/#LOSE/ =~ result)
171 assert(/#WIN/ =~ result2)
174 def test_inline_comment_ja_utf8
175 result, result2 = handshake do
176 move "+2625FU,'
\93ú
\96{
\8cêUTF8".toutf8
181 assert(/#LOSE/ =~ result)
182 assert(/#WIN/ =~ result2)
187 class TestWhiteMovesBlack < BaseClient
188 def test_white_moves_black
189 result, result2 = handshake do
194 assert(/#ILLEGAL_MOVE/ =~ result)
195 assert(/#WIN/ =~ result)
196 assert(/#ILLEGAL_MOVE/ =~ result2)
197 assert(/#LOSE/ =~ result2)
206 class TestLoginCSAWithoutTripGoodGamename < CSABaseClient
209 @game_name = "csawotrip"
215 result, result2 = handshake do
220 assert(/#LOSE/ =~ result)
221 assert(/#WIN/ =~ result2)
225 class TestLoginCSAWithTripGoodGamename < CSABaseClient
228 @game_name = "csawtrip"
235 @p1.login_command += ",atrip"
236 @p2.login_command += ",anothertrip"
240 result, result2 = handshake do
245 assert(/#LOSE/ =~ result)
246 assert(/#WIN/ =~ result2)
250 class TestChallenge < CSABaseClient
253 @game_name = "challenge"
260 @p1.login_command += ",atrip"
261 @p2.login_command += ",anothertrip"
265 result, result2 = handshake do
267 @p1.wait(/CHALLENGE ACCEPTED/)
269 @p2.wait(/CHALLENGE ACCEPTED/)
279 class TestFloodgateGame < BaseClient
282 @game_name = "floodgate"
286 @p1 = SocketPlayer.new @game_name, @p1_name, "*"
287 @p2 = SocketPlayer.new @game_name, @p2_name, "*"
302 class TestFloodgateGameWrongTebam < BaseClient
305 @game_name = "floodgate"
314 @p1.wait %r!##\[ERROR\] You are not allowed!
323 class TestDuplicatedMoves < BaseClient
325 result, result2 = handshake do
327 @p1.puts "+8786FU" # defer
328 @p1.puts "+9796FU" # defer
334 assert(/#WIN/ =~ result)
335 assert(/#LOSE/ =~ result2)
339 result, result2 = handshake do
341 @p1.puts "+8786FU" # defer
342 @p1.puts "%TORYO" # defer
347 assert(/#LOSE/ =~ result)
348 assert(/#WIN/ =~ result2)
352 result, result2 = handshake do
354 @p1.puts "+8786FU" # defer
360 assert(/#LOSE/ =~ result)
361 assert(/#WIN/ =~ result2)
365 class TestFunctionalChatCommand < BaseClient
367 result, result2 = handshake do
368 @p1.puts"%%CHAT Hello"
369 @p1.wait %r!##\[CHAT\].*Hello!
370 @p2.wait %r!##\[CHAT\].*Hello!
379 class TestTwoSameMoves < CSABaseClient
382 @game_name = "2moves"
387 def test_two_same_moves
388 result, result2 = handshake do
391 @p2.puts "-8384FU" # ignored
392 sleep 0.1 # wait for finish of the command above
395 assert(/#ILLEGAL_MOVE/ !~ result)
396 assert(/#ILLEGAL_MOVE/ !~ result2)