1
0
mirror of https://github.com/musix-org/musix-oss synced 2025-06-17 04:26:00 +00:00
This commit is contained in:
MatteZ02
2020-03-03 22:30:50 +02:00
parent edfcc6f474
commit 30022c7634
11800 changed files with 1984416 additions and 1 deletions

52
node_modules/ref/test/address.js generated vendored Normal file
View File

@ -0,0 +1,52 @@
var ref = require('../')
var assert = require('assert')
var inspect = require('util').inspect
describe('address', function () {
var buf = new Buffer('hello')
it('should return 0 for the NULL pointer', function () {
assert.strictEqual(0, ref.address(ref.NULL))
})
it('should give a positive value for any other Buffer', function () {
var address = ref.address(buf)
assert.equal(typeof address, 'number')
assert(isFinite(address))
assert(address > 0)
})
it('should accept an offset value for the 2nd argument', function () {
var address = ref.address(buf)
assert.equal(address + 0, ref.address(buf, 0))
assert.equal(address + 1, ref.address(buf, 1))
assert.equal(address + 2, ref.address(buf, 2))
assert.equal(address + 3, ref.address(buf, 3))
assert.equal(address + 4, ref.address(buf, 4))
assert.equal(address + 5, ref.address(buf, 5))
})
it('should accept a negative offset value for the 2nd argument', function () {
var address = ref.address(buf)
assert.equal(address - 0, ref.address(buf, -0))
assert.equal(address - 1, ref.address(buf, -1))
assert.equal(address - 2, ref.address(buf, -2))
assert.equal(address - 3, ref.address(buf, -3))
assert.equal(address - 4, ref.address(buf, -4))
assert.equal(address - 5, ref.address(buf, -5))
})
it('should have an offset of zero when none is given', function () {
assert.equal(ref.address(buf), ref.address(buf, 0))
})
describe('inspect()', function () {
it('should overwrite the default Buffer#inspect() to print the memory address', function () {
assert(inspect(buf).indexOf(buf.hexAddress()) !== -1)
})
})
})

17
node_modules/ref/test/alloc.js generated vendored Normal file
View File

@ -0,0 +1,17 @@
var assert = require('assert')
var ref = require('../')
describe('alloc()', function () {
it('should return a new Buffer of "bool" size', function () {
var buf = ref.alloc(ref.types.bool)
assert.equal(ref.sizeof.bool, buf.length)
})
it('should coerce string type names', function () {
var buf = ref.alloc('bool')
assert.strictEqual(ref.types.bool, buf.type)
})
})

36
node_modules/ref/test/bool.js generated vendored Normal file
View File

@ -0,0 +1,36 @@
var assert = require('assert')
var ref = require('../')
describe('bool', function () {
var buf = ref.alloc('bool')
it('should return JS "false" for a value of 0', function () {
buf[0] = 0
assert.strictEqual(false, ref.get(buf))
})
it('should return JS "true" for a value of 1', function () {
buf[0] = 1
assert.strictEqual(true, ref.get(buf))
})
it('should write a JS "false" value as 0', function () {
ref.set(buf, 0, false)
assert.strictEqual(0, buf[0])
})
it('should write a JS "true" value as 1', function () {
ref.set(buf, 0, true)
assert.strictEqual(1, buf[0])
})
it('should allow uint8 number values to be written to it', function () {
var val = 255
ref.set(buf, 0, val)
assert.strictEqual(true, ref.get(buf))
assert.strictEqual(val, buf[0])
})
})

17
node_modules/ref/test/char.js generated vendored Normal file
View File

@ -0,0 +1,17 @@
var assert = require('assert')
var ref = require('../')
describe('char', function () {
it('should accept a JS String, and write the first char\'s code', function () {
var val = 'a'
var buf = ref.alloc('char', val)
assert.strictEqual(val.charCodeAt(0), buf.deref())
buf = ref.alloc('uchar', val)
assert.strictEqual(val.charCodeAt(0), buf.deref())
})
})

