[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

test[S8FFI] CIF

SwikiCodeRobot @> #testS8FFICIF

"should return a Buffer representing the ffi_cif instance"
| cif |
cif := S8FFI current cif: (S8Ref type: #void) types: #() abi: #default.
(NodeBuffer isBuffer: cif handle) ifFalse: [
	^self error: 'Must be a buffer'
]

"should throw an Error when given an invalid type"
| typeConstructor ffiType badType |
typeConstructor := S8FFI current ffi: #type.
{'	ffiType = new typeConstructor(); '}.
ffiType
	basicAt: #size put: 0;
	basicAt: #alignment put: 0;
	basicAt: #type put: 0;
	basicAt: #elements put: S8Ref null json.
badType := #size -> 1
	,(#indirection -> 1)
	,(#ffi_type -> ffiType ref).
[	S8FFI current cif: badType types: #() abi: #default.
] on: Error do: [:ex| ^self print: 'ok - ' ,ex toString stream nextLine ].
self error: 'It should be an error'

"should throw an Error when given an invalid ABI argument"
| cif |
[	cif := S8FFI current cif: (S8Ref type: #void) types: #() abi: -1.
] on: Error do: [:ex| ^self print: 'ok - ' ,ex toString stream nextLine ].
self error: 'It should be an error'