1 $:.unshift File.join(File.dirname(__FILE__), "..")
2 $topdir = File.expand_path File.dirname(__FILE__)
5 require 'test/mock_game'
6 require 'test/mock_log_message'
7 require 'test/mock_player'
8 require 'shogi_server/login'
9 require 'shogi_server/player'
10 require 'shogi_server/command'
16 @games["dummy_game_id"] = MockGame.new
24 $p1.status = "game_waiting"
28 $p2.status = "game_waiting"
41 return [MockPlayer.new]
52 def get_player(status, game_id, sente, searcher)
65 [$p1,$p2].each {|pp| yield pp}
68 def find_rival(player, game_name)
70 when nil # no preference
71 return get_player("game_waiting", game_name, nil, player)
72 when true # rival must be gote
73 return get_player("game_waiting", game_name, false, player)
74 when false # rival must be sente
75 return get_player("game_waiting", game_name, true, player)
83 class TestFactoryMethod < Test::Unit::TestCase
87 @p.name = "test_factory_method_player"
88 $league = MockLeague.new
91 def test_keep_alive_command
92 cmd = ShogiServer::Command.factory("", @p)
93 assert_instance_of(ShogiServer::SpecialCommand, cmd)
96 def test_keep_alive_command_space
97 cmd = ShogiServer::Command.factory(" ", @p)
98 assert_instance_of(ShogiServer::SpecialCommand, cmd)
101 def test_move_command
102 cmd = ShogiServer::Command.factory("+7776FU", @p)
103 assert_instance_of(ShogiServer::MoveCommand, cmd)
106 def test_special_command
107 cmd = ShogiServer::Command.factory("%TORYO", @p)
108 assert_instance_of(ShogiServer::SpecialCommand, cmd)
111 def test_special_command_timeout
112 cmd = ShogiServer::Command.factory(:timeout, @p)
113 assert_instance_of(ShogiServer::SpecialCommand, cmd)
116 def test_execption_command
117 cmd = ShogiServer::Command.factory(:exception, @p)
118 assert_instance_of(ShogiServer::ExceptionCommand, cmd)
121 def test_reject_command
122 cmd = ShogiServer::Command.factory("REJECT", @p)
123 assert_instance_of(ShogiServer::RejectCommand, cmd)
126 def test_agree_command
127 cmd = ShogiServer::Command.factory("AGREE", @p)
128 assert_instance_of(ShogiServer::AgreeCommand, cmd)
131 def test_show_command
132 cmd = ShogiServer::Command.factory("%%SHOW game_id", @p)
133 assert_instance_of(ShogiServer::ShowCommand, cmd)
136 def test_monitoron_command
137 cmd = ShogiServer::Command.factory("%%MONITORON game_id", @p)
138 assert_instance_of(ShogiServer::MonitorOnCommand, cmd)
141 def test_monitor2on_command
142 cmd = ShogiServer::Command.factory("%%MONITOR2ON game_id", @p)
143 assert_instance_of(ShogiServer::Monitor2OnCommand, cmd)
146 def test_monitoroff_command
147 cmd = ShogiServer::Command.factory("%%MONITOROFF game_id", @p)
148 assert_instance_of(ShogiServer::MonitorOffCommand, cmd)
151 def test_monitor2off_command
152 cmd = ShogiServer::Command.factory("%%MONITOR2OFF game_id", @p)
153 assert_instance_of(ShogiServer::Monitor2OffCommand, cmd)
156 def test_help_command
157 cmd = ShogiServer::Command.factory("%%HELP", @p)
158 assert_instance_of(ShogiServer::HelpCommand, cmd)
161 def test_rating_command
162 cmd = ShogiServer::Command.factory("%%RATING", @p)
163 assert_instance_of(ShogiServer::RatingCommand, cmd)
166 def test_version_command
167 cmd = ShogiServer::Command.factory("%%VERSION", @p)
168 assert_instance_of(ShogiServer::VersionCommand, cmd)
171 def test_game_command
172 cmd = ShogiServer::Command.factory("%%GAME", @p)
173 assert_instance_of(ShogiServer::GameCommand, cmd)
176 def test_game_challenge_command_game
177 cmd = ShogiServer::Command.factory("%%GAME default-1500-0 +", @p)
178 assert_instance_of(ShogiServer::GameChallengeCommand, cmd)
181 def test_game_challenge_command_game_fischer
182 cmd = ShogiServer::Command.factory("%%GAME default-600-10F +", @p)
183 assert_instance_of(ShogiServer::GameChallengeCommand, cmd)
186 def test_game_challenge_command_challenge
187 cmd = ShogiServer::Command.factory("%%CHALLENGE default-1500-0 -", @p)
188 assert_instance_of(ShogiServer::GameChallengeCommand, cmd)
191 def test_game_challenge_command_challenge_fischer
192 cmd = ShogiServer::Command.factory("%%CHALLENGE default-600-10F -", @p)
193 assert_instance_of(ShogiServer::GameChallengeCommand, cmd)
196 def test_chat_command
197 cmd = ShogiServer::Command.factory("%%CHAT hello", @p)
198 assert_instance_of(ShogiServer::ChatCommand, cmd)
201 def test_list_command
202 cmd = ShogiServer::Command.factory("%%LIST", @p)
203 assert_instance_of(ShogiServer::ListCommand, cmd)
207 cmd = ShogiServer::Command.factory("%%WHO", @p)
208 assert_instance_of(ShogiServer::WhoCommand, cmd)
211 def test_logout_command
212 cmd = ShogiServer::Command.factory("LOGOUT", @p)
213 assert_instance_of(ShogiServer::LogoutCommand, cmd)
216 def test_challenge_command
217 cmd = ShogiServer::Command.factory("CHALLENGE", @p)
218 assert_instance_of(ShogiServer::ChallengeCommand, cmd)
221 def test_space_command
222 cmd = ShogiServer::Command.factory(" ", @p)
223 assert_instance_of(ShogiServer::SpaceCommand, cmd)
226 def test_setbuoy_command
227 cmd = ShogiServer::Command.factory("%%SETBUOY buoy_test-1500-0 +7776FU", @p)
228 assert_instance_of(ShogiServer::SetBuoyCommand, cmd)
231 def test_setbuoy_command_fischer
232 cmd = ShogiServer::Command.factory("%%SETBUOY buoy_test-600-10F +7776FU", @p)
233 assert_instance_of(ShogiServer::SetBuoyCommand, cmd)
236 def test_setbuoy_command_with_counter
237 cmd = ShogiServer::Command.factory("%%SETBUOY buoy_test-1500-0 +7776FU 3", @p)
238 assert_instance_of(ShogiServer::SetBuoyCommand, cmd)
241 def test_setbuoy_command_with_counter_fischer
242 cmd = ShogiServer::Command.factory("%%SETBUOY buoy_test-600-10F +7776FU 3", @p)
243 assert_instance_of(ShogiServer::SetBuoyCommand, cmd)
246 def test_deletebuoy_command
247 cmd = ShogiServer::Command.factory("%%DELETEBUOY buoy_test-1500-0", @p)
248 assert_instance_of(ShogiServer::DeleteBuoyCommand, cmd)
251 def test_deletebuoy_command_fischer
252 cmd = ShogiServer::Command.factory("%%DELETEBUOY buoy_test-600-10F", @p)
253 assert_instance_of(ShogiServer::DeleteBuoyCommand, cmd)
256 def test_getbuoycount_command
257 cmd = ShogiServer::Command.factory("%%GETBUOYCOUNT buoy_test-1500-0", @p)
258 assert_instance_of(ShogiServer::GetBuoyCountCommand, cmd)
261 def test_getbuoycount_command_fischer
262 cmd = ShogiServer::Command.factory("%%GETBUOYCOUNT buoy_test-600-10F", @p)
263 assert_instance_of(ShogiServer::GetBuoyCountCommand, cmd)
266 def test_fork_command
267 cmd = ShogiServer::Command.factory("%%FORK server-denou-14400-60+p1+p2+20130223185013 buoy_denou-14400-60", @p)
268 assert_instance_of(ShogiServer::ForkCommand, cmd)
271 def test_fork_command_fischer
272 cmd = ShogiServer::Command.factory("%%FORK server-denou-14400-60F+p1+p2+20130223185013 buoy_denou-14400-60F", @p)
273 assert_instance_of(ShogiServer::ForkCommand, cmd)
276 def test_fork_command2
277 cmd = ShogiServer::Command.factory("%%FORK server-denou-14400-60+p1+p2+20130223185013", @p)
278 assert_instance_of(ShogiServer::ForkCommand, cmd)
281 def test_fork_command2_fischer
282 cmd = ShogiServer::Command.factory("%%FORK server-denou-14400-60F+p1+p2+20130223185013", @p)
283 assert_instance_of(ShogiServer::ForkCommand, cmd)
286 def test_void_command
287 cmd = ShogiServer::Command.factory("%%%HOGE", @p)
288 assert_instance_of(ShogiServer::VoidCommand, cmd)
292 cmd = ShogiServer::Command.factory("should_be_error", @p)
293 assert_instance_of(ShogiServer::ErrorCommand, cmd)
295 assert_match(/unknown command: should_be_error/, cmd.msg)
299 cmd = ShogiServer::Command.factory("LOGIN hoge foo", @p)
300 assert_instance_of(ShogiServer::ErrorCommand, cmd)
302 assert_no_match( /unknown command: LOGIN hoge foo/, cmd.msg)
304 cmd = ShogiServer::Command.factory("LOGin hoge foo", @p)
305 assert_instance_of(ShogiServer::ErrorCommand, cmd)
307 assert_no_match(/unknown command: LOGIN hoge foo/, cmd.msg)
309 cmd = ShogiServer::Command.factory("LOGIN hoge foo", @p)
310 assert_instance_of(ShogiServer::ErrorCommand, cmd)
312 assert_no_match(/unknown command: LOGIN hoge foo/, cmd.msg)
314 cmd = ShogiServer::Command.factory("LOGINhoge foo", @p)
315 assert_instance_of(ShogiServer::ErrorCommand, cmd)
317 assert_no_match(/unknown command: LOGIN hoge foo/, cmd.msg)
323 class TestMoveCommand < Test::Unit::TestCase
332 cmd = ShogiServer::MoveCommand.new("+7776FU", @p)
334 assert_equal(:continue, rc)
338 cmd = ShogiServer::MoveCommand.new("+7776FU,'comment", @p)
340 assert_equal(:continue, rc)
341 assert_equal("'*comment", @game.log.first)
344 def test_comment_illegal
345 cmd = ShogiServer::MoveCommand.new("+7776FU 'comment", @p)
347 assert_equal(:continue, rc)
348 assert_nil(@game.log.first)
352 @game.finish_flag = true
353 @p.protocol = ShogiServer::LoginCSA::PROTOCOL
354 cmd = ShogiServer::MoveCommand.new("+7776FU", @p)
356 assert_equal(:return, rc)
362 class TestSpecialComand < Test::Unit::TestCase
371 @game.finish_flag = true
372 cmd = ShogiServer::SpecialCommand.new("%TORYO", @p)
374 assert_equal(:continue, rc)
377 def test_toryo_csa_protocol
378 @game.finish_flag = true
379 @p.protocol = ShogiServer::LoginCSA::PROTOCOL
380 cmd = ShogiServer::SpecialCommand.new("%TORYO", @p)
382 assert_equal(:return, rc)
386 cmd = ShogiServer::SpecialCommand.new(:timeout, @p)
388 assert_equal(:continue, rc)
391 def test_expired_game
392 @p.status = "agree_waiting"
393 @game.prepared_expire = true
394 assert(!@game.rejected)
395 cmd = ShogiServer::SpecialCommand.new(:timeout, @p)
397 assert_equal(:continue, rc)
398 assert(@game.rejected)
401 def test_expired_game_csa_protocol
402 @p.protocol = ShogiServer::LoginCSA::PROTOCOL
403 @p.status = "agree_waiting"
404 @game.prepared_expire = true
405 assert(!@game.rejected)
406 cmd = ShogiServer::SpecialCommand.new(:timeout, @p)
408 assert_equal(:return, rc)
409 assert(@game.rejected)
413 @p.status = "should_be_ignored"
414 cmd = ShogiServer::SpecialCommand.new(:timeout, @p)
416 assert_equal(:continue, rc)
420 cmd = ShogiServer::SpecialCommand.new("", @p)
422 assert_equal(:continue, rc)
425 def test_keep_alive_space
426 cmd = ShogiServer::SpecialCommand.new(" ", @p)
428 assert_equal(:continue, rc)
434 class TestExceptionCommand < Test::Unit::TestCase
440 cmd = ShogiServer::ExceptionCommand.new(:exception, @p)
442 assert_equal(:return, rc)
448 class TestRejectCommand < Test::Unit::TestCase
457 @p.status = "agree_waiting"
458 assert(!@game.rejected)
459 cmd = ShogiServer::RejectCommand.new("REJECT", @p)
462 assert_equal(:continue, rc)
463 assert(@game.rejected)
466 def test_call_csa_protocol
467 @p.protocol = ShogiServer::LoginCSA::PROTOCOL
468 @p.status = "agree_waiting"
469 assert(!@game.rejected)
470 cmd = ShogiServer::RejectCommand.new("REJECT", @p)
473 assert_equal(:return, rc)
474 assert(@game.rejected)
478 @p.status = "should_be_ignored"
479 cmd = ShogiServer::RejectCommand.new("REJECT", @p)
482 assert_equal(:continue, rc)
483 assert(!@game.rejected)
489 class TestAgreeCommand < Test::Unit::TestCase
494 @p.status = "agree_waiting"
497 def test_not_start_yet
498 cmd = ShogiServer::AgreeCommand.new("AGREE", @p)
500 assert_equal(:continue, rc)
501 assert(!@game.started)
505 @game.is_startable_status = true
506 cmd = ShogiServer::AgreeCommand.new("AGREE", @p)
508 assert_equal(:continue, rc)
509 assert(@game.started)
513 @p.status = "should_be_ignored"
514 cmd = ShogiServer::AgreeCommand.new("AGREE", @p)
516 assert_equal(:continue, rc)
517 assert(!@game.started)
523 class TestShowCommand < Test::Unit::TestCase
531 cmd = ShogiServer::ShowCommand.new("%%SHOW hoge", @p, @game)
534 assert_equal(:continue, rc)
537 def test_call_nil_game
538 cmd = ShogiServer::ShowCommand.new("%%SHOW hoge", @p, nil)
541 assert_equal(:continue, rc)
547 class TestMonitorOnCommand < Test::Unit::TestCase
555 cmd = ShogiServer::MonitorOnCommand.new("%%MONITORON hoge", @p, nil)
558 assert_equal(:continue, rc)
561 def test_call_read_logfile
563 cmd = ShogiServer::MonitorOnCommand.new("%%MONITORON hoge", @p, game)
565 assert_equal("##[MONITOR][dummy_game_id] dummy_game_show\n##[MONITOR][dummy_game_id] line1\n##[MONITOR][dummy_game_id] line2\n##[MONITOR][dummy_game_id] +OK\n", @p.out.join)
566 assert_equal(:continue, rc)
572 class TestMonitor2OnCommand < Test::Unit::TestCase
580 cmd = ShogiServer::Monitor2OnCommand.new("%%MONITOR2ON hoge", @p, nil)
583 assert_equal(:continue, rc)
586 def test_call_read_logfile
587 $tempfile = Tempfile.new("TC_command_test_call_read_logfile")
588 $tempfile.write "hoge\nfoo\n"
594 cmd = ShogiServer::Monitor2OnCommand.new("%%MONITOR2ON hoge", @p, game)
596 assert_equal("##[MONITOR2][dummy_game_id] hoge\n##[MONITOR2][dummy_game_id] foo\n##[MONITOR2][dummy_game_id] +OK\n", @p.out.join)
597 assert_equal(:continue, rc)
604 class TestMonitorOffCommand < Test::Unit::TestCase
612 cmd = ShogiServer::MonitorOffCommand.new("%%MONITOROFF hoge", @p, nil)
615 assert_equal(:continue, rc)
621 class TestMonitor2OffCommand < Test::Unit::TestCase
629 cmd = ShogiServer::Monitor2OffCommand.new("%%MONITOR2OFF hoge", @p, nil)
632 assert_equal(:continue, rc)
638 class TestHelpCommand < Test::Unit::TestCase
646 cmd = ShogiServer::HelpCommand.new("%%HELP", @p)
649 assert_equal(:continue, rc)
655 class TestRatingCommand < Test::Unit::TestCase
663 players = [MockPlayer.new]
664 cmd = ShogiServer::RatingCommand.new("%%RATING", @p, players)
667 assert_equal(:continue, rc)
673 class TestVersionCommand < Test::Unit::TestCase
681 cmd = ShogiServer::VersionCommand.new("%%VERSION", @p)
684 assert_equal(:continue, rc)
690 class TestGameCommand < Test::Unit::TestCase
697 def test_call_connected
698 @p.status = "connected"
699 cmd = ShogiServer::GameCommand.new("%%GAME", @p)
702 assert_equal(:continue, rc)
703 assert_equal("connected", @p.status)
706 def test_call_game_waiting
707 @p.status = "game_waiting"
708 cmd = ShogiServer::GameCommand.new("%%GAME", @p)
711 assert_equal(:continue, rc)
712 assert_equal("connected", @p.status)
715 def test_call_agree_waiting
716 @p.status = "agree_waiting"
717 cmd = ShogiServer::GameCommand.new("%%GAME", @p)
720 assert_equal(:continue, rc)
721 assert_equal("agree_waiting", @p.status)
727 class TestChatCommand < Test::Unit::TestCase
735 players = [["dummy_name", MockPlayer.new]]
736 cmd = ShogiServer::ChatCommand.new("%%CHAT hoge", @p, "dummy message", players)
739 assert_equal(:continue, rc)
742 def test_call_csa_protocol
743 players = [["dummy_name", MockPlayer.new]]
744 players.each do |name, p|
745 p.protocol = ShogiServer::LoginCSA::PROTOCOL
747 cmd = ShogiServer::ChatCommand.new("%%CHAT hoge", @p, "dummy message", players)
750 assert_equal(:continue, rc)
756 class TestListCommand < Test::Unit::TestCase
764 games = [["dummy_game_id", MockGame.new]]
765 cmd = ShogiServer::ListCommand.new("%%LIST", @p, games)
768 assert_equal(:continue, rc)
775 class TestWhoCommand < Test::Unit::TestCase
783 players = [["dummy_name", MockPlayer.new]]
784 cmd = ShogiServer::WhoCommand.new("%%LIST", @p, players)
787 assert_equal(:continue, rc)
794 class TestLogoutCommand < Test::Unit::TestCase
802 cmd = ShogiServer::LogoutCommand.new("LOGOUT", @p)
805 assert_equal(:return, rc)
812 class TestChallengeCommand < Test::Unit::TestCase
819 cmd = ShogiServer::ChallengeCommand.new("CHALLENGE", @p)
822 assert_equal(:continue, rc)
828 class TestSpaceCommand < Test::Unit::TestCase
835 cmd = ShogiServer::SpaceCommand.new(" ", @p)
838 assert_equal(:continue, rc)
844 class TestErrorCommand < Test::Unit::TestCase
851 cmd = ShogiServer::ErrorCommand.new("", @p)
854 assert_equal(:continue, rc)
858 class BaseTestBuoyCommand < Test::Unit::TestCase
861 $league = MockLeague.new
864 @buoy = ShogiServer::Buoy.new
872 file = File.join($topdir, "buoy.yaml")
873 File.delete file if File.exist? file
884 class TestSetBuoyCommand < BaseTestBuoyCommand
888 @p.name = "set_buoy_player"
892 assert @buoy.is_new_game?("buoy_hoge-1500-0")
893 cmd = ShogiServer::SetBuoyCommand.new "%%SETBUOY", @p, "buoy_hoge-1500-0", "+7776FU", 2
895 assert_equal :continue, rt
896 assert !@buoy.is_new_game?("buoy_hoge-1500-0")
897 assert !$p1.out.empty?
898 assert !$p2.out.empty?
899 buoy_game2 = @buoy.get_game("buoy_hoge-1500-0")
900 assert_equal ShogiServer::BuoyGame.new("buoy_hoge-1500-0", "+7776FU", @p.name, 1), buoy_game2
904 assert @buoy.is_new_game?("buoy_hoge-1500-0")
905 cmd = ShogiServer::SetBuoyCommand.new "%%SETBUOY", @p, "buoy_hoge-1500-0", "+7776FU", 1
907 assert_equal :continue, rt
908 assert @buoy.is_new_game?("buoy_hoge-1500-0")
909 assert !$p1.out.empty?
910 assert !$p2.out.empty?
913 def test_call_error_not_buoy_game_name
914 assert @buoy.is_new_game?("buoy_hoge-1500-0")
915 cmd = ShogiServer::SetBuoyCommand.new "%%SETBUOY", @p, "buoyhoge-1500-0", "+7776FU", 1
917 assert_equal :continue, rt
918 assert $p1.out.empty?
919 assert $p2.out.empty?
920 assert @buoy.is_new_game?("buoy_hoge-1500-0")
923 def test_call_error_duplicated_game_name
924 assert @buoy.is_new_game?("buoy_duplicated-1500-0")
925 bg = ShogiServer::BuoyGame.new("buoy_duplicated-1500-0", ["+7776FU"], @p.name, 1)
927 assert !@buoy.is_new_game?("buoy_duplicated-1500-0")
929 cmd = ShogiServer::SetBuoyCommand.new "%%SETBUOY", @p, "buoy_duplicated-1500-0", "+7776FU", 1
931 assert_equal :continue, rt
932 assert $p1.out.empty?
933 assert $p2.out.empty?
934 assert !@buoy.is_new_game?("buoy_duplicated-1500-0")
937 def test_call_error_bad_moves
938 assert @buoy.is_new_game?("buoy_badmoves-1500-0")
939 cmd = ShogiServer::SetBuoyCommand.new "%%SETBUOY", @p, "buoy_badmoves-1500-0", "+7776FU+8786FU", 1
941 assert_equal :continue, rt
942 assert $p1.out.empty?
943 assert $p2.out.empty?
944 assert @buoy.is_new_game?("buoy_badmoves-1500-0")
947 def test_call_error_bad_counter
948 assert @buoy.is_new_game?("buoy_badcounter-1500-0")
949 cmd = ShogiServer::SetBuoyCommand.new "%%SETBUOY", @p, "buoy_badcounter-1500-0", "+7776FU", 0
951 assert_equal :continue, rt
952 assert $p1.out.empty?
953 assert $p2.out.empty?
954 assert @buoy.is_new_game?("buoy_badcounter-1500-0")
961 class TestDeleteBuoyCommand < BaseTestBuoyCommand
963 buoy_game = ShogiServer::BuoyGame.new("buoy_testdeletebuoy-1500-0", "+7776FU", @p.name, 1)
964 assert @buoy.is_new_game?(buoy_game.game_name)
965 @buoy.add_game buoy_game
966 assert !@buoy.is_new_game?(buoy_game.game_name)
967 cmd = ShogiServer::DeleteBuoyCommand.new "%%DELETEBUOY", @p, buoy_game.game_name
969 assert_equal :continue, rt
970 assert $p1.out.empty?
971 assert $p2.out.empty?
972 assert @buoy.is_new_game?(buoy_game.game_name)
975 def test_call_not_exist
976 buoy_game = ShogiServer::BuoyGame.new("buoy_notexist-1500-0", "+7776FU", @p.name, 1)
977 assert @buoy.is_new_game?(buoy_game.game_name)
978 cmd = ShogiServer::DeleteBuoyCommand.new "%%DELETEBUOY", @p, buoy_game.game_name
980 assert_equal :continue, rt
981 assert $p1.out.empty?
982 assert $p2.out.empty?
983 assert @buoy.is_new_game?(buoy_game.game_name)
986 def test_call_another_player
987 buoy_game = ShogiServer::BuoyGame.new("buoy_anotherplayer-1500-0", "+7776FU", "another_player", 1)
988 assert @buoy.is_new_game?(buoy_game.game_name)
989 @buoy.add_game(buoy_game)
990 assert !@buoy.is_new_game?(buoy_game.game_name)
992 cmd = ShogiServer::DeleteBuoyCommand.new "%%DELETEBUOY", @p, buoy_game.game_name
994 assert_equal :continue, rt
995 assert_equal "##[ERROR] you are not allowed to delete a buoy game that you did not set: buoy_anotherplayer-1500-0\n", @p.out.first
996 assert !@buoy.is_new_game?(buoy_game.game_name)
1002 class TestForkCommand < Test::Unit::TestCase
1004 @player = MockPlayer.new
1007 def test_new_buoy_game_name
1008 src = "%%FORK server+denou-14400-60+p1+p2+20130223185013"
1009 c = ShogiServer::ForkCommand.new src, @player, "server+denou-14400-60+p1+p2+20130223185013", nil, 13
1010 c.decide_new_buoy_game_name
1011 assert_equal "buoy_denou_13-14400-60", c.new_buoy_game
1014 def test_new_buoy_game_name2
1015 src = "%%FORK server+denou-14400-060+p1+p2+20130223185013"
1016 c = ShogiServer::ForkCommand.new src, @player, "server+denou-14400-060+p1+p2+20130223185013", nil, 13
1017 c.decide_new_buoy_game_name
1018 assert_equal "buoy_denou_13-14400-060", c.new_buoy_game
1024 class TestGetBuoyCountCommand < BaseTestBuoyCommand
1026 buoy_game = ShogiServer::BuoyGame.new("buoy_testdeletebuoy-1500-0", "+7776FU", @p.name, 1)
1027 assert @buoy.is_new_game?(buoy_game.game_name)
1028 @buoy.add_game buoy_game
1029 assert !@buoy.is_new_game?(buoy_game.game_name)
1030 cmd = ShogiServer::GetBuoyCountCommand.new "%%GETBUOYCOUNT", @p, buoy_game.game_name
1032 assert_equal :continue, rt
1033 assert_equal ["##[GETBUOYCOUNT] 1\n", "##[GETBUOYCOUNT] +OK\n"], @p.out
1036 def test_call_not_exist
1037 buoy_game = ShogiServer::BuoyGame.new("buoy_notexist-1500-0", "+7776FU", @p.name, 1)
1038 assert @buoy.is_new_game?(buoy_game.game_name)
1039 cmd = ShogiServer::GetBuoyCountCommand.new "%%GETBUOYCOUNT", @p, buoy_game.game_name
1041 assert_equal :continue, rt
1042 assert_equal ["##[GETBUOYCOUNT] -1\n", "##[GETBUOYCOUNT] +OK\n"], @p.out
1048 class TestMonitorHandler < Test::Unit::TestCase
1049 def test_not_equal_players
1050 @player1 = MockPlayer.new
1051 @handler1 = ShogiServer::MonitorHandler1.new @player1
1052 @player2 = MockPlayer.new
1053 @handler2 = ShogiServer::MonitorHandler1.new @player2
1055 assert_not_equal(@handler1, @handler2)
1059 @player1 = MockPlayer.new
1060 @handler1 = ShogiServer::MonitorHandler1.new @player1
1061 @handler2 = ShogiServer::MonitorHandler1.new @player1
1063 assert_equal(@handler1, @handler2)
1069 class TestMonitorHandler1 < Test::Unit::TestCase
1071 @player = MockPlayer.new
1072 @handler = ShogiServer::MonitorHandler1.new @player
1076 assert_equal(1, @handler.type)
1080 assert_equal("MONITOR", @handler.header)
1084 assert_equal @handler, @handler
1085 assert_not_equal @handler, nil
1089 assert_not_equal(@handler, ShogiServer::MonitorHandler2.new(@player))
1093 @handler.write_safe("game_id", "hoge")
1094 assert_equal("##[MONITOR][game_id] hoge\n##[MONITOR][game_id] +OK\n",
1101 class TestMonitorHandler2 < Test::Unit::TestCase
1103 @player = MockPlayer.new
1104 @handler = ShogiServer::MonitorHandler2.new @player
1108 assert_equal(2, @handler.type)
1112 assert_equal("MONITOR2", @handler.header)
1116 assert_equal @handler, @handler
1117 assert_not_equal @handler, nil
1121 assert_not_equal(@handler, ShogiServer::MonitorHandler1.new(@player))
1125 @handler.write_safe("game_id", "hoge")
1126 assert_equal("##[MONITOR2][game_id] hoge\n##[MONITOR2][game_id] +OK\n",
1130 def test_write_safe2
1131 @handler.write_safe("game_id", "hoge\nfoo")
1132 assert_equal("##[MONITOR2][game_id] hoge\n##[MONITOR2][game_id] foo\n##[MONITOR2][game_id] +OK\n",