48
node_modules/ref/test/coerce.js generated vendored Normal file
View File

@ -0,0 +1,48 @@
var assert = require('assert')
var ref = require('../')
describe('coerce', function () {
it('should return `ref.types.void` for "void"', function () {
var type = ref.coerceType('void')
assert.strictEqual(ref.types.void, type)
})
it('should return a ref type when a "*" is present', function () {
var type = ref.coerceType('void *')
assert(type !== ref.types.void)
assert.equal(type.indirection, ref.types.void.indirection + 1)
})
it('should coerce the "type" property of a Buffer', function () {
var buf = new Buffer(ref.sizeof.int)
buf.type = 'int'
var type = ref.getType(buf)
assert.strictEqual(ref.types.int, type)
assert.strictEqual('int', buf.type)
})
it('should coerce "Object" to `ref.types.Object`', function () {
assert.strictEqual(ref.types.Object, ref.coerceType('Object'))
})
it('should coerce the optional type in `ref.get()`', function () {
var b = new Buffer(ref.sizeof.int8)
b[0] = 5
assert.strictEqual(5, ref.get(b, 0, 'int8'))
})
it('should coerce the optional type in `ref.set()`', function () {
var b = new Buffer(ref.sizeof.int8)
ref.set(b, 0, 5, 'int8')
assert.strictEqual(5, b[0])
})
it('should throw a TypeError if a "type" can not be inferred', function () {
assert.throws(function () {
ref.coerceType({ })
}, /could not determine a proper \"type\"/)
})
})

170
node_modules/ref/test/int64.js generated vendored Normal file
View File

@ -0,0 +1,170 @@
var assert = require('assert')
var ref = require('../')
describe('int64', function () {
var JS_MAX_INT = +9007199254740992
var JS_MIN_INT = -9007199254740992
it('should allow simple ints to be written and read', function () {
var buf = new Buffer(ref.sizeof.int64)
var val = 123456789
ref.writeInt64(buf, 0, val)
var rtn = ref.readInt64(buf, 0)
assert.equal(val, rtn)
})
it('should allow INT64_MAX to be written and read', function () {
var buf = new Buffer(ref.sizeof.int64)
var val = '9223372036854775807'
ref.writeInt64(buf, 0, val)
var rtn = ref.readInt64(buf, 0)
assert.equal(val, rtn)
})
it('should allow a hex String to be input (signed)', function () {
var buf = new Buffer(ref.sizeof.int64)
var val = '-0x1234567890'
ref.writeInt64(buf, 0, val)
var rtn = ref.readInt64(buf, 0)
assert.equal(parseInt(val, 16), rtn)
})
it('should allow an octal String to be input (signed)', function () {
var buf = new Buffer(ref.sizeof.int64)
var val = '-0777'
ref.writeInt64(buf, 0, val)
var rtn = ref.readInt64(buf, 0)
assert.equal(parseInt(val, 8), rtn)
})
it('should allow a hex String to be input (unsigned)', function () {
var buf = new Buffer(ref.sizeof.uint64)
var val = '0x1234567890'
ref.writeUInt64(buf, 0, val)
var rtn = ref.readUInt64(buf, 0)
assert.equal(parseInt(val, 16), rtn)
})
it('should allow an octal String to be input (unsigned)', function () {
var buf = new Buffer(ref.sizeof.uint64)
var val = '0777'
ref.writeUInt64(buf, 0, val)
var rtn = ref.readUInt64(buf, 0)
assert.equal(parseInt(val, 8), rtn)
})
it('should return a Number when reading JS_MIN_INT', function () {
var buf = new Buffer(ref.sizeof.int64)
ref.writeInt64(buf, 0, JS_MIN_INT)
var rtn = ref.readInt64(buf, 0)
assert.equal('number', typeof rtn)
assert.equal(JS_MIN_INT, rtn)
})
it('should return a Number when reading JS_MAX_INT', function () {
var buf = new Buffer(ref.sizeof.int64)
ref.writeInt64(buf, 0, JS_MAX_INT)
var rtn = ref.readInt64(buf, 0)
assert.equal('number', typeof rtn)
assert.equal(JS_MAX_INT, rtn)
})
it('should return a String when reading JS_MAX_INT+1', function () {
var buf = new Buffer(ref.sizeof.int64)
var plus_one = '9007199254740993'
ref.writeInt64(buf, 0, plus_one)
var rtn = ref.readInt64(buf, 0)
assert.equal('string', typeof rtn)
assert.equal(plus_one, rtn)
})
it('should return a String when reading JS_MIN_INT-1', function () {
var buf = new Buffer(ref.sizeof.int64)
var minus_one = '-9007199254740993'
ref.writeInt64(buf, 0, minus_one)
var rtn = ref.readInt64(buf, 0)
assert.equal('string', typeof rtn)
assert.equal(minus_one, rtn)
})
it('should return a Number when reading 0, even when written as a String', function () {
var buf = new Buffer(ref.sizeof.int64)
var zero = '0'
ref.writeInt64(buf, 0, zero)
var rtn = ref.readInt64(buf, 0)
assert.equal('number', typeof rtn)
assert.equal(0, rtn)
})
it('should throw a "no digits" Error when writing an invalid String (signed)', function () {
assert.throws(function () {
var buf = new Buffer(ref.sizeof.int64)
ref.writeInt64(buf, 0, 'foo')
}, /no digits we found in input String/)
})
it('should throw a "no digits" Error when writing an invalid String (unsigned)', function () {
assert.throws(function () {
var buf = new Buffer(ref.sizeof.uint64)
ref.writeUInt64(buf, 0, 'foo')
}, /no digits we found in input String/)
})
it('should throw an "out of range" Error when writing an invalid String (signed)', function () {
var e;
try {
var buf = new Buffer(ref.sizeof.int64)
ref.writeInt64(buf, 0, '10000000000000000000000000')
} catch (_e) {
e = _e;
}
assert(/input String numerical value out of range/.test(e.message));
})
it('should throw an "out of range" Error when writing an invalid String (unsigned)', function () {
var e;
try {
var buf = new Buffer(ref.sizeof.uint64)
ref.writeUInt64(buf, 0, '10000000000000000000000000')
} catch (_e) {
e = _e;
}
assert(/input String numerical value out of range/.test(e.message));
})
it('should throw an Error when reading an int64_t from the NULL pointer', function () {
assert.throws(function () {
ref.readInt64(ref.NULL)
})
})
it('should throw an Error when reading an uint64_t from the NULL pointer', function () {
assert.throws(function () {
ref.readUInt64(ref.NULL)
})
})
;['LE', 'BE'].forEach(function (endianness) {
describe(endianness, function () {
it('should read and write a signed ' + endianness + ' 64-bit integer', function () {
var val = -123456789
var buf = new Buffer(ref.sizeof.int64)
ref['writeInt64' + endianness](buf, 0, val)
assert.equal(val, ref['readInt64' + endianness](buf, 0))
})
it('should read and write an unsigned ' + endianness + ' 64-bit integer', function () {
var val = 123456789
var buf = new Buffer(ref.sizeof.uint64)
ref['writeUInt64' + endianness](buf, 0, val)
assert.equal(val, ref['readUInt64' + endianness](buf, 0))
})
})
})
})

24
node_modules/ref/test/iojs3issue.js generated vendored Normal file
View File

@ -0,0 +1,24 @@
var assert = require('assert')
var ref = require('../')
// This will check if the new Buffer implementation behaves like the pre io.js 3.0 one did:
describe('iojs3issue', function () {
it('should not crash', function() {
for (var i = 0; i < 10; i++) {
gc()
var buf = new Buffer(8)
buf.fill(0)
var buf2 = ref.ref(buf)
var buf3 = ref.deref(buf2)
}
})
it('should not crash too', function() {
for (var i = 0; i < 10; i++) {
gc()
var buf = new Buffer(7)
buf.fill(0)
var buf2 = ref.ref(buf)
var buf3 = ref.deref(buf2)
}
})
})

16
node_modules/ref/test/isNull.js generated vendored Normal file
View File

@ -0,0 +1,16 @@
var assert = require('assert')
var ref = require('../')
describe('isNull', function () {
it('should return "true" for the NULL pointer', function () {
assert.strictEqual(true, ref.isNull(ref.NULL))
})
it('should return "false" for a valid Buffer', function () {
var buf = new Buffer('hello')
assert.strictEqual(false, ref.isNull(buf))
})
})

74
node_modules/ref/test/object.js generated vendored Normal file
View File

@ -0,0 +1,74 @@
var assert = require('assert')
var weak = require('weak')
var ref = require('../')
describe('Object', function () {
var obj = {
foo: 'bar'
, test: Math.random()
, now: new Date()
}
beforeEach(gc)
it('should write and read back an Object in a Buffer', function () {
var buf = new Buffer(ref.sizeof.Object)
ref.writeObject(buf, 0, obj)
var out = ref.readObject(buf)
assert.strictEqual(obj, out)
assert.deepEqual(obj, out)
})
it('should retain references to written Objects', function (done) {
var o_gc = false
var buf_gc = false
var o = { foo: 'bar' }
var buf = new Buffer(ref.sizeof.Object)
weak(o, function () { o_gc = true })
weak(buf, function () { buf_gc = true })
ref.writeObject(buf, 0, o)
assert(!o_gc, '"o" has been garbage collected too soon')
assert(!buf_gc, '"buf" has been garbage collected too soon')
// try to GC `o`
o = null
gc()
assert(!o_gc, '"o" has been garbage collected too soon')
assert(!buf_gc, '"buf" has been garbage collected too soon')
// now GC `buf`
buf = null
setImmediate(function () {
gc()
assert(buf_gc, '"buf" has not been garbage collected')
assert(o_gc, '"o" has not been garbage collected')
done()
});
})
it('should throw an Error when reading an Object from the NULL pointer', function () {
assert.throws(function () {
ref.NULL.readObject()
})
})
describe('offset', function () {
it('should read two Objects next to each other in memory', function () {
var buf = new Buffer(ref.sizeof.pointer * 2)
var a = {}
var b = {}
buf.writeObject(a, 0 * ref.sizeof.pointer)
buf.writeObject(b, 1 * ref.sizeof.pointer)
var _a = buf.readObject(0 * ref.sizeof.pointer)
var _b = buf.readObject(1 * ref.sizeof.pointer)
assert.strictEqual(a, _a)
assert.strictEqual(b, _b)
})
})
})

80
node_modules/ref/test/pointer.js generated vendored Normal file
View File

@ -0,0 +1,80 @@
var assert = require('assert')
var weak = require('weak')
var ref = require('../')
describe('pointer', function () {
var test = new Buffer('hello world')
beforeEach(gc)
it('should write and read back a pointer (Buffer) in a Buffer', function () {
var buf = new Buffer(ref.sizeof.pointer)
ref.writePointer(buf, 0, test)
var out = ref.readPointer(buf, 0, test.length)
assert.strictEqual(out.length, test.length)
for (var i = 0, l = out.length; i < l; i++) {
assert.strictEqual(out[i], test[i])
}
assert.strictEqual(ref.address(out), ref.address(test))
})
it('should retain references to a written pointer in a Buffer', function (done) {
var child_gc = false
var parent_gc = false
var child = new Buffer('a pointer holding some data...')
var parent = new Buffer(ref.sizeof.pointer)
weak(child, function () { child_gc = true })
weak(parent, function () { parent_gc = true })
ref.writePointer(parent, 0, child)
assert(!child_gc, '"child" has been garbage collected too soon')
assert(!parent_gc, '"parent" has been garbage collected too soon')
// try to GC `child`
child = null
gc()
assert(!child_gc, '"child" has been garbage collected too soon')
assert(!parent_gc, '"parent" has been garbage collected too soon')
// now GC `parent`
parent = null
setImmediate(function () {
gc()
assert(parent_gc, '"parent" has not been garbage collected')
assert(child_gc, '"child" has not been garbage collected')
done()
});
})
it('should throw an Error when reading from the NULL pointer', function () {
assert.throws(function () {
ref.NULL.readPointer()
})
})
it('should return a 0-length Buffer when reading a NULL pointer', function () {
var buf = new Buffer(ref.sizeof.pointer)
ref.writePointer(buf, 0, ref.NULL)
var out = ref.readPointer(buf, 0, 100)
assert.strictEqual(out.length, 0)
})
describe('offset', function () {
it('should read two pointers next to each other in memory', function () {
var buf = new Buffer(ref.sizeof.pointer * 2)
var a = new Buffer('hello')
var b = new Buffer('world')
buf.writePointer(a, 0 * ref.sizeof.pointer)
buf.writePointer(b, 1 * ref.sizeof.pointer)
var _a = buf.readPointer(0 * ref.sizeof.pointer)
var _b = buf.readPointer(1 * ref.sizeof.pointer)
assert.equal(a.address(), _a.address())
assert.equal(b.address(), _b.address())
})
})
})

61
node_modules/ref/test/ref-deref.js generated vendored Normal file
View File

@ -0,0 +1,61 @@
var assert = require('assert')
var ref = require('../')
describe('ref(), deref()', function () {
beforeEach(gc)
it('should work 1 layer deep', function () {
var test = new Buffer('one layer deep')
var one = ref.ref(test)
var _test = ref.deref(one)
assert.equal(test.length, _test.length)
assert.equal(test.toString(), _test.toString())
})
it('should work 2 layers deep', function () {
var test = new Buffer('two layers deep')
var one = ref.ref(test)
var two = ref.ref(one)
var _one = ref.deref(two)
var _test = ref.deref(_one)
assert.equal(ref.address(one), ref.address(_one))
assert.equal(ref.address(test), ref.address(_test))
assert.equal(one.length, _one.length)
assert.equal(test.length, _test.length)
assert.equal(test.toString(), _test.toString())
})
it('should throw when derefing a Buffer with no "type"', function () {
var test = new Buffer('???')
assert.throws(function () {
ref.deref(test)
}, /unknown "type"/)
})
it('should throw when derefing a Buffer with no "type" 2', function () {
var test = new Buffer('???')
var r = ref.ref(test)
var _test = ref.deref(r)
assert.equal(ref.address(test), ref.address(_test))
assert.throws(function () {
ref.deref(_test)
}, /unknown "type"/)
})
it('should deref() a "char" type properly', function () {
var test = new Buffer(ref.sizeof.char)
test.type = ref.types.char
test[0] = 50
assert.equal(50, ref.deref(test))
test[0] = 127
assert.equal(127, ref.deref(test))
})
it('should not throw when calling ref()/deref() on a `void` type', function () {
var test = ref.alloc(ref.types.void)
assert.strictEqual(null, test.deref())
})
})

57
node_modules/ref/test/reinterpret.js generated vendored Normal file
View File

@ -0,0 +1,57 @@
var assert = require('assert')
var weak = require('weak')
var ref = require('../')
describe('reinterpret()', function () {
beforeEach(gc)
it('should return a new Buffer instance at the same address', function () {
var buf = new Buffer('hello world')
var small = buf.slice(0, 0)
assert.strictEqual(0, small.length)
assert.strictEqual(buf.address(), small.address())
var reinterpreted = small.reinterpret(buf.length)
assert.strictEqual(buf.address(), reinterpreted.address())
assert.strictEqual(buf.length, reinterpreted.length)
assert.strictEqual(buf.toString(), reinterpreted.toString())
})
it('should return a new Buffer instance starting at the offset address', function () {
var buf = new Buffer('hello world')
var offset = 3
var small = buf.slice(offset, buf.length)
assert.strictEqual(buf.length - offset, small.length)
assert.strictEqual(buf.address() + offset, small.address())
var reinterpreted = buf.reinterpret(small.length, offset)
assert.strictEqual(small.address(), reinterpreted.address())
assert.strictEqual(small.length, reinterpreted.length)
assert.strictEqual(small.toString(), reinterpreted.toString())
})
it('should retain a reference to the original Buffer when reinterpreted', function () {
var origGCd = false
var otherGCd = false
var buf = new Buffer(1)
weak(buf, function () { origGCd = true })
var other = buf.reinterpret(0)
weak(other, function () { otherGCd = true })
assert(!origGCd, '"buf" has been garbage collected too soon')
assert(!otherGCd, '"other" has been garbage collected too soon')
// try to GC `buf`
buf = null
gc()
assert(!origGCd, '"buf" has been garbage collected too soon')
assert(!otherGCd, '"other" has been garbage collected too soon')
// now GC `other`
other = null
gc()
assert(otherGCd, '"other" has not been garbage collected')
assert(origGCd, '"buf" has not been garbage collected')
})
})

45
node_modules/ref/test/reinterpretUntilZeros.js generated vendored Normal file
View File

@ -0,0 +1,45 @@
var fs = require('fs')
var assert = require('assert')
var weak = require('weak')
var ref = require('../')
describe('reinterpretUntilZeros()', function () {
beforeEach(gc)
it('should return a new Buffer instance up until the first 0', function () {
var buf = new Buffer('hello\0world')
var buf2 = buf.reinterpretUntilZeros(1)
assert.equal(buf2.length, 'hello'.length)
assert.equal(buf2.toString(), 'hello')
})
it('should return a new Buffer instance up until the first 0 starting from offset', function () {
var buf = new Buffer('hello\0world')
var buf2 = buf.reinterpretUntilZeros(1, 3)
assert.equal(buf2.length, 'lo'.length)
assert.equal(buf2.toString(), 'lo')
})
it('should return a new Buffer instance up until the first 2-byte sequence of 0s', function () {
var str = 'hello world'
var buf = new Buffer(50)
var len = buf.write(str, 'ucs2')
buf.writeInt16LE(0, len) // NULL terminate the string
var buf2 = buf.reinterpretUntilZeros(2)
assert.equal(str.length, buf2.length / 2)
assert.equal(buf2.toString('ucs2'), str)
})
it('should return a large Buffer instance > 10,000 bytes with UTF16-LE char bytes', function () {
var data = fs.readFileSync(__dirname + '/utf16le.bin');
var strBuf = ref.reinterpretUntilZeros(data, 2);
assert(strBuf.length > 10000);
var str = strBuf.toString('ucs2');
// the data in `utf16le.bin` should be a JSON parsable string
assert(JSON.parse(str));
})
})

98
node_modules/ref/test/string.js generated vendored Normal file
View File

@ -0,0 +1,98 @@
var assert = require('assert')
var ref = require('../')
describe('C string', function () {
describe('readCString()', function () {
it('should return "" for a Buffer containing "\\0"', function () {
var buf = new Buffer('\0')
assert.strictEqual('', buf.readCString(0))
})
it('should return "hello" for a Buffer containing "hello\\0world"', function () {
var buf = new Buffer('hello\0world')
assert.strictEqual('hello', buf.readCString(0))
})
it('should throw an Error when reading from the NULL pointer', function () {
assert.throws(function () {
ref.NULL.readCString()
})
})
})
describe('writeCString()', function () {
it('should write a C string (NULL terminated) to a Buffer', function () {
var buf = new Buffer(20)
var str = 'hello world'
buf.writeCString(str)
for (var i = 0; i < str.length; i++) {
assert.equal(str.charCodeAt(i), buf[i])
}
assert.equal(0, buf[str.length])
})
})
describe('allocCString()', function () {
it('should return a new Buffer containing the given string', function () {
var buf = ref.allocCString('hello world')
assert.strictEqual('hello world', buf.readCString())
})
it('should return the NULL pointer for `null` values', function () {
var buf = ref.allocCString(null)
assert(buf.isNull())
assert.strictEqual(0, buf.address())
})
it('should return the NULL pointer for `undefined` values', function () {
var buf = ref.allocCString(undefined)
assert(buf.isNull())
assert.strictEqual(0, buf.address())
})
it('should return the NULL pointer for a NULL pointer Buffer', function () {
var buf = ref.allocCString(ref.NULL)
assert(buf.isNull())
assert.strictEqual(0, buf.address())
})
})
describe('CString', function () {
it('should return JS `null` when given a pointer pointing to NULL', function () {
var buf = ref.alloc(ref.types.CString)
buf.writePointer(ref.NULL)
assert.strictEqual(null, buf.deref())
// another version of the same test
assert.strictEqual(null, ref.get(ref.NULL_POINTER, 0, ref.types.CString))
})
it('should read a utf8 string from a Buffer', function () {
var str = 'hello world'
var buf = ref.alloc(ref.types.CString)
buf.writePointer(new Buffer(str + '\0'))
assert.strictEqual(str, buf.deref())
})
// https://github.com/node-ffi/node-ffi/issues/169
it('should set a Buffer as backing store', function () {
var str = 'hey!'
var store = new Buffer(str + '\0')
var buf = ref.alloc(ref.types.CString)
ref.set(buf, 0, store)
assert.equal(str, ref.get(buf, 0))
})
})
})

86
node_modules/ref/test/types.js generated vendored Normal file
View File

@ -0,0 +1,86 @@
var assert = require('assert')
var ref = require('../')
describe('types', function () {
describe('refType()', function () {
it('should return a new "type" with its `indirection` level increased by 1', function () {
var int = ref.types.int
var intPtr = ref.refType(int)
assert.equal(int.size, intPtr.size)
assert.equal(int.indirection + 1, intPtr.indirection)
})
it('should coerce string types', function () {
var intPtr = ref.refType('int')
assert.equal(2, intPtr.indirection)
assert.equal(intPtr.size, ref.types.int.size)
})
it('should override and update a read-only name property', function () {
// a type similar to ref-struct's StructType
// used for types refType name property test
function StructType() {}
StructType.size = 0
StructType.indirection = 0
// read-only name property
assert.equal(StructType.name, 'StructType')
try {
StructType.name = 'foo'
} catch (err) {
// ignore
}
assert.equal(StructType.name, 'StructType')
// name property should be writable and updated
var newObj = ref.refType(StructType)
var newProp = Object.getOwnPropertyDescriptor(newObj, 'name')
assert.equal(newProp.writable, true)
assert.equal(newObj.name, 'StructType*')
})
})
describe('derefType()', function () {
it('should return a new "type" with its `indirection` level decreased by 1', function () {
var intPtr = Object.create(ref.types.int)
intPtr.indirection++
var int = ref.derefType(intPtr)
assert.equal(intPtr.size, intPtr.size)
assert.equal(intPtr.indirection - 1, int.indirection)
})
it('should throw an Error when given a "type" with its `indirection` level already at 1', function () {
assert.throws(function () {
ref.derefType(ref.types.int)
})
})
})
describe('size', function () {
Object.keys(ref.types).forEach(function (name) {
if (name === 'void') return
it('sizeof(' + name + ') should be >= 1', function () {
var type = ref.types[name]
assert.equal('number', typeof type.size)
assert(type.size >= 1)
})
})
})
describe('alignment', function () {
Object.keys(ref.types).forEach(function (name) {
if (name === 'void') return
it('alignof(' + name + ') should be >= 1', function () {
var type = ref.types[name]
assert.equal('number', typeof type.alignment)
assert(type.alignment >= 1)
})
})
})
})

BIN
node_modules/ref/test/utf16le.bin generated vendored Normal file

Binary file not shown.