OSDN Git Service

* [shogi-server] Support a graceful shutdown. (Closes #38544)
[shogi-server/shogi-server.git] / test / TC_login.rb
index e79bf37..a792e53 100644 (file)
@@ -5,6 +5,8 @@ require 'shogi_server/player'
 require 'shogi_server/login'
 require 'shogi_server/handicapped_boards'
 
 require 'shogi_server/login'
 require 'shogi_server/handicapped_boards'
 
+$options ||= {}
+
 class ShogiServer::BasicPlayer
   attr_accessor :protocol
 end
 class ShogiServer::BasicPlayer
   attr_accessor :protocol
 end
@@ -18,12 +20,23 @@ class TestLogin < Test::Unit::TestCase
     @p_x1.name = "hoge"
     @csa = ShogiServer::LoginCSA.new(@p_csa,"floodgate-900-0,xyz")
     @x1 = ShogiServer::Loginx1.new(@p_x1, "xyz")
     @p_x1.name = "hoge"
     @csa = ShogiServer::LoginCSA.new(@p_csa,"floodgate-900-0,xyz")
     @x1 = ShogiServer::Loginx1.new(@p_x1, "xyz")
+
+    $options["max-identifier"] = ShogiServer::Default_Max_Identifier_Length
   end
 
   def test_player_id
     assert(@p_x1.player_id == @p_csa.player_id)
   end
 
   end
 
   def test_player_id
     assert(@p_x1.player_id == @p_csa.player_id)
   end
 
+  def test_good_identifier
+    assert_true(ShogiServer::Login::good_identifier? "hoge")
+    assert_true(ShogiServer::Login::good_identifier? "12345678901234567890123456789012")
+
+    $options["max-identifier"] = 128
+    assert_true(ShogiServer::Login::good_identifier? "0"*128)
+    assert_false(ShogiServer::Login::good_identifier? "0"*129)
+  end
+
   def test_login_factory_x1
     player = ShogiServer::BasicPlayer.new
     player.name = "hoge"
   def test_login_factory_x1
     player = ShogiServer::BasicPlayer.new
     player.name = "hoge"
@@ -40,15 +53,105 @@ class TestLogin < Test::Unit::TestCase
     assert_instance_of(ShogiServer::LoginCSA, login)
     assert_equal("xyz", player.password)
     assert_equal(@p_csa.player_id, player.player_id)
     assert_instance_of(ShogiServer::LoginCSA, login)
     assert_equal("xyz", player.password)
     assert_equal(@p_csa.player_id, player.player_id)
+    assert_equal("*", login.turn_preference)
+  end
+
+  def test_login_factory_csa_fischer
+    player = ShogiServer::BasicPlayer.new
+    player.name = "hoge"
+    login = ShogiServer::Login::factory("LOGIN hoge floodagate-600-10F,xyz", player)
+    assert_instance_of(ShogiServer::LoginCSA, login)
+    assert_equal("xyz", player.password)
+    assert_equal(@p_csa.player_id, player.player_id)
+    assert_equal("*", login.turn_preference)
+  end
+
+  def test_login_factory_csa_no_gamename
+    player = ShogiServer::BasicPlayer.new
+    player.name = "hoge"
+    login = ShogiServer::Login::factory("LOGIN hoge xyz", player)
+    assert_instance_of(ShogiServer::LoginCSA, login)
+    assert_equal("xyz", player.password)
+    assert_equal(@p_csa.player_id, player.player_id)
+    assert_equal("*", login.turn_preference)
+    assert_equal(ShogiServer::Default_Game_Name, login.gamename)
+  end
+
+  def test_login_factory_csa_with_black
+    player = ShogiServer::BasicPlayer.new
+    player.name = "hoge"
+    login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-0-B,xyz", player)
+    assert_instance_of(ShogiServer::LoginCSA, login)
+    assert_equal("xyz", player.password)
+    assert_equal(@p_csa.player_id, player.player_id)
+    assert_equal("+", login.turn_preference)
+    assert_equal("floodgate-900-0", login.gamename)
+  end
+
+  def test_login_factory_csa_with_black_fischer
+    player = ShogiServer::BasicPlayer.new
+    player.name = "hoge"
+    login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-10F-B,xyz", player)
+    assert_instance_of(ShogiServer::LoginCSA, login)
+    assert_equal("xyz", player.password)
+    assert_equal(@p_csa.player_id, player.player_id)
+    assert_equal("+", login.turn_preference)
+    assert_equal("floodgate-900-10F", login.gamename)
+  end
+
+  def test_login_factory_csa_with_white
+    player = ShogiServer::BasicPlayer.new
+    player.name = "hoge"
+    login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-0-W,xyz", player)
+    assert_instance_of(ShogiServer::LoginCSA, login)
+    assert_equal("xyz", player.password)
+    assert_equal(@p_csa.player_id, player.player_id)
+    assert_equal("-", login.turn_preference)
+    assert_equal("floodgate-900-0", login.gamename)
+  end
+
+  def test_login_factory_csa_with_white_fischer
+    player = ShogiServer::BasicPlayer.new
+    player.name = "hoge"
+    login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-10F-W,xyz", player)
+    assert_instance_of(ShogiServer::LoginCSA, login)
+    assert_equal("xyz", player.password)
+    assert_equal(@p_csa.player_id, player.player_id)
+    assert_equal("-", login.turn_preference)
+    assert_equal("floodgate-900-10F", login.gamename)
   end
 
   def test_login_factory_csa_without_trip
     player = ShogiServer::BasicPlayer.new
     player.name = "hoge"
   end
 
   def test_login_factory_csa_without_trip
     player = ShogiServer::BasicPlayer.new
     player.name = "hoge"
-    login = ShogiServer::Login::factory("LOGIN hoge floodagate-900-0", player)
+    login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-0", player)
+    assert_instance_of(ShogiServer::LoginCSA, login)
+    assert_nil(player.password)
+    assert_equal(nil, player.player_id)
+    assert_equal("*", login.turn_preference)
+    assert_equal("floodgate-900-0", login.gamename)
+  end
+
+  def test_login_factory_csa_without_trip_with_black
+    player = ShogiServer::BasicPlayer.new
+    player.name = "hoge"
+    login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-0-B", player)
+    assert_instance_of(ShogiServer::LoginCSA, login)
+    assert_nil(player.password)
+    assert_equal(nil, player.player_id)
+    assert_equal("+", login.turn_preference)
+    assert_equal("floodgate-900-0", login.gamename)
+  end
+
+  def test_login_factory_csa_without_trip_with_white
+    player = ShogiServer::BasicPlayer.new
+    player.name = "hoge"
+    login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-0-W", player)
     assert_instance_of(ShogiServer::LoginCSA, login)
     assert_nil(player.password)
     assert_equal(nil, player.player_id)
     assert_instance_of(ShogiServer::LoginCSA, login)
     assert_nil(player.password)
     assert_equal(nil, player.player_id)
+    assert_equal("-", login.turn_preference)
+    assert_equal("floodgate-900-0", login.gamename)
   end
 end
 
   end
 end