summaryrefslogtreecommitdiffstats
path: root/test/dl
diff options
context:
space:
mode:
Diffstat (limited to 'test/dl')
-rw-r--r--test/dl/test_cptr.rb52
-rw-r--r--test/dl/test_dl2.rb31
2 files changed, 61 insertions, 22 deletions
diff --git a/test/dl/test_cptr.rb b/test/dl/test_cptr.rb
index 55a53f97d..4157f8336 100644
--- a/test/dl/test_cptr.rb
+++ b/test/dl/test_cptr.rb
@@ -29,5 +29,57 @@ module DL
assert_equal free.ptr, ptr.free.ptr
end
+
+ def test_null?
+ ptr = CPtr.new(0)
+ assert ptr.null?
+ end
+
+ def test_size
+ ptr = CPtr.malloc(4)
+ assert_equal 4, ptr.size
+ DL.free ptr.to_i
+ end
+
+ def test_size=
+ ptr = CPtr.malloc(4)
+ ptr.size = 10
+ assert_equal 10, ptr.size
+ DL.free ptr.to_i
+ end
+
+ def test_aref_aset
+ check = Proc.new{|str,ptr|
+ assert_equal(str.size(), ptr.size())
+ assert_equal(str, ptr.to_s())
+ assert_equal(str[0,2], ptr.to_s(2))
+ assert_equal(str[0,2], ptr[0,2])
+ assert_equal(str[1,2], ptr[1,2])
+ assert_equal(str[1,0], ptr[1,0])
+ assert_equal(str[0].ord, ptr[0])
+ assert_equal(str[1].ord, ptr[1])
+ }
+ str = 'abc'
+ ptr = CPtr[str]
+ check.call(str, ptr)
+
+ str[0] = "c"
+ assert_equal 'c'.ord, ptr[0] = "c".ord
+ check.call(str, ptr)
+
+ str[0,2] = "aa"
+ assert_equal 'aa', ptr[0,2] = "aa"
+ check.call(str, ptr)
+
+ ptr2 = CPtr['cdeeee']
+ str[0,2] = "cd"
+ assert_equal ptr2, ptr[0,2] = ptr2
+ check.call(str, ptr)
+
+ ptr3 = CPtr['vvvv']
+ str[0,2] = "vv"
+ assert_equal ptr3.to_i, ptr[0,2] = ptr3.to_i
+ check.call(str, ptr)
+ end
end
end
diff --git a/test/dl/test_dl2.rb b/test/dl/test_dl2.rb
index d391e976e..ac1414920 100644
--- a/test/dl/test_dl2.rb
+++ b/test/dl/test_dl2.rb
@@ -5,6 +5,15 @@ module DL
class TestDL < TestBase
# TODO: refactor test repetition
+ def test_free_secure
+ assert_raises(SecurityError) do
+ Thread.new do
+ $SAFE = 4
+ DL.free(0)
+ end.join
+ end
+ end
+
def test_realloc
str = "abc"
ptr_id = DL.realloc(0, 4)
@@ -133,27 +142,5 @@ class TestDL < TestBase
ary2 = dlunwrap(addr)
assert_equal(ary, ary2)
end
-
- def test_cptr()
- check = Proc.new{|str,ptr|
- assert_equal(str.size(), ptr.size())
- assert_equal(str, ptr.to_s())
- assert_equal(str[0,2], ptr.to_s(2))
- assert_equal(str[0,2], ptr[0,2])
- assert_equal(str[1,2], ptr[1,2])
- assert_equal(str[1,0], ptr[1,0])
- assert_equal(str[0].ord, ptr[0])
- assert_equal(str[1].ord, ptr[1])
- }
- str = 'abc'
- ptr = CPtr[str]
- check.call(str, ptr)
- str[0] = "c"
- ptr[0] = "c".ord
- check.call(str, ptr)
- str[0,2] = "aa"
- ptr[0,2] = "aa"
- check.call(str, ptr)
- end
end
end # module DL