OSDN Git Service

Merge remote-tracking branch 'origin/master' into wdoor-stable
[shogi-server/shogi-server.git] / test / TC_fork.rb
index 64f5f0c..6079802 100644 (file)
@@ -1,3 +1,4 @@
+$:.unshift File.dirname(__FILE__)
 $:.unshift File.join(File.dirname(__FILE__), "..")
 $topdir = File.expand_path File.dirname(__FILE__)
 require "baseclient"
@@ -15,8 +16,11 @@ class TestFork < BaseClient
   def test_wrong_game
     @admin = SocketPlayer.new "dummy", "admin", false
     @admin.connect
+    sleep 0.1
     @admin.reader
+    sleep 0.1
     @admin.login
+    sleep 0.1
 
     result, result2 = handshake do
       @admin.puts "%%FORK wronggame-900-0 buoy_WrongGame-900-0"
@@ -30,8 +34,11 @@ class TestFork < BaseClient
   def test_too_short_fork
     @admin = SocketPlayer.new "dummy", "admin", false
     @admin.connect
+    sleep 0.1
     @admin.reader
+    sleep 0.1
     @admin.login
+    sleep 0.1
 
     result, result2 = handshake do
       source_game = parse_game_name(@admin)
@@ -48,8 +55,12 @@ class TestFork < BaseClient
     
     @admin = SocketPlayer.new "dummy", "admin", "*"
     @admin.connect
+    sleep 0.1
     @admin.reader
+    sleep 0.1
     @admin.login
+    sleep 0.1
+
     assert buoy.is_new_game?("buoy_Fork-1500-0")
 
     result, result2 = handshake do
@@ -62,26 +73,90 @@ class TestFork < BaseClient
     @p1 = SocketPlayer.new "buoy_Fork", "p1", true
     @p2 = SocketPlayer.new "buoy_Fork", "p2", false
     @p1.connect
+    sleep 0.1
     @p2.connect
+    sleep 0.1
     @p1.reader
+    sleep 0.1
     @p2.reader
+    sleep 0.1
     @p1.login
+    sleep 0.1
     @p2.login
-    sleep 1
+    sleep 0.1
     @p1.game
+    sleep 0.1
     @p2.game
-    sleep 1
     @p1.agree
+    sleep 0.1
     @p2.agree
-    sleep 1
+    sleep 0.1
     assert /^Total_Time:1500/ =~ @p1.message
     assert /^Total_Time:1500/ =~ @p2.message
     @p2.move("-3334FU")
-    sleep 1
+    sleep 0.1
     @p1.toryo
-    sleep 1
+    sleep 0.1
+    @p2.logout
+    sleep 0.1
+    @p1.logout
+    sleep 0.1
+
+    @admin.logout
+  end
+
+  def test_fork2
+    buoy = ShogiServer::Buoy.new
+    
+    @admin = SocketPlayer.new "dummy", "admin", "*"
+    @admin.connect
+    sleep 0.1
+    @admin.reader
+    sleep 0.1
+    @admin.login
+    sleep 0.1
+
+    result, result2 = handshake do
+      source_game = parse_game_name(@admin)
+      sleep 0.2
+      @admin.puts "%%FORK #{source_game}" # nil for new_buoy_game name
+      sleep 1.2
+      assert /##\[FORK\]: new buoy game name: buoy_TestFork_1-1500-0/ =~ @admin.message
+    end
+
+    assert buoy.is_new_game?("buoy_TestFork_1-1500-0")
+    @p1 = SocketPlayer.new "buoy_TestFork_1", "p1", true
+    @p2 = SocketPlayer.new "buoy_TestFork_1", "p2", false
+    @p1.connect
+    sleep 0.1
+    @p2.connect
+    sleep 0.1
+    @p1.reader
+    sleep 0.1
+    @p2.reader
+    sleep 0.1
+    @p1.login
+    sleep 0.1
+    @p2.login
+    sleep 0.1
+    @p1.game
+    sleep 0.1
+    @p2.game
+    sleep 0.1
+    @p1.agree
+    sleep 0.1
+    @p2.agree
+    sleep 0.1
+    assert /^Total_Time:1500/ =~ @p1.message
+    assert /^Total_Time:1500/ =~ @p2.message
+    @p2.move("-3334FU")
+    sleep 0.1
+    @p1.toryo
+    sleep 0.1
     @p2.logout
+    sleep 0.1
     @p1.logout
+    sleep 0.1
 
     @admin.logout
   end