2017-09-12 07:52:23 -04:00
|
|
|
# frozen_string_literal: true
|
2011-01-23 08:20:58 -05:00
|
|
|
begin
|
|
|
|
require_relative 'helper'
|
|
|
|
rescue LoadError
|
|
|
|
end
|
2010-05-06 02:59:24 -04:00
|
|
|
|
|
|
|
class TestFiddle < Fiddle::TestCase
|
2010-12-27 14:34:00 -05:00
|
|
|
def test_windows_constant
|
|
|
|
require 'rbconfig'
|
|
|
|
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
|
|
|
|
assert Fiddle::WINDOWS, "Fiddle::WINDOWS should be 'true' on Windows platforms"
|
|
|
|
else
|
|
|
|
refute Fiddle::WINDOWS, "Fiddle::WINDOWS should be 'false' on non-Windows platforms"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-10 19:32:05 -04:00
|
|
|
def test_dlopen_linker_script_input_linux
|
|
|
|
omit("This is only for Linux") unless RUBY_PLATFORM.match?("linux")
|
|
|
|
if Dir.glob("/usr/lib/*/libncurses.so").empty?
|
|
|
|
omit("libncurses.so is needed")
|
|
|
|
end
|
|
|
|
# libncurses.so uses INPUT() on Debian GNU/Linux
|
|
|
|
# $ cat /usr/lib/x86_64-linux-gnu/libncurses.so
|
|
|
|
# INPUT(libncurses.so.6 -ltinfo)
|
|
|
|
handle = Fiddle.dlopen("libncurses.so")
|
|
|
|
begin
|
|
|
|
assert_equal("libncurses.so",
|
|
|
|
File.basename(handle.file_name, ".*"))
|
|
|
|
ensure
|
|
|
|
handle.close
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_dlopen_linker_script_group_linux
|
|
|
|
omit("This is only for Linux") unless RUBY_PLATFORM.match?("linux")
|
|
|
|
# libc.so uses GROUP() on Debian GNU/Linux
|
|
|
|
# $ cat /usr/lib/x86_64-linux-gnu/libc.so
|
|
|
|
# /* GNU ld script
|
|
|
|
# Use the shared library, but some functions are only in
|
|
|
|
# the static library, so try that secondarily. */
|
|
|
|
# OUTPUT_FORMAT(elf64-x86-64)
|
|
|
|
# GROUP ( /lib/x86_64-linux-gnu/libc.so.6 /usr/lib/x86_64-linux-gnu/libc_nonshared.a AS_NEEDED ( /lib64/ld-linux-x86-64.so.2 ) )
|
|
|
|
handle = Fiddle.dlopen("libc.so")
|
|
|
|
begin
|
|
|
|
assert_equal("libc.so",
|
|
|
|
File.basename(handle.file_name, ".*"))
|
|
|
|
ensure
|
|
|
|
handle.close
|
|
|
|
end
|
|
|
|
end
|
2011-01-23 08:20:58 -05:00
|
|
|
end if defined?(Fiddle)
|