4 class TestClientAtmark < BaseClient
7 cmd "LOGIN testsente@p1 dummy x1"
8 cmd "%%GAME testClientAtmark-1500-0 +"
10 cmd2 "LOGIN testgote@p2 dummy2 x1"
11 cmd2 "%%CHALLENGE testClientAtmark-1500-0 -"
15 result, result2 = handshake do
18 assert(/#LOSE/ =~ result)
19 assert(/#WIN/ =~ result2)
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, "*testClientAtmark-1500-0*")
26 log_files = Dir.glob(path)
27 assert(!log_files.empty?)
28 log_content = File.open(log_files.sort.last).read
30 # "$EVENT", "$START_TIME" and "'$END_TIME" are removed since they vary dinamically.
35 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
36 P2 * -HI * * * * * -KA *
37 P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
41 P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
42 P8 * +KA * * * * * +HI *
43 P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
45 'rating:testsente@p1+275876e34cf609db118f3d84b799a790:testgote@p2+c0c40e7a94eea7e2c238b75273087710
51 'P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
52 'P2 * -HI * * * * * -KA *
53 'P3-FU-FU-FU-FU-FU-FU * -FU-FU
54 'P4 * * * * * * -FU * *
56 'P6 * * * * * * * +FU *
57 'P7+FU+FU+FU+FU+FU+FU+FU * +FU
58 'P8 * +KA * * * * * +HI *
59 'P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
61 'summary:toryo:testsente@p1 lose:testgote@p2 win
64 log_content.gsub!(/^\$.*?\n/m, "")
65 log_content.gsub!(/^'\$.*?\n/m, "")
66 assert_equal(should_be, log_content)
71 class TestComment < BaseClient
73 result, result2 = handshake do
76 assert(/#LOSE/ =~ result)
77 assert(/#WIN/ =~ result2)
80 def test_inline_comment
81 result, result2 = handshake do
82 cmd "+2625FU,'comment"
86 assert(/#LOSE/ =~ result)
87 assert(/#WIN/ =~ result2)
90 def test_inline_comment_ja_euc
91 result, result2 = handshake do
92 cmd "+2625FU,'
\93ú
\96{
\8cêEUC"
96 assert(/#LOSE/ =~ result)
97 assert(/#WIN/ =~ result2)
100 def test_inline_comment_ja_utf8
101 result, result2 = handshake do
102 cmd "+2625FU,'
\93ú
\96{
\8cêUTF8".toutf8
106 assert(/#LOSE/ =~ result)
107 assert(/#WIN/ =~ result2)
112 class TestWhiteMovesBlack < BaseClient
113 def test_white_moves_black
114 result, result2 = handshake do
119 assert(/#ILLEGAL_MOVE/ =~ result)
120 assert(/#WIN/ =~ result)
121 assert(/#ILLEGAL_MOVE/ =~ result2)
122 assert(/#LOSE/ =~ result2)
127 class CSABaseClient < BaseClient
129 # In CSA mode, the server decides sente or gote at random; and sockets are closed
130 # just after the game ends (i.e. %TORYO is sent)
135 sleep 0.5 # wait for game matching
140 if /Your_Turn:\+/ =~ str
142 @sente_socket = @socket1
144 @gote_socket = @socket2
147 @sente_socket = @socket2
149 @gote_socket = @socket1
152 yield if block_given?
154 result = read_nonblock(@sente_socket)
155 result2 = read_nonblock(@gote_socket)
160 eval "#{@sente} \"#{str}\""
164 eval "#{@gote} \"#{str}\""
168 class TestLoginCSAWithoutTripGoodGamename < CSABaseClient
170 cmd "LOGIN wo_trip_p1 testcase-1500-0"
171 cmd2 "LOGIN wo_trip_p2 testcase-1500-0"
175 result, result2 = handshake do
178 assert(/#LOSE/ =~ result)
179 assert(/#WIN/ =~ result2)
183 class TestLoginCSAWithTripGoodGamename < CSABaseClient
185 cmd "LOGIN w_trip_p1 testcase-1500-0,atrip"
186 cmd2 "LOGIN w_trip_p2 testcase-1500-0,anothertrip"
190 result, result2 = handshake do
194 assert(/#LOSE/ =~ result)
195 assert(/#WIN/ =~ result2)
199 class TestChallenge < CSABaseClient
201 cmd "LOGIN w_trip_p1 testcase-1500-0,atrip"
202 cmd2 "LOGIN w_trip_p2 testcase-1500-0,anothertrip"
206 result, result2 = handshake do
207 sente_cmd "CHALLENGE"
210 assert_match(/CHALLENGE ACCEPTED/, result)
211 assert_match(/CHALLENGE ACCEPTED/, result2)
215 class TestFloodgateGame < BaseClient
217 classname = self.class.name
218 gamename = "floodgate-900-0"
219 cmd "LOGIN sente#{classname} dummy x1"
220 cmd "%%GAME #{gamename} *"
222 cmd2 "LOGIN gote#{classname} dummy2 x1"
223 cmd2 "%%GAME #{gamename} *"
232 class TestFloodgateGameWrongTebam < BaseClient
234 classname = self.class.name
235 gamename = "floodgate-900-0"
236 cmd "LOGIN sente#{classname} dummy x1"
237 cmd("%%GAME #{gamename} +")
243 reply = read_nonblock(@socket1)
244 assert_match(/##\[ERROR\] You are not allowed/m, reply)
248 class TestDuplicatedMoves < BaseClient
250 result, result2 = handshake do
252 cmd "+8786FU" # defer
253 cmd "+9796FU" # defer
256 cmd2 "%TORYO" # defer
259 assert(/#WIN/ =~ result)
260 assert(/#LOSE/ =~ result2)
264 result, result2 = handshake do
266 cmd "+8786FU" # defer
272 assert(/#LOSE/ =~ result)
273 assert(/#WIN/ =~ result2)
277 result, result2 = handshake do
279 cmd "+8786FU" # defer
285 assert(/#LOSE/ =~ result)
286 assert(/#WIN/ =~ result2)
290 class TestFunctionalChatCommand < BaseClient
294 str = read_nonblock(@socket2)