-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(win32-api): helper bufferToStruct()
- Loading branch information
1 parent
fbaf9ea
commit 86539fd
Showing
4 changed files
with
213 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import assert from 'node:assert/strict' | ||
|
||
import { fileShortPath } from '@waiting/shared-core' | ||
import ref from 'ref-napi' | ||
|
||
import { | ||
DModel as M, | ||
DTypes as W, | ||
DStruct as DS, | ||
StructFactory, | ||
ucsBufferFrom, | ||
bufferToStruct, | ||
} from '../../src/index.js' | ||
import { githubPrinterNames } from '../config.unittest.js' | ||
import { CI } from '../root.config.js' | ||
|
||
|
||
describe(fileShortPath(import.meta.url), () => { | ||
|
||
describe('Should work ', () => { | ||
it('useStringBuffer: false', async () => { | ||
const docInfo = StructFactory<M.DOC_INFO_1>(DS.DOC_INFO_1, { useStringBuffer: false }) | ||
assert(Buffer.isBuffer(docInfo.pDocName)) | ||
docInfo.pDocName = ucsBufferFrom('nodefoo') | ||
docInfo.pDatatype = ucsBufferFrom('RAW') | ||
|
||
const docInfoBuf = docInfo.ref() | ||
const arr = bufferToStruct<M.DOC_INFO_1>(docInfoBuf, DS.DOC_INFO_1) | ||
assert(arr.length === 1) | ||
const [struct] = arr | ||
assert(struct) | ||
assert(struct.pDocName.toString() === 'nodefoo') | ||
assert(struct.pDatatype.toString() === 'RAW') | ||
void arr | ||
}) | ||
|
||
it.skip('useStringBuffer: true not support', async () => { | ||
const name = 'nodefoo' | ||
const docInfo = StructFactory<M.DOC_INFO_1>(DS.DOC_INFO_1, { useStringBuffer: true, maxCharLength: 16 }) | ||
const docInfo2 = StructFactory<M.DOC_INFO_1>(DS.DOC_INFO_1, { useStringBuffer: false, maxCharLength: 16 }) | ||
// assert(typeof docInfo.pDocName === 'string') | ||
docInfo.pDocName = ucsBufferFrom(name) | ||
docInfo.pDatatype = ucsBufferFrom('RAW') | ||
|
||
docInfo2.pDocName = ucsBufferFrom(name) | ||
docInfo2.pDatatype = ucsBufferFrom('RAW') | ||
|
||
const docInfoBuf = docInfo.ref() | ||
const docInfoBuf2 = docInfo2.ref() | ||
const arr = bufferToStruct(docInfoBuf, DS.DOC_INFO_1) | ||
assert(arr) | ||
void arr | ||
}) | ||
|
||
}) | ||
|
||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters