4 class TestClientAtmark < BaseClient
7 cmd "LOGIN testsente@p1 dummy x1"
8 cmd "%%GAME testcase-1500-0 +"
10 cmd2 "LOGIN testgote@p2 dummy2 x1"
11 cmd2 "%%CHALLENGE testcase-1500-0 -"
15 result, result2 = handshake do
18 assert(/#LOSE/ =~ result)
19 assert(/#WIN/ =~ result2)
24 class TestComment < BaseClient
26 result, result2 = handshake do
29 assert(/#LOSE/ =~ result)
30 assert(/#WIN/ =~ result2)
33 def test_inline_comment
34 result, result2 = handshake do
35 cmd "+2625FU,'comment"
39 assert(/#LOSE/ =~ result)
40 assert(/#WIN/ =~ result2)
43 def test_inline_comment_ja_euc
44 result, result2 = handshake do
45 cmd "+2625FU,'
\93ú
\96{
\8cêEUC"
49 assert(/#LOSE/ =~ result)
50 assert(/#WIN/ =~ result2)
53 def test_inline_comment_ja_utf8
54 result, result2 = handshake do
55 cmd "+2625FU,'
\93ú
\96{
\8cêUTF8".toutf8
59 assert(/#LOSE/ =~ result)
60 assert(/#WIN/ =~ result2)
65 class TestWhiteMovesBlack < BaseClient
66 def test_white_moves_black
67 result, result2 = handshake do
72 assert(/#ILLEGAL_MOVE/ =~ result)
73 assert(/#WIN/ =~ result)
74 assert(/#ILLEGAL_MOVE/ =~ result2)
75 assert(/#LOSE/ =~ result2)
80 class CSABaseClient < BaseClient
82 # In CSA mode, the server decides sente or gote at random; and sockets are closed
83 # just after the game ends (i.e. %TORYO is sent)
88 sleep 0.5 # wait for game matching
93 if /Your_Turn:\+/ =~ str
95 @sente_socket = @socket1
97 @gote_socket = @socket2
100 @sente_socket = @socket2
102 @gote_socket = @socket1
105 yield if block_given?
107 result = read_nonblock(@sente_socket)
108 result2 = read_nonblock(@gote_socket)
113 eval "#{@sente} \"#{str}\""
117 eval "#{@gote} \"#{str}\""
121 class TestLoginCSAWithoutTripGoodGamename < CSABaseClient
123 cmd "LOGIN wo_trip_p1 testcase-1500-0"
124 cmd2 "LOGIN wo_trip_p2 testcase-1500-0"
128 result, result2 = handshake do
131 assert(/#LOSE/ =~ result)
132 assert(/#WIN/ =~ result2)
136 class TestLoginCSAWithTripGoodGamename < CSABaseClient
138 cmd "LOGIN w_trip_p1 testcase-1500-0,atrip"
139 cmd2 "LOGIN w_trip_p2 testcase-1500-0,anothertrip"
143 result, result2 = handshake do
147 assert(/#LOSE/ =~ result)
148 assert(/#WIN/ =~ result2)
152 class TestChallenge < CSABaseClient
154 cmd "LOGIN w_trip_p1 testcase-1500-0,atrip"
155 cmd2 "LOGIN w_trip_p2 testcase-1500-0,anothertrip"
159 result, result2 = handshake do
160 sente_cmd "CHALLENGE"
163 assert_match(/CHALLENGE ACCEPTED/, result)
164 assert_match(/CHALLENGE ACCEPTED/, result2)
168 class TestFloodgateGame < BaseClient
170 classname = self.class.name
171 gamename = "floodgate-900-0"
172 cmd "LOGIN sente#{classname} dummy x1"
173 cmd "%%GAME #{gamename} *"
175 cmd2 "LOGIN gote#{classname} dummy2 x1"
176 cmd2 "%%GAME #{gamename} *"
185 class TestFloodgateGameWrongTebam < BaseClient
187 classname = self.class.name
188 gamename = "floodgate-900-0"
189 cmd "LOGIN sente#{classname} dummy x1"
190 cmd("%%GAME #{gamename} +")
196 reply = read_nonblock(@socket1)
197 assert_match(/##\[ERROR\] You are not allowed/m, reply)
201 class TestDuplicatedMoves < BaseClient
203 result, result2 = handshake do
205 cmd "+8786FU" # defer
206 cmd "+9796FU" # defer
209 cmd2 "%TORYO" # defer
212 assert(/#WIN/ =~ result)
213 assert(/#LOSE/ =~ result2)
217 result, result2 = handshake do
219 cmd "+8786FU" # defer
225 assert(/#LOSE/ =~ result)
226 assert(/#WIN/ =~ result2)
230 result, result2 = handshake do
232 cmd "+8786FU" # defer
238 assert(/#LOSE/ =~ result)
239 assert(/#WIN/ =~ result2)