From fcbf63e62c627deae76c1b8cb8c0876c536ed811 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Mon, 16 Mar 2020 18:49:26 +0900 Subject: Fresh start --- jni/ruby/test/mkmf/base.rb | 139 +++++++++++++++++++++++++++++ jni/ruby/test/mkmf/test_config.rb | 16 ++++ jni/ruby/test/mkmf/test_constant.rb | 37 ++++++++ jni/ruby/test/mkmf/test_convertible.rb | 34 +++++++ jni/ruby/test/mkmf/test_find_executable.rb | 50 +++++++++++ jni/ruby/test/mkmf/test_flags.rb | 56 ++++++++++++ jni/ruby/test/mkmf/test_framework.rb | 48 ++++++++++ jni/ruby/test/mkmf/test_have_func.rb | 14 +++ jni/ruby/test/mkmf/test_have_library.rb | 55 ++++++++++++ jni/ruby/test/mkmf/test_have_macro.rb | 35 ++++++++ jni/ruby/test/mkmf/test_libs.rb | 86 ++++++++++++++++++ jni/ruby/test/mkmf/test_signedness.rb | 29 ++++++ jni/ruby/test/mkmf/test_sizeof.rb | 47 ++++++++++ 13 files changed, 646 insertions(+) create mode 100644 jni/ruby/test/mkmf/base.rb create mode 100644 jni/ruby/test/mkmf/test_config.rb create mode 100644 jni/ruby/test/mkmf/test_constant.rb create mode 100644 jni/ruby/test/mkmf/test_convertible.rb create mode 100644 jni/ruby/test/mkmf/test_find_executable.rb create mode 100644 jni/ruby/test/mkmf/test_flags.rb create mode 100644 jni/ruby/test/mkmf/test_framework.rb create mode 100644 jni/ruby/test/mkmf/test_have_func.rb create mode 100644 jni/ruby/test/mkmf/test_have_library.rb create mode 100644 jni/ruby/test/mkmf/test_have_macro.rb create mode 100644 jni/ruby/test/mkmf/test_libs.rb create mode 100644 jni/ruby/test/mkmf/test_signedness.rb create mode 100644 jni/ruby/test/mkmf/test_sizeof.rb (limited to 'jni/ruby/test/mkmf') diff --git a/jni/ruby/test/mkmf/base.rb b/jni/ruby/test/mkmf/base.rb new file mode 100644 index 0000000..ea6a9d8 --- /dev/null +++ b/jni/ruby/test/mkmf/base.rb @@ -0,0 +1,139 @@ +$extmk = true + +require 'test/unit' +require 'mkmf' +require 'tmpdir' + +$extout = '$(topdir)/'+RbConfig::CONFIG["EXTOUT"] +RbConfig::CONFIG['topdir'] = CONFIG['topdir'] = File.expand_path(CONFIG['topdir']) +RbConfig::CONFIG["extout"] = CONFIG["extout"] = $extout +$INCFLAGS << " -I." +$extout_prefix = "$(extout)$(target_prefix)/" + +class TestMkmf < Test::Unit::TestCase + MKMFLOG = proc {File.read("mkmf.log") rescue ""} + + class Capture + attr_accessor :origin + def initialize + @buffer = "" + @filter = nil + @out = true + @origin = nil + end + def clear + @buffer.clear + end + def flush + STDOUT.print @filter ? @filter.call(@buffer) : @buffer + clear + end + def reopen(io) + case io + when Capture + initialize_copy(io) + when File + @out = false + @origin.reopen(io) if @origin + when IO + @out = true + @origin.reopen(io) if @origin + else + @out = false + end + end + def filter(&block) + @filter = block + end + def write(s) + @buffer << s if @out + end + end +end + +module TestMkmf::Base + attr_reader :stdout + + def mkmflog(msg) + proc {MKMFLOG[] << msg} + end + + def setup + @rbconfig = rbconfig0 = RbConfig::CONFIG + @mkconfig = mkconfig0 = RbConfig::MAKEFILE_CONFIG + rbconfig = { + "hdrdir" => $hdrdir, + "srcdir" => $srcdir, + "topdir" => $topdir, + } + mkconfig = { + "hdrdir" => "$(top_srcdir)/include", + "srcdir" => "$(top_srcdir)", + "topdir" => $topdir, + } + rbconfig0.each_pair {|key, val| rbconfig[key] ||= val.dup} + mkconfig0.each_pair {|key, val| mkconfig[key] ||= val.dup} + RbConfig.module_eval { + remove_const(:CONFIG) + const_set(:CONFIG, rbconfig) + remove_const(:MAKEFILE_CONFIG) + const_set(:MAKEFILE_CONFIG, mkconfig) + } + MakeMakefile.class_eval { + remove_const(:CONFIG) + const_set(:CONFIG, mkconfig) + } + @tmpdir = Dir.mktmpdir + @curdir = Dir.pwd + @mkmfobj = Object.new + @stdout = TestMkmf::Capture.new + Dir.chdir(@tmpdir) + @quiet, Logging.quiet = Logging.quiet, true + init_mkmf + $INCFLAGS[0, 0] = "-I. " + end + + def teardown + rbconfig0 = @rbconfig + mkconfig0 = @mkconfig + RbConfig.module_eval { + remove_const(:CONFIG) + const_set(:CONFIG, rbconfig0) + remove_const(:MAKEFILE_CONFIG) + const_set(:MAKEFILE_CONFIG, mkconfig0) + } + MakeMakefile.class_eval { + remove_const(:CONFIG) + const_set(:CONFIG, mkconfig0) + } + Logging.quiet = @quiet + Logging.log_close + FileUtils.rm_f("mkmf.log") + Dir.chdir(@curdir) + FileUtils.rm_rf(@tmpdir) + end + + def mkmf(*args, &block) + @stdout.clear + stdout, @stdout.origin, $stdout = @stdout.origin, $stdout, @stdout + @mkmfobj.instance_eval(*args, &block) + ensure + $stdout, @stdout.origin = @stdout.origin, stdout + end + + def config_value(name) + create_tmpsrc("---config-value=#{name}") + xpopen(cpp_command('')) do |f| + f.grep(/^---config-value=(.*)/) {return $1} + end + nil + end +end + +class TestMkmf + include TestMkmf::Base + + def assert_separately(args, src, *rest) + super(args + ["-r#{__FILE__}"], "extend TestMkmf::Base; setup\n#{src}", *rest) + end +end diff --git a/jni/ruby/test/mkmf/test_config.rb b/jni/ruby/test/mkmf/test_config.rb new file mode 100644 index 0000000..7bf537e --- /dev/null +++ b/jni/ruby/test/mkmf/test_config.rb @@ -0,0 +1,16 @@ +$extmk = true + +require 'test/unit' +require 'mkmf' + +class TestMkmf < Test::Unit::TestCase + class TestConfig < Test::Unit::TestCase + def test_dir_config + bug8074 = '[Bug #8074]' + lib = RbConfig.expand(RbConfig::MAKEFILE_CONFIG["libdir"], "exec_prefix"=>"") + assert_separately %w[-rmkmf - -- --with-foo-dir=/test/foo], %{ + assert_equal(%w[/test/foo/include /test/foo#{lib}], dir_config("foo"), #{bug8074.dump}) + } + end + end +end diff --git a/jni/ruby/test/mkmf/test_constant.rb b/jni/ruby/test/mkmf/test_constant.rb new file mode 100644 index 0000000..fd1f940 --- /dev/null +++ b/jni/ruby/test/mkmf/test_constant.rb @@ -0,0 +1,37 @@ +require_relative 'base' + +class TestMkmf + class TestTryConstant < TestMkmf + def test_simple + assert_equal( 0, mkmf {try_constant("0")}, MKMFLOG) + assert_equal( 1, mkmf {try_constant("1")}, MKMFLOG) + assert_equal(-1, mkmf {try_constant("-1")}, MKMFLOG) + end + + def test_sizeof + assert_equal(config_value("SIZEOF_INT").to_i, mkmf {try_constant("sizeof(int)")}, MKMFLOG) + assert_equal(config_value("SIZEOF_LONG").to_i, mkmf {try_constant("sizeof(long)")}, MKMFLOG) + assert_equal(config_value("SIZEOF_VOIDP").to_i, mkmf {try_constant("sizeof(void*)")}, MKMFLOG) + assert_equal(config_value("SIZEOF_VALUE").to_i, mkmf {try_constant("sizeof(Qnil)")}, MKMFLOG) + end + + def test_long + sizeof_int = config_value("SIZEOF_INT").to_i + sizeof_long = config_value("SIZEOF_LONG").to_i + if sizeof_long > sizeof_int + type = 'long' + else + sizeof_long_long = config_value("SIZEOF_LONG_LONG").to_i + return if !sizeof_long_long or sizeof_long_long <= sizeof_int + type = 'LONG_LONG' + end + + decl = "#define CONFTEST_VALUE (unsigned #{type})(((unsigned #{type})1)<<(CHAR_BIT*sizeof(int)))" + assert_operator(mkmf {try_constant("CONFTEST_VALUE", [[decl]])}, :>, 0, MKMFLOG) + end + + def test_large_unsigned + assert_operator(mkmf {try_constant("1U<<(CHAR_BIT*sizeof(int)-1)")}, :>, 0, MKMFLOG) + end + end +end diff --git a/jni/ruby/test/mkmf/test_convertible.rb b/jni/ruby/test/mkmf/test_convertible.rb new file mode 100644 index 0000000..eec2d12 --- /dev/null +++ b/jni/ruby/test/mkmf/test_convertible.rb @@ -0,0 +1,34 @@ +require_relative 'base' + +class TestMkmf + class TestConvertible < TestMkmf + def test_typeof_builtin + ["", ["signed ", ""], "unsigned "].each do |signed, prefix| + %w[short int long].each do |type| + assert_equal((prefix || signed)+type, + mkmf {convertible_int(signed+type)}, MKMFLOG) + end + end + end + + def test_typeof_typedef + ["", ["signed ", ""], "unsigned "].each do |signed, prefix| + %w[short int long].each do |type| + open("confdefs.h", "w") {|f| + f.puts "typedef #{signed}#{type} test1_t;" + } + $defs.clear + assert_equal((prefix || signed)+type, + mkmf {convertible_int("test1_t", "confdefs.h")}, MKMFLOG) + (u = signed[/^u/]) and u.upcase! + assert_include($defs, "-DTYPEOF_TEST1_T="+"#{prefix||signed}#{type}".quote) + assert_include($defs, "-DPRI_TEST1T_PREFIX=PRI_#{type.upcase}_PREFIX") + assert_include($defs, "-DTEST1T2NUM=#{u}#{type.upcase}2NUM") + assert_include($defs, "-DNUM2TEST1T=NUM2#{u}#{type.upcase}") + end + end + ensure + File.unlink("confdefs.h") + end + end +end diff --git a/jni/ruby/test/mkmf/test_find_executable.rb b/jni/ruby/test/mkmf/test_find_executable.rb new file mode 100644 index 0000000..fe45ef2 --- /dev/null +++ b/jni/ruby/test/mkmf/test_find_executable.rb @@ -0,0 +1,50 @@ +require_relative 'base' + +class TestMkmf + class TestFindExecutable < TestMkmf + def setup + super + @path, ENV["PATH"] = ENV["PATH"], @tmpdir + end + + def teardown + ENV["PATH"] = @path + super + end + + def test_find_executable + bug2669 = '[ruby-core:27912]' + name = "foobar#{$$}#{rand(1000)}" + exts = mkmf {self.class::CONFIG['EXECUTABLE_EXTS']}.split + stdout.filter {|s| s.sub(name, "")} + exts[0] ||= "" + exts.each do |ext| + full = name+ext + begin + open(full, "w") {|ff| ff.chmod(0755)} + result = mkmf {find_executable(name)} + ensure + File.unlink(full) + end + assert_equal("#{@tmpdir}/#{name}#{ext}", result, bug2669) + end + end + + def test_find_executable_dir + name = "foobar#{$$}#{rand(1000)}" + exts = mkmf {self.class::CONFIG['EXECUTABLE_EXTS']}.split + stdout.filter {|s| s.sub(name, "")} + exts[0] ||= "" + exts.each do |ext| + full = name+ext + begin + Dir.mkdir(full) + result = mkmf {find_executable(name)} + ensure + Dir.rmdir(full) + end + assert_nil(result) + end + end + end +end diff --git a/jni/ruby/test/mkmf/test_flags.rb b/jni/ruby/test/mkmf/test_flags.rb new file mode 100644 index 0000000..e49d474 --- /dev/null +++ b/jni/ruby/test/mkmf/test_flags.rb @@ -0,0 +1,56 @@ +require_relative 'base' + +class TestMkmf + class TestFlags < TestMkmf + def test_valid_warnflags + val = $extmk + warnflags = $warnflags + makefile = mkmf do + $extmk = false + self.class::CONFIG['warnflags'] = %w"-Wextra + -Wno-unused-parameter -Wno-parentheses -Wno-long-long + -Wno-missing-field-initializers -Werror=pointer-arith + -Werror=write-strings -Werror=declaration-after-statement + -Werror=shorten-64-to-32 + -Werror-implicit-function-declaration + ".join(' ') + self.class::CONFIG['GCC'] = 'yes' + init_mkmf(self.class::CONFIG) + configuration '.' + end + generated_flags = makefile.grep(/warnflags/).first[/^warnflags = (.*)$/, 1].split + + assert_equal %w" + -Wextra -Wno-unused-parameter -Wno-parentheses + -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith + -Wwrite-strings -Wdeclaration-after-statement + -Wshorten-64-to-32 -Wimplicit-function-declaration + ", generated_flags + + ensure + $warnflags = warnflags + $extmk = val + end + + def test_try_ldflag_invalid_opt + assert_separately([], <<-'end;') #do + assert(!try_ldflags("nosuch.c"), TestMkmf::MKMFLOG) + assert(have_devel?, TestMkmf::MKMFLOG) + end; + end + + def test_try_cflag_invalid_opt + assert_separately([], <<-'end;') #do + assert(!try_cflags("nosuch.c"), TestMkmf::MKMFLOG) + assert(have_devel?, TestMkmf::MKMFLOG) + end; + end + + def test_try_cppflag_invalid_opt + assert_separately([], <<-'end;') #do + assert(!try_cppflags("nosuch.c"), TestMkmf::MKMFLOG) + assert(have_devel?, TestMkmf::MKMFLOG) + end; + end + end +end diff --git a/jni/ruby/test/mkmf/test_framework.rb b/jni/ruby/test/mkmf/test_framework.rb new file mode 100644 index 0000000..cad6b05 --- /dev/null +++ b/jni/ruby/test/mkmf/test_framework.rb @@ -0,0 +1,48 @@ +require_relative 'base' + +class TestMkmf + class TestHaveFramework < TestMkmf + def create_framework(fw, hdrname = "#{fw}.h") + Dir.mktmpdir("frameworks") do |dir| + fwdir = "#{dir}/#{fw}.framework" + hdrdir = "#{fwdir}/Headers" + FileUtils.mkdir_p(hdrdir) + File.write("#{hdrdir}/#{hdrname}", "") + src = "#{fwdir}/main.c" + File.write(src, "void #{fw}(void) {}") + cmd = LINK_SO.dup + RbConfig.expand(cmd, RbConfig::CONFIG.merge("OBJS"=>src)) + cmd.gsub!("$@", "#{fwdir}/#{fw}") + cmd.gsub!(/ -bundle /, ' -dynamiclib ') + assert(xsystem(cmd), MKMFLOG) + $INCFLAGS << " " << "-F#{dir}".quote + yield fw, hdrname + end + end + + def test_core_foundation_framework + assert(have_framework("CoreFoundation"), mkmflog("try as Objective-C")) + end + + def test_multi_frameworks + assert(have_framework("CoreFoundation"), mkmflog("try as Objective-C")) + create_framework("MkmfTest") do |fw| + assert(have_framework(fw), MKMFLOG) + end + end + + def test_empty_framework + create_framework("MkmfTest") do |fw| + assert(have_framework(fw), MKMFLOG) + end + end + + def test_different_name_header + _bug8593 = '[ruby-core:55745] [Bug #8593]' + create_framework("MkmfTest", "test_mkmf.h") do |fw, hdrname| + assert(!have_framework(fw), MKMFLOG) + assert(have_framework([fw, hdrname]), MKMFLOG) + end + end + end +end if /darwin/ =~ RUBY_PLATFORM diff --git a/jni/ruby/test/mkmf/test_have_func.rb b/jni/ruby/test/mkmf/test_have_func.rb new file mode 100644 index 0000000..8049ffb --- /dev/null +++ b/jni/ruby/test/mkmf/test_have_func.rb @@ -0,0 +1,14 @@ +require_relative 'base' +require 'tempfile' + +class TestMkmf + class TestHaveFunc < TestMkmf + def test_have_func + assert_equal(true, have_func("ruby_init"), MKMFLOG) + end + + def test_not_have_func + assert_equal(false, have_func("no_ruby_init"), MKMFLOG) + end + end +end diff --git a/jni/ruby/test/mkmf/test_have_library.rb b/jni/ruby/test/mkmf/test_have_library.rb new file mode 100644 index 0000000..bf17b85 --- /dev/null +++ b/jni/ruby/test/mkmf/test_have_library.rb @@ -0,0 +1,55 @@ +require_relative 'base' +require 'tempfile' + +class TestMkmf + class TestHaveLibrary < TestMkmf + LIBRARY_NAME = 'mkmftest' + HEADER_NAME = "#{LIBRARY_NAME}.h" + FUNC_NAME = 'ruby_mkmftest_foo' + ARPREFIX = config_string('LIBRUBY_A') {|lib| lib[/\A\w+/]} + + def create_library(libname = LIBRARY_NAME) + lib = "#{ARPREFIX}#{libname}.#{$LIBEXT}" + open(HEADER_NAME, "w") do |hdr| + hdr.puts "void #{FUNC_NAME}(void);" + hdr.puts "void #{FUNC_NAME}_fake(void);" + end + create_tmpsrc("#include \"#{HEADER_NAME}\"\n""void #{FUNC_NAME}(void) {}") + assert(xsystem(cc_command), "compile failed: #{cc_command}") + command = "#{CONFIG['AR']} #{config_string('ARFLAGS') || 'cru '}#{lib} #{CONFTEST}.#{$OBJEXT}" + assert(xsystem(command), "making library failed: #{command}") + File.unlink("#{CONFTEST}.#{$OBJEXT}") + config_string('RANLIB') do |ranlib| + command = "#{ranlib} #{lib}" + assert(xsystem(command), "ranlib failed: #{command}") + end + end + + def assert_have_library(*args) + assert_equal(true, have_library(LIBRARY_NAME, *args), MKMFLOG) + end + + def assert_not_have_library(*args) + assert_equal(false, have_library(LIBRARY_NAME, *args), MKMFLOG) + end + + def test_have_library + create_library + assert_have_library + end + + def test_have_library_with_name + create_library + assert_have_library(FUNC_NAME, HEADER_NAME) + end + + def test_not_have_library + assert_not_have_library + end + + def test_not_have_library_with_name + create_library + assert_not_have_library("#{FUNC_NAME}_fake", HEADER_NAME) + end + end +end diff --git a/jni/ruby/test/mkmf/test_have_macro.rb b/jni/ruby/test/mkmf/test_have_macro.rb new file mode 100644 index 0000000..43c4029 --- /dev/null +++ b/jni/ruby/test/mkmf/test_have_macro.rb @@ -0,0 +1,35 @@ +require_relative 'base' +require 'tempfile' + +class TestMkmf + class TestHaveMacro < TestMkmf + MACRO_NAME = "RUBY_MKMFTEST_FOOBAR" + + def test_have_macro_opt + assert_equal(true, have_macro(MACRO_NAME, nil, "-D#{MACRO_NAME}"), MKMFLOG) + end + + def test_have_macro_header + Tempfile.create(%w"test_mkmf .h", ".") do |tmp| + tmp.puts("#undef #{MACRO_NAME}") + tmp.puts("#define #{MACRO_NAME} 1") + tmp.close + base = File.basename(tmp.path) + assert_equal(true, have_macro(MACRO_NAME, base, "-I."), MKMFLOG) + end + end + + def test_not_have_macro_opt + assert_equal(false, have_macro(MACRO_NAME, nil, "-U#{MACRO_NAME}"), MKMFLOG) + end + + def test_not_have_macro_header + Tempfile.create(%w"test_mkmf .h", ".") do |tmp| + tmp.puts("#undef #{MACRO_NAME}") + tmp.close + base = File.basename(tmp.path) + assert_equal(false, have_macro(MACRO_NAME, base, "-I."), MKMFLOG) + end + end + end +end diff --git a/jni/ruby/test/mkmf/test_libs.rb b/jni/ruby/test/mkmf/test_libs.rb new file mode 100644 index 0000000..27674df --- /dev/null +++ b/jni/ruby/test/mkmf/test_libs.rb @@ -0,0 +1,86 @@ +require_relative 'base' + +class TestMkmf + class TestLibs < TestMkmf + def test_split_libs + assert_equal(%w[-lfoo -lbar], split_libs("-lfoo -lbar")) + assert_equal(%w[-ObjC -framework\ Ruby], split_libs("-ObjC -framework Ruby"), 'Bug #6987') + end + + def assert_in_order(array, x, y, mesg = nil) + mesg = "#{x} must proceed to #{y}#{': ' if mesg}#{mesg}" + assert_operator(array.index(x), :<, array.rindex(y), mesg) + end + + def test_merge_simple + bug = '[ruby-dev:21765]' + assert_equal([], merge_libs(%w[])) + assert_equal(%w[a b], merge_libs(%w[a], %w[b])) + array = merge_libs(%w[a c], %w[b]) + assert_in_order(array, "a", "c", bug) + end + + def test_merge_seq + bug = '[ruby-dev:21765]' + array = merge_libs(%w[a c d], %w[c b e]) + assert_in_order(array, "a", "c", bug) + assert_in_order(array, "c", "d", bug) + assert_in_order(array, "c", "b", bug) + assert_in_order(array, "b", "e", bug) + end + + def test_merge_seq_pre + bug = '[ruby-dev:21765]' + array = merge_libs(%w[a c d], %w[b c d e]) + assert_in_order(array, "a", "c", bug) + assert_in_order(array, "c", "d", bug) + assert_in_order(array, "b", "c", bug) + assert_in_order(array, "d", "e", bug) + end + + def test_merge_cyclic + bug = '[ruby-dev:21765]' + array = merge_libs(%w[a c d], %w[b c b]) + assert_in_order(array, "a", "c", bug) + assert_in_order(array, "c", "d", bug) + assert_in_order(array, "b", "c", bug) + assert_in_order(array, "c", "b", bug) + end + + def test_merge_cyclic_2 + bug = '[ruby-dev:21765]' + array = merge_libs(%w[a c a d], %w[b c b]) + assert_in_order(array, "a", "c", bug) + assert_in_order(array, "c", "a", bug) + assert_in_order(array, "c", "d", bug) + assert_in_order(array, "a", "d", bug) + assert_in_order(array, "b", "c", bug) + assert_in_order(array, "c", "b", bug) + end + + def test_merge_reversal + bug = '[ruby-dev:22440]' + array = merge_libs(%w[a b c], %w[c d a]) + assert_in_order(array, "a", "b" , bug) + assert_in_order(array, "c", "d" , bug) + ## assume that a and c have no dependency + end + + def test_merge_reversal_followed + bug7467 = '[ruby-core:50314] [Bug #7467]' + array = nil + assert_nothing_raised(bug7467) { + array = merge_libs(%w[a b c d e f g h], %w[d c d e], []) + } + assert_in_order(array, "a", "b", bug7467) + assert_in_order(array, "b", "c", bug7467) + assert_in_order(array, "c", "d", bug7467) + assert_in_order(array, "d", "e", bug7467) + assert_in_order(array, "e", "f", bug7467) + assert_in_order(array, "f", "g", bug7467) + assert_in_order(array, "g", "h", bug7467) + assert_in_order(array, "d", "c", bug7467) + assert_in_order(array, "c", "e", bug7467) + end + end +end if RUBY_ENGINE == "ruby" diff --git a/jni/ruby/test/mkmf/test_signedness.rb b/jni/ruby/test/mkmf/test_signedness.rb new file mode 100644 index 0000000..8d58073 --- /dev/null +++ b/jni/ruby/test/mkmf/test_signedness.rb @@ -0,0 +1,29 @@ +require_relative 'base' + +class TestMkmf + class TestSignedness < TestMkmf + def test_typeof_builtin + bug4144 = '[ruby-dev:42731]' + [["", "-1"], ["signed ", "-1"], ["unsigned ", "+1"]].each do |signed, expect| + %w[short int long].each do |type| + assert_equal(expect.to_i, mkmf {check_signedness(signed+type)}, mkmflog(bug4144)) + end + end + end + + def test_typeof_typedef + [["", "-1"], ["signed ", "-1"], ["unsigned ", "+1"]].each do |signed, expect| + %w[short int long].each do |type| + open("confdefs.h", "w") {|f| + f.puts "typedef #{signed}#{type} test1_t;" + } + $defs.clear + assert_equal(expect.to_i, mkmf {check_signedness("test1_t", "confdefs.h")}, MKMFLOG) + assert_include($defs, "-DSIGNEDNESS_OF_TEST1_T=#{expect}") + end + end + ensure + File.unlink("confdefs.h") + end + end +end diff --git a/jni/ruby/test/mkmf/test_sizeof.rb b/jni/ruby/test/mkmf/test_sizeof.rb new file mode 100644 index 0000000..c014422 --- /dev/null +++ b/jni/ruby/test/mkmf/test_sizeof.rb @@ -0,0 +1,47 @@ +require_relative 'base' + +class TestMkmf + class TestSizeof < TestMkmf + def setup + super + @sizeof_short = config_value("SIZEOF_SHORT").to_i + @sizeof_int = config_value("SIZEOF_INT").to_i + @sizeof_long = config_value("SIZEOF_LONG").to_i + @sizeof_long_long = config_value("SIZEOF_LONG_LONG").to_i + @sizeof___int64 = config_value("SIZEOF___INT64").to_i + end + + def test_sizeof_builtin + %w[char short int long float double void*].each do |type| + assert_kind_of(Integer, mkmf {check_sizeof(type)}, MKMFLOG) + end + assert_operator(@sizeof_short, :<=, @sizeof_int) + assert_operator(@sizeof_int, :<=, @sizeof_long) + assert_operator(@sizeof_long, :<=, @sizeof_long_long) unless @sizeof_long_long.zero? + assert_equal(8, @sizeof___int64) unless @sizeof___int64.zero? + end + + def test_sizeof_struct + open("confdefs.h", "w") {|f| + f.puts "typedef struct {char x;} test1_t;" + } + assert_equal(1, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG) + + open("confdefs.h", "w") {|f| + f.puts "typedef struct {char x, y;} test1_t;" + } + assert_equal(2, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG) + + open("confdefs.h", "w") {|f| + f.puts "typedef struct {int x;} test1_t;" + } + assert_equal(@sizeof_int, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG) + open("confdefs.h", "w") {|f| + f.puts "typedef struct {int x, y;} test1_t;" + } + assert_equal(2 * @sizeof_int, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG) + ensure + File.unlink("confdefs.h") + end + end +end -- cgit v1.2.3