File: test_fiddle.rb

package info (click to toggle)
ruby3.3 3.3.8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 153,620 kB
  • sloc: ruby: 1,244,308; ansic: 836,474; yacc: 28,074; pascal: 6,748; sh: 3,913; python: 1,719; cpp: 1,158; makefile: 742; asm: 712; javascript: 394; lisp: 97; perl: 62; awk: 36; sed: 23; xml: 4
file content (58 lines) | stat: -rw-r--r-- 1,936 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# frozen_string_literal: true
begin
  require_relative 'helper'
rescue LoadError
end

class TestFiddle < Fiddle::TestCase
  def test_nil_true_etc
    assert_equal Fiddle::Qtrue, Fiddle.dlwrap(true)
    assert_equal Fiddle::Qfalse, Fiddle.dlwrap(false)
    assert_equal Fiddle::Qnil, Fiddle.dlwrap(nil)
    assert Fiddle::Qundef
  end

  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

  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, ".*").gsub(/\.so.\d+/,'.so'))
    ensure
      handle.close
    end
  end
end if defined?(Fiddle)