OSDN Git Service

shogi_server/command.rb: Prevent a possible password from be logged in a log file...
[shogi-server/shogi-server.git] / test / TC_command.rb
index 973eea6..fb2e134 100644 (file)
@@ -117,6 +117,11 @@ class TestFactoryMethod < Test::Unit::TestCase
     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)
@@ -197,9 +202,38 @@ class TestFactoryMethod < Test::Unit::TestCase
     assert_instance_of(ShogiServer::GetBuoyCountCommand, cmd)
   end
 
+  def test_void_command
+    cmd = ShogiServer::Command.factory("%%%HOGE", @p)
+    assert_instance_of(ShogiServer::VoidCommand, cmd)
+  end
+
   def test_error
     cmd = ShogiServer::Command.factory("should_be_error", @p)
     assert_instance_of(ShogiServer::ErrorCommand, cmd)
+    cmd.call
+    assert_match /unknown command should_be_error/, cmd.msg
+  end
+
+  def test_error_login
+    cmd = ShogiServer::Command.factory("LOGIN hoge foo", @p)
+    assert_instance_of(ShogiServer::ErrorCommand, cmd)
+    cmd.call
+    assert_no_match /unknown command LOGIN hoge foo/, cmd.msg
+
+    cmd = ShogiServer::Command.factory("LOGin hoge foo", @p)
+    assert_instance_of(ShogiServer::ErrorCommand, cmd)
+    cmd.call
+    assert_no_match /unknown command LOGIN hoge foo/, cmd.msg
+
+    cmd = ShogiServer::Command.factory("LOGIN  hoge foo", @p)
+    assert_instance_of(ShogiServer::ErrorCommand, cmd)
+    cmd.call
+    assert_no_match /unknown command LOGIN hoge foo/, cmd.msg
+
+    cmd = ShogiServer::Command.factory("LOGINhoge foo", @p)
+    assert_instance_of(ShogiServer::ErrorCommand, cmd)
+    cmd.call
+    assert_no_match /unknown command LOGIN hoge foo/, cmd.msg
   end
 end
 
@@ -498,6 +532,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
@@ -888,7 +939,7 @@ end
 #
 #
 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
@@ -921,6 +972,15 @@ class TestMonitorHandler1 < Test::Unit::TestCase
   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")
@@ -945,6 +1005,15 @@ class TestMonitorHandler2 < Test::Unit::TestCase
     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",