OSDN Git Service

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