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::KeepAliveCommand, cmd)
97 cmd = ShogiServer::Command.factory("+7776FU", @p)
98 assert_instance_of(ShogiServer::MoveCommand, cmd)
101 def test_special_command
102 cmd = ShogiServer::Command.factory("%TORYO", @p)
103 assert_instance_of(ShogiServer::SpecialCommand, cmd)
106 def test_special_command_timeout
107 cmd = ShogiServer::Command.factory(:timeout, @p)
108 assert_instance_of(ShogiServer::SpecialCommand, cmd)
111 def test_execption_command
112 cmd = ShogiServer::Command.factory(:exception, @p)
113 assert_instance_of(ShogiServer::ExceptionCommand, cmd)
116 def test_reject_command
117 cmd = ShogiServer::Command.factory("REJECT", @p)
118 assert_instance_of(ShogiServer::RejectCommand, cmd)
121 def test_agree_command
122 cmd = ShogiServer::Command.factory("AGREE", @p)
123 assert_instance_of(ShogiServer::AgreeCommand, cmd)
126 def test_show_command
127 cmd = ShogiServer::Command.factory("%%SHOW game_id", @p)
128 assert_instance_of(ShogiServer::ShowCommand, cmd)
131 def test_monitoron_command
132 cmd = ShogiServer::Command.factory("%%MONITORON game_id", @p)
133 assert_instance_of(ShogiServer::MonitorOnCommand, cmd)
136 def test_monitor2on_command
137 cmd = ShogiServer::Command.factory("%%MONITOR2ON game_id", @p)
138 assert_instance_of(ShogiServer::Monitor2OnCommand, cmd)
141 def test_monitoroff_command
142 cmd = ShogiServer::Command.factory("%%MONITOROFF game_id", @p)
143 assert_instance_of(ShogiServer::MonitorOffCommand, cmd)
146 def test_monitor2off_command
147 cmd = ShogiServer::Command.factory("%%MONITOR2OFF game_id", @p)
148 assert_instance_of(ShogiServer::Monitor2OffCommand, cmd)
151 def test_help_command
152 cmd = ShogiServer::Command.factory("%%HELP", @p)
153 assert_instance_of(ShogiServer::HelpCommand, cmd)
156 def test_rating_command
157 cmd = ShogiServer::Command.factory("%%RATING", @p)
158 assert_instance_of(ShogiServer::RatingCommand, cmd)
161 def test_version_command
162 cmd = ShogiServer::Command.factory("%%VERSION", @p)
163 assert_instance_of(ShogiServer::VersionCommand, cmd)
166 def test_game_command
167 cmd = ShogiServer::Command.factory("%%GAME", @p)
168 assert_instance_of(ShogiServer::GameCommand, cmd)
171 def test_game_challenge_command_game
172 cmd = ShogiServer::Command.factory("%%GAME default-1500-0 +", @p)
173 assert_instance_of(ShogiServer::GameChallengeCommand, cmd)
176 def test_game_challenge_command_game_fischer
177 cmd = ShogiServer::Command.factory("%%GAME default-600-10F +", @p)
178 assert_instance_of(ShogiServer::GameChallengeCommand, cmd)
181 def test_game_challenge_command_challenge
182 cmd = ShogiServer::Command.factory("%%CHALLENGE default-1500-0 -", @p)
183 assert_instance_of(ShogiServer::GameChallengeCommand, cmd)
186 def test_game_challenge_command_challenge_fischer
187 cmd = ShogiServer::Command.factory("%%CHALLENGE default-600-10F -", @p)
188 assert_instance_of(ShogiServer::GameChallengeCommand, cmd)
191 def test_chat_command
192 cmd = ShogiServer::Command.factory("%%CHAT hello", @p)
193 assert_instance_of(ShogiServer::ChatCommand, cmd)
196 def test_list_command
197 cmd = ShogiServer::Command.factory("%%LIST", @p)
198 assert_instance_of(ShogiServer::ListCommand, cmd)
202 cmd = ShogiServer::Command.factory("%%WHO", @p)
203 assert_instance_of(ShogiServer::WhoCommand, cmd)
206 def test_logout_command
207 cmd = ShogiServer::Command.factory("LOGOUT", @p)
208 assert_instance_of(ShogiServer::LogoutCommand, cmd)
211 def test_challenge_command
212 cmd = ShogiServer::Command.factory("CHALLENGE", @p)
213 assert_instance_of(ShogiServer::ChallengeCommand, cmd)
216 def test_space_command
217 cmd = ShogiServer::Command.factory(" ", @p)
218 assert_instance_of(ShogiServer::SpaceCommand, cmd)
221 def test_setbuoy_command
222 cmd = ShogiServer::Command.factory("%%SETBUOY buoy_test-1500-0 +7776FU", @p)
223 assert_instance_of(ShogiServer::SetBuoyCommand, cmd)
226 def test_setbuoy_command_fischer
227 cmd = ShogiServer::Command.factory("%%SETBUOY buoy_test-600-10F +7776FU", @p)
228 assert_instance_of(ShogiServer::SetBuoyCommand, cmd)
231 def test_setbuoy_command_with_counter
232 cmd = ShogiServer::Command.factory("%%SETBUOY buoy_test-1500-0 +7776FU 3", @p)
233 assert_instance_of(ShogiServer::SetBuoyCommand, cmd)
236 def test_setbuoy_command_with_counter_fischer
237 cmd = ShogiServer::Command.factory("%%SETBUOY buoy_test-600-10F +7776FU 3", @p)
238 assert_instance_of(ShogiServer::SetBuoyCommand, cmd)
241 def test_deletebuoy_command
242 cmd = ShogiServer::Command.factory("%%DELETEBUOY buoy_test-1500-0", @p)
243 assert_instance_of(ShogiServer::DeleteBuoyCommand, cmd)
246 def test_deletebuoy_command_fischer
247 cmd = ShogiServer::Command.factory("%%DELETEBUOY buoy_test-600-10F", @p)
248 assert_instance_of(ShogiServer::DeleteBuoyCommand, cmd)
251 def test_getbuoycount_command
252 cmd = ShogiServer::Command.factory("%%GETBUOYCOUNT buoy_test-1500-0", @p)
253 assert_instance_of(ShogiServer::GetBuoyCountCommand, cmd)
256 def test_getbuoycount_command_fischer
257 cmd = ShogiServer::Command.factory("%%GETBUOYCOUNT buoy_test-600-10F", @p)
258 assert_instance_of(ShogiServer::GetBuoyCountCommand, cmd)
261 def test_fork_command
262 cmd = ShogiServer::Command.factory("%%FORK server-denou-14400-60+p1+p2+20130223185013 buoy_denou-14400-60", @p)
263 assert_instance_of(ShogiServer::ForkCommand, cmd)
266 def test_fork_command_fischer
267 cmd = ShogiServer::Command.factory("%%FORK server-denou-14400-60F+p1+p2+20130223185013 buoy_denou-14400-60F", @p)
268 assert_instance_of(ShogiServer::ForkCommand, cmd)
271 def test_fork_command2
272 cmd = ShogiServer::Command.factory("%%FORK server-denou-14400-60+p1+p2+20130223185013", @p)
273 assert_instance_of(ShogiServer::ForkCommand, cmd)
276 def test_fork_command2_fischer
277 cmd = ShogiServer::Command.factory("%%FORK server-denou-14400-60F+p1+p2+20130223185013", @p)
278 assert_instance_of(ShogiServer::ForkCommand, cmd)
281 def test_void_command
282 cmd = ShogiServer::Command.factory("%%%HOGE", @p)
283 assert_instance_of(ShogiServer::VoidCommand, cmd)
287 cmd = ShogiServer::Command.factory("should_be_error", @p)
288 assert_instance_of(ShogiServer::ErrorCommand, cmd)
290 assert_match(/unknown command: should_be_error/, cmd.msg)
294 cmd = ShogiServer::Command.factory("LOGIN hoge foo", @p)
295 assert_instance_of(ShogiServer::ErrorCommand, cmd)
297 assert_no_match( /unknown command: LOGIN hoge foo/, 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("LOGINhoge foo", @p)
310 assert_instance_of(ShogiServer::ErrorCommand, cmd)
312 assert_no_match(/unknown command: LOGIN hoge foo/, cmd.msg)
318 class TestKeepAliveCommand < Test::Unit::TestCase
324 cmd = ShogiServer::KeepAliveCommand.new("", @p)
326 assert_equal(:continue, rc)
332 class TestMoveCommand < Test::Unit::TestCase
341 cmd = ShogiServer::MoveCommand.new("+7776FU", @p)
343 assert_equal(:continue, rc)
347 cmd = ShogiServer::MoveCommand.new("+7776FU,'comment", @p)
349 assert_equal(:continue, rc)
350 assert_equal("'*comment", @game.log.first)
354 @game.finish_flag = true
355 @p.protocol = ShogiServer::LoginCSA::PROTOCOL
356 cmd = ShogiServer::MoveCommand.new("+7776FU", @p)
358 assert_equal(:return, rc)
364 class TestSpecialComand < Test::Unit::TestCase
373 @game.finish_flag = true
374 cmd = ShogiServer::SpecialCommand.new("%TORYO", @p)
376 assert_equal(:continue, rc)
379 def test_toryo_csa_protocol
380 @game.finish_flag = true
381 @p.protocol = ShogiServer::LoginCSA::PROTOCOL
382 cmd = ShogiServer::SpecialCommand.new("%TORYO", @p)
384 assert_equal(:return, rc)
388 cmd = ShogiServer::SpecialCommand.new(:timeout, @p)
390 assert_equal(:continue, rc)
393 def test_expired_game
394 @p.status = "agree_waiting"
395 @game.prepared_expire = true
396 assert(!@game.rejected)
397 cmd = ShogiServer::SpecialCommand.new(:timeout, @p)
399 assert_equal(:continue, rc)
400 assert(@game.rejected)
403 def test_expired_game_csa_protocol
404 @p.protocol = ShogiServer::LoginCSA::PROTOCOL
405 @p.status = "agree_waiting"
406 @game.prepared_expire = true
407 assert(!@game.rejected)
408 cmd = ShogiServer::SpecialCommand.new(:timeout, @p)
410 assert_equal(:return, rc)
411 assert(@game.rejected)
415 @p.status = "should_be_ignored"
416 cmd = ShogiServer::SpecialCommand.new(:timeout, @p)
418 assert_equal(:continue, rc)
424 class TestExceptionCommand < Test::Unit::TestCase
430 cmd = ShogiServer::ExceptionCommand.new(:exception, @p)
432 assert_equal(:return, rc)
438 class TestRejectCommand < Test::Unit::TestCase
447 @p.status = "agree_waiting"
448 assert(!@game.rejected)
449 cmd = ShogiServer::RejectCommand.new("REJECT", @p)
452 assert_equal(:continue, rc)
453 assert(@game.rejected)
456 def test_call_csa_protocol
457 @p.protocol = ShogiServer::LoginCSA::PROTOCOL
458 @p.status = "agree_waiting"
459 assert(!@game.rejected)
460 cmd = ShogiServer::RejectCommand.new("REJECT", @p)
463 assert_equal(:return, rc)
464 assert(@game.rejected)
468 @p.status = "should_be_ignored"
469 cmd = ShogiServer::RejectCommand.new("REJECT", @p)
472 assert_equal(:continue, rc)
473 assert(!@game.rejected)
479 class TestAgreeCommand < Test::Unit::TestCase
484 @p.status = "agree_waiting"
487 def test_not_start_yet
488 cmd = ShogiServer::AgreeCommand.new("AGREE", @p)
490 assert_equal(:continue, rc)
491 assert(!@game.started)
495 @game.is_startable_status = true
496 cmd = ShogiServer::AgreeCommand.new("AGREE", @p)
498 assert_equal(:continue, rc)
499 assert(@game.started)
503 @p.status = "should_be_ignored"
504 cmd = ShogiServer::AgreeCommand.new("AGREE", @p)
506 assert_equal(:continue, rc)
507 assert(!@game.started)
513 class TestShowCommand < Test::Unit::TestCase
521 cmd = ShogiServer::ShowCommand.new("%%SHOW hoge", @p, @game)
524 assert_equal(:continue, rc)
527 def test_call_nil_game
528 cmd = ShogiServer::ShowCommand.new("%%SHOW hoge", @p, nil)
531 assert_equal(:continue, rc)
537 class TestMonitorOnCommand < Test::Unit::TestCase
545 cmd = ShogiServer::MonitorOnCommand.new("%%MONITORON hoge", @p, nil)
548 assert_equal(:continue, rc)
551 def test_call_read_logfile
553 cmd = ShogiServer::MonitorOnCommand.new("%%MONITORON hoge", @p, game)
555 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)
556 assert_equal(:continue, rc)
562 class TestMonitor2OnCommand < Test::Unit::TestCase
570 cmd = ShogiServer::Monitor2OnCommand.new("%%MONITOR2ON hoge", @p, nil)
573 assert_equal(:continue, rc)
576 def test_call_read_logfile
577 $tempfile = Tempfile.new("TC_command_test_call_read_logfile")
578 $tempfile.write "hoge\nfoo\n"
584 cmd = ShogiServer::Monitor2OnCommand.new("%%MONITOR2ON hoge", @p, game)
586 assert_equal("##[MONITOR2][dummy_game_id] hoge\n##[MONITOR2][dummy_game_id] foo\n##[MONITOR2][dummy_game_id] +OK\n", @p.out.join)
587 assert_equal(:continue, rc)
594 class TestMonitorOffCommand < Test::Unit::TestCase
602 cmd = ShogiServer::MonitorOffCommand.new("%%MONITOROFF hoge", @p, nil)
605 assert_equal(:continue, rc)
611 class TestMonitor2OffCommand < Test::Unit::TestCase
619 cmd = ShogiServer::Monitor2OffCommand.new("%%MONITOR2OFF hoge", @p, nil)
622 assert_equal(:continue, rc)
628 class TestHelpCommand < Test::Unit::TestCase
636 cmd = ShogiServer::HelpCommand.new("%%HELP", @p)
639 assert_equal(:continue, rc)
645 class TestRatingCommand < Test::Unit::TestCase
653 players = [MockPlayer.new]
654 cmd = ShogiServer::RatingCommand.new("%%RATING", @p, players)
657 assert_equal(:continue, rc)
663 class TestVersionCommand < Test::Unit::TestCase
671 cmd = ShogiServer::VersionCommand.new("%%VERSION", @p)
674 assert_equal(:continue, rc)
680 class TestGameCommand < Test::Unit::TestCase
687 def test_call_connected
688 @p.status = "connected"
689 cmd = ShogiServer::GameCommand.new("%%GAME", @p)
692 assert_equal(:continue, rc)
693 assert_equal("connected", @p.status)
696 def test_call_game_waiting
697 @p.status = "game_waiting"
698 cmd = ShogiServer::GameCommand.new("%%GAME", @p)
701 assert_equal(:continue, rc)
702 assert_equal("connected", @p.status)
705 def test_call_agree_waiting
706 @p.status = "agree_waiting"
707 cmd = ShogiServer::GameCommand.new("%%GAME", @p)
710 assert_equal(:continue, rc)
711 assert_equal("agree_waiting", @p.status)
717 class TestChatCommand < Test::Unit::TestCase
725 players = [["dummy_name", MockPlayer.new]]
726 cmd = ShogiServer::ChatCommand.new("%%CHAT hoge", @p, "dummy message", players)
729 assert_equal(:continue, rc)
732 def test_call_csa_protocol
733 players = [["dummy_name", MockPlayer.new]]
734 players.each do |name, p|
735 p.protocol = ShogiServer::LoginCSA::PROTOCOL
737 cmd = ShogiServer::ChatCommand.new("%%CHAT hoge", @p, "dummy message", players)
740 assert_equal(:continue, rc)
746 class TestListCommand < Test::Unit::TestCase
754 games = [["dummy_game_id", MockGame.new]]
755 cmd = ShogiServer::ListCommand.new("%%LIST", @p, games)
758 assert_equal(:continue, rc)
765 class TestWhoCommand < Test::Unit::TestCase
773 players = [["dummy_name", MockPlayer.new]]
774 cmd = ShogiServer::WhoCommand.new("%%LIST", @p, players)
777 assert_equal(:continue, rc)
784 class TestLogoutCommand < Test::Unit::TestCase
792 cmd = ShogiServer::LogoutCommand.new("LOGOUT", @p)
795 assert_equal(:return, rc)
802 class TestChallengeCommand < Test::Unit::TestCase
809 cmd = ShogiServer::ChallengeCommand.new("CHALLENGE", @p)
812 assert_equal(:continue, rc)
818 class TestSpaceCommand < Test::Unit::TestCase
825 cmd = ShogiServer::SpaceCommand.new("", @p)
828 assert_equal(:continue, rc)
834 class TestErrorCommand < Test::Unit::TestCase
841 cmd = ShogiServer::ErrorCommand.new("", @p)
844 assert_equal(:continue, rc)
848 class BaseTestBuoyCommand < Test::Unit::TestCase
851 $league = MockLeague.new
854 @buoy = ShogiServer::Buoy.new
862 file = File.join($topdir, "buoy.yaml")
863 File.delete file if File.exist? file
874 class TestSetBuoyCommand < BaseTestBuoyCommand
878 @p.name = "set_buoy_player"
882 assert @buoy.is_new_game?("buoy_hoge-1500-0")
883 cmd = ShogiServer::SetBuoyCommand.new "%%SETBUOY", @p, "buoy_hoge-1500-0", "+7776FU", 2
885 assert_equal :continue, rt
886 assert !@buoy.is_new_game?("buoy_hoge-1500-0")
887 assert !$p1.out.empty?
888 assert !$p2.out.empty?
889 buoy_game2 = @buoy.get_game("buoy_hoge-1500-0")
890 assert_equal ShogiServer::BuoyGame.new("buoy_hoge-1500-0", "+7776FU", @p.name, 1), buoy_game2
894 assert @buoy.is_new_game?("buoy_hoge-1500-0")
895 cmd = ShogiServer::SetBuoyCommand.new "%%SETBUOY", @p, "buoy_hoge-1500-0", "+7776FU", 1
897 assert_equal :continue, rt
898 assert @buoy.is_new_game?("buoy_hoge-1500-0")
899 assert !$p1.out.empty?
900 assert !$p2.out.empty?
903 def test_call_error_not_buoy_game_name
904 assert @buoy.is_new_game?("buoy_hoge-1500-0")
905 cmd = ShogiServer::SetBuoyCommand.new "%%SETBUOY", @p, "buoyhoge-1500-0", "+7776FU", 1
907 assert_equal :continue, rt
908 assert $p1.out.empty?
909 assert $p2.out.empty?
910 assert @buoy.is_new_game?("buoy_hoge-1500-0")
913 def test_call_error_duplicated_game_name
914 assert @buoy.is_new_game?("buoy_duplicated-1500-0")
915 bg = ShogiServer::BuoyGame.new("buoy_duplicated-1500-0", ["+7776FU"], @p.name, 1)
917 assert !@buoy.is_new_game?("buoy_duplicated-1500-0")
919 cmd = ShogiServer::SetBuoyCommand.new "%%SETBUOY", @p, "buoy_duplicated-1500-0", "+7776FU", 1
921 assert_equal :continue, rt
922 assert $p1.out.empty?
923 assert $p2.out.empty?
924 assert !@buoy.is_new_game?("buoy_duplicated-1500-0")
927 def test_call_error_bad_moves
928 assert @buoy.is_new_game?("buoy_badmoves-1500-0")
929 cmd = ShogiServer::SetBuoyCommand.new "%%SETBUOY", @p, "buoy_badmoves-1500-0", "+7776FU+8786FU", 1
931 assert_equal :continue, rt
932 assert $p1.out.empty?
933 assert $p2.out.empty?
934 assert @buoy.is_new_game?("buoy_badmoves-1500-0")
937 def test_call_error_bad_counter
938 assert @buoy.is_new_game?("buoy_badcounter-1500-0")
939 cmd = ShogiServer::SetBuoyCommand.new "%%SETBUOY", @p, "buoy_badcounter-1500-0", "+7776FU", 0
941 assert_equal :continue, rt
942 assert $p1.out.empty?
943 assert $p2.out.empty?
944 assert @buoy.is_new_game?("buoy_badcounter-1500-0")
951 class TestDeleteBuoyCommand < BaseTestBuoyCommand
953 buoy_game = ShogiServer::BuoyGame.new("buoy_testdeletebuoy-1500-0", "+7776FU", @p.name, 1)
954 assert @buoy.is_new_game?(buoy_game.game_name)
955 @buoy.add_game buoy_game
956 assert !@buoy.is_new_game?(buoy_game.game_name)
957 cmd = ShogiServer::DeleteBuoyCommand.new "%%DELETEBUOY", @p, buoy_game.game_name
959 assert_equal :continue, rt
960 assert $p1.out.empty?
961 assert $p2.out.empty?
962 assert @buoy.is_new_game?(buoy_game.game_name)
965 def test_call_not_exist
966 buoy_game = ShogiServer::BuoyGame.new("buoy_notexist-1500-0", "+7776FU", @p.name, 1)
967 assert @buoy.is_new_game?(buoy_game.game_name)
968 cmd = ShogiServer::DeleteBuoyCommand.new "%%DELETEBUOY", @p, buoy_game.game_name
970 assert_equal :continue, rt
971 assert $p1.out.empty?
972 assert $p2.out.empty?
973 assert @buoy.is_new_game?(buoy_game.game_name)
976 def test_call_another_player
977 buoy_game = ShogiServer::BuoyGame.new("buoy_anotherplayer-1500-0", "+7776FU", "another_player", 1)
978 assert @buoy.is_new_game?(buoy_game.game_name)
979 @buoy.add_game(buoy_game)
980 assert !@buoy.is_new_game?(buoy_game.game_name)
982 cmd = ShogiServer::DeleteBuoyCommand.new "%%DELETEBUOY", @p, buoy_game.game_name
984 assert_equal :continue, rt
985 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
986 assert !@buoy.is_new_game?(buoy_game.game_name)
992 class TestForkCommand < Test::Unit::TestCase
994 @player = MockPlayer.new
997 def test_new_buoy_game_name
998 src = "%%FORK server+denou-14400-60+p1+p2+20130223185013"
999 c = ShogiServer::ForkCommand.new src, @player, "server+denou-14400-60+p1+p2+20130223185013", nil, 13
1000 c.decide_new_buoy_game_name
1001 assert_equal "buoy_denou_13-14400-60", c.new_buoy_game
1004 def test_new_buoy_game_name2
1005 src = "%%FORK server+denou-14400-060+p1+p2+20130223185013"
1006 c = ShogiServer::ForkCommand.new src, @player, "server+denou-14400-060+p1+p2+20130223185013", nil, 13
1007 c.decide_new_buoy_game_name
1008 assert_equal "buoy_denou_13-14400-060", c.new_buoy_game
1014 class TestGetBuoyCountCommand < BaseTestBuoyCommand
1016 buoy_game = ShogiServer::BuoyGame.new("buoy_testdeletebuoy-1500-0", "+7776FU", @p.name, 1)
1017 assert @buoy.is_new_game?(buoy_game.game_name)
1018 @buoy.add_game buoy_game
1019 assert !@buoy.is_new_game?(buoy_game.game_name)
1020 cmd = ShogiServer::GetBuoyCountCommand.new "%%GETBUOYCOUNT", @p, buoy_game.game_name
1022 assert_equal :continue, rt
1023 assert_equal ["##[GETBUOYCOUNT] 1\n", "##[GETBUOYCOUNT] +OK\n"], @p.out
1026 def test_call_not_exist
1027 buoy_game = ShogiServer::BuoyGame.new("buoy_notexist-1500-0", "+7776FU", @p.name, 1)
1028 assert @buoy.is_new_game?(buoy_game.game_name)
1029 cmd = ShogiServer::GetBuoyCountCommand.new "%%GETBUOYCOUNT", @p, buoy_game.game_name
1031 assert_equal :continue, rt
1032 assert_equal ["##[GETBUOYCOUNT] -1\n", "##[GETBUOYCOUNT] +OK\n"], @p.out
1038 class TestMonitorHandler < Test::Unit::TestCase
1039 def test_not_equal_players
1040 @player1 = MockPlayer.new
1041 @handler1 = ShogiServer::MonitorHandler1.new @player1
1042 @player2 = MockPlayer.new
1043 @handler2 = ShogiServer::MonitorHandler1.new @player2
1045 assert_not_equal(@handler1, @handler2)
1049 @player1 = MockPlayer.new
1050 @handler1 = ShogiServer::MonitorHandler1.new @player1
1051 @handler2 = ShogiServer::MonitorHandler1.new @player1
1053 assert_equal(@handler1, @handler2)
1059 class TestMonitorHandler1 < Test::Unit::TestCase
1061 @player = MockPlayer.new
1062 @handler = ShogiServer::MonitorHandler1.new @player
1066 assert_equal(1, @handler.type)
1070 assert_equal("MONITOR", @handler.header)
1074 assert_equal @handler, @handler
1075 assert_not_equal @handler, nil
1079 assert_not_equal(@handler, ShogiServer::MonitorHandler2.new(@player))
1083 @handler.write_safe("game_id", "hoge")
1084 assert_equal("##[MONITOR][game_id] hoge\n##[MONITOR][game_id] +OK\n",
1091 class TestMonitorHandler2 < Test::Unit::TestCase
1093 @player = MockPlayer.new
1094 @handler = ShogiServer::MonitorHandler2.new @player
1098 assert_equal(2, @handler.type)
1102 assert_equal("MONITOR2", @handler.header)
1106 assert_equal @handler, @handler
1107 assert_not_equal @handler, nil
1111 assert_not_equal(@handler, ShogiServer::MonitorHandler1.new(@player))
1115 @handler.write_safe("game_id", "hoge")
1116 assert_equal("##[MONITOR2][game_id] hoge\n##[MONITOR2][game_id] +OK\n",
1120 def test_write_safe2
1121 @handler.write_safe("game_id", "hoge\nfoo")
1122 assert_equal("##[MONITOR2][game_id] hoge\n##[MONITOR2][game_id] foo\n##[MONITOR2][game_id] +OK\n",