Marcel Taeumel uploaded a new version of FFI-Tests to project FFI:
http://source.squeak.org/FFI/FFI-Tests-mt.24.mcz ==================== Summary ==================== Name: FFI-Tests-mt.24 Author: mt Time: 4 May 2021, 12:23:31.205881 pm UUID: 1baeb097-81ea-2345-8bb8-b100fdb55983 Ancestors: FFI-Tests-mt.23 More tests. Complements FFI-Kernel-mt.128 =============== Diff against FFI-Tests-mt.23 =============== Item was added: + ----- Method: ExternalStructureTests>>test01FromToInternal (in category 'tests - external data') ----- + test01FromToInternal + "Access a sub-range in the external data. Internal memory will be copied if not accessed through a read-writer." + + | points portion | + points := FFITestPoint2 allocate: 5. + portion := points from: 2 to: 3. + self assert: portion getHandle isInternalMemory. + + portion withIndexDo: [:point :index | point setX: index+1 setY: index+1]. + self "Forgot to use a read-writer..." + assert: { 0@0 . 0@0 . 0@0 . 0@0 . 0@0 } + equals: (points collect: [:each | each asPoint]). + + portion withIndexDo: [:point :index | point setX: index+1 setY: index+1]. + self "Forgot to use a read-writer early enough..." + assert: { 0@0 . 0@0 . 0@0 . 0@0 . 0@0 } + equals: (points collect: [:each | each asPoint]). + + portion := points writer from: 2 to: 3. + portion withIndexDo: [:point :index | point setX: index+1 setY: index+1]. + self + assert: { 0@0 . 2@2 . 3@3 . 0@0 . 0@0 } + equals: (points collect: [:each | each asPoint]). + + points zeroMemory. + portion := points reader from: 2 to: 3. + portion writer withIndexDo: [:point :index | point setX: index+1 setY: index+1]. + self "Both #reader and #writer used. No worries." + assert: { 0@0 . 2@2 . 3@3 . 0@0 . 0@0 } + equals: (points collect: [:each | each asPoint]).! Item was added: + ----- Method: ExternalStructureTests>>test02FromToExternal (in category 'tests - external data') ----- + test02FromToExternal + "Access a sub-range in the external data. External memory will not be copied." + + | points portion | + points := heapObject := FFITestPoint2 allocateExternal: 5. + points zeroMemory. + + portion := points from: 2 to: 3. + self assert: portion getHandle isExternalAddress. + + portion withIndexDo: [:point :index | point setX: index+1 setY: index+1]. + self + assert: { 0@0 . 2@2 . 3@3 . 0@0 . 0@0 } + equals: (points collect: [:each | each asPoint]).! Item was added: + ----- Method: ExternalStructureTests>>test03CopyFromExternalToInternal (in category 'tests - external data') ----- + test03CopyFromExternalToInternal + + | points copy | + points := FFITestPoint2 allocateExternal: 5. + points zeroMemory. + self assert: points getHandle isExternalAddress. + + copy := points copyFrom: 2 to: 3. + self assert: copy getHandle isInternalMemory. + + "We need a writer to modify internal memory." + copy withIndexDo: [:point :index | point setX: index+1 setY: index+1]. + self deny: { 2@2 . 3@3 } equals: (copy collect: [:each | each asPoint]). + copy writer withIndexDo: [:point :index | point setX: index+1 setY: index+1]. + self assert: { 2@2 . 3@3 } equals: (copy collect: [:each | each asPoint]). + + "Check that we did not touch the external memory." + self + assert: { 0@0 . 0@0 . 0@0 . 0@0 . 0@0 } + equals: (points collect: [:each | each asPoint]).! Item was added: + ----- Method: ExternalStructureTests>>test04CopyFromInternalToInternal (in category 'tests - external data') ----- + test04CopyFromInternalToInternal + + | points copy | + points := FFITestPoint2 allocate: 5. + self assert: points getHandle isInternalMemory. + + copy := points copyFrom: 2 to: 3. + self assert: copy getHandle isInternalMemory. + + "We need a writer to modify internal memory." + copy withIndexDo: [:point :index | point setX: index+1 setY: index+1]. + self deny: { 2@2 . 3@3 } equals: (copy collect: [:each | each asPoint]). + copy writer withIndexDo: [:point :index | point setX: index+1 setY: index+1]. + self assert: { 2@2 . 3@3 } equals: (copy collect: [:each | each asPoint]). + + "Check that we did not touch the original." + self + assert: { 0@0 . 0@0 . 0@0 . 0@0 . 0@0 } + equals: (points collect: [:each | each asPoint]).! Item was changed: ----- Method: ExternalStructureTests>>test06AccessingTypeAliasForAtomic (in category 'tests') ----- test06AccessingTypeAliasForAtomic | char | self should: [FFITestCharAlias new] raise: Error. char := FFITestCharAlias fromHandle: $C. self assert: $C equals: char value. char value: $A. self assert: $A equals: char value. char zeroMemory. + self assert: 0 equals: char value asInteger.! - self assert: $0 equals: char value.! |
Free forum by Nabble | Edit this page |