summaryrefslogtreecommitdiff
path: root/ext/dl/test/test_func.rb
diff options
context:
space:
mode:
authorttate <ttate@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-02-04 13:35:37 +0000
committerttate <ttate@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-02-04 13:35:37 +0000
commitbda37095ca990568069aaf07dc6b3fa8ceebc327 (patch)
tree15043d94698579d6ab19544542479a42385cd1b5 /ext/dl/test/test_func.rb
parent4ae9132605dc7b0297bcda408ca7a2ad7de39d2f (diff)
added new files.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7883 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/dl/test/test_func.rb')
-rw-r--r--ext/dl/test/test_func.rb62
1 files changed, 62 insertions, 0 deletions
diff --git a/ext/dl/test/test_func.rb b/ext/dl/test/test_func.rb
new file mode 100644
index 0000000000..64a32d9565
--- /dev/null
+++ b/ext/dl/test/test_func.rb
@@ -0,0 +1,62 @@
+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)
+ r2 = f.call(?2)
+ rr = f.call(?r)
+ assert_positive(r1)
+ assert_positive(r2)
+ assert_zero(rr)
+ end
+
+ def test_atof()
+ f = Function.new(CFunc.new(@libc['atof'], TYPE_FLOAT, '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