• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1require 'google/protobuf'
2require 'test/unit'
3
4class BackendTest < Test::Unit::TestCase
5  # Verifies the implementation of Protobuf is the preferred one.
6  # See protobuf.rb for the logic that defines PREFER_FFI.
7  def test_prefer_ffi_aligns_with_implementation
8    expected = Google::Protobuf::PREFER_FFI ? :FFI : :NATIVE
9    assert_equal expected, Google::Protobuf::IMPLEMENTATION
10  end
11
12  def test_prefer_ffi
13    unless ENV['PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION'] =~ /ffi/i
14      omit"FFI implementation requires environment variable PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION=FFI to activate."
15    end
16    assert_equal true, Google::Protobuf::PREFER_FFI
17  end
18  def test_ffi_implementation
19    unless ENV['PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION'] =~ /ffi/i
20      omit "FFI implementation requires environment variable PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION=FFI to activate."
21    end
22    assert_equal :FFI, Google::Protobuf::IMPLEMENTATION
23  end
24
25  def test_prefer_native
26    if ENV.include?('PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION') and ENV['PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION'] !~ /native/i
27      omit"Native implementation requires omitting environment variable PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION or setting it to `NATIVE` to activate."
28    end
29    assert_equal false, Google::Protobuf::PREFER_FFI
30  end
31  def test_native_implementation
32    if ENV.include?('PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION') and ENV['PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION'] !~ /native/i
33      omit"Native implementation requires omitting environment variable PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION or setting it to `NATIVE` to activate."
34    end
35    assert_equal :NATIVE, Google::Protobuf::IMPLEMENTATION
36  end
37end
38