[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

test[S8ObjC] messages

SwikiCodeRobot @> #testS8ObjCMessages

"Test access to well known messages"
| cls messages |
cls := ObjCClass named: #NSObject.
messages := cls methods.
#( alloc new ) do: [:selector|
	(messages includes: selector) ifFalse: [
		self error: 'Missing selector #',selector
	].
].#ok


"Test ancestors of an instance of a class"
| object messages |
object := (ObjCClass named: #NSObject) newInstanceHandle.
messages := object methods.
#( alloc new ) do: [:selector|
	(messages includes: selector) ifTrue: [
		self error: 'Error should not implement #',selector
	].
].
#( init dealloc ) do: [:selector|
	(messages includes: selector) ifFalse: [
		self error: 'Missing selector #',selector
	].
].
"messages do: [:selector|
	((ObjCClass named: #NSObject) instancesRespondToSelector: selector) ifFalse: [
		self error: 'Wrong result for #',selector
	].
]."
#ok


"DNU - Query for selectors"
((ObjCClass named: #NSObject) handle
	value: #respondsToSelector
	value: #alloc) ifFalse: [
	self error: 'Wrong result, must be true'
].

((ObjCClass named: #NSObject) newInstanceHandle
	value: #respondsToSelector
	value: #description) ifFalse: [
	self error: 'Wrong result, must be true'
].

((ObjCClass named: #NSObject) newInstanceHandle
	value: #respondsToSelector
	value: 'an invalid selector') ifTrue: [
	self error: 'Wrong result, must be false'
].

"Why this trigger an error? it should be something wrong at low level!!"
(ObjCClass named: #NSObject) newInstanceHandle
	value: #respondsToSelector
	value: #toString