
var assert = require('assert')
  , ref = require('ref')
  , ffi = require('../')
  , int = ref.types.int

describe('Callback', function () {

  afterEach(gc)

  it('should create a C function pointer from a JS function', function () {
    var callback = ffi.Callback('void', [ ], function (val) { })
    assert(Buffer.isBuffer(callback))
  })

  it('should be invokable by an ffi\'d ForeignFunction', function () {
    var funcPtr = ffi.Callback(int, [ int ], Math.abs)
    var func = ffi.ForeignFunction(funcPtr, int, [ int ])
    assert.equal(1234, func(-1234))
  })

  describe('async', function () {

    it('should be invokable asynchronously by an ffi\'d ForeignFunction', function () {
      var funcPtr = ffi.Callback(int, [ int ], Math.abs)
      var func = ffi.ForeignFunction(funcPtr, int, [ int ])
      func.async(-9999, function (err, res) {
        assert.equal(null, err)
        assert.equal(9999, res)
      })
    })

  })

})

@@ -564,16 +564,240 @@
 )%0A  %7D)%0A%0A
+  it('should work with a %22void%22 return type', function () %7B%0A    var funcPtr = ffi.Callback('void', %5B %5D, function (val) %7B %7D)%0A    var func = ffi.ForeignFunction(funcPtr, 'void', %5B %5D)%0A    assert.strictEqual(null, func())%0A  %7D)%0A%0A
   descri

add a test for a Callback with a `void` return type