Marcel Taeumel uploaded a new version of FFI-Tests to project FFI:
http://source.squeak.org/FFI/FFI-Tests-mt.20.mcz ==================== Summary ==================== Name: FFI-Tests-mt.20 Author: mt Time: 19 June 2020, 9:54:16.867059 am UUID: 574eaeaa-cd4e-2749-a31a-553c251419b9 Ancestors: FFI-Tests-mt.19 Adds tests for type alias issue. See http://forum.world.st/FFI-ExternalTypeAlias-td5118709.html Also do some test re-organization. =============== Diff against FFI-Tests-mt.19 =============== Item was changed: + ----- Method: FFIPluginTests>>test8IntSum (in category 'tests') ----- - ----- Method: FFIPluginTests>>test8IntSum (in category 'simple tests') ----- test8IntSum "Test using generic FFI spec" | result meth n interval | meth := ExternalLibraryFunction name:'ffiTest8IntSum' module: FFITestLibrary moduleName callType: 0 returnType: ExternalType long argumentTypes: (Array new: (n := 8) withAll: ExternalType long). interval := 1 - n * n to: n * n by: 2 * n + 1. result := meth invokeWithArguments: interval asArray. self assert: interval sum equals: result! Item was changed: + ----- Method: FFIPluginTests>>test8LongLongSum (in category 'tests') ----- - ----- Method: FFIPluginTests>>test8LongLongSum (in category 'simple tests') ----- test8LongLongSum "Test using generic FFI spec" | result meth n interval | meth := ExternalLibraryFunction name:'ffiTest8LongLongSum' module: FFITestLibrary moduleName callType: 0 returnType: ExternalType signedLongLong argumentTypes: (Array new: (n := 8) withAll: ExternalType signedLongLong). interval := 1 - n * n << 32 + (1 - n * n) to: n * n - n << 32 + (3 * n * n) by: 2 * n << 32 + (3 * n). result := meth invokeWithArguments: interval asArray. self assert: interval sum equals: result! Item was changed: + ----- Method: FFIPluginTests>>testAccessingUnion (in category 'tests - union') ----- - ----- Method: FFIPluginTests>>testAccessingUnion (in category 'union tests') ----- testAccessingUnion | ufi | ufi := FFITestUfi new. ufi i1: 2. self assert: 2 equals: ufi i1. ufi f1: 1.0. self assert: 1.0 equals: ufi f1. self assert: 1.0 asIEEE32BitWord equals: ufi i1. ufi i1: 2.0 asIEEE32BitWord. self assert: 2.0 equals: ufi f1.! Item was changed: + ----- Method: FFIPluginTests>>testConstructedCharCall (in category 'tests') ----- - ----- Method: FFIPluginTests>>testConstructedCharCall (in category 'simple tests') ----- testConstructedCharCall "Test using generic FFI spec" | result meth | meth := ExternalLibraryFunction name:'ffiTestChars' module: FFITestLibrary moduleName + callType: ExternalFunction callTypeCDecl returnType: ExternalType char - callType: 0 returnType: ExternalType char argumentTypes: (Array new: 4 withAll: ExternalType char). result := meth invokeWith: $A with: 65 with: 65.0 with: true. self assert: result isCharacter. self assert: 130 equals: result asciiValue! Item was changed: + ----- Method: FFIPluginTests>>testConstructedDoubleCall (in category 'tests') ----- - ----- Method: FFIPluginTests>>testConstructedDoubleCall (in category 'simple tests') ----- testConstructedDoubleCall "Test using generic FFI spec" | result meth | meth := ExternalLibraryFunction name:'ffiTestDoubles' module: FFITestLibrary moduleName + callType: ExternalFunction callTypeCDecl returnType: ExternalType double - callType: 0 returnType: ExternalType double argumentTypes: (Array new: 2 withAll: ExternalType double). result := meth invokeWithArguments: (Array with: 41 with: true). self assert: 42.0 equals: result! Item was changed: + ----- Method: FFIPluginTests>>testConstructedFloatCall (in category 'tests') ----- - ----- Method: FFIPluginTests>>testConstructedFloatCall (in category 'simple tests') ----- testConstructedFloatCall "Test using generic FFI spec" | result meth | meth := ExternalLibraryFunction name:'ffiTestFloats' module: FFITestLibrary moduleName + callType: ExternalFunction callTypeCDecl returnType: ExternalType float - callType: 0 returnType: ExternalType float argumentTypes: (Array new: 2 withAll: ExternalType float). result := meth invokeWith: $A with: 65.0. self assert: 130.0 equals: result! Item was changed: + ----- Method: FFIPluginTests>>testConstructedIntCall (in category 'tests') ----- - ----- Method: FFIPluginTests>>testConstructedIntCall (in category 'simple tests') ----- testConstructedIntCall "Test using generic FFI spec" | result meth | meth := ExternalLibraryFunction name:'ffiTestInts' module: FFITestLibrary moduleName + callType: ExternalFunction callTypeCDecl returnType: ExternalType signedLong - callType: 0 returnType: ExternalType signedLong argumentTypes: (Array new: 4 withAll: ExternalType signedLong). result := meth invokeWith: $A with: 65 with: 65.0 with: true. self assert: 130 equals: result! Item was changed: + ----- Method: FFIPluginTests>>testConstructedPrintString (in category 'tests') ----- - ----- Method: FFIPluginTests>>testConstructedPrintString (in category 'simple tests') ----- testConstructedPrintString "Test using generic FFI spec" | result meth | meth := ExternalLibraryFunction name:'ffiPrintString' module: FFITestLibrary moduleName + callType: ExternalFunction callTypeCDecl returnType: ExternalType string - callType: 0 returnType: ExternalType string argumentTypes: (Array with: ExternalType string). result := meth invokeWith:'Hello World!!'. self assert: 'Hello World!!' equals: result! Item was changed: + ----- Method: FFIPluginTests>>testConstructedShortCall (in category 'tests') ----- - ----- Method: FFIPluginTests>>testConstructedShortCall (in category 'simple tests') ----- testConstructedShortCall "Test using generic FFI spec" | result meth | meth := ExternalLibraryFunction name:'ffiTestShorts' module: FFITestLibrary moduleName + callType: ExternalFunction callTypeCDecl returnType: ExternalType short - callType: 0 returnType: ExternalType short argumentTypes: (Array new: 4 withAll: ExternalType short). result := meth invokeWithArguments: (Array with: $A with: 65 with: 65.0 with: true). self assert: 130 equals: result! Item was changed: + ----- Method: FFIPluginTests>>testFloats13Sum (in category 'tests') ----- - ----- Method: FFIPluginTests>>testFloats13Sum (in category 'simple tests') ----- testFloats13Sum "Test using generic FFI spec" | result meth n args | meth := ExternalLibraryFunction name:'ffiTestFloats13' module: FFITestLibrary moduleName callType: 0 returnType: ExternalType float argumentTypes: (Array new: (n := 13) withAll: ExternalType float). args := (123.456 to: 3.21 * 13 + 123.456 by: 3.21) asArray first: 13. result := meth invokeWithArguments: args. self assert: (result between: args sum - 0.0005 and: args sum + 0.0005)! Item was changed: + ----- Method: FFIPluginTests>>testGenericBoolCall (in category 'tests') ----- - ----- Method: FFIPluginTests>>testGenericBoolCall (in category 'simple tests') ----- testGenericBoolCall "Test using generic FFI spec" | result | result := FFITestLibrary ffiTestBool: true with: false with: true with: false. self assert: result.! Item was changed: + ----- Method: FFIPluginTests>>testGenericBoolCall2 (in category 'tests') ----- - ----- Method: FFIPluginTests>>testGenericBoolCall2 (in category 'simple tests') ----- testGenericBoolCall2 "Test using generic FFI spec" | result | result := FFITestLibrary ffiTestBool: false with: false with: true with: true. self deny: result.! Item was changed: + ----- Method: FFIPluginTests>>testGenericBoolCall3 (in category 'tests') ----- - ----- Method: FFIPluginTests>>testGenericBoolCall3 (in category 'simple tests') ----- testGenericBoolCall3 "Test using generic FFI spec" | result | result := FFITestLibrary ffiTestBool: -1 with: 1 with: 0 with: 0. self deny: result.! Item was changed: + ----- Method: FFIPluginTests>>testGenericCharCall (in category 'tests') ----- - ----- Method: FFIPluginTests>>testGenericCharCall (in category 'simple tests') ----- testGenericCharCall "Test using generic FFI spec" | result | result := FFITestLibrary ffiTestChar: $A with: 65 with: 65.0 with: true. self assert: result isCharacter. self assert: result asciiValue = 130.! Item was changed: + ----- Method: FFIPluginTests>>testGenericDoubleCall (in category 'tests') ----- - ----- Method: FFIPluginTests>>testGenericDoubleCall (in category 'simple tests') ----- testGenericDoubleCall "Test using generic FFI spec" | result | result := FFITestLibrary ffiTestDoubles: $A with: 65.0. self assert: result = 130.0! Item was changed: + ----- Method: FFIPluginTests>>testGenericDoubleCall2 (in category 'tests') ----- - ----- Method: FFIPluginTests>>testGenericDoubleCall2 (in category 'simple tests') ----- testGenericDoubleCall2 "Test using generic FFI spec" | result | result := FFITestLibrary ffiTestDoubles9: 1.0 d: 2.0 d: 3.0 d: 4.0 d: 5.0 d: 6.0 d: 7.0 d: 8.0 d: 9.0. self assert: result = 45.0! Item was changed: + ----- Method: FFIPluginTests>>testGenericFloatCall (in category 'tests') ----- - ----- Method: FFIPluginTests>>testGenericFloatCall (in category 'simple tests') ----- testGenericFloatCall "Test using generic FFI spec" | result | result := FFITestLibrary ffiTestFloats: $A with: 65.0. self assert: result = 130.0! Item was changed: + ----- Method: FFIPluginTests>>testGenericIntCall (in category 'tests') ----- - ----- Method: FFIPluginTests>>testGenericIntCall (in category 'simple tests') ----- testGenericIntCall "Test using generic FFI spec" | result | self flag: #ffiLongVsInt. result := FFITestLibrary ffiTestInt: $A with: 65 with: 65.0 with: true. self assert: result = 130.! Item was changed: + ----- Method: FFIPluginTests>>testGenericLongCall (in category 'tests') ----- - ----- Method: FFIPluginTests>>testGenericLongCall (in category 'simple tests') ----- testGenericLongCall "Test using generic FFI spec" | result | self flag: #ffiLongVsInt. result := FFITestLibrary ffiTestLong: $A with: 65 with: 65.0 with: true. self assert: result = 130.! Item was changed: + ----- Method: FFIPluginTests>>testGenericMixedDoublesIntAndStruct (in category 'tests') ----- - ----- Method: FFIPluginTests>>testGenericMixedDoublesIntAndStruct (in category 'simple tests') ----- testGenericMixedDoublesIntAndStruct "Test using generic FFI spec" | result i struct | i := 42. struct := FFITestPoint4 new. struct x: 1. struct y: 2. struct z: 3. struct w: 4. result := FFITestLibrary ffiTestMixedDoublesIntAndStruct: 1.0 d: 2.0 d: 3.0 d: 4.0 d: 5.0 d: 6.0 d: 7.0 d: 8.0 d: 9.0 i: 42 s: struct. self assert: (result closeTo: 45.0 + 42 + 10) ! Item was changed: + ----- Method: FFIPluginTests>>testGenericMixedFloatsAndDouble (in category 'tests') ----- - ----- Method: FFIPluginTests>>testGenericMixedFloatsAndDouble (in category 'simple tests') ----- testGenericMixedFloatsAndDouble "Test using generic FFI spec" | result | result := FFITestLibrary ffiTestMixedFloatsAndDouble: 1.2 with: 3.4 with: 5.6 with: 7.8. self assert: (result closeTo: 1.2 + 3.4 + 5.6 + 7.8) ! Item was changed: + ----- Method: FFIPluginTests>>testGenericPrintString (in category 'tests') ----- - ----- Method: FFIPluginTests>>testGenericPrintString (in category 'simple tests') ----- testGenericPrintString "Test using generic FFI spec" | result | result := FFITestLibrary ffiPrintString:'Hello World!!'. self assert: result = 'Hello World!!'.! Item was changed: + ----- Method: FFIPluginTests>>testGenericShortCall (in category 'tests') ----- - ----- Method: FFIPluginTests>>testGenericShortCall (in category 'simple tests') ----- testGenericShortCall "Test using generic FFI spec" | result | result := FFITestLibrary ffiTestShort: $A with: 65 with: 65.0 with: true. self assert: result = 130.! Item was added: + ----- Method: FFIPluginTests>>testIntAliasCall (in category 'tests - type alias') ----- + testIntAliasCall + + | result | + result := FFITestLibrary + ffiTestIntAlias4IntSum: (FFITestIntAlias fromHandle: 1) + with: (FFITestIntAlias fromHandle: 2) + with: (FFITestIntAlias fromHandle: 3) + with: (FFITestIntAlias fromHandle: 4). + self assert: 10 equals: result.! Item was added: + ----- Method: FFIPluginTests>>testIntAliasCallReturnIntAlias (in category 'tests - type alias') ----- + testIntAliasCallReturnIntAlias + + | result | + result := FFITestLibrary + ffiTestIntAlias4IntSum: (FFITestIntAlias fromHandle: 1) + with: (FFITestIntAlias fromHandle: 2) + with: (FFITestIntAlias fromHandle: 3) + with: (FFITestIntAlias fromHandle: 4). + self + assert: (result isKindOf: FFITestIntAlias); + assert: 10 equals: result value.! Item was added: + ----- Method: FFIPluginTests>>testIntCallReturnIntAlias (in category 'tests - type alias') ----- + testIntCallReturnIntAlias + + | result | + result := FFITestLibrary ffiTestIntAlias4IntSum: 1 with: 2 with: 3 with: 4. + self + assert: (result isKindOf: FFITestIntAlias); + assert: 10 equals: result value.! Item was changed: + ----- Method: FFIPluginTests>>testLibraryCharCall (in category 'tests - library') ----- - ----- Method: FFIPluginTests>>testLibraryCharCall (in category 'simple tests') ----- testLibraryCharCall "Test using call from ExternalLibrary" | result | result := FFITestLibrary new ffiTestChar: $A with: 65 with: 65.0 with: true. self assert: result isCharacter. self assert: result asciiValue = 130.! Item was changed: + ----- Method: FFIPluginTests>>testLibraryDoubleCall (in category 'tests - library') ----- - ----- Method: FFIPluginTests>>testLibraryDoubleCall (in category 'simple tests') ----- testLibraryDoubleCall "Test using call from ExternalLibrary" | result | result := FFITestLibrary new ffiTestDoubles: $A with: 65.0. self assert: result = 130.0! Item was changed: + ----- Method: FFIPluginTests>>testLibraryFloatCall (in category 'tests - library') ----- - ----- Method: FFIPluginTests>>testLibraryFloatCall (in category 'simple tests') ----- testLibraryFloatCall "Test using call from ExternalLibrary" | result | result := FFITestLibrary new ffiTestFloats: $A with: 65.0. self assert: result = 130.0! Item was changed: + ----- Method: FFIPluginTests>>testLibraryIntCall (in category 'tests - library') ----- - ----- Method: FFIPluginTests>>testLibraryIntCall (in category 'simple tests') ----- testLibraryIntCall "Test using call from ExternalLibrary" | result | result := FFITestLibrary new ffiTestInt: $A with: 65 with: 65.0 with: true. self assert: result = 130.! Item was changed: + ----- Method: FFIPluginTests>>testLibraryPrintString (in category 'tests - library') ----- - ----- Method: FFIPluginTests>>testLibraryPrintString (in category 'simple tests') ----- testLibraryPrintString "Test using call from ExternalLibrary" | result | result := FFITestLibrary new ffiPrintString:'Hello World!!'. self assert: result = 'Hello World!!'.! Item was changed: + ----- Method: FFIPluginTests>>testLoadSymbolFromModule (in category 'tests - other') ----- - ----- Method: FFIPluginTests>>testLoadSymbolFromModule (in category 'other tests') ----- testLoadSymbolFromModule | address | "Ok" address := ExternalAddress loadSymbol: 'ffiTestFloats' module: FFITestLibrary moduleName. self deny: address isNil. self deny: address isNull. "Symbol does not exists" self should: [ ExternalAddress loadSymbol: 'ffi_does_not_exist' module: FFITestLibrary moduleName ] raise: Error. "Module does not exists" self should: [ ExternalAddress loadSymbol: 'ffiTestFloats' module: 'NonExistingModule' ] raise: Error. ! Item was changed: + ----- Method: FFIPluginTests>>testLongLongA1 (in category 'tests') ----- - ----- Method: FFIPluginTests>>testLongLongA1 (in category 'simple tests') ----- testLongLongA1 "Test passing a char and two longlongs." | byte long1 long2 long3 | byte := 42. long1 := 16r123456789012. long2 := (-1 << 31). long3 := FFITestLibrary ffiTestLongLongA1: byte with: long1 with: long2. self assert: long3 = (byte + long1 + long2)! Item was changed: + ----- Method: FFIPluginTests>>testLongLongA3 (in category 'tests') ----- - ----- Method: FFIPluginTests>>testLongLongA3 (in category 'simple tests') ----- testLongLongA3 "Test passing a char, a longlong, and another char." | byte1 long1 byte2 long2 | byte1 := 3. long1 := 16r123456789012. byte2 := 4. long2 := FFITestLibrary ffiTestLongLongA3: byte1 with: long1 with: byte2. self assert: long2 = (byte1 + long1 + byte2)! Item was changed: + ----- Method: FFIPluginTests>>testLongLongs (in category 'tests') ----- - ----- Method: FFIPluginTests>>testLongLongs (in category 'simple tests') ----- testLongLongs "Test passing and returning longlongs" | long1 long2 long3 | long1 := 16r123456789012. long2 := (-1 << 31). long3 := FFITestLibrary ffiTestLongLong: long1 with: long2. self assert: long3 = (long1 + long2)! Item was changed: + ----- Method: FFIPluginTests>>testMixedDoublesAndLongsSum (in category 'tests') ----- - ----- Method: FFIPluginTests>>testMixedDoublesAndLongsSum (in category 'simple tests') ----- testMixedDoublesAndLongsSum "Test using generic FFI spec" | result meth n args | meth := ExternalLibraryFunction name:'ffiTestMixedDoublesAndLongs' module: FFITestLibrary moduleName callType: 0 returnType: ExternalType double argumentTypes: ((1 to: (n := 20)) collect:[:i| i odd ifTrue: [ExternalType double] ifFalse: [ExternalType c_long]]). args := (1 to: n) collect: [:i| i odd ifTrue: [(i // 2) odd ifTrue: [123.456 * (10 raisedTo: i)] ifFalse: [-654.321 * (10 raisedTo: i)]] ifFalse: [(i // 2) odd ifTrue: [54321 * i] ifFalse: [-54321 * i]]]. result := meth invokeWithArguments: args asArray. self assert: args sum equals: result! Item was changed: + ----- Method: FFIPluginTests>>testMixedIntAndStruct (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testMixedIntAndStruct (in category 'structure tests') ----- testMixedIntAndStruct "Test passing an integer and two structures." | i1 pt1 pt2 result | i1 := 42. pt1 := FFITestPoint2 new. pt1 x: 3. pt1 y: 4. pt2 := FFITestPoint2 new. pt2 x: 5. pt2 y: 6. result := FFITestLibrary ffiTestMixedIntAndStruct: i1 with: pt1 with: pt2. self assert: result = 60.! Item was changed: + ----- Method: FFIPluginTests>>testMixedIntAndStruct2 (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testMixedIntAndStruct2 (in category 'structure tests') ----- testMixedIntAndStruct2 "Test passing an integer and two structures." | i1 pt1 result | i1 := 42. pt1 := FFITestPoint4 new. pt1 x: 3. pt1 y: 4. pt1 z: 5. pt1 w: 6. result := FFITestLibrary ffiTestMixedIntAndStruct2: i1 with: pt1. self assert: result = 60.! Item was changed: + ----- Method: FFIPluginTests>>testMixedIntAndStruct3 (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testMixedIntAndStruct3 (in category 'structure tests') ----- testMixedIntAndStruct3 "Test passing an integer and a small structure." | i1 pt1 result | i1 := 42. pt1 := FFISmallStruct1 new. pt1 x: 3. pt1 y: 4. result := FFITestLibrary ffiTestMixedIntAndStruct3: i1 with: pt1. self assert: result = 49! Item was changed: + ----- Method: FFIPluginTests>>testPoint2 (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testPoint2 (in category 'structure tests') ----- testPoint2 "Test passing and returning up of structures >32bit and <= 64 bit" | pt1 pt2 pt3 | pt1 := FFITestPoint2 new. pt1 x: 1. pt1 y: 2. pt2 := FFITestPoint2 new. pt2 x: 3. pt2 y: 4. pt3 := FFITestLibrary ffiTestPoint2: pt1 with: pt2. self assert: pt3 x = 4. self assert: pt3 y = 6.! Item was changed: + ----- Method: FFIPluginTests>>testPoint4 (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testPoint4 (in category 'structure tests') ----- testPoint4 "Test passing and returning up of structures > 64 bit" | 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 := FFITestLibrary ffiTestPoint4: pt1 with: pt2. 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>>testPointers (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testPointers (in category 'structure tests') ----- testPointers "Test passing and returning of pointers to structs" | 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 := FFITestLibrary ffiTestPointers: pt1 with: pt2. 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>>testReturnStructPassingUnionUfdUdSi2 (in category 'tests - union') ----- - ----- Method: FFIPluginTests>>testReturnStructPassingUnionUfdUdSi2 (in category 'union tests') ----- testReturnStructPassingUnionUfdUdSi2 "Test returning struct made from 2 unions" | ufd udSi2 sUfdUdSi2 | ufd := FFITestLibrary ffiTestInitUfdWithDouble: Float pi. udSi2 := FFITestLibrary ffiTestInitUdSi2WithInt: 1 int: 2. sUfdUdSi2 := FFITestLibrary ffiTestInitSUfd: ufd udSi2: udSi2. self assert: Float pi equals: sUfdUdSi2 ufd1 d1. self assert: 1 equals: sUfdUdSi2 udSii2 sii1 i1. self assert: 2 equals: sUfdUdSi2 udSii2 sii1 i2.! Item was changed: + ----- Method: FFIPluginTests>>testReturnStructPassingUnionUfdUfi (in category 'tests - union') ----- - ----- Method: FFIPluginTests>>testReturnStructPassingUnionUfdUfi (in category 'union tests') ----- testReturnStructPassingUnionUfdUfi "Test returning struct made from 2 unions" | ufd ufi sUfdUfi | ufd := FFITestLibrary ffiTestInitUfdWithDouble: Float pi. ufi := FFITestLibrary ffiTestInitUfiWithInt: 1. sUfdUfi := FFITestLibrary ffiTestInitSUfd: ufd ufi: ufi. self assert: Float pi equals: sUfdUfi ufd1 d1. self assert: 1 equals: sUfdUfi ufi2 i1.! Item was changed: + ----- Method: FFIPluginTests>>testReturnStructSSdi5 (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testReturnStructSSdi5 (in category 'structure tests') ----- testReturnStructSSdi5 "Test returning struct with five struct double int (64 + 32 bits)" | ssdi5 | ssdi5 := FFITestLibrary ffiTestReturnSSdi5. self assert: ssdi5 sdi1 d1 = 1.0. self assert: ssdi5 sdi2 d1 = 2.0. self assert: ssdi5 sdi3 d1 = 3.0. self assert: ssdi5 sdi4 d1 = 4.0. self assert: ssdi5 sdi5 d1 = 5.0. self assert: ssdi5 sdi1 i2 = 1. self assert: ssdi5 sdi2 i2 = 2. self assert: ssdi5 sdi3 i2 = 3. self assert: ssdi5 sdi4 i2 = 4. self assert: ssdi5 sdi5 i2 = 5.! Item was changed: + ----- Method: FFIPluginTests>>testReturnStructSd2 (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testReturnStructSd2 (in category 'structure tests') ----- testReturnStructSd2 "Test returning struct with two double" | sd2 | sd2 := FFITestLibrary ffiTestReturnSd2. self assert: sd2 d1 = 1.0. self assert: sd2 d2 = 2.0.! Item was changed: + ----- Method: FFIPluginTests>>testReturnStructSdi (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testReturnStructSdi (in category 'structure tests') ----- testReturnStructSdi "Test returning struct double int (64 + 32 bits)" | sdi | sdi := FFITestLibrary ffiTestReturnSdi. self assert: sdi d1 = 1.0. self assert: sdi i2 = 2.! Item was changed: + ----- Method: FFIPluginTests>>testReturnStructSf2 (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testReturnStructSf2 (in category 'structure tests') ----- testReturnStructSf2 "Test returning struct with two float" | sf2 | sf2 := FFITestLibrary ffiTestReturnSf2. self assert: sf2 f1 = 1.0. self assert: sf2 f2 = 2.0.! Item was changed: + ----- Method: FFIPluginTests>>testReturnStructSf2d (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testReturnStructSf2d (in category 'structure tests') ----- testReturnStructSf2d "Test returning struct with two float one double" | sf2d | sf2d := FFITestLibrary ffiTestReturnSf2d. self assert: sf2d f1 = 1.0. self assert: sf2d f2 = 2.0. self assert: sf2d d3 = 3.0.! Item was changed: + ----- Method: FFIPluginTests>>testReturnStructSf4 (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testReturnStructSf4 (in category 'structure tests') ----- testReturnStructSf4 "Test returning struct with four float" | sf4 | sf4 := FFITestLibrary ffiTestReturnSf4. self assert: sf4 f1 = 1.0. self assert: sf4 f2 = 2.0. self assert: sf4 f3 = 3.0. self assert: sf4 f4 = 4.0.! Item was changed: + ----- Method: FFIPluginTests>>testReturnStructSfdf (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testReturnStructSfdf (in category 'structure tests') ----- testReturnStructSfdf "Test returning struct with float double float" | sfdf | sfdf := FFITestLibrary ffiTestReturnSfdf. self assert: sfdf f1 = 1.0. self assert: sfdf d2 = 2.0. self assert: sfdf f3 = 3.0.! Item was changed: + ----- Method: FFIPluginTests>>testReturnStructSfi (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testReturnStructSfi (in category 'structure tests') ----- testReturnStructSfi "Test returning struct with float int (32 + 32 bits)" | sfi | sfi := FFITestLibrary ffiTestReturnSfi. self assert: sfi f1 = 1.0. self assert: sfi i2 = 2.! Item was changed: + ----- Method: FFIPluginTests>>testReturnStructSi2 (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testReturnStructSi2 (in category 'structure tests') ----- testReturnStructSi2 "Test returning struct with two int (32 bits)" | si2 | si2 := FFITestLibrary ffiTestReturnSi2. self assert: si2 i1 = 1. self assert: si2 i2 = 2.! Item was changed: + ----- Method: FFIPluginTests>>testReturnStructSl2 (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testReturnStructSl2 (in category 'structure tests') ----- testReturnStructSl2 "Test returning struct with two long long int (64 bits)" | sl2 | sl2 := FFITestLibrary ffiTestReturnSl2. self assert: sl2 l1 = 1. self assert: sl2 l2 = 2.! Item was changed: + ----- Method: FFIPluginTests>>testReturnStructSs2 (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testReturnStructSs2 (in category 'structure tests') ----- testReturnStructSs2 "Test returning struct with two short int (16 bits)" | ss2 | ss2 := FFITestLibrary ffiTestReturnSs2. self assert: ss2 s1 = 1. self assert: ss2 s2 = 2.! Item was changed: + ----- Method: FFIPluginTests>>testReturnStructSs2i (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testReturnStructSs2i (in category 'structure tests') ----- testReturnStructSs2i "Test returning struct with two short int (16 bits) one int (32 bits)" | ss2i | ss2i := FFITestLibrary ffiTestReturnSs2i. self assert: ss2i s1 = 1. self assert: ss2i s2 = 2. self assert: ss2i i3 = 3.! Item was changed: + ----- Method: FFIPluginTests>>testReturnStructSs4 (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testReturnStructSs4 (in category 'structure tests') ----- testReturnStructSs4 "Test returning struct with four short int (16 bits)" | ss4 | ss4 := FFITestLibrary ffiTestReturnSs4. self assert: ss4 s1 = 1. self assert: ss4 s2 = 2. self assert: ss4 s3 = 3. self assert: ss4 s4 = 4.! Item was changed: + ----- Method: FFIPluginTests>>testReturnStructSsSsf (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testReturnStructSsSsf (in category 'structure tests') ----- testReturnStructSsSsf "Test returning struct with short and sub structure short-float" | ssSsf | ssSsf := FFITestLibrary ffiTestReturnSsSsf. self assert: ssSsf s1 = 1. self assert: ssSsf ssf2 s1 = 2. self assert: ssSsf ssf2 f2 = 3.0.! Item was changed: + ----- Method: FFIPluginTests>>testReturnStructSsSsi (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testReturnStructSsSsi (in category 'structure tests') ----- testReturnStructSsSsi "Test returning struct with short and sub structure short-int" | ssSsi | ssSsi := FFITestLibrary ffiTestReturnSsSsi. self assert: ssSsi s1 = 1. self assert: ssSsi ssi2 s1 = 2. self assert: ssSsi ssi2 i2 = 3.! Item was changed: + ----- Method: FFIPluginTests>>testReturnStructSsf (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testReturnStructSsf (in category 'structure tests') ----- testReturnStructSsf "Test returning struct with short float (16 + 32 bits)" | ssf | ssf := FFITestLibrary ffiTestReturnSsf. self assert: ssf s1 = 1. self assert: ssf f2 = 2.0.! Item was changed: + ----- Method: FFIPluginTests>>testReturnStructSsi (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testReturnStructSsi (in category 'structure tests') ----- testReturnStructSsi "Test returning struct with short int (16 + 32 bits)" | ssi | ssi := FFITestLibrary ffiTestReturnSsi. self assert: ssi s1 = 1. self assert: ssi i2 = 2.! Item was changed: + ----- Method: FFIPluginTests>>testReturnStructSsis (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testReturnStructSsis (in category 'structure tests') ----- testReturnStructSsis "Test returning struct with short int short (16 + 32 + 16 bits)" | ssis | ssis := FFITestLibrary ffiTestReturnSsis. self assert: ssis s1 = 1. self assert: ssis i2 = 2. self assert: ssis s3 = 3.! Item was changed: + ----- Method: FFIPluginTests>>testReturnStructSslf (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testReturnStructSslf (in category 'structure tests') ----- testReturnStructSslf "Test returning struct with short longlong float (16 + 64 + 32 bits)" | sslf | sslf := FFITestLibrary ffiTestReturnSslf. self assert: sslf s1 = 1. self assert: sslf l2 = 2. self assert: sslf f3 = 3.0.! Item was changed: + ----- Method: FFIPluginTests>>testReturnStructSsls (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testReturnStructSsls (in category 'structure tests') ----- testReturnStructSsls "Test returning struct with short longlong short (16 + 64 + 16 bits)" | ssls | ssls := FFITestLibrary ffiTestReturnSsls. self assert: ssls s1 = 1. self assert: ssls l2 = 2. self assert: ssls s3 = 3.! Item was changed: + ----- Method: FFIPluginTests>>testReturnUnionUdSi2 (in category 'tests - union') ----- - ----- Method: FFIPluginTests>>testReturnUnionUdSi2 (in category 'union tests') ----- testReturnUnionUdSi2 "Test returning union with double or 2 int (64 or 64 bits)" | udSi2 | udSi2 := FFITestLibrary ffiTestInitUdSi2WithDouble: Float pi. self assert: Float pi equals: udSi2 d1. self assert: (Float pi basicAt: 1) equals: udSi2 sii1 i2. "Assume Little Endianness" self assert: (Float pi basicAt: 2) equals: udSi2 sii1 i1. udSi2 := FFITestLibrary ffiTestInitUdSi2WithInt: 1 int: 2. self assert: 1 equals: udSi2 sii1 i1. self assert: 2 equals: udSi2 sii1 i2.! Item was changed: + ----- Method: FFIPluginTests>>testReturnUnionUfd (in category 'tests - union') ----- - ----- Method: FFIPluginTests>>testReturnUnionUfd (in category 'union tests') ----- testReturnUnionUfd "Test returning union with float or double (32 or 64 bits)" | ufd | ufd := FFITestLibrary ffiTestInitUfdWithFloat: 1.0. self assert: 1.0 equals: ufd f1. ufd := FFITestLibrary ffiTestInitUfdWithDouble: 2.0. self assert: 2 equals: ufd d1.! Item was changed: + ----- Method: FFIPluginTests>>testReturnUnionUfi (in category 'tests - union') ----- - ----- Method: FFIPluginTests>>testReturnUnionUfi (in category 'union tests') ----- testReturnUnionUfi "Test returning union with float or int (32 or 32 bits)" | ufi | ufi := FFITestLibrary ffiTestInitUfiWithFloat: 1.0. self assert: 1.0 equals: ufi f1. self assert: 1.0 asIEEE32BitWord equals: ufi i1. ufi := FFITestLibrary ffiTestInitUfiWithInt: 2. self assert: 2 equals: ufi i1.! Item was changed: + ----- Method: FFIPluginTests>>testSmallStructureReturn (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testSmallStructureReturn (in category 'structure tests') ----- testSmallStructureReturn "Test returning small structures (<4 bytes) which are returned in a register on some platforms." | pt1 | pt1 := FFITestLibrary ffiTestSmallStructReturn. self assert: pt1 x = 3. self assert: pt1 y = 4.! Item was changed: + ----- Method: FFIPluginTests>>testSumStructSSdi5 (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testSumStructSSdi5 (in category 'structure tests') ----- testSumStructSSdi5 "Test passing a structure larger than 8 eighbytes" | sdi1 sdi2 sdi3 sdi4 sdi5 ssdi5 sum | sdi1 := FFITestSdi new. sdi1 d1: 0.5; i2: 16r12345678. sdi2 := FFITestSdi new. sdi2 d1: 0.25; i2: 16r01234567. sdi3 := FFITestSdi new. sdi3 d1: 0.125; i2: 3. sdi4 := FFITestSdi new. sdi4 d1: 2.0; i2: 1. sdi5 := FFITestSdi new. sdi5 d1: 4.0; i2: 2. ssdi5 := FFITestSSdi5 new. ssdi5 sdi1: sdi1; sdi2: sdi2; sdi3: sdi3; sdi4: sdi4; sdi5: sdi5. sum := FFITestLibrary ffiTestSumStructSdi5: ssdi5. self assert: 0.5 + 16r12345678 + 0.25 + 16r01234567 + 0.125 + 3 + 2.0 + 1 + 4.0 + 2 equals: sum! Item was changed: + ----- Method: FFIPluginTests>>testSumStructSdi (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testSumStructSdi (in category 'structure tests') ----- testSumStructSdi "Test passing structure double int" | sdi sum | sdi := FFITestSdi new. sdi d1: 0.5; i2: 16r12345678. sum := FFITestLibrary ffiTestSumSdi: sdi. self assert: 0.5 + 16r12345678 equals: sum! Item was changed: + ----- Method: FFIPluginTests>>testSumStructSdi2 (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testSumStructSdi2 (in category 'structure tests') ----- testSumStructSdi2 "Test passing 2 structure double int" | sdi1 sdi2 sum | sdi1 := FFITestSdi new. sdi1 d1: 0.5; i2: 16r12345678. sdi2 := FFITestSdi new. sdi2 d1: 0.25; i2: 16r01234567. sum := FFITestLibrary ffiTestSumSdi: sdi1 sdi: sdi2. self assert: 0.5 + 16r12345678 + 0.25 + 16r01234567 equals: sum! Item was changed: + ----- Method: FFIPluginTests>>testSumStructSdi4 (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testSumStructSdi4 (in category 'structure tests') ----- testSumStructSdi4 "Test passing 4 structure double int" | sdi1 sdi2 sdi3 sdi4 sum | sdi1 := FFITestSdi new. sdi1 d1: 0.5; i2: 16r12345678. sdi2 := FFITestSdi new. sdi2 d1: 0.25; i2: 16r01234567. sdi3 := FFITestSdi new. sdi3 d1: 0.125; i2: 3. sdi4 := FFITestSdi new. sdi4 d1: 2.0; i2: 1. sum := FFITestLibrary ffiTestSumSdi: sdi1 sdi: sdi2 sdi: sdi3 sdi: sdi4. self assert: 0.5 + 16r12345678 + 0.25 + 16r01234567 + 0.125 + 3 + 2.0 + 1 equals: sum! Item was changed: + ----- Method: FFIPluginTests>>testSumStructSfd (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testSumStructSfd (in category 'structure tests') ----- testSumStructSfd "Test passing structure float double" | sfd sum | sfd := FFITestSfd new. sfd f1: 0.5; d2: 305419896.0. sum := FFITestLibrary ffiTestSumSfd: sfd. self assert: 0.5 + 305419896.0 equals: sum! Item was changed: + ----- Method: FFIPluginTests>>testSumStructSfd2 (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testSumStructSfd2 (in category 'structure tests') ----- testSumStructSfd2 "Test passing 2 structure float double " | sfd1 sfd2 sum | sfd1 := FFITestSfd new. sfd1 f1: 0.5; d2: 305419896.0. sfd2 := FFITestSfd new. sfd2 f1: 0.25; d2: 19088743.0. sum := FFITestLibrary ffiTestSumSfd: sfd1 sfd: sfd2. self assert: 0.5 + 305419896.0 + 0.25 + 19088743.0 equals: sum! Item was changed: + ----- Method: FFIPluginTests>>testSumStructSfd4 (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testSumStructSfd4 (in category 'structure tests') ----- testSumStructSfd4 "Test passing 4 structure float double" | sfd1 sfd2 sfd3 sfd4 sum | sfd1 := FFITestSfd new. sfd1 f1: 0.5; d2: 305419896.0. sfd2 := FFITestSfd new. sfd2 f1: 0.25; d2: 19088743.0. sfd3 := FFITestSfd new. sfd3 f1: 0.125; d2: 3. sfd4 := FFITestSfd new. sfd4 f1: 2.0; d2: 1. sum := FFITestLibrary ffiTestSumSfd: sfd1 sfd: sfd2 sfd: sfd3 sfd: sfd4. self assert: 0.5 + 305419896.0 + 0.25 + 19088743.0 + 0.125 + 3.0 + 2.0 + 1.0 equals: sum! Item was changed: + ----- Method: FFIPluginTests>>testSumStructSslf (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testSumStructSslf (in category 'structure tests') ----- testSumStructSslf "Test passing structure short long float" | sslf sum | sslf := FFITestSslf new. sslf s1: -32768; l2: 16r1234560000; f3: 65536.0. sum := FFITestLibrary ffiTestSumSslf: sslf. self assert: -32768 + 16r1234560000 + 65536.0 equals: sum! Item was changed: + ----- Method: FFIPluginTests>>testSumdWithStructSdi4 (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testSumdWithStructSdi4 (in category 'structure tests') ----- testSumdWithStructSdi4 "Test passing 4 structure double int" | sdi1 sdi2 sdi3 sdi4 sum | sdi1 := FFITestSdi new. sdi1 d1: 0.5; i2: 16r12345678. sdi2 := FFITestSdi new. sdi2 d1: 0.25; i2: 16r01234567. sdi3 := FFITestSdi new. sdi3 d1: 0.125; i2: 3. sdi4 := FFITestSdi new. sdi4 d1: 2.0; i2: 1. sum := FFITestLibrary ffiTestSumd: 5.0 withSdi: sdi1 sdi: sdi2 sdi: sdi3 sdi: sdi4. self assert: 5.0 + 0.5 + 16r12345678 + 0.25 + 16r01234567 + 0.125 + 3 + 2.0 + 1 equals: sum! Item was changed: + ----- Method: FFIPluginTests>>testSumdiWithStructSdi4 (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testSumdiWithStructSdi4 (in category 'structure tests') ----- testSumdiWithStructSdi4 "Test passing 4 structure double int" | sdi1 sdi2 sdi3 sdi4 sum | sdi1 := FFITestSdi new. sdi1 d1: 0.5; i2: 16r12345678. sdi2 := FFITestSdi new. sdi2 d1: 0.25; i2: 16r01234567. sdi3 := FFITestSdi new. sdi3 d1: 0.125; i2: 3. sdi4 := FFITestSdi new. sdi4 d1: 2.0; i2: 1. sum := FFITestLibrary ffiTestSumd: 5.0 i: 6 withSdi: sdi1 sdi: sdi2 sdi: sdi3 sdi: sdi4. self assert: 5.0 + 6 + 0.5 + 16r12345678 + 0.25 + 16r01234567 + 0.125 + 3 + 2.0 + 1 equals: sum! Item was changed: + ----- Method: FFIPluginTests>>testSumfWithStructSfd4 (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testSumfWithStructSfd4 (in category 'structure tests') ----- testSumfWithStructSfd4 "Test passing 4 structure float double" | sfd1 sfd2 sfd3 sfd4 sum | sfd1 := FFITestSfd new. sfd1 f1: 0.5; d2: 305419896.0. sfd2 := FFITestSfd new. sfd2 f1: 0.25; d2: 19088743.0. sfd3 := FFITestSfd new. sfd3 f1: 0.125; d2: 3. sfd4 := FFITestSfd new. sfd4 f1: 2.0; d2: 1. sum := FFITestLibrary ffiTestSumf: 5.0 withSfd: sfd1 sfd: sfd2 sfd: sfd3 sfd: sfd4. self assert: 5.0 + 0.5 + 305419896.0 + 0.25 + 19088743.0 + 0.125 + 3.0 + 2.0 + 1.0 equals: sum! Item was changed: + ----- Method: FFIPluginTests>>testSumiWithStructSdi4 (in category 'tests - structure') ----- - ----- Method: FFIPluginTests>>testSumiWithStructSdi4 (in category 'structure tests') ----- testSumiWithStructSdi4 "Test passing 4 structure double int" | sdi1 sdi2 sdi3 sdi4 sum | sdi1 := FFITestSdi new. sdi1 d1: 0.5; i2: 16r12345678. sdi2 := FFITestSdi new. sdi2 d1: 0.25; i2: 16r01234567. sdi3 := FFITestSdi new. sdi3 d1: 0.125; i2: 3. sdi4 := FFITestSdi new. sdi4 d1: 2.0; i2: 1. sum := FFITestLibrary ffiTestSumi: 5 withSdi: sdi1 sdi: sdi2 sdi: sdi3 sdi: sdi4. self assert: 5 + 0.5 + 16r12345678 + 0.25 + 16r01234567 + 0.125 + 3 + 2.0 + 1 equals: sum! Item was changed: + ----- Method: FFIPluginTests>>testUintRange (in category 'tests') ----- - ----- Method: FFIPluginTests>>testUintRange (in category 'simple tests') ----- testUintRange "Simple test for making sure the FFI can call certain numbers in the uint range." | result | self flag: #ffiLongVsInt. self shouldnt:[result := FFITestLibrary ffiTestUint: 3894967296 "1<<32-4e8 " with: 3894967296 with: 3103854339 with: 3103854339] raise: Error. self should: result = -8e8.! Item was changed: + ----- Method: FFIPluginTests>>testUlongRange (in category 'tests') ----- - ----- Method: FFIPluginTests>>testUlongRange (in category 'simple tests') ----- testUlongRange "Simple test for making sure the FFI can call certain numbers in the ulong range. Note: since primitive is using unsigned int under the hood, avoid an integer overflow by choosing appropriate unsigned values. Note: only first two parameters are added" | result | self flag: #ffiLongVsInt. self shouldnt:[result := FFITestLibrary ffiTestUlong: 3894967296 "1<<32-4e8 " with: 3894967296 with: 3103854339 with: 3103854339] raise: Error. self should: result = -8e8.! Item was added: + ExternalTypeAlias subclass: #FFITestIntAlias + instanceVariableNames: '' + classVariableNames: '' + poolDictionaries: '' + category: 'FFI-Tests-Fixtures'! Item was added: + ----- Method: FFITestIntAlias class>>originalTypeName (in category 'type alias') ----- + originalTypeName + + ^ 'int'! Item was added: + ----- Method: FFITestLibrary class>>ffiTest4IntAliasSum:with:with:with: (in category 'primitives - type alias') ----- + ffiTest4IntAliasSum: c1 with: c2 with: c3 with: c4 + "FFITestLibrary ffiTest4IntSum: 1 with: 2 with: 3 with: 4" + <cdecl: int 'ffiTest4IntSum' (FFITestIntAlias FFITestIntAlias FFITestIntAlias FFITestIntAlias) module:'SqueakFFIPrims'> + ^self externalCallFailed! Item was added: + ----- Method: FFITestLibrary class>>ffiTestIntAlias4IntAliasSum:with:with:with: (in category 'primitives - type alias') ----- + ffiTestIntAlias4IntAliasSum: c1 with: c2 with: c3 with: c4 + "FFITestLibrary ffiTest4IntSum: 1 with: 2 with: 3 with: 4" + <cdecl: int 'ffiTest4IntSum' (FFITestIntAlias FFITestIntAlias FFITestIntAlias FFITestIntAlias) module:'SqueakFFIPrims'> + ^self externalCallFailed! Item was added: + ----- Method: FFITestLibrary class>>ffiTestIntAlias4IntSum:with:with:with: (in category 'primitives - type alias') ----- + ffiTestIntAlias4IntSum: c1 with: c2 with: c3 with: c4 + "FFITestLibrary ffiTest4IntSum: 1 with: 2 with: 3 with: 4" + <cdecl: FFITestIntAlias 'ffiTest4IntSum' (int int int int) module:'SqueakFFIPrims'> + ^self externalCallFailed! |
Free forum by Nabble | Edit this page |