Marcel Taeumel uploaded a new version of FFI-Tests to project FFI:
http://source.squeak.org/FFI/FFI-Tests-mt.35.mcz==================== Summary ====================
Name: FFI-Tests-mt.35
Author: mt
Time: 15 May 2021, 5:13:37.884141 pm
UUID: da76b19f-4787-5641-92cb-4a80f44054b8
Ancestors: FFI-Tests-mt.34
Complements FFI-Kernel-mt.148
=============== Diff against FFI-Tests-mt.34 ===============
Item was removed:
- ----- Method: FFIAllocateTests>>test05ArrayFromCString (in category 'tests - array') -----
- test05ArrayFromCString
-
- | data |
-
- ExternalData allowDetectForUnknownSizeDuring: [
- data := self allocate: ExternalType char size: 4.
- data setContentType: ExternalType byte.
- data setSize: nil.
- self assert: data size isNil.
-
- #[65 66 67 0] withIndexDo: [:byte :index | data at: index put: byte].
- data setContentType: ExternalType char.
- self assert: 'ABC' equals: data fromCString.
-
- data := self allocate: ExternalType char size: 9.
- data setType: ExternalType byte.
- self assert: data size isNil.
-
- #[65 66 67 0 68 69 70 0 0] withIndexDo: [:byte :index | data at: index put: byte].
- data setType: ExternalType char.
- self assert:#('ABC' 'DEF') equals: data fromCStrings].!
Item was added:
+ ----- Method: FFIAllocateTests>>test05ArrayReadWriteCString (in category 'tests - array') -----
+ test05ArrayReadWriteCString
+
+ | array string |
+ string := 'Hello Squeak!!'.
+ self assert: string isByteString.
+
+ ExternalData allowDetectForUnknownSizeDuring: [
+ array := self allocate: ExternalType byte size: 0.
+ self should: [array toCString: string] raise: Error. "Wrong type"
+ array := self allocate: ExternalType char size: string size.
+ self should: [array toCString: string] raise: Error. "Wrong size"
+
+ array := self allocate: ExternalType char size: string size + 1.
+ array toCString: string.
+ self assert: array size isNil. "It's NUL-terminated now."
+ self assert: string equals: array fromCString.
+
+ array := self allocate: ExternalType string size: string size + 1.
+ self should: [array toCString: string] raise: Error. "Use 'char' for allocation."].!
Item was added:
+ ----- Method: FFIAllocateTests>>test09ArrayReadCStringList (in category 'tests - array') -----
+ test09ArrayReadCStringList
+
+ | data |
+ ExternalData allowDetectForUnknownSizeDuring: [
+ data := self allocate: ExternalType char size: 9.
+ data setType: ExternalType byte.
+ self assert: data size isNil.
+
+ #[65 66 67 0 68 69 70 0 0] withIndexDo: [:byte :index | data at: index put: byte].
+ data setType: ExternalType char.
+ self assert:#('ABC' 'DEF') equals: data fromCStrings].!