-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a7c4fc8
commit ef2c51d
Showing
6 changed files
with
179 additions
and
162 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
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,60 @@ | ||
import { deepStrictEqual } from "assert" | ||
import { | ||
load, | ||
DataType, | ||
arrayConstructor, | ||
createPointer, | ||
restorePointer, | ||
unwrapPointer, | ||
} from "../index" | ||
import { logGreen } from "./utils" | ||
import { person, personType } from "./types" | ||
|
||
export const testObject = () => { | ||
const personObj = load({ | ||
library: "libsum", | ||
funcName: "getStruct", | ||
retType: personType, | ||
paramsType: [ | ||
personType | ||
], | ||
paramsValue: [person], | ||
freeResultMemory: false | ||
}); | ||
deepStrictEqual(person, personObj); | ||
logGreen('test getStruct succeed') | ||
const createdPerson = load({ | ||
library: "libsum", | ||
funcName: "createPerson", | ||
retType: personType, | ||
paramsType: [], | ||
paramsValue: [], | ||
}); | ||
deepStrictEqual(createdPerson, person); | ||
logGreen('test createdPerson succeed') | ||
let personPointer = createPointer({ | ||
paramsType: [personType], | ||
paramsValue: [person] | ||
}) | ||
const personObjByPointer = load({ | ||
library: "libsum", | ||
funcName: "getStruct", | ||
retType: personType, | ||
paramsType: [ | ||
DataType.External | ||
], | ||
freeResultMemory: false, | ||
paramsValue: unwrapPointer(personPointer), | ||
}); | ||
deepStrictEqual(person, personObjByPointer); | ||
logGreen('test getStructByPointer succeed') | ||
personPointer = createPointer({ | ||
paramsType: [personType], | ||
paramsValue: [person] | ||
}) | ||
const restorePersonObjByPointer = restorePointer({ | ||
paramsValue: personPointer, | ||
retType: [personType] | ||
}) | ||
deepStrictEqual(person, restorePersonObjByPointer[0]) | ||
} |
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,108 @@ | ||
import { DataType, arrayConstructor } from "../index" | ||
|
||
export const parent = { | ||
age: 43, | ||
doubleArray: [1.1, 2.2, 3.3], | ||
parent: {}, | ||
doubleProps: 3.3, | ||
name: "tom father", | ||
stringArray: ["tom", "father"], | ||
i32Array: [5, 6, 7], | ||
staticBytes: Buffer.from(new Array(16).fill(88)), | ||
boolTrue: true, | ||
boolFalse: false, | ||
longVal: 5294967296, | ||
stackStruct: { | ||
age: 22, | ||
}, | ||
byte: 66, | ||
byteArray: Buffer.from([103, 104]), | ||
}; | ||
export const person = { | ||
age: 23, | ||
doubleArray: [1.1, 2.2, 3.3], | ||
parent, | ||
doubleProps: 1.1, | ||
name: "tom", | ||
stringArray: ["tom"], | ||
i32Array: [1, 2, 3, 4], | ||
staticBytes: Buffer.from(new Array(16).fill(99)), | ||
boolTrue: true, | ||
boolFalse: false, | ||
longVal: 4294967296, | ||
stackStruct: { | ||
age: 16 | ||
}, | ||
byte: 65, | ||
byteArray: Buffer.from([101, 102]), | ||
}; | ||
export const parentType = { | ||
age: DataType.I32, | ||
doubleArray: arrayConstructor({ | ||
type: DataType.DoubleArray, | ||
length: parent.doubleArray.length, | ||
}), | ||
parent: {}, | ||
doubleProps: DataType.Double, | ||
name: DataType.String, | ||
stringArray: arrayConstructor({ | ||
type: DataType.StringArray, | ||
length: parent.stringArray.length, | ||
}), | ||
i32Array: arrayConstructor({ | ||
type: DataType.I32Array, | ||
length: parent.i32Array.length, | ||
}), | ||
staticBytes: arrayConstructor({ | ||
type: DataType.U8Array, | ||
length: parent.staticBytes.length, | ||
ffiTypeTag: DataType.StackArray | ||
}), | ||
boolTrue: DataType.Boolean, | ||
boolFalse: DataType.Boolean, | ||
longVal: DataType.I64, | ||
stackStruct: { | ||
age: DataType.I32, | ||
ffiTypeTag: DataType.StackStruct, | ||
}, | ||
byte: DataType.U8, | ||
byteArray: arrayConstructor({ | ||
type: DataType.U8Array, | ||
length: parent.byteArray.length, | ||
}), | ||
}; | ||
export const personType = { | ||
age: DataType.I32, | ||
doubleArray: arrayConstructor({ | ||
type: DataType.DoubleArray, | ||
length: person.doubleArray.length, | ||
}), | ||
parent: parentType, | ||
doubleProps: DataType.Double, | ||
name: DataType.String, | ||
stringArray: arrayConstructor({ | ||
type: DataType.StringArray, | ||
length: person.stringArray.length, | ||
}), | ||
i32Array: arrayConstructor({ | ||
type: DataType.I32Array, | ||
length: person.i32Array.length, | ||
}), | ||
staticBytes: arrayConstructor({ | ||
type: DataType.U8Array, | ||
length: person.staticBytes.length, | ||
ffiTypeTag: DataType.StackArray | ||
}), | ||
boolTrue: DataType.Boolean, | ||
boolFalse: DataType.Boolean, | ||
longVal: DataType.I64, | ||
stackStruct: { | ||
ffiTypeTag: DataType.StackStruct, | ||
age: DataType.I32, | ||
}, | ||
byte: DataType.U8, | ||
byteArray: arrayConstructor({ | ||
type: DataType.U8Array, | ||
length: person.byteArray.length, | ||
}), | ||
}; |
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,4 @@ | ||
export const logGreen = (text) => { | ||
if (process.env.SILENT) return | ||
console.log('\x1b[32m%s\x1b[0m', text); | ||
} |