OSDN Git Service

* [mk_rate]
[shogi-server/shogi-server.git] / test / TC_command.rb
1 $:.unshift File.join(File.dirname(__FILE__), "..")
2 $topdir = File.expand_path File.dirname(__FILE__)
3 require 'test/unit'
4 require 'mock_game'
5 require 'mock_log_message'
6 require 'test/mock_player'
7 require 'shogi_server/login'
8 require 'shogi_server/player'
9 require 'shogi_server/command'
10
11
12 class MockLeague
13   def initialize
14     @games = {}
15     @games["dummy_game_id"] = MockGame.new
16   end
17
18   def games
19     return @games
20   end
21
22   def rated_players
23     return []
24   end
25
26   def players
27     return [MockPlayer.new]
28   end
29
30   def event
31     return "test"
32   end
33
34   def dir
35     return $topdir
36   end
37
38   def get_player(status, game_id, sente, searcher)
39     if sente == true
40       $p1 = MockPlayer.new
41       $p1.name = "p1"
42       return $p1
43     elsif sente == false
44       $p2 = MockPlayer.new
45       $p2.name = "p2"
46       return $p2
47     elsif sente == nil
48       return nil
49     else
50       return nil
51     end
52   end
53 end
54
55
56 class TestFactoryMethod < Test::Unit::TestCase 
57
58   def setup
59     @p = MockPlayer.new
60     @p.name = "test_factory_method_player"
61     $league = MockLeague.new
62   end
63
64   def test_keep_alive_command
65     cmd = ShogiServer::Command.factory("", @p)
66     assert_instance_of(ShogiServer::KeepAliveCommand, cmd)
67   end
68
69   def test_move_command
70     cmd = ShogiServer::Command.factory("+7776FU", @p)
71     assert_instance_of(ShogiServer::MoveCommand, cmd)
72   end
73
74   def test_special_command
75     cmd = ShogiServer::Command.factory("%TORYO", @p)
76     assert_instance_of(ShogiServer::SpecialCommand, cmd)
77   end
78
79   def test_special_command_timeout
80     cmd = ShogiServer::Command.factory(:timeout, @p)
81     assert_instance_of(ShogiServer::SpecialCommand, cmd)
82   end
83
84   def test_execption_command
85     cmd = ShogiServer::Command.factory(:exception, @p)
86     assert_instance_of(ShogiServer::ExceptionCommand, cmd)
87   end
88
89   def test_reject_command
90     cmd = ShogiServer::Command.factory("REJECT", @p)
91     assert_instance_of(ShogiServer::RejectCommand, cmd)
92   end
93
94   def test_agree_command
95     cmd = ShogiServer::Command.factory("AGREE", @p)
96     assert_instance_of(ShogiServer::AgreeCommand, cmd)
97   end
98
99   def test_show_command
100     cmd = ShogiServer::Command.factory("%%SHOW game_id", @p)
101     assert_instance_of(ShogiServer::ShowCommand, cmd)
102   end
103
104   def test_monitoron_command
105     cmd = ShogiServer::Command.factory("%%MONITORON game_id", @p)
106     assert_instance_of(ShogiServer::MonitorOnCommand, cmd)
107   end
108
109   def test_monitoroff_command
110     cmd = ShogiServer::Command.factory("%%MONITOROFF game_id", @p)
111     assert_instance_of(ShogiServer::MonitorOffCommand, cmd)
112   end
113
114   def test_help_command
115     cmd = ShogiServer::Command.factory("%%HELP", @p)
116     assert_instance_of(ShogiServer::HelpCommand, cmd)
117   end
118
119   def test_rating_command
120     cmd = ShogiServer::Command.factory("%%RATING", @p)
121     assert_instance_of(ShogiServer::RatingCommand, cmd)
122   end
123
124   def test_version_command
125     cmd = ShogiServer::Command.factory("%%VERSION", @p)
126     assert_instance_of(ShogiServer::VersionCommand, cmd)
127   end
128
129   def test_game_command
130     cmd = ShogiServer::Command.factory("%%GAME", @p)
131     assert_instance_of(ShogiServer::GameCommand, cmd)
132   end
133
134   def test_game_challenge_command_game
135     cmd = ShogiServer::Command.factory("%%GAME default-1500-0 +", @p)
136     assert_instance_of(ShogiServer::GameChallengeCommand, cmd)
137   end
138
139   def test_game_challenge_command_challenge
140     cmd = ShogiServer::Command.factory("%%CHALLENGE default-1500-0 -", @p)
141     assert_instance_of(ShogiServer::GameChallengeCommand, cmd)
142   end
143
144   def test_chat_command
145     cmd = ShogiServer::Command.factory("%%CHAT hello", @p)
146     assert_instance_of(ShogiServer::ChatCommand, cmd)
147   end
148
149   def test_list_command
150     cmd = ShogiServer::Command.factory("%%LIST", @p)
151     assert_instance_of(ShogiServer::ListCommand, cmd)
152   end
153
154   def test_who_command
155     cmd = ShogiServer::Command.factory("%%WHO", @p)
156     assert_instance_of(ShogiServer::WhoCommand, cmd)
157   end
158
159   def test_logout_command
160     cmd = ShogiServer::Command.factory("LOGOUT", @p)
161     assert_instance_of(ShogiServer::LogoutCommand, cmd)
162   end
163
164   def test_challenge_command
165     cmd = ShogiServer::Command.factory("CHALLENGE", @p)
166     assert_instance_of(ShogiServer::ChallengeCommand, cmd)
167   end
168
169   def test_space_command
170     cmd = ShogiServer::Command.factory(" ", @p)
171     assert_instance_of(ShogiServer::SpaceCommand, cmd)
172   end
173
174   def test_setbuoy_command
175     cmd = ShogiServer::Command.factory("%%SETBUOY buoy_test-1500-0 +7776FU", @p)
176     assert_instance_of(ShogiServer::SetBuoyCommand, cmd)
177   end
178
179   def test_setbuoy_command_with_counter
180     cmd = ShogiServer::Command.factory("%%SETBUOY buoy_test-1500-0 +7776FU 3", @p)
181     assert_instance_of(ShogiServer::SetBuoyCommand, cmd)
182   end
183
184   def test_deletebuoy_command
185     cmd = ShogiServer::Command.factory("%%DELETEBUOY buoy_test-1500-0", @p)
186     assert_instance_of(ShogiServer::DeleteBuoyCommand, cmd)
187   end
188
189   def test_getbuoycount_command
190     cmd = ShogiServer::Command.factory("%%GETBUOYCOUNT buoy_test-1500-0", @p)
191     assert_instance_of(ShogiServer::GetBuoyCountCommand, cmd)
192   end
193
194   def test_error
195     cmd = ShogiServer::Command.factory("should_be_error", @p)
196     assert_instance_of(ShogiServer::ErrorCommand, cmd)
197   end
198 end
199
200 #
201 #
202 class TestKeepAliveCommand < Test::Unit::TestCase 
203   def setup
204     @p = MockPlayer.new
205   end
206
207   def test_call
208     cmd = ShogiServer::KeepAliveCommand.new("", @p)
209     rc = cmd.call
210     assert_equal(:continue, rc)
211   end
212 end
213
214 #
215 #
216 class TestMoveCommand < Test::Unit::TestCase
217   def setup
218     @p = MockPlayer.new
219     @game = MockGame.new
220     @p.game = @game
221     @p.status = "game"
222   end
223
224   def test_call
225     cmd = ShogiServer::MoveCommand.new("+7776FU", @p)
226     rc = cmd.call
227     assert_equal(:continue, rc)
228   end
229
230   def test_comment
231     cmd = ShogiServer::MoveCommand.new("+7776FU,'comment", @p)
232     rc = cmd.call
233     assert_equal(:continue, rc)
234     assert_equal("'*comment", @game.log.first)
235   end
236
237   def test_x1_return
238     @game.finish_flag = true
239     @p.protocol = ShogiServer::LoginCSA::PROTOCOL
240     cmd = ShogiServer::MoveCommand.new("+7776FU", @p)
241     rc = cmd.call
242     assert_equal(:return, rc)
243   end
244 end
245
246 #
247 #
248 class TestSpecialComand < Test::Unit::TestCase
249   def setup
250     @p = MockPlayer.new
251     @game = MockGame.new
252     @p.game = @game
253     @p.status = "game"
254   end
255
256   def test_toryo
257     @game.finish_flag = true
258     cmd = ShogiServer::SpecialCommand.new("%TORYO", @p)
259     rc = cmd.call
260     assert_equal(:continue, rc)
261   end
262
263   def test_toryo_csa_protocol
264     @game.finish_flag = true
265     @p.protocol = ShogiServer::LoginCSA::PROTOCOL
266     cmd = ShogiServer::SpecialCommand.new("%TORYO", @p)
267     rc = cmd.call
268     assert_equal(:return, rc)
269   end
270
271   def test_timeout
272     cmd = ShogiServer::SpecialCommand.new(:timeout, @p)
273     rc = cmd.call
274     assert_equal(:continue, rc)
275   end
276
277   def test_expired_game
278     @p.status = "agree_waiting"
279     @game.prepared_expire = true
280     assert(!@game.rejected)
281     cmd = ShogiServer::SpecialCommand.new(:timeout, @p)
282     rc = cmd.call
283     assert_equal(:continue, rc)
284     assert(@game.rejected)
285   end
286
287   def test_expired_game_csa_protocol
288     @p.protocol = ShogiServer::LoginCSA::PROTOCOL
289     @p.status = "agree_waiting"
290     @game.prepared_expire = true
291     assert(!@game.rejected)
292     cmd = ShogiServer::SpecialCommand.new(:timeout, @p)
293     rc = cmd.call
294     assert_equal(:return, rc)
295     assert(@game.rejected)
296   end
297
298   def test_error
299     @p.status = "should_be_ignored"
300     cmd = ShogiServer::SpecialCommand.new(:timeout, @p)
301     rc = cmd.call
302     assert_equal(:continue, rc)
303   end
304 end
305
306 #
307 #
308 class TestExceptionCommand < Test::Unit::TestCase 
309   def setup
310     @p = MockPlayer.new
311   end
312
313   def test_call
314     cmd = ShogiServer::ExceptionCommand.new(:exception, @p)
315     rc = cmd.call
316     assert_equal(:return, rc)
317   end
318 end
319
320 #
321 #
322 class TestRejectCommand < Test::Unit::TestCase 
323   def setup
324     @p = MockPlayer.new
325     @game = MockGame.new
326     @p.game = @game
327     @p.status = "game"
328   end
329
330   def test_call
331     @p.status = "agree_waiting"
332     assert(!@game.rejected)
333     cmd = ShogiServer::RejectCommand.new("REJECT", @p)
334     rc = cmd.call
335
336     assert_equal(:continue, rc)
337     assert(@game.rejected)
338   end
339
340   def test_call_csa_protocol
341     @p.protocol = ShogiServer::LoginCSA::PROTOCOL
342     @p.status = "agree_waiting"
343     assert(!@game.rejected)
344     cmd = ShogiServer::RejectCommand.new("REJECT", @p)
345     rc = cmd.call
346
347     assert_equal(:return, rc)
348     assert(@game.rejected)
349   end
350
351   def test_error
352     @p.status = "should_be_ignored"
353     cmd = ShogiServer::RejectCommand.new("REJECT", @p)
354     rc = cmd.call
355
356     assert_equal(:continue, rc)
357     assert(!@game.rejected)
358   end
359 end
360
361 #
362 #
363 class TestAgreeCommand < Test::Unit::TestCase 
364   def setup
365     @p = MockPlayer.new
366     @game = MockGame.new
367     @p.game = @game
368     @p.status = "agree_waiting"
369   end
370
371   def test_not_start_yet
372     cmd = ShogiServer::AgreeCommand.new("AGREE", @p)
373     rc = cmd.call
374     assert_equal(:continue, rc)
375     assert(!@game.started)
376   end
377
378   def test_start
379     @game.is_startable_status = true
380     cmd = ShogiServer::AgreeCommand.new("AGREE", @p)
381     rc = cmd.call
382     assert_equal(:continue, rc)
383     assert(@game.started)
384   end
385
386   def test_error
387     @p.status = "should_be_ignored"
388     cmd = ShogiServer::AgreeCommand.new("AGREE", @p)
389     rc = cmd.call
390     assert_equal(:continue, rc)
391     assert(!@game.started)
392   end
393 end
394
395 #
396 #
397 class TestShowCommand < Test::Unit::TestCase 
398   def setup
399     @p = MockPlayer.new
400     @game = MockGame.new
401     @p.game = @game
402   end
403
404   def test_call
405     cmd = ShogiServer::ShowCommand.new("%%SHOW hoge", @p, @game)
406     rc = cmd.call
407
408     assert_equal(:continue, rc)
409   end
410
411   def test_call_nil_game
412     cmd = ShogiServer::ShowCommand.new("%%SHOW hoge", @p, nil)
413     rc = cmd.call
414
415     assert_equal(:continue, rc)
416   end
417 end
418
419 #
420 #
421 class TestMonitorOnCommand < Test::Unit::TestCase 
422   def setup
423     @p = MockPlayer.new
424     @game = MockGame.new
425     @p.game = @game
426   end
427
428   def test_call
429     cmd = ShogiServer::MonitorOnCommand.new("%%MONITORON hoge", @p, nil)
430     rc = cmd.call
431
432     assert_equal(:continue, rc)
433   end
434 end
435
436 #
437 #
438 class TestMonitorOffCommand < Test::Unit::TestCase 
439   def setup
440     @p = MockPlayer.new
441     @game = MockGame.new
442     @p.game = @game
443   end
444
445   def test_call
446     cmd = ShogiServer::MonitorOffCommand.new("%%MONITOROFF hoge", @p, nil)
447     rc = cmd.call
448
449     assert_equal(:continue, rc)
450   end
451 end
452
453 #
454 #
455 class TestHelpCommand < Test::Unit::TestCase 
456   def setup
457     @p = MockPlayer.new
458     @game = MockGame.new
459     @p.game = @game
460   end
461
462   def test_call
463     cmd = ShogiServer::HelpCommand.new("%%HELP", @p)
464     rc = cmd.call
465
466     assert_equal(:continue, rc)
467   end
468 end
469
470 #
471 #
472 class TestRatingCommand < Test::Unit::TestCase 
473   def setup
474     @p = MockPlayer.new
475     @game = MockGame.new
476     @p.game = @game
477   end
478
479   def test_call
480     players = [MockPlayer.new]
481     cmd = ShogiServer::RatingCommand.new("%%RATING", @p, players)
482     rc = cmd.call
483
484     assert_equal(:continue, rc)
485   end
486 end
487
488 #
489 #
490 class TestVersionCommand < Test::Unit::TestCase 
491   def setup
492     @p = MockPlayer.new
493     @game = MockGame.new
494     @p.game = @game
495   end
496
497   def test_call
498     cmd = ShogiServer::VersionCommand.new("%%VERSION", @p)
499     rc = cmd.call
500
501     assert_equal(:continue, rc)
502   end
503 end
504
505 #
506 #
507 class TestGameCommand < Test::Unit::TestCase 
508   def setup
509     @p = MockPlayer.new
510     @game = MockGame.new
511     @p.game = @game
512   end
513
514   def test_call_connected
515     @p.status = "connected"
516     cmd = ShogiServer::GameCommand.new("%%GAME", @p)
517     rc = cmd.call
518
519     assert_equal(:continue, rc)
520     assert_equal("connected", @p.status)
521   end
522
523   def test_call_game_waiting
524     @p.status = "game_waiting"
525     cmd = ShogiServer::GameCommand.new("%%GAME", @p)
526     rc = cmd.call
527
528     assert_equal(:continue, rc)
529     assert_equal("connected", @p.status)
530   end
531
532   def test_call_agree_waiting
533     @p.status = "agree_waiting"
534     cmd = ShogiServer::GameCommand.new("%%GAME", @p)
535     rc = cmd.call
536
537     assert_equal(:continue, rc)
538     assert_equal("agree_waiting", @p.status)
539   end
540 end
541
542 #
543 #
544 class TestChatCommand < Test::Unit::TestCase 
545   def setup
546     @p = MockPlayer.new
547     @game = MockGame.new
548     @p.game = @game
549   end
550
551   def test_call
552     players = [["dummy_name", MockPlayer.new]]
553     cmd = ShogiServer::ChatCommand.new("%%CHAT hoge", @p, "dummy message", players)
554     rc = cmd.call
555
556     assert_equal(:continue, rc)
557   end
558
559   def test_call_csa_protocol
560     players = [["dummy_name", MockPlayer.new]]
561     players.each do |name, p|
562       p.protocol = ShogiServer::LoginCSA::PROTOCOL
563     end
564     cmd = ShogiServer::ChatCommand.new("%%CHAT hoge", @p, "dummy message", players)
565     rc = cmd.call
566
567     assert_equal(:continue, rc)
568   end
569 end
570
571 #
572 #
573 class TestListCommand < Test::Unit::TestCase 
574   def setup
575     @p = MockPlayer.new
576     @game = MockGame.new
577     @p.game = @game
578   end
579
580   def test_call
581     games = [["dummy_game_id", MockGame.new]]
582     cmd = ShogiServer::ListCommand.new("%%LIST", @p, games)
583     rc = cmd.call
584
585     assert_equal(:continue, rc)
586   end
587
588 end
589
590 #
591 #
592 class TestWhoCommand < Test::Unit::TestCase 
593   def setup
594     @p = MockPlayer.new
595     @game = MockGame.new
596     @p.game = @game
597   end
598
599   def test_call
600     players = [["dummy_name", MockPlayer.new]]
601     cmd = ShogiServer::WhoCommand.new("%%LIST", @p, players)
602     rc = cmd.call
603
604     assert_equal(:continue, rc)
605   end
606
607 end
608
609 #
610 #
611 class TestLogoutCommand < Test::Unit::TestCase 
612   def setup
613     @p = MockPlayer.new
614     @game = MockGame.new
615     @p.game = @game
616   end
617
618   def test_call
619     cmd = ShogiServer::LogoutCommand.new("LOGOUT", @p)
620     rc = cmd.call
621
622     assert_equal(:return, rc)
623   end
624
625 end
626
627 #
628 #
629 class TestChallengeCommand < Test::Unit::TestCase 
630   def setup
631     @p = MockPlayer.new
632     @game = MockGame.new
633   end
634
635   def test_call
636     cmd = ShogiServer::ChallengeCommand.new("CHALLENGE", @p)
637     rc = cmd.call
638
639     assert_equal(:continue, rc)
640   end
641 end
642
643 #
644 #
645 class TestSpaceCommand < Test::Unit::TestCase 
646   def setup
647     @p = MockPlayer.new
648     @game = MockGame.new
649   end
650
651   def test_call
652     cmd = ShogiServer::SpaceCommand.new("", @p)
653     rc = cmd.call
654
655     assert_equal(:continue, rc)
656   end
657 end
658
659 #
660 #
661 class TestErrorCommand < Test::Unit::TestCase 
662   def setup
663     @p = MockPlayer.new
664     @game = MockGame.new
665   end
666
667   def test_call
668     cmd = ShogiServer::ErrorCommand.new("", @p)
669     rc = cmd.call
670
671     assert_equal(:continue, rc)
672   end
673 end
674
675 class BaseTestBuoyCommand < Test::Unit::TestCase
676   def setup
677     @p = MockPlayer.new
678     $p1 = nil
679     $p2 = nil
680
681     delete_buoy_yaml
682     @buoy = ShogiServer::Buoy.new
683   end
684
685   def teadown
686     delete_buoy_yaml
687   end
688
689   def delete_buoy_yaml
690     file = File.join($topdir, "buoy.yaml")
691     File.delete file if File.exist? file
692   end
693
694   def test_dummy
695     assert true
696   end
697 end
698
699
700 #
701 #
702 class TestSetBuoyCommand < BaseTestBuoyCommand
703   
704   def setup
705     super
706     @p.name = "set_buoy_player"
707   end
708
709   def test_call_2
710     assert @buoy.is_new_game?("buoy_hoge-1500-0")
711     cmd = ShogiServer::SetBuoyCommand.new "%%SETBUOY", @p, "buoy_hoge-1500-0", "+7776FU", 2
712     rt = cmd.call
713     assert :continue, rt
714     assert !@buoy.is_new_game?("buoy_hoge-1500-0")
715     assert !$p1.out.empty?
716     assert !$p2.out.empty?
717     buoy_game2 = @buoy.get_game("buoy_hoge-1500-0")
718     assert_equal ShogiServer::BuoyGame.new("buoy_hoge-1500-0", "+7776FU", @p.name, 1), buoy_game2
719   end
720
721   def test_call_1
722     assert @buoy.is_new_game?("buoy_hoge-1500-0")
723     cmd = ShogiServer::SetBuoyCommand.new "%%SETBUOY", @p, "buoy_hoge-1500-0", "+7776FU", 1
724     rt = cmd.call
725     assert :continue, rt
726     assert @buoy.is_new_game?("buoy_hoge-1500-0")
727     assert !$p1.out.empty?
728     assert !$p2.out.empty?
729   end
730
731   def test_call_error_not_buoy_game_name
732     assert @buoy.is_new_game?("buoy_hoge-1500-0")
733     cmd = ShogiServer::SetBuoyCommand.new "%%SETBUOY", @p, "buoyhoge-1500-0", "+7776FU", 1
734     rt = cmd.call
735     assert :continue, rt
736     assert !$p1
737     assert !$p2
738     assert @buoy.is_new_game?("buoy_hoge-1500-0")
739   end
740
741   def test_call_error_duplicated_game_name
742     assert @buoy.is_new_game?("buoy_duplicated-1500-0")
743     bg = ShogiServer::BuoyGame.new("buoy_duplicated-1500-0", ["+7776FU"], @p.name, 1)
744     @buoy.add_game bg
745     assert !@buoy.is_new_game?("buoy_duplicated-1500-0")
746     
747     cmd = ShogiServer::SetBuoyCommand.new "%%SETBUOY", @p, "buoy_duplicated-1500-0", "+7776FU", 1
748     rt = cmd.call
749     assert :continue, rt
750     assert !$p1
751     assert !$p2
752     assert !@buoy.is_new_game?("buoy_duplicated-1500-0")
753   end
754
755   def test_call_error_bad_moves
756     assert @buoy.is_new_game?("buoy_badmoves-1500-0")
757     cmd = ShogiServer::SetBuoyCommand.new "%%SETBUOY", @p, "buoy_badmoves-1500-0", "+7776FU+8786FU", 1
758     rt = cmd.call
759     assert :continue, rt
760     assert !$p1
761     assert !$p2
762     assert @buoy.is_new_game?("buoy_badmoves-1500-0")
763   end
764
765   def test_call_error_bad_counter
766     assert @buoy.is_new_game?("buoy_badcounter-1500-0")
767     cmd = ShogiServer::SetBuoyCommand.new "%%SETBUOY", @p, "buoy_badcounter-1500-0", "+7776FU", 0
768     rt = cmd.call
769     assert :continue, rt
770     assert !$p1
771     assert !$p2
772     assert @buoy.is_new_game?("buoy_badcounter-1500-0")
773   end
774 end
775
776
777 #
778 #
779 class TestDeleteBuoyCommand < BaseTestBuoyCommand
780   def test_call
781     buoy_game = ShogiServer::BuoyGame.new("buoy_testdeletebuoy-1500-0", "+7776FU", @p.name, 1)
782     assert @buoy.is_new_game?(buoy_game.game_name)
783     @buoy.add_game buoy_game
784     assert !@buoy.is_new_game?(buoy_game.game_name)
785     cmd = ShogiServer::DeleteBuoyCommand.new "%%DELETEBUOY", @p, buoy_game.game_name
786     rt = cmd.call
787     assert :continue, rt
788     assert !$p1
789     assert !$p2
790     assert @buoy.is_new_game?(buoy_game.game_name)
791   end
792
793   def test_call_not_exist
794     buoy_game = ShogiServer::BuoyGame.new("buoy_notexist-1500-0", "+7776FU", @p.name, 1)
795     assert @buoy.is_new_game?(buoy_game.game_name)
796     cmd = ShogiServer::DeleteBuoyCommand.new "%%DELETEBUOY", @p, buoy_game.game_name
797     rt = cmd.call
798     assert :continue, rt
799     assert !$p1
800     assert !$p2
801     assert @buoy.is_new_game?(buoy_game.game_name)
802   end
803
804   def test_call_another_player
805     buoy_game = ShogiServer::BuoyGame.new("buoy_anotherplayer-1500-0", "+7776FU", "another_player", 1)
806     assert @buoy.is_new_game?(buoy_game.game_name)
807     @buoy.add_game(buoy_game)
808     assert !@buoy.is_new_game?(buoy_game.game_name)
809
810     cmd = ShogiServer::DeleteBuoyCommand.new "%%DELETEBUOY", @p, buoy_game.game_name
811     rt = cmd.call
812     assert :continue, rt
813     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
814     assert !@buoy.is_new_game?(buoy_game.game_name)
815   end
816 end
817
818 #
819 #
820 class TestGetBuoyCountCommand < BaseTestBuoyCommand
821   def test_call
822     buoy_game = ShogiServer::BuoyGame.new("buoy_testdeletebuoy-1500-0", "+7776FU", @p.name, 1)
823     assert @buoy.is_new_game?(buoy_game.game_name)
824     @buoy.add_game buoy_game
825     assert !@buoy.is_new_game?(buoy_game.game_name)
826     cmd = ShogiServer::GetBuoyCountCommand.new "%%GETBUOYCOUNT", @p, buoy_game.game_name
827     rt = cmd.call
828     assert :continue, rt
829     assert_equal ["##[GETBUOYCOUNT] 1\n", "##[GETBUOYCOUNT] +OK\n"], @p.out
830   end
831
832   def test_call_not_exist
833     buoy_game = ShogiServer::BuoyGame.new("buoy_notexist-1500-0", "+7776FU", @p.name, 1)
834     assert @buoy.is_new_game?(buoy_game.game_name)
835     cmd = ShogiServer::GetBuoyCountCommand.new "%%GETBUOYCOUNT", @p, buoy_game.game_name
836     rt = cmd.call
837     assert :continue, rt
838     assert_equal ["##[GETBUOYCOUNT] -1\n", "##[GETBUOYCOUNT] +OK\n"], @p.out
839   end
840 end
841
842