OSDN Git Service

e79bf371562e90679135515e1118e57587f2b4d8
[shogi-server/shogi-server.git] / test / TC_login.rb
1 $:.unshift File.join(File.dirname(__FILE__), "..")
2 require 'test/unit'
3 require 'shogi_server'
4 require 'shogi_server/player'
5 require 'shogi_server/login'
6 require 'shogi_server/handicapped_boards'
7
8 class ShogiServer::BasicPlayer
9   attr_accessor :protocol
10 end
11
12
13 class TestLogin < Test::Unit::TestCase 
14   def setup
15     @p_csa = ShogiServer::BasicPlayer.new
16     @p_csa.name = "hoge"
17     @p_x1 = ShogiServer::BasicPlayer.new
18     @p_x1.name = "hoge"
19     @csa = ShogiServer::LoginCSA.new(@p_csa,"floodgate-900-0,xyz")
20     @x1 = ShogiServer::Loginx1.new(@p_x1, "xyz")
21   end
22
23   def test_player_id
24     assert(@p_x1.player_id == @p_csa.player_id)
25   end
26
27   def test_login_factory_x1
28     player = ShogiServer::BasicPlayer.new
29     player.name = "hoge"
30     login = ShogiServer::Login::factory("LOGIN hoge xyz x1", player)
31     assert_instance_of(ShogiServer::Loginx1, login)
32     assert_equal("xyz", player.password)
33     assert_equal(@p_x1.player_id, player.player_id)
34   end
35
36   def test_login_factory_csa
37     player = ShogiServer::BasicPlayer.new
38     player.name = "hoge"
39     login = ShogiServer::Login::factory("LOGIN hoge floodagate-900-0,xyz", player)
40     assert_instance_of(ShogiServer::LoginCSA, login)
41     assert_equal("xyz", player.password)
42     assert_equal(@p_csa.player_id, player.player_id)
43   end
44
45   def test_login_factory_csa_without_trip
46     player = ShogiServer::BasicPlayer.new
47     player.name = "hoge"
48     login = ShogiServer::Login::factory("LOGIN hoge floodagate-900-0", player)
49     assert_instance_of(ShogiServer::LoginCSA, login)
50     assert_nil(player.password)
51     assert_equal(nil, player.player_id)
52   end
53 end
54