1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/ext/dl/test/test_func.rb
ko1 d0ed5a9378 * ext/dl/test/test_base.rb: add libc search logic.
this patch is written by Takehiro Kubo.
  [ruby-core:20963] [Bug #932]
* ext/dl/dl.h: Add ",..." as the last argument.
  this patch is written by Takehiro Kubo.
  Bug #633 [ruby-core:19289]
* ext/dl/lib/dl/stack.rb: add add_padding() to calculate
  alignment.  this patch is written by Takehiro Kubo.
  Bug #633 [ruby-core:19289]
* ext/dl/test/test_func.rb: atof()'s return value is double.
  this patch is written by Takehiro Kubo.
  Bug #633 [ruby-core:19289]
* ext/dl/test/test_import.rb:
  - atof()'s return value is double.
  - The types of qsort's second and third argument are size_t.
  - fprintf()'s return value is int.
  this patch is written by Takehiro Kubo.
  Bug #633 [ruby-core:19289]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21182 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-12-29 14:54:24 +00:00

62 lines
1.9 KiB
Ruby

require 'test_base'
require 'dl/func'
module DL
class TestFunc < TestBase
def test_strcpy()
f = Function.new(CFunc.new(@libc['strcpy'], TYPE_VOIDP, 'strcpy'),
[TYPE_VOIDP, TYPE_VOIDP])
buff = "000"
str = f.call(buff, "123")
assert_equal("123", buff)
assert_equal("123", str.to_s)
end
def test_isdigit()
f = Function.new(CFunc.new(@libc['isdigit'], TYPE_INT, 'isdigit'),
[TYPE_INT])
r1 = f.call(?1.ord)
r2 = f.call(?2.ord)
rr = f.call(?r.ord)
assert_positive(r1)
assert_positive(r2)
assert_zero(rr)
end
def test_atof()
f = Function.new(CFunc.new(@libc['atof'], TYPE_DOUBLE, 'atof'),
[TYPE_VOIDP])
r = f.call("12.34")
assert_match(12.00..13.00, r)
end
def test_strtod()
f = Function.new(CFunc.new(@libc['strtod'], TYPE_DOUBLE, 'strtod'),
[TYPE_VOIDP, TYPE_VOIDP])
buff1 = "12.34"
buff2 = " "
r = f.call(buff1, buff2)
assert_match(12.00..13.00, r)
end
def test_qsort1()
cb = Function.new(CFunc.new(0, TYPE_INT, '<callback>qsort'),
[TYPE_VOIDP, TYPE_VOIDP]){|x,y| CPtr.new(x)[0] <=> CPtr.new(y)[0]}
qsort = Function.new(CFunc.new(@libc['qsort'], TYPE_VOID, 'qsort'),
[TYPE_VOIDP, TYPE_INT, TYPE_INT, TYPE_VOIDP])
buff = "9341"
qsort.call(buff, buff.size, 1, cb)
assert_equal("1349", buff)
end
def test_qsort2()
cb = TempFunction.new(CFunc.new(0, TYPE_INT, '<callback>qsort'),
[TYPE_VOIDP, TYPE_VOIDP])
qsort = Function.new(CFunc.new(@libc['qsort'], TYPE_VOID, 'qsort'),
[TYPE_VOIDP, TYPE_INT, TYPE_INT, TYPE_VOIDP])
buff = "9341"
qsort.call(buff, buff.size, 1, cb){|x,y| CPtr.new(x)[0] <=> CPtr.new(y)[0]}
assert_equal("1349", buff)
end
end
end