OSDN Git Service

Fix #36821: Allow to customize maximum lenght of a login indentifier
[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 $options ||= {}
9
10 class ShogiServer::BasicPlayer
11   attr_accessor :protocol
12 end
13
14
15 class TestLogin < Test::Unit::TestCase 
16   def setup
17     @p_csa = ShogiServer::BasicPlayer.new
18     @p_csa.name = "hoge"
19     @p_x1 = ShogiServer::BasicPlayer.new
20     @p_x1.name = "hoge"
21     @csa = ShogiServer::LoginCSA.new(@p_csa,"floodgate-900-0,xyz")
22     @x1 = ShogiServer::Loginx1.new(@p_x1, "xyz")
23
24     $options["max-identifier"] = ShogiServer::Default_Max_Identifier_Length
25   end
26
27   def test_player_id
28     assert(@p_x1.player_id == @p_csa.player_id)
29   end
30
31   def test_good_identifier
32     assert_true(ShogiServer::Login::good_identifier? "hoge")
33     assert_true(ShogiServer::Login::good_identifier? "12345678901234567890123456789012")
34
35     $options["max-identifier"] = 128
36     assert_true(ShogiServer::Login::good_identifier? "0"*128)
37     assert_false(ShogiServer::Login::good_identifier? "0"*129)
38   end
39
40   def test_login_factory_x1
41     player = ShogiServer::BasicPlayer.new
42     player.name = "hoge"
43     login = ShogiServer::Login::factory("LOGIN hoge xyz x1", player)
44     assert_instance_of(ShogiServer::Loginx1, login)
45     assert_equal("xyz", player.password)
46     assert_equal(@p_x1.player_id, player.player_id)
47   end
48
49   def test_login_factory_csa
50     player = ShogiServer::BasicPlayer.new
51     player.name = "hoge"
52     login = ShogiServer::Login::factory("LOGIN hoge floodagate-900-0,xyz", player)
53     assert_instance_of(ShogiServer::LoginCSA, login)
54     assert_equal("xyz", player.password)
55     assert_equal(@p_csa.player_id, player.player_id)
56     assert_equal("*", login.turn_preference)
57   end
58
59   def test_login_factory_csa_fischer
60     player = ShogiServer::BasicPlayer.new
61     player.name = "hoge"
62     login = ShogiServer::Login::factory("LOGIN hoge floodagate-600-10F,xyz", player)
63     assert_instance_of(ShogiServer::LoginCSA, login)
64     assert_equal("xyz", player.password)
65     assert_equal(@p_csa.player_id, player.player_id)
66     assert_equal("*", login.turn_preference)
67   end
68
69   def test_login_factory_csa_no_gamename
70     player = ShogiServer::BasicPlayer.new
71     player.name = "hoge"
72     login = ShogiServer::Login::factory("LOGIN hoge xyz", player)
73     assert_instance_of(ShogiServer::LoginCSA, login)
74     assert_equal("xyz", player.password)
75     assert_equal(@p_csa.player_id, player.player_id)
76     assert_equal("*", login.turn_preference)
77     assert_equal(ShogiServer::Default_Game_Name, login.gamename)
78   end
79
80   def test_login_factory_csa_with_black
81     player = ShogiServer::BasicPlayer.new
82     player.name = "hoge"
83     login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-0-B,xyz", player)
84     assert_instance_of(ShogiServer::LoginCSA, login)
85     assert_equal("xyz", player.password)
86     assert_equal(@p_csa.player_id, player.player_id)
87     assert_equal("+", login.turn_preference)
88     assert_equal("floodgate-900-0", login.gamename)
89   end
90
91   def test_login_factory_csa_with_black_fischer
92     player = ShogiServer::BasicPlayer.new
93     player.name = "hoge"
94     login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-10F-B,xyz", player)
95     assert_instance_of(ShogiServer::LoginCSA, login)
96     assert_equal("xyz", player.password)
97     assert_equal(@p_csa.player_id, player.player_id)
98     assert_equal("+", login.turn_preference)
99     assert_equal("floodgate-900-10F", login.gamename)
100   end
101
102   def test_login_factory_csa_with_white
103     player = ShogiServer::BasicPlayer.new
104     player.name = "hoge"
105     login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-0-W,xyz", player)
106     assert_instance_of(ShogiServer::LoginCSA, login)
107     assert_equal("xyz", player.password)
108     assert_equal(@p_csa.player_id, player.player_id)
109     assert_equal("-", login.turn_preference)
110     assert_equal("floodgate-900-0", login.gamename)
111   end
112
113   def test_login_factory_csa_with_white_fischer
114     player = ShogiServer::BasicPlayer.new
115     player.name = "hoge"
116     login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-10F-W,xyz", player)
117     assert_instance_of(ShogiServer::LoginCSA, login)
118     assert_equal("xyz", player.password)
119     assert_equal(@p_csa.player_id, player.player_id)
120     assert_equal("-", login.turn_preference)
121     assert_equal("floodgate-900-10F", login.gamename)
122   end
123
124   def test_login_factory_csa_without_trip
125     player = ShogiServer::BasicPlayer.new
126     player.name = "hoge"
127     login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-0", player)
128     assert_instance_of(ShogiServer::LoginCSA, login)
129     assert_nil(player.password)
130     assert_equal(nil, player.player_id)
131     assert_equal("*", login.turn_preference)
132     assert_equal("floodgate-900-0", login.gamename)
133   end
134
135   def test_login_factory_csa_without_trip_with_black
136     player = ShogiServer::BasicPlayer.new
137     player.name = "hoge"
138     login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-0-B", player)
139     assert_instance_of(ShogiServer::LoginCSA, login)
140     assert_nil(player.password)
141     assert_equal(nil, player.player_id)
142     assert_equal("+", login.turn_preference)
143     assert_equal("floodgate-900-0", login.gamename)
144   end
145
146   def test_login_factory_csa_without_trip_with_white
147     player = ShogiServer::BasicPlayer.new
148     player.name = "hoge"
149     login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-0-W", player)
150     assert_instance_of(ShogiServer::LoginCSA, login)
151     assert_nil(player.password)
152     assert_equal(nil, player.player_id)
153     assert_equal("-", login.turn_preference)
154     assert_equal("floodgate-900-0", login.gamename)
155   end
156 end
157