Sha256: 6882735ca57969c9c179f650cf29ab5798ba47dd196ab3e8fd2886a2538c31ae

Contents?: true

Size: 929 Bytes

Versions: 13

Compression:

Stored size: 929 Bytes

Contents

require 'testlib/helper.rb'
require 'thread'

class TestThread < Test::Unit::TestCase
  include GetText

  bindtextdomain "test1", :path => "locale"

  def setup
    Locale.init(:driver => :env)
    @mutex = Mutex.new
  end

  def invoke_thread(tag, language, sleep_time)
    Thread.start do
      @mutex.synchronize {
        Thread.current["language"] = language
        GetText.current_locale = tag
      }
      (1..10).each do |v|
        @mutex.synchronize{
          assert_equal Thread.current["language"], _("language") 
        }
        print "."
        $stdout.flush
        sleep sleep_time
      end
    end
  end

  def test_thread
    th1 = invoke_thread("ja_JP.eucJP", "japanese", 0.4)
    th2 = invoke_thread("fr", "french", 0.3)
    th3 = invoke_thread("en", "language", 0.1)
    th4 = invoke_thread("zh_CN", "language", 0.2) # No translation.
    th1.join
    th2.join   
    th3.join
    th4.join
  end
end

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
experteer-gettext-2.0.4.1 test/test_thread.rb
experteer-gettext-2.0.4.2 test/test_thread.rb
experteer-gettext-2.0.4 test/test_thread.rb
fair-gettext-2.0.7 test/test_thread.rb
fair-gettext-2.0.6 test/test_thread.rb
fair-gettext-2.0.5 test/test_thread.rb
fair-gettext-2.0.4 test/test_thread.rb
fair-gettext-2.0.3 test/test_thread.rb
fair-gettext-2.0.2 test/test_thread.rb
gettext-2.1.0 test/test_thread.rb
gettext-2.0.2 test/test_thread.rb
gettext-2.0.3 test/test_thread.rb
gettext-2.0.4 test/test_thread.rb