-
-
Notifications
You must be signed in to change notification settings - Fork 35.8k
Expand file tree
/
Copy pathtest.js
More file actions
67 lines (57 loc) · 2.07 KB
/
test.js
File metadata and controls
67 lines (57 loc) · 2.07 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
56
57
58
59
60
61
62
63
64
65
66
67
'use strict';
const common = require('../../common');
const assert = require('assert');
const test_sharedarraybuffer = require(`./build/${common.buildType}/test_sharedarraybuffer`);
{
const sab = new SharedArrayBuffer(16);
const ab = new ArrayBuffer(16);
const obj = {};
const arr = [];
assert.strictEqual(test_sharedarraybuffer.TestIsSharedArrayBuffer(sab), true);
assert.strictEqual(test_sharedarraybuffer.TestIsSharedArrayBuffer(ab), false);
assert.strictEqual(test_sharedarraybuffer.TestIsSharedArrayBuffer(obj), false);
assert.strictEqual(test_sharedarraybuffer.TestIsSharedArrayBuffer(arr), false);
assert.strictEqual(test_sharedarraybuffer.TestIsSharedArrayBuffer(null), false);
assert.strictEqual(test_sharedarraybuffer.TestIsSharedArrayBuffer(undefined), false);
}
// Test node_api_create_sharedarraybuffer
{
const sab = test_sharedarraybuffer.TestCreateSharedArrayBuffer(16);
assert(sab instanceof SharedArrayBuffer);
assert.strictEqual(sab.byteLength, 16);
}
// Test node_api_create_get_sharedarraybuffer_info
{
const sab = new SharedArrayBuffer(32);
const byteLength = test_sharedarraybuffer.TestGetSharedArrayBufferInfo(sab);
assert.strictEqual(byteLength, 32);
}
// Test data access
{
const sab = new SharedArrayBuffer(8);
const result = test_sharedarraybuffer.TestSharedArrayBufferData(sab);
assert.strictEqual(result, true);
// Check if data was written correctly
const view = new Uint8Array(sab);
for (let i = 0; i < 8; i++) {
assert.strictEqual(view[i], i % 256);
}
}
// Test data pointer from existing SharedArrayBuffer
{
const sab = new SharedArrayBuffer(16);
const result = test_sharedarraybuffer.TestSharedArrayBufferData(sab);
assert.strictEqual(result, true);
}
// Test zero-length SharedArrayBuffer
{
const sab = test_sharedarraybuffer.TestCreateSharedArrayBuffer(0);
assert(sab instanceof SharedArrayBuffer);
assert.strictEqual(sab.byteLength, 0);
}
// Test invalid arguments
{
assert.throws(() => {
test_sharedarraybuffer.TestGetSharedArrayBufferInfo({});
}, { name: 'Error', message: 'Invalid argument' });
}