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

test[jx8-android] 013 - Numbers and Bytes

"taking a byte"
| number r |
number := Java current newByte: 7.
'java.lang.Byte' = number getClass getName ifFalse: [
	self error: 'Invalid class'
].
#7 = number handle toString ifFalse: [
	self error: 'Invalid object'
].
r := Java current
	callStaticMethodSync: #Test
	method: #staticByte
	with: number.
r = 7 ifFalse: [
	self error: 'Invalid result'
]


"taking a short"
| number r |
number := Java current newShort: 7.
'java.lang.Short' = number getClass getName ifFalse: [
	self error: 'Invalid class'
].
#7 = number handle toString ifFalse: [
	self error: 'Invalid object'
].
r := Java current
	callStaticMethodSync: #Test
	method: #staticShort
	with: number.
r = 7 ifFalse: [
	self error: 'Invalid result'
]


"taking a double"
| number r |
number := Java current newDouble: 3.14.
'java.lang.Double' = number getClass getName ifFalse: [
	self error: 'Invalid class'
].
'3.14' = number handle toString ifFalse: [
	self error: 'Invalid object'
].
r := Java current
	callStaticMethodSync: #Test
	method: #staticDouble
	with: number.
(r - 3.14) abs < 0.0001 ifFalse: [
	self error: 'Invalid result'
]


"taking a float"
| number r |
number := Java current newFloat: 3.14.
'java.lang.Float' = number getClass getName ifFalse: [
	self error: 'Invalid class'
].
'3.14' = number handle toString ifFalse: [
	self error: 'Invalid object'
].
r := Java current
	callStaticMethodSync: #Test
	method: #staticFloat
	with: number.
(r - 3.14) abs < 0.0001 ifFalse: [
	self error: 'Invalid result'
]


"taking a long"
| number r |
number := Java current newLong: 1.
'java.lang.Long' = number getClass getName ifFalse: [
	self error: 'Invalid class'
].
#1 = number handle toString ifFalse: [
	self error: 'Invalid object'
].
r := Java current
	callStaticMethodSync: #Test
	method: #staticLong
	with: number.
r = 1 ifFalse: [
	self error: 'Invalid result'
]


"taking a char (number)"
| number r |
number := Java current newChar: $a asciiValue.
'java.lang.Character' = number getClass getName ifFalse: [
	self error: 'Invalid class'
].
$a = number handle toString ifFalse: [
	self error: 'Invalid object'
].
r := Java current
	callStaticMethodSync: #Test
	method: #staticChar
	with: number.
r = $a asciiValue ifFalse: [
	self error: 'Invalid result'
]


"taking a char (string)"
| number r |
number := Java current newChar: $a.
'java.lang.Character' = number getClass getName ifFalse: [
	self error: 'Invalid class'
].
$a = number handle toString ifFalse: [
	self error: 'Invalid object'
].
r := Java current
	callStaticMethodSync: #Test
	method: #staticChar
	with: number.
r = $a asciiValue ifFalse: [
	self error: 'Invalid result'
]


"string (Unicode BMP)"
| c r |
c := String fromCharCode: 16r2605.
r := Java current
	callStaticMethodSync: #Test
	method: #staticString
	with: c.
r = c ifFalse: [
	self error: 'Invalid result'
] 


"string (Unicode SMP)"
| c r |
"The below string is U+1F596, represented as surrogate pairs"
c := String fromCharCode: #(16rD83D 16rDD96).
r := Java current
	callStaticMethodSync: #Test
	method: #staticString
	with: c.
r = c ifFalse: [
	self error: 'Invalid result'
] 


"string (with null char)"
| c r |
c := String fromCharCode: 0.
r := Java current
	callStaticMethodSync: #Test
	method: #staticString
	with: c.
r = c ifFalse: [
	self error: 'Invalid result'
]