Project

General

Profile

Bug #7492 » dl2.patch

phasis68 (Heesob Park), 03/17/2014 01:10 AM

View differences:

test_dl2.rb → test_dl2.rb.new
19 19
    assert_equal ptr_id, ptr.to_i
20 20

  
21 21
    cfunc  = CFunc.new(@libc['strcpy'], TYPE_VOIDP, 'strcpy')
22
             cfunc.call([ptr_id,str].pack("l!p").unpack("l!*"))
22
             cfunc.call([ptr_id,str].pack(PackInfo::PACK_MAP[TYPE_VOIDP]+"p").unpack(PackInfo::PACK_MAP[TYPE_VOIDP]+"*"))
23 23
    assert_equal("abc\0", ptr[0,4])
24 24
    DL.free ptr_id
25 25
  end
......
33 33
    assert_equal ptr_id, ptr.to_i
34 34

  
35 35
    cfunc  = CFunc.new(@libc['strcpy'], TYPE_VOIDP, 'strcpy')
36
             cfunc.call([ptr_id,str].pack("l!p").unpack("l!*"))
36
             cfunc.call([ptr_id,str].pack(PackInfo::PACK_MAP[TYPE_VOIDP]+"p").unpack(PackInfo::PACK_MAP[TYPE_VOIDP]+"*"))
37 37
    assert_equal("abc\0", ptr[0,4])
38 38
    DL.free ptr_id
39 39
  end
40 40

  
41 41
  def test_call_int()
42 42
    cfunc = CFunc.new(@libc['atoi'], TYPE_INT, 'atoi')
43
    x = cfunc.call(["100"].pack("p").unpack("l!*"))
43
    x = cfunc.call(["100"].pack("p").unpack(PackInfo::PACK_MAP[TYPE_VOIDP]+"*"))
44 44
    assert_equal(100, x)
45 45

  
46 46
    cfunc = CFunc.new(@libc['atoi'], TYPE_INT, 'atoi')
47
    x = cfunc.call(["-100"].pack("p").unpack("l!*"))
47
    x = cfunc.call(["-100"].pack("p").unpack(PackInfo::PACK_MAP[TYPE_VOIDP]+"*"))
48 48
    assert_equal(-100, x)
49 49
  end
50 50

  
51 51
  def test_call_long()
52 52
    cfunc = CFunc.new(@libc['atol'], TYPE_LONG, 'atol')
53
    x = cfunc.call(["100"].pack("p").unpack("l!*"))
53
    x = cfunc.call(["100"].pack("p").unpack(PackInfo::PACK_MAP[TYPE_VOIDP]+"*"))
54 54
    assert_equal(100, x)
55 55
    cfunc = CFunc.new(@libc['atol'], TYPE_LONG, 'atol')
56
    x = cfunc.call(["-100"].pack("p").unpack("l!*"))
56
    x = cfunc.call(["-100"].pack("p").unpack(PackInfo::PACK_MAP[TYPE_VOIDP]+"*"))
57 57
    assert_equal(-100, x)
58 58
  end
59 59

  
60 60
  def test_call_double()
61 61
    cfunc = CFunc.new(@libc['atof'], TYPE_DOUBLE, 'atof')
62
    x = cfunc.call(["0.1"].pack("p").unpack("l!*"))
62
    x = cfunc.call(["0.1"].pack("p").unpack(PackInfo::PACK_MAP[TYPE_VOIDP]+"*"))
63 63
    assert_in_delta(0.1, x)
64 64

  
65 65
    cfunc = CFunc.new(@libc['atof'], TYPE_DOUBLE, 'atof')
66
    x = cfunc.call(["-0.1"].pack("p").unpack("l!*"))
66
    x = cfunc.call(["-0.1"].pack("p").unpack(PackInfo::PACK_MAP[TYPE_VOIDP]+"*"))
67 67
    assert_in_delta(-0.1, x)
68 68
  end
69 69

  
......
83 83

  
84 84
  def test_strlen()
85 85
    cfunc = CFunc.new(@libc['strlen'], TYPE_INT, 'strlen')
86
    x = cfunc.call(["abc"].pack("p").unpack("l!*"))
86
    x = cfunc.call(["abc"].pack("p").unpack(PackInfo::PACK_MAP[TYPE_VOIDP]+"*"))
87 87
    assert_equal("abc".size, x)
88 88
  end
89 89