OSDN Git Service

Merge branch '201312-usiToCsa'
[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     assert_equal("*", login.turn_preference)
44   end
45
46   def test_login_factory_csa_no_gamename
47     player = ShogiServer::BasicPlayer.new
48     player.name = "hoge"
49     login = ShogiServer::Login::factory("LOGIN hoge xyz", player)
50     assert_instance_of(ShogiServer::LoginCSA, login)
51     assert_equal("xyz", player.password)
52     assert_equal(@p_csa.player_id, player.player_id)
53     assert_equal("*", login.turn_preference)
54     assert_equal(ShogiServer::Default_Game_Name, login.gamename)
55   end
56
57   def test_login_factory_csa_with_black
58     player = ShogiServer::BasicPlayer.new
59     player.name = "hoge"
60     login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-0-B,xyz", player)
61     assert_instance_of(ShogiServer::LoginCSA, login)
62     assert_equal("xyz", player.password)
63     assert_equal(@p_csa.player_id, player.player_id)
64     assert_equal("+", login.turn_preference)
65     assert_equal("floodgate-900-0", login.gamename)
66   end
67
68   def test_login_factory_csa_with_white
69     player = ShogiServer::BasicPlayer.new
70     player.name = "hoge"
71     login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-0-W,xyz", player)
72     assert_instance_of(ShogiServer::LoginCSA, login)
73     assert_equal("xyz", player.password)
74     assert_equal(@p_csa.player_id, player.player_id)
75     assert_equal("-", login.turn_preference)
76     assert_equal("floodgate-900-0", login.gamename)
77   end
78
79   def test_login_factory_csa_without_trip
80     player = ShogiServer::BasicPlayer.new
81     player.name = "hoge"
82     login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-0", player)
83     assert_instance_of(ShogiServer::LoginCSA, login)
84     assert_nil(player.password)
85     assert_equal(nil, player.player_id)
86     assert_equal("*", login.turn_preference)
87     assert_equal("floodgate-900-0", login.gamename)
88   end
89
90   def test_login_factory_csa_without_trip_with_black
91     player = ShogiServer::BasicPlayer.new
92     player.name = "hoge"
93     login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-0-B", player)
94     assert_instance_of(ShogiServer::LoginCSA, login)
95     assert_nil(player.password)
96     assert_equal(nil, player.player_id)
97     assert_equal("+", login.turn_preference)
98     assert_equal("floodgate-900-0", login.gamename)
99   end
100
101   def test_login_factory_csa_without_trip_with_white
102     player = ShogiServer::BasicPlayer.new
103     player.name = "hoge"
104     login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-0-W", player)
105     assert_instance_of(ShogiServer::LoginCSA, login)
106     assert_nil(player.password)
107     assert_equal(nil, player.player_id)
108     assert_equal("-", login.turn_preference)
109     assert_equal("floodgate-900-0", login.gamename)
110   end
111 end
112