OSDN Git Service

Provided more test cases for Monitor features.
authorDaigo Moriwaki <daigo@debian.org>
Tue, 1 Jun 2010 14:22:04 +0000 (23:22 +0900)
committerDaigo Moriwaki <daigo@debian.org>
Tue, 1 Jun 2010 14:22:04 +0000 (23:22 +0900)
shogi_server/command.rb
test/TC_command.rb
test/TC_game.rb

index c8b00c0..d661f90 100644 (file)
@@ -374,7 +374,7 @@ module ShogiServer
     end
   end
 
     end
   end
 
-  class Monitor2OffCommand < MonitorOffCommand # same
+  class Monitor2OffCommand < MonitorOffCommand
     def initialize(str, player, game)
       super
     end
     def initialize(str, player, game)
       super
     end
index 973eea6..db3b333 100644 (file)
@@ -117,6 +117,11 @@ class TestFactoryMethod < Test::Unit::TestCase
     assert_instance_of(ShogiServer::MonitorOffCommand, cmd)
   end
 
     assert_instance_of(ShogiServer::MonitorOffCommand, cmd)
   end
 
+  def test_monitor2off_command
+    cmd = ShogiServer::Command.factory("%%MONITOR2OFF game_id", @p)
+    assert_instance_of(ShogiServer::Monitor2OffCommand, cmd)
+  end
+
   def test_help_command
     cmd = ShogiServer::Command.factory("%%HELP", @p)
     assert_instance_of(ShogiServer::HelpCommand, cmd)
   def test_help_command
     cmd = ShogiServer::Command.factory("%%HELP", @p)
     assert_instance_of(ShogiServer::HelpCommand, cmd)
@@ -498,6 +503,23 @@ end
 
 #
 #
 
 #
 #
+class TestMonitor2OffCommand < Test::Unit::TestCase 
+  def setup
+    @p = MockPlayer.new
+    @game = MockGame.new
+    @p.game = @game
+  end
+
+  def test_call
+    cmd = ShogiServer::Monitor2OffCommand.new("%%MONITOR2OFF hoge", @p, nil)
+    rc = cmd.call
+
+    assert_equal(:continue, rc)
+  end
+end
+
+#
+#
 class TestHelpCommand < Test::Unit::TestCase 
   def setup
     @p = MockPlayer.new
 class TestHelpCommand < Test::Unit::TestCase 
   def setup
     @p = MockPlayer.new
@@ -888,7 +910,7 @@ end
 #
 #
 class TestMonitorHandler < Test::Unit::TestCase
 #
 #
 class TestMonitorHandler < Test::Unit::TestCase
-  def test_not_equal
+  def test_not_equal_players
     @player1 = MockPlayer.new
     @handler1 = ShogiServer::MonitorHandler1.new @player1
     @player2 = MockPlayer.new
     @player1 = MockPlayer.new
     @handler1 = ShogiServer::MonitorHandler1.new @player1
     @player2 = MockPlayer.new
@@ -921,6 +943,15 @@ class TestMonitorHandler1 < Test::Unit::TestCase
   def test_header
     assert_equal("MONITOR", @handler.header)
   end
   def test_header
     assert_equal("MONITOR", @handler.header)
   end
+  
+  def test_equal
+    assert_equal @handler, @handler
+    assert_not_equal @handler, nil
+  end
+
+  def test_not_equal
+    assert_not_equal(@handler, ShogiServer::MonitorHandler2.new(@player))
+  end
 
   def test_write_safe
     @handler.write_safe("game_id", "hoge")
 
   def test_write_safe
     @handler.write_safe("game_id", "hoge")
@@ -945,6 +976,15 @@ class TestMonitorHandler2 < Test::Unit::TestCase
     assert_equal("MONITOR2", @handler.header)
   end
 
     assert_equal("MONITOR2", @handler.header)
   end
 
+  def test_equal
+    assert_equal @handler, @handler
+    assert_not_equal @handler, nil
+  end
+
+  def test_not_equal
+    assert_not_equal(@handler, ShogiServer::MonitorHandler1.new(@player))
+  end
+
   def test_write_safe
     @handler.write_safe("game_id", "hoge")
     assert_equal("##[MONITOR2][game_id] hoge\n##[MONITOR2][game_id] +OK\n", 
   def test_write_safe
     @handler.write_safe("game_id", "hoge")
     assert_equal("##[MONITOR2][game_id] hoge\n##[MONITOR2][game_id] +OK\n", 
index d126850..09ab2a7 100644 (file)
@@ -335,5 +335,32 @@ T1
 T1
 EOF
   end
 T1
 EOF
   end
+  
+  def test_monitor_add
+    game_name = "hoge-1500-0"
+    board = ShogiServer::Board.new
+    board.initial
+    p1 = MockPlayer.new
+    p1.sente = true
+    p1.name  = "p1"
+    p2 = MockPlayer.new
+    p2.sente = false
+    p2.name  = "p2"
+    
+    game = ShogiServer::Game.new game_name, p1, p2, board 
+    handler1 = ShogiServer::MonitorHandler1.new p1
+    handler2 = ShogiServer::MonitorHandler2.new p2
+
+    assert_equal(0, game.monitors.size)
+    game.monitoron(handler1)
+    assert_equal(1, game.monitors.size)
+    game.monitoron(handler2)
+    assert_equal(2, game.monitors.size)
+    game.monitoroff(handler1)
+    assert_equal(1, game.monitors.size)
+    assert_equal(handler2, game.monitors.last)
+    game.monitoroff(handler2)
+    assert_equal(0, game.monitors.size)
+  end
 end
 
 end