OSDN Git Service

Fix #37023: utils/csa-filter.rb: Allow csa-filter.rb to filter games by a winner...
[shogi-server/shogi-server.git] / test / TC_fork.rb
1 $:.unshift File.dirname(__FILE__)
2 $:.unshift File.join(File.dirname(__FILE__), "..")
3 $topdir = File.expand_path File.dirname(__FILE__)
4 require "baseclient"
5 require "shogi_server/buoy.rb"
6
7 class TestFork < BaseClient
8   def parse_game_name(player)
9     player.puts "%%LIST"
10     sleep 1
11     if /##\[LIST\] (.*)/ =~ player.message
12       return $1
13     end
14   end
15
16   def test_wrong_game
17     @admin = SocketPlayer.new "dummy", "admin", false
18     @admin.connect
19     sleep 0.1
20     @admin.reader
21     sleep 0.1
22     @admin.login
23     sleep 0.1
24
25     result, result2 = handshake do
26       @admin.puts "%%FORK wronggame-900-0 buoy_WrongGame-900-0"
27       sleep 1
28     end
29
30     assert /##\[ERROR\] wrong source game name/ =~ @admin.message
31     @admin.logout
32   end
33
34   def test_too_short_fork
35     @admin = SocketPlayer.new "dummy", "admin", false
36     @admin.connect
37     sleep 0.1
38     @admin.reader
39     sleep 0.1
40     @admin.login
41     sleep 0.1
42
43     result, result2 = handshake do
44       source_game = parse_game_name(@admin)
45       @admin.puts "%%FORK #{source_game} buoy_TooShortFork-900-0 0"
46       sleep 1
47     end
48
49     assert /##\[ERROR\] number of moves to fork is out of range/ =~ @admin.message
50     @admin.logout
51   end
52
53   def test_fork
54     buoy = ShogiServer::Buoy.new
55     
56     @admin = SocketPlayer.new "dummy", "admin", "*"
57     @admin.connect
58     sleep 0.1
59     @admin.reader
60     sleep 0.1
61     @admin.login
62     sleep 0.1
63
64     assert buoy.is_new_game?("buoy_Fork-1500-0")
65
66     result, result2 = handshake do
67       source_game = parse_game_name(@admin)
68       @admin.puts "%%FORK #{source_game} buoy_Fork-1500-0"
69       sleep 1
70     end
71
72     assert buoy.is_new_game?("buoy_Fork-1500-0")
73     @p1 = SocketPlayer.new "buoy_Fork", "p1", true
74     @p2 = SocketPlayer.new "buoy_Fork", "p2", false
75     @p1.connect
76     sleep 0.1
77     @p2.connect
78     sleep 0.1
79     @p1.reader
80     sleep 0.1
81     @p2.reader
82     sleep 0.1
83     @p1.login
84     sleep 0.1
85     @p2.login
86     sleep 0.1
87     @p1.game
88     sleep 0.1
89     @p2.game
90     @p1.agree
91     sleep 0.1
92     @p2.agree
93     sleep 0.1
94     assert /^Total_Time:1500/ =~ @p1.message
95     assert /^Total_Time:1500/ =~ @p2.message
96     @p2.move("-3334FU")
97     sleep 0.1
98     @p1.toryo
99     sleep 0.1
100     @p2.logout
101     sleep 0.1
102     @p1.logout
103     sleep 0.1
104
105     @admin.logout
106   end
107
108   def test_fork2
109     buoy = ShogiServer::Buoy.new
110     
111     @admin = SocketPlayer.new "dummy", "admin", "*"
112     @admin.connect
113     sleep 0.1
114     @admin.reader
115     sleep 0.1
116     @admin.login
117     sleep 0.1
118
119     result, result2 = handshake do
120       source_game = parse_game_name(@admin)
121       sleep 0.2
122       @admin.puts "%%FORK #{source_game}" # nil for new_buoy_game name
123       sleep 1.2
124       assert /##\[FORK\]: new buoy game name: buoy_TestFork_1-1500-0/ =~ @admin.message
125     end
126
127     assert buoy.is_new_game?("buoy_TestFork_1-1500-0")
128     @p1 = SocketPlayer.new "buoy_TestFork_1", "p1", true
129     @p2 = SocketPlayer.new "buoy_TestFork_1", "p2", false
130     @p1.connect
131     sleep 0.1
132     @p2.connect
133     sleep 0.1
134     @p1.reader
135     sleep 0.1
136     @p2.reader
137     sleep 0.1
138     @p1.login
139     sleep 0.1
140     @p2.login
141     sleep 0.1
142     @p1.game
143     sleep 0.1
144     @p2.game
145     sleep 0.1
146     @p1.agree
147     sleep 0.1
148     @p2.agree
149     sleep 0.1
150     assert /^Total_Time:1500/ =~ @p1.message
151     assert /^Total_Time:1500/ =~ @p2.message
152     @p2.move("-3334FU")
153     sleep 0.1
154     @p1.toryo
155     sleep 0.1
156     @p2.logout
157     sleep 0.1
158     @p1.logout
159     sleep 0.1
160
161     @admin.logout
162   end
163 end