dynamic_library.js
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var assert = require('assert')
, path = require('path')
, ref = require('ref')
, ffi = require('../')
, fs = require('fs-extra')
, DynamicLibrary = ffi.DynamicLibrary
describe('DynamicLibrary', function () {
it('should be a function', function () {
assert.equal('function', typeof DynamicLibrary)
})
it('should return a "DynamicLibrary" instance when invoked', function () {
var lib = process.platform == 'win32' ? 'msvcrt' : 'libc'
var handle = DynamicLibrary(lib + ffi.LIB_EXT)
assert(handle instanceof DynamicLibrary)
})
describe('get()', function () {
it('should return a "pointer" Buffer to a symbol', function () {
var lib = process.platform == 'win32' ? 'msvcrt' : 'libc'
var handle = DynamicLibrary(lib + ffi.LIB_EXT)
var symbol = handle.get('free')
assert(Buffer.isBuffer(symbol))
assert.equal(0, symbol.length)
})
it('should set the "name" property to the name of the symbol', function () {
var lib = process.platform == 'win32' ? 'msvcrt' : 'libc'
var handle = DynamicLibrary(lib + ffi.LIB_EXT)
var name = 'free'
var symbol = handle.get(name)
assert.equal(name, symbol.name)
})
it('should load libraries when pathname contains unicode characters', function() {
// Directory and file names are "I can't read this" and "Or this"
// translated into Simplified Chinese by Google Translate
var lib = path.join(__dirname, 'build', 'Release', 'ffi_tests.node') // .node file is just a dynamic library
var toDir = path.join(__dirname, 'build', 'Release', String.fromCharCode(0x6211, 0x65e0, 0x6cd5, 0x9605, 0x8bfb))
var toLib = path.join(toDir, String.fromCharCode(0x6216, 0x8005, 0x8fd9) + '.node')
fs.mkdirsSync(toDir);
fs.copySync(lib, toLib);
var handle = DynamicLibrary(toLib)
var name = 'ExportedFunction'
var symbol = handle.get(name)
assert.equal(name, symbol.name)
})
})
})