Marcel Taeumel uploaded a new version of FFI-Tests to project FFI:
http://source.squeak.org/FFI/FFI-Tests-mt.38.mcz ==================== Summary ==================== Name: FFI-Tests-mt.38 Author: mt Time: 16 May 2021, 7:50:25.29658 am UUID: b32d1ecd-c367-cd43-907d-e0a00c06d6b5 Ancestors: FFI-Tests-mt.37 Complements FFI-Kernel-mt.151 =============== Diff against FFI-Tests-mt.37 =============== Item was changed: ----- Method: FFIAllocateTests>>test04GlobalVariableInArray (in category 'tests') ----- test04GlobalVariableInArray "If you happen to have to address to a global variable you can use a type alias or just external data for it. See ExternalObject class >> #fromHandle:." | global | global := self allocate: ExternalType int32_t size: 1. + self assert: global isFFIArray. - self assert: global isArray. self assert: 0 equals: global value. global value: 42. self assert: 42 equals: global value.! Item was changed: ----- Method: FFIAllocateTests>>test10ArrayClasses (in category 'tests - array') ----- test10ArrayClasses "For integer and float types, allocate arrays and check for specific array classes. Then construct a conventional byte array for an external data structure. A copy should also convert into a specific array class with the same contents." ExternalType useArrayClassesDuring: [ ExternalType atomicTypes do: [:contentType | (contentType isIntegerType or: [contentType isFloatType] or: [contentType isCharType]) ifTrue: [ | array arrayType data copy | array := self allocate: contentType size: 5. arrayType := array externalType. + self assert: array isFFIArray. - self assert: array isArray. self assert: 5 equals: array size. self assert: array byteSize equals: arrayType byteSize. contentType = ExternalType signedChar ifFalse: [ self flag: #discuss. "mt: What is signedChar even for?" self assert: contentType equals: array contentType]. self deny: array isNull. self deny: (array isKindOf: ExternalData). self assert: array equals: array getHandle. self shouldnt: [array at: 1 put: contentType allocate] raise: Error. self shouldnt: [array zeroMemory] raise: Error. self should: [array setContentType: ExternalType byte] raise: Error. self should: [array setSize: 42] raise: Error. data := ExternalData fromHandle: (ByteArray new: arrayType byteSize) type: arrayType. copy := data copy. "From external data into raw-bits array." self deny: array equals: data. self assert: array equals: copy. ]]].! Item was changed: ----- Method: FFIPluginTests>>testArrayResultWithPoint (in category 'tests - arrays') ----- testArrayResultWithPoint "Test returning of pointers to arrays" | pt1 pt2 pt3 | pt1 := FFITestPoint4 new. pt1 x: 1. pt1 y: 2. pt1 z: 3. pt1 w: 4. pt2 := FFITestPoint4 new. pt2 x: 5. pt2 y: 6. pt2 z: 7. pt2 w: 8. pt3 := heapObject := FFITestLibrary ffiTestArrayResultWith: pt1 with: pt2. + self assert: pt3 isFFIArray. - self assert: pt3 isArray. pt3 := pt3 value. self assert: pt3 x = 6. self assert: pt3 y = 8. self assert: pt3 z = 10. self assert: pt3 w = 12.! Item was changed: ----- Method: FFIPluginTests>>testArrayResultWithString (in category 'tests - arrays') ----- testArrayResultWithString "Note that the result does not have to be free'd because the FFITestLibrary is just passing along a Smalltalkg string. I think." | string result | string := 'Hello Squeak!!'. result := FFITestLibrary ffiTestArrayResultWithString: string. + self assert: result isFFIArray. - self assert: result isArray. ExternalData allowDetectForUnknownSizeDuring: [ self assert: string equals: result fromCString].! |
Free forum by Nabble | Edit this page |