Skip to content

Commit

Permalink
More tests + do not mistake the 'self' string for the #self symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
guillep committed Oct 1, 2019
1 parent 73535b8 commit 8c167dd
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/UnifiedFFI-Tests/FFIAbstractTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Class {
'intType',
'int32Type',
'voidType',
'charType'
'charType',
'uint32Type'
],
#category : #'UnifiedFFI-Tests-Tests'
}
Expand Down Expand Up @@ -44,6 +45,7 @@ FFIAbstractTest >> setUp [
super setUp.
intType := FFIInt32.
int32Type := FFIInt32.
uint32Type := FFIUInt32.
voidType := FFIVoid.
charType := FFICharacterType.
]
14 changes: 14 additions & 0 deletions src/UnifiedFFI-Tests/FFIFunctionParserTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,20 @@ FFIFunctionParserTest >> testTypedStringArgumentIsString [
self assertValue: argument is: 'a stringy'
]

{ #category : #tests }
FFIFunctionParserTest >> testTypedStringSelfArgumentHasDefinedType [
| argument |
argument := self parseArgument: 'stringy ''self'''.
self assertType: argument named: 'stringy'
]

{ #category : #tests }
FFIFunctionParserTest >> testTypedStringSelfArgumentIsString [
| argument |
argument := self parseArgument: 'stringy ''self'''.
self assertValue: argument is: 'self'
]

{ #category : #tests }
FFIFunctionParserTest >> testTypedTrueArgumentHasDefinedType [
| argument |
Expand Down
120 changes: 116 additions & 4 deletions src/UnifiedFFI-Tests/FFIFunctionResolutionTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,30 @@ FFIFunctionResolutionTest >> testResolveArgumentVariableWithExplicitTypeResolves
self assert: argument resolvedType class equals: intType
]

{ #category : #tests }
FFIFunctionResolutionTest >> testResolveClassVariableShouldBeInt32Type [

| argument receiver context resolver |
argument := FFIVariableArgument
name: 'AsciiOrder'
typeName: 'int'
arity: 0.

receiver := 'aString'.
context := Context
sender: nil
receiver: receiver
method: String>>#asDate
arguments: #().
resolver := FFICallout new
sender: context;
yourself.

argument resolveUsing: resolver.

self assert: argument resolvedType class equals: int32Type
]

{ #category : #tests }
FFIFunctionResolutionTest >> testResolveClassVariableShouldSetClassVariableLoader [

Expand All @@ -117,11 +141,12 @@ FFIFunctionResolutionTest >> testResolveClassVariableShouldSetClassVariableLoade
argument resolveUsing: resolver.
argument loader emitArgument: self context: context.

self assert: stack pop equals: { #classVariable . (String classPool bindingOf: #AsciiOrder )}
self assert: stack pop equals: { #classVariable . (String classPool bindingOf: #AsciiOrder )}.
self assert: argument resolvedType class equals: int32Type
]

{ #category : #tests }
FFIFunctionResolutionTest >> testResolveConstantFalseShouldSetConstantZeroLoader [
FFIFunctionResolutionTest >> testResolveConstantFalseShouldBeInt32Type [

| argument resolver |
argument := FFIConstantArgument new
Expand All @@ -137,6 +162,33 @@ FFIFunctionResolutionTest >> testResolveConstantFalseShouldSetConstantZeroLoader
self assert: argument resolvedType class equals: int32Type
]

{ #category : #tests }
FFIFunctionResolutionTest >> testResolveConstantFalseShouldSetConstantZeroLoader [

| argument |
argument := FFIConstantArgument new
value: false;
yourself.

argument resolveUsing: FFICallout new.
argument loader emitArgument: self context: nil.

self assert: stack pop equals: { #literal . 0 }.
]

{ #category : #tests }
FFIFunctionResolutionTest >> testResolveConstantIntegerShouldBeInt32 [

| argument |
argument := FFIConstantArgument new
value: 1;
yourself.

argument resolveUsing: FFICallout new.

self assert: argument resolvedType class equals: uint32Type
]

{ #category : #tests }
FFIFunctionResolutionTest >> testResolveConstantIntegerShouldSetConstantLoader [

Expand All @@ -151,6 +203,20 @@ FFIFunctionResolutionTest >> testResolveConstantIntegerShouldSetConstantLoader [
self assert: stack pop equals: { #literal . 1}.
]

{ #category : #tests }
FFIFunctionResolutionTest >> testResolveConstantNULLShouldBeVoidPointerType [

| argument |
argument := FFIConstantArgument new
value: 'NULL';
yourself.

argument resolveUsing: FFICallout new.

self assert: argument resolvedType class equals: voidType.
self assert: argument resolvedType pointerArity equals: 1
]

{ #category : #tests }
FFIFunctionResolutionTest >> testResolveConstantNULLShouldSetConstantNullLoader [

Expand All @@ -165,6 +231,20 @@ FFIFunctionResolutionTest >> testResolveConstantNULLShouldSetConstantNullLoader
self assert: stack pop equals: { #literal . ExternalAddress null}.
]

{ #category : #tests }
FFIFunctionResolutionTest >> testResolveConstantNilShouldBeVoidPointerType [

| argument |
argument := FFIConstantArgument new
value: nil;
yourself.

argument resolveUsing: FFICallout new.

self assert: argument resolvedType class equals: voidType.
self assert: argument resolvedType pointerArity equals: 1
]

{ #category : #tests }
FFIFunctionResolutionTest >> testResolveConstantNilShouldSetConstantNullLoader [

Expand All @@ -184,7 +264,7 @@ FFIFunctionResolutionTest >> testResolveConstantSelfOfExternalObjectShouldSetCon

| argument receiver context resolver |
argument := FFIConstantArgument new
value: 'self';
value: #self;
yourself.

receiver := FFIExternalObjectForTest new.
Expand All @@ -209,7 +289,7 @@ FFIFunctionResolutionTest >> testResolveConstantSelfShouldResolveToExternalObjec

| argument receiver context resolver |
argument := FFIConstantArgument new
value: 'self';
value: #self;
yourself.

receiver := FFIExternalObjectForTest new.
Expand All @@ -228,6 +308,38 @@ FFIFunctionResolutionTest >> testResolveConstantSelfShouldResolveToExternalObjec
self assert: argument resolvedType equals: (receiver class asExternalTypeOn: nil)
]

{ #category : #tests }
FFIFunctionResolutionTest >> testResolveConstantSelfStringShouldSetConstantLoader [

| argument |
argument := FFIConstantArgument new
value: 'self';
type: (FFITypeDeclaration typeName: 'char' arity: 1);
yourself.

argument resolveUsing: FFICallout new.
argument loader emitArgument: self context: nil.

self assert: stack pop equals: { #literal . 'self' }.
]

{ #category : #tests }
FFIFunctionResolutionTest >> testResolveConstantTrueShouldBeInt32Type [

| argument resolver |
argument := FFIConstantArgument new
value: true;
yourself.

resolver := FFICallout new
requestor: self;
yourself.

argument resolveUsing: resolver.

self assert: argument resolvedType class equals: int32Type
]

{ #category : #tests }
FFIFunctionResolutionTest >> testResolveConstantTrueShouldSetConstantOneLoader [

Expand Down
2 changes: 1 addition & 1 deletion src/UnifiedFFI/FFIConstantArgument.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ FFIConstantArgument >> resolveUsing: aResolver [
resolvedType := type resolveUsing: aResolver forArgument: self.
resolvedType loader: loader.
^ self ].
value = 'self' ifTrue: [
value == #self ifTrue: [
loader := resolvedType := type resolveUsing: aResolver forArgument: self.
loader loader: FFISelfArgument new.
^ self ].
Expand Down
15 changes: 12 additions & 3 deletions src/UnifiedFFI/FFIUndefinedTypeDeclaration.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,19 @@ FFIUndefinedTypeDeclaration >> resolveUsing: aResolver forArgument: aFFIValueArg
ifTrue: [ ^ (aFFIValueArgument value >=0
ifTrue: [ aResolver resolveType: #uint32 ]
ifFalse: [ aResolver resolveType: #int32 ]) ].
(aFFIValueArgument value = 'self') ifTrue: [
(aFFIValueArgument value == #self) ifTrue: [
^ (aResolver requestor asExternalTypeOn: aResolver)
prepareAsSelfFromCalloutDeclaration ].

"This is actually a class variable with a value..."
^ aResolver resolveType: aFFIValueArgument value
^ aFFIValueArgument value isSymbol
ifTrue: [
"This is actually a class variable with a value..."
aResolver resolveType: aFFIValueArgument value ]
ifFalse: [ self unsupportedUntypedLiteral: aFFIValueArgument value ]
]

{ #category : #errors }
FFIUndefinedTypeDeclaration >> unsupportedUntypedLiteral: aLiteral [

FFIUnsupportedUntypedLiteral signalFor: aLiteral
]
30 changes: 30 additions & 0 deletions src/UnifiedFFI/FFIUnsupportedUntypedLiteral.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"
I am an error indicating that an unsupported untyped literal has been used.
I contain the unsupported literal so the user can query me.
"
Class {
#name : #FFIUnsupportedUntypedLiteral,
#superclass : #Error,
#instVars : [
'literal'
],
#category : #'UnifiedFFI-Exceptions'
}

{ #category : #signalling }
FFIUnsupportedUntypedLiteral class >> signalFor: aLiteral [

self new
literal: aLiteral;
signal
]

{ #category : #accessing }
FFIUnsupportedUntypedLiteral >> literal [
^ literal
]

{ #category : #accessing }
FFIUnsupportedUntypedLiteral >> literal: anObject [
literal := anObject
]

0 comments on commit 8c167dd

Please sign in to comment.