OSDN Git Service

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