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

test[S8ObjC] 031 message sending

SwikiCodeRobot @> 400

"(object) message sends  (object return type, w/o arguments)"
| cls instance |
cls := ObjCClass named: #JX8IosTest in: #Foundation.
instance := cls newInstanceHandle.
10 timesRepeat: [:i|
	self print: '---- loop ',i.
	#(	yourself testString
	) do: [:selector| | result |
		5 timesRepeat: [
			result := instance value: selector.
		].self print: #sent.
		5 timesRepeat: [
			self print: selector ,$= 
				,'[',(self typeOf: result),']'
				",result Note: #toString will crash".
			Smalltalk gc.
		].
	].
	Smalltalk gc.
].
self print: #done.


"messages with arguments"
| cls instance test |
cls := ObjCClass named: #JX8IosTest in: #Foundation.
instance := cls newInstanceHandle.
test := [:selector :value :k| | result arg |
	arg := value isString ifTrue: [
		value = #self ifTrue: [ instance ]
			ifFalse: [ S8ObjC value: value ]
	] ifFalse: [ value ].
	result := arg isNil
		ifTrue: [ instance value: selector ]
		ifFalse: [ instance value: selector value: arg ].
	(k isNil ifTrue: [result isNil] ifFalse: [k = result]) ifFalse: [
		self print: 'Error ',selector ,': ' ,value,' returned ',result ,' (must be ',k,')'
	].
].
10 timesRepeat: [:i|
	self print: '---- loop ',i.
	#(	#(vv nil nil)	#(vi 123 nil)	#(vb true nil)
		#(vf 123 nil)	#(vd 123 nil)	#(vs #hello nil)
		#(vo self nil)
		#(iv nil 42)	#(ii 123 123)	#(ib true 42)
		#(if 123 123)	#(id 123 123)	#(is #hello 5)
		#(io #self 42)	#(io #hello 7)
	) do: [:tuple| test valueWithArguments: tuple ].
].
Smalltalk gc.
self print: #done.


"sending halt:"
| cls instance nsString |
cls := ObjCClass named: #JX8IosTest in: #Foundation.
instance := cls newInstanceHandle.
nsString := S8ObjC value: #hello.
instance value: #halt value: nsString.
Smalltalk gc.
self print: #done.