OSDN Git Service

Bump up the revision to 20160409.
[shogi-server/shogi-server.git] / test / TC_functional.rb
index 511598c..ea3f874 100644 (file)
@@ -1,4 +1,7 @@
-require "baseclient"
+# -*- coding: windows-31j -*-
+$:.unshift File.join(File.dirname(__FILE__), "..")
+$topdir = File.expand_path File.dirname(__FILE__)
+require "test/baseclient"
 require "kconv"
 
 class TestClientAtmark < BaseClient
@@ -25,13 +28,16 @@ class TestClientAtmark < BaseClient
     path = File.join( File.dirname(__FILE__), "..", year, month, day, "*atmark-1500-0*")
     log_files = Dir.glob(path)
     assert(!log_files.empty?) 
-    log_content = File.open(log_files.sort.last).read
+    sleep 0.1
+    log_content = File.read(log_files.sort.last)
 
     # "$EVENT", "$START_TIME" and "'$END_TIME" are removed since they vary dinamically.
     should_be = <<-EOF
 V2
 N+atmark_B@p1
 N-atmark_W@p2
+'Max_Moves:256
+'Least_Time_Per_Move:0
 P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
 P2 * -HI *  *  *  *  * -KA * 
 P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
@@ -44,9 +50,9 @@ P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
 +
 'rating:atmark_B@p1+275876e34cf609db118f3d84b799a790:atmark_W@p2+275876e34cf609db118f3d84b799a790
 +2726FU
-T1
+T0
 -3334FU
-T1
+T0
 %TORYO
 'P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
 'P2 * -HI *  *  *  *  * -KA * 
@@ -67,6 +73,75 @@ EOF
   end
 end
 
+class TestHandicappedGame < BaseClient
+  # login with trip
+  def set_name
+    super
+    @game_name = "hc2p_hoge"
+    @p1_name = "B"
+    @p2_name = "W"
+  end
+
+  def test_toryo
+    result, result2 = handshake do
+      @p1.toryo
+      wait_finish
+    end
+    assert(/#LOSE/ =~ result)
+    assert(/#WIN/  =~ result2)
+
+    now = Time.now
+    year  = now.strftime("%Y")
+    month = now.strftime("%m")
+    day   = now.strftime("%d")
+    path = File.join( File.dirname(__FILE__), "..", year, month, day, "*hc2p_hoge-1500-0*")
+    log_files = Dir.glob(path)
+    assert(!log_files.empty?) 
+    sleep 0.1
+    log_content = File.read(log_files.sort.last)
+
+    # "$EVENT", "$START_TIME" and "'$END_TIME" are removed since they vary dinamically.
+    should_be = <<-EOF
+V2
+N+hc2p_hoge_B
+N-hc2p_hoge_W
+'Max_Moves:256
+'Least_Time_Per_Move:0
+P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
+P2 * -HI *  *  *  *  * -KA * 
+P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
+P4 *  *  *  *  *  *  *  *  * 
+P5 *  *  *  *  *  *  *  *  * 
+P6 *  *  *  *  *  *  *  *  * 
+P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
+P8 *  *  *  *  *  *  *  *  * 
+P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
++
+'rating:hc2p_hoge_B+275876e34cf609db118f3d84b799a790:hc2p_hoge_W+275876e34cf609db118f3d84b799a790
++2726FU
+T0
+-3334FU
+T0
+%TORYO
+'P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
+'P2 * -HI *  *  *  *  * -KA * 
+'P3-FU-FU-FU-FU-FU-FU * -FU-FU
+'P4 *  *  *  *  *  * -FU *  * 
+'P5 *  *  *  *  *  *  *  *  * 
+'P6 *  *  *  *  *  *  * +FU * 
+'P7+FU+FU+FU+FU+FU+FU+FU * +FU
+'P8 *  *  *  *  *  *  *  *  * 
+'P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
+'+
+'summary:toryo:hc2p_hoge_B lose:hc2p_hoge_W win
+EOF
+
+    log_content.gsub!(/^\$.*?\n/m, "")
+    log_content.gsub!(/^'\$.*?\n/m, "")
+    assert_equal(should_be, log_content)
+  end
+end
+
 
 class TestComment < BaseClient
   def test_toryo
@@ -318,6 +393,7 @@ class TestTwoSameMoves < CSABaseClient
       move  "+2726FU"
       move "-8384FU"
       @p2.puts "-8384FU" # ignored
+      sleep 0.1 # wait for finish of the command above
       move "+2625FU"
     end
     assert(/#ILLEGAL_MOVE/ !~ result)