[View] [Edit] [Lock] [References] [Attachments] [History] [Home] [Changes] [Search] [Help]
test[S8Ref] object
"Set test variables"
TestObj :=
(#foo -> #bar
,(#test -> #{Math} random)
,(#now -> DateTime now)
).
"should write and read back an Object in a Buffer"
| buffer sizeof value result |
buffer := NodeBuffer size: (S8Ref sizeOf: #Object).
value := JS @ TestObj json.
S8Ref current writeObject: buffer offset: 0 value: value.
Smalltalk gc.
result := JS @ (S8Ref current readObject: buffer offset: 0).
value description = result description ifFalse: [ self error: 'Wrong value' ].
#ok
"should throw an Error when reading an Object from the NULL pointer"
| null | Smalltalk gc.
null := S8Ref null.
[ null readObject
] on: Error do: [:ex| ^self print: 'ok - ' ,ex toString stream nextLine ].
self error: 'Must throw an error'
"should read two Objects next to each other in memory"
| buffer sizeof sz valueA resultA valueB resultB | Smalltalk gc.
sz := S8Ref sizeOf: #pointer.
buffer := NodeBuffer size: sz * 2.
valueA := Object new json.
valueB := Object new json.
S8Ref current writeInt64: buffer offset: 0 value: valueA.
S8Ref current writeInt64: buffer offset: sz value: valueB.
resultA := S8Ref current readInt64: buffer offset: 0.
resultB := S8Ref current readInt64: buffer offset: sz.
valueA = resultA ifFalse: [ self error: 'Wrong value A' ].
valueB = resultB ifFalse: [ self error: 'Wrong value B' ].
"Remove test variables"
Smalltalk removeKey: #TestObj ifAbsent: [].
self print: #done.