OSDN Git Service

2cbf06077132c69597afc2ea9b05527e67fbfc6e
[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_fischer
47     player = ShogiServer::BasicPlayer.new
48     player.name = "hoge"
49     login = ShogiServer::Login::factory("LOGIN hoge floodagate-600-10F,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   end
55
56   def test_login_factory_csa_no_gamename
57     player = ShogiServer::BasicPlayer.new
58     player.name = "hoge"
59     login = ShogiServer::Login::factory("LOGIN hoge xyz", player)
60     assert_instance_of(ShogiServer::LoginCSA, login)
61     assert_equal("xyz", player.password)
62     assert_equal(@p_csa.player_id, player.player_id)
63     assert_equal("*", login.turn_preference)
64     assert_equal(ShogiServer::Default_Game_Name, login.gamename)
65   end
66
67   def test_login_factory_csa_with_black
68     player = ShogiServer::BasicPlayer.new
69     player.name = "hoge"
70     login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-0-B,xyz", player)
71     assert_instance_of(ShogiServer::LoginCSA, login)
72     assert_equal("xyz", player.password)
73     assert_equal(@p_csa.player_id, player.player_id)
74     assert_equal("+", login.turn_preference)
75     assert_equal("floodgate-900-0", login.gamename)
76   end
77
78   def test_login_factory_csa_with_black_fischer
79     player = ShogiServer::BasicPlayer.new
80     player.name = "hoge"
81     login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-10F-B,xyz", player)
82     assert_instance_of(ShogiServer::LoginCSA, login)
83     assert_equal("xyz", player.password)
84     assert_equal(@p_csa.player_id, player.player_id)
85     assert_equal("+", login.turn_preference)
86     assert_equal("floodgate-900-10F", login.gamename)
87   end
88
89   def test_login_factory_csa_with_white
90     player = ShogiServer::BasicPlayer.new
91     player.name = "hoge"
92     login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-0-W,xyz", player)
93     assert_instance_of(ShogiServer::LoginCSA, login)
94     assert_equal("xyz", player.password)
95     assert_equal(@p_csa.player_id, player.player_id)
96     assert_equal("-", login.turn_preference)
97     assert_equal("floodgate-900-0", login.gamename)
98   end
99
100   def test_login_factory_csa_with_white
101     player = ShogiServer::BasicPlayer.new
102     player.name = "hoge"
103     login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-10F-W,xyz", player)
104     assert_instance_of(ShogiServer::LoginCSA, login)
105     assert_equal("xyz", player.password)
106     assert_equal(@p_csa.player_id, player.player_id)
107     assert_equal("-", login.turn_preference)
108     assert_equal("floodgate-900-10F", login.gamename)
109   end
110
111   def test_login_factory_csa_without_trip
112     player = ShogiServer::BasicPlayer.new
113     player.name = "hoge"
114     login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-0", player)
115     assert_instance_of(ShogiServer::LoginCSA, login)
116     assert_nil(player.password)
117     assert_equal(nil, player.player_id)
118     assert_equal("*", login.turn_preference)
119     assert_equal("floodgate-900-0", login.gamename)
120   end
121
122   def test_login_factory_csa_without_trip_with_black
123     player = ShogiServer::BasicPlayer.new
124     player.name = "hoge"
125     login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-0-B", player)
126     assert_instance_of(ShogiServer::LoginCSA, login)
127     assert_nil(player.password)
128     assert_equal(nil, player.player_id)
129     assert_equal("+", login.turn_preference)
130     assert_equal("floodgate-900-0", login.gamename)
131   end
132
133   def test_login_factory_csa_without_trip_with_white
134     player = ShogiServer::BasicPlayer.new
135     player.name = "hoge"
136     login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-0-W", player)
137     assert_instance_of(ShogiServer::LoginCSA, login)
138     assert_nil(player.password)
139     assert_equal(nil, player.player_id)
140     assert_equal("-", login.turn_preference)
141     assert_equal("floodgate-900-0", login.gamename)
142   end
143 end
144