Sha256: e06d70956737881c79d4c93e9e2c54b01f20727bd9924bfda913d9a0835862eb

Contents?: true

Size: 922 Bytes

Versions: 50

Compression:

Stored size: 922 Bytes

Contents

# -*- coding: utf-8 -*-

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

50 entries across 50 versions & 1 rubygems

Version Path
gettext-3.4.9 test/test_thread.rb
gettext-3.4.8 test/test_thread.rb
gettext-3.4.7 test/test_thread.rb
gettext-3.4.6 test/test_thread.rb
gettext-3.4.5 test/test_thread.rb
gettext-3.4.4 test/test_thread.rb
gettext-3.4.3 test/test_thread.rb
gettext-3.4.2 test/test_thread.rb
gettext-3.4.1 test/test_thread.rb
gettext-3.4.0 test/test_thread.rb
gettext-3.3.9 test/test_thread.rb
gettext-3.3.8 test/test_thread.rb
gettext-3.3.7 test/test_thread.rb
gettext-3.3.6 test/test_thread.rb
gettext-3.3.5 test/test_thread.rb
gettext-3.3.4 test/test_thread.rb
gettext-3.3.3 test/test_thread.rb
gettext-3.3.2 test/test_thread.rb
gettext-3.3.1 test/test_thread.rb
gettext-3.3.0 test/test_thread.rb