OSDN Git Service

Followed the change of the error message format.
[shogi-server/shogi-server.git] / test / TC_command.rb
index dc1c0f5..012ec82 100644 (file)
@@ -233,6 +233,11 @@ class TestFactoryMethod < Test::Unit::TestCase
     assert_instance_of(ShogiServer::ForkCommand, cmd)
   end
 
+  def test_fork_command2
+    cmd = ShogiServer::Command.factory("%%FORK server-denou-14400-60+p1+p2+20130223185013", @p)
+    assert_instance_of(ShogiServer::ForkCommand, cmd)
+  end
+
   def test_void_command
     cmd = ShogiServer::Command.factory("%%%HOGE", @p)
     assert_instance_of(ShogiServer::VoidCommand, cmd)
@@ -242,29 +247,29 @@ class TestFactoryMethod < Test::Unit::TestCase
     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
+    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
+    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
+    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
+    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
+    assert_no_match /unknown command: LOGIN hoge foo/, cmd.msg
   end
 end
 
@@ -842,7 +847,7 @@ class TestSetBuoyCommand < BaseTestBuoyCommand
     assert !$p1.out.empty?
     assert !$p2.out.empty?
     buoy_game2 = @buoy.get_game("buoy_hoge-1500-0")
-    assert_equal ShogiServer::BuoyGame.new("buoy_hoge-1500-0", "+7776FU", @p.name, 1, nil, nil), buoy_game2
+    assert_equal ShogiServer::BuoyGame.new("buoy_hoge-1500-0", "+7776FU", @p.name, 1), buoy_game2
   end
 
   def test_call_1
@@ -867,7 +872,7 @@ class TestSetBuoyCommand < BaseTestBuoyCommand
 
   def test_call_error_duplicated_game_name
     assert @buoy.is_new_game?("buoy_duplicated-1500-0")
-    bg = ShogiServer::BuoyGame.new("buoy_duplicated-1500-0", ["+7776FU"], @p.name, 1, nil, nil)
+    bg = ShogiServer::BuoyGame.new("buoy_duplicated-1500-0", ["+7776FU"], @p.name, 1)
     @buoy.add_game bg
     assert !@buoy.is_new_game?("buoy_duplicated-1500-0")
     
@@ -905,7 +910,7 @@ end
 #
 class TestDeleteBuoyCommand < BaseTestBuoyCommand
   def test_call
-    buoy_game = ShogiServer::BuoyGame.new("buoy_testdeletebuoy-1500-0", "+7776FU", @p.name, 1, nil, nil)
+    buoy_game = ShogiServer::BuoyGame.new("buoy_testdeletebuoy-1500-0", "+7776FU", @p.name, 1)
     assert @buoy.is_new_game?(buoy_game.game_name)
     @buoy.add_game buoy_game
     assert !@buoy.is_new_game?(buoy_game.game_name)
@@ -918,7 +923,7 @@ class TestDeleteBuoyCommand < BaseTestBuoyCommand
   end
 
   def test_call_not_exist
-    buoy_game = ShogiServer::BuoyGame.new("buoy_notexist-1500-0", "+7776FU", @p.name, 1, nil, nil)
+    buoy_game = ShogiServer::BuoyGame.new("buoy_notexist-1500-0", "+7776FU", @p.name, 1)
     assert @buoy.is_new_game?(buoy_game.game_name)
     cmd = ShogiServer::DeleteBuoyCommand.new "%%DELETEBUOY", @p, buoy_game.game_name
     rt = cmd.call
@@ -929,7 +934,7 @@ class TestDeleteBuoyCommand < BaseTestBuoyCommand
   end
 
   def test_call_another_player
-    buoy_game = ShogiServer::BuoyGame.new("buoy_anotherplayer-1500-0", "+7776FU", "another_player", 1, nil, nil)
+    buoy_game = ShogiServer::BuoyGame.new("buoy_anotherplayer-1500-0", "+7776FU", "another_player", 1)
     assert @buoy.is_new_game?(buoy_game.game_name)
     @buoy.add_game(buoy_game)
     assert !@buoy.is_new_game?(buoy_game.game_name)
@@ -944,9 +949,24 @@ end
 
 #
 #
+class TestForkCommand < Test::Unit::TestCase
+  def setup
+    @player = MockPlayer.new
+  end
+
+  def test_new_buoy_game_name
+    src = "%%FORK server+denou-14400-60+p1+p2+20130223185013"
+    c = ShogiServer::ForkCommand.new src, @player, "server+denou-14400-60+p1+p2+20130223185013", nil, 13
+    c.decide_new_buoy_game_name
+    assert_equal "buoy_denou_13-14400-60", c.new_buoy_game
+  end
+end
+
+#
+#
 class TestGetBuoyCountCommand < BaseTestBuoyCommand
   def test_call
-    buoy_game = ShogiServer::BuoyGame.new("buoy_testdeletebuoy-1500-0", "+7776FU", @p.name, 1, nil, nil)
+    buoy_game = ShogiServer::BuoyGame.new("buoy_testdeletebuoy-1500-0", "+7776FU", @p.name, 1)
     assert @buoy.is_new_game?(buoy_game.game_name)
     @buoy.add_game buoy_game
     assert !@buoy.is_new_game?(buoy_game.game_name)
@@ -957,7 +977,7 @@ class TestGetBuoyCountCommand < BaseTestBuoyCommand
   end
 
   def test_call_not_exist
-    buoy_game = ShogiServer::BuoyGame.new("buoy_notexist-1500-0", "+7776FU", @p.name, 1, nil, nil)
+    buoy_game = ShogiServer::BuoyGame.new("buoy_notexist-1500-0", "+7776FU", @p.name, 1)
     assert @buoy.is_new_game?(buoy_game.game_name)
     cmd = ShogiServer::GetBuoyCountCommand.new "%%GETBUOYCOUNT", @p, buoy_game.game_name
     rt = cmd.call
@@ -1056,4 +1076,3 @@ class TestMonitorHandler2 < Test::Unit::TestCase
                  @player.out.join)
   end
 end
-