Bug #7492 » dl2.patch
test_dl2.rb → test_dl2.rb.new | ||
---|---|---|
assert_equal ptr_id, ptr.to_i
|
||
cfunc = CFunc.new(@libc['strcpy'], TYPE_VOIDP, 'strcpy')
|
||
cfunc.call([ptr_id,str].pack("l!p").unpack("l!*"))
|
||
cfunc.call([ptr_id,str].pack(PackInfo::PACK_MAP[TYPE_VOIDP]+"p").unpack(PackInfo::PACK_MAP[TYPE_VOIDP]+"*"))
|
||
assert_equal("abc\0", ptr[0,4])
|
||
DL.free ptr_id
|
||
end
|
||
... | ... | |
assert_equal ptr_id, ptr.to_i
|
||
cfunc = CFunc.new(@libc['strcpy'], TYPE_VOIDP, 'strcpy')
|
||
cfunc.call([ptr_id,str].pack("l!p").unpack("l!*"))
|
||
cfunc.call([ptr_id,str].pack(PackInfo::PACK_MAP[TYPE_VOIDP]+"p").unpack(PackInfo::PACK_MAP[TYPE_VOIDP]+"*"))
|
||
assert_equal("abc\0", ptr[0,4])
|
||
DL.free ptr_id
|
||
end
|
||
def test_call_int()
|
||
cfunc = CFunc.new(@libc['atoi'], TYPE_INT, 'atoi')
|
||
x = cfunc.call(["100"].pack("p").unpack("l!*"))
|
||
x = cfunc.call(["100"].pack("p").unpack(PackInfo::PACK_MAP[TYPE_VOIDP]+"*"))
|
||
assert_equal(100, x)
|
||
cfunc = CFunc.new(@libc['atoi'], TYPE_INT, 'atoi')
|
||
x = cfunc.call(["-100"].pack("p").unpack("l!*"))
|
||
x = cfunc.call(["-100"].pack("p").unpack(PackInfo::PACK_MAP[TYPE_VOIDP]+"*"))
|
||
assert_equal(-100, x)
|
||
end
|
||
def test_call_long()
|
||
cfunc = CFunc.new(@libc['atol'], TYPE_LONG, 'atol')
|
||
x = cfunc.call(["100"].pack("p").unpack("l!*"))
|
||
x = cfunc.call(["100"].pack("p").unpack(PackInfo::PACK_MAP[TYPE_VOIDP]+"*"))
|
||
assert_equal(100, x)
|
||
cfunc = CFunc.new(@libc['atol'], TYPE_LONG, 'atol')
|
||
x = cfunc.call(["-100"].pack("p").unpack("l!*"))
|
||
x = cfunc.call(["-100"].pack("p").unpack(PackInfo::PACK_MAP[TYPE_VOIDP]+"*"))
|
||
assert_equal(-100, x)
|
||
end
|
||
def test_call_double()
|
||
cfunc = CFunc.new(@libc['atof'], TYPE_DOUBLE, 'atof')
|
||
x = cfunc.call(["0.1"].pack("p").unpack("l!*"))
|
||
x = cfunc.call(["0.1"].pack("p").unpack(PackInfo::PACK_MAP[TYPE_VOIDP]+"*"))
|
||
assert_in_delta(0.1, x)
|
||
cfunc = CFunc.new(@libc['atof'], TYPE_DOUBLE, 'atof')
|
||
x = cfunc.call(["-0.1"].pack("p").unpack("l!*"))
|
||
x = cfunc.call(["-0.1"].pack("p").unpack(PackInfo::PACK_MAP[TYPE_VOIDP]+"*"))
|
||
assert_in_delta(-0.1, x)
|
||
end
|
||
... | ... | |
def test_strlen()
|
||
cfunc = CFunc.new(@libc['strlen'], TYPE_INT, 'strlen')
|
||
x = cfunc.call(["abc"].pack("p").unpack("l!*"))
|
||
x = cfunc.call(["abc"].pack("p").unpack(PackInfo::PACK_MAP[TYPE_VOIDP]+"*"))
|
||
assert_equal("abc".size, x)
|
||
end
|
||