OSDN Git Service

Enhanced the CSA Login mode to accept a turn preference.
[shogi-server/shogi-server.git] / test / TC_login.rb
index cbca07f..ad4cc93 100644 (file)
@@ -1,6 +1,9 @@
 $:.unshift File.join(File.dirname(__FILE__), "..")
 require 'test/unit'
-load 'shogi-server'
+require 'shogi_server'
+require 'shogi_server/player'
+require 'shogi_server/login'
+require 'shogi_server/handicapped_boards'
 
 class ShogiServer::BasicPlayer
   attr_accessor :protocol
@@ -25,6 +28,8 @@ class TestLogin < Test::Unit::TestCase
     player = ShogiServer::BasicPlayer.new
     player.name = "hoge"
     login = ShogiServer::Login::factory("LOGIN hoge xyz x1", player)
+    assert_instance_of(ShogiServer::Loginx1, login)
+    assert_equal("xyz", player.password)
     assert_equal(@p_x1.player_id, player.player_id)
   end
 
@@ -32,7 +37,76 @@ class TestLogin < Test::Unit::TestCase
     player = ShogiServer::BasicPlayer.new
     player.name = "hoge"
     login = ShogiServer::Login::factory("LOGIN hoge floodagate-900-0,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_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_without_trip
+    player = ShogiServer::BasicPlayer.new
+    player.name = "hoge"
+    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_equal("-", login.turn_preference)
+    assert_equal("floodgate-900-0", login.gamename)
+  end
 end
+