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

test[S8Ref] pointer

"Set test variables"
TestObj := NodeBuffer string: 'hello world'.


"should write and read back a pointer (Buffer) in a Buffer"
| buffer sizeof value result | Smalltalk gc.
buffer := NodeBuffer size: (S8Ref sizeOf: #pointer).
value := TestObj.

true ifTrue: [ ^self print: 'excluded - will crash in #writePointer:' ].

S8Ref current writePointer: buffer offset: 0 value: value.
result := S8Ref current readPointer: buffer offset: 0.
value#length = result#length ifFalse: [ self error: 'Wrong size' ].
(S8Ref current address: value) = (S8Ref current address: result) ifFalse: [ self error: 'Wrong address' ].
1 to: value length do: [:i|
  (value at: i) = (result at: i) ifFalse: [ self error: 'Invalid contents at ' ,i ]
].


"should throw an Error when reading an Object from the NULL pointer"
| null | Smalltalk gc.
null := S8Ref null.
[ null readPointer
] on: Error do: [:ex| ^self print: 'ok - ' ,ex toString stream nextLine ].
self error: 'Must throw an error'


"should return a 0-length Buffer when reading a NULL pointer"
| sizeof buffer value result | Smalltalk gc.
buffer := NodeBuffer size: (S8Ref sizeOf: #pointer).
value := S8Ref null.

true ifTrue: [ ^self print: 'excluded - will crash in #writePointer:' ].

S8Ref current writePointer: buffer offset: 0 value: value.
result := S8Ref current readPointer: buffer offset: 0 size: 100.
result length = 0 ifFalse: [ self error: 'Must be size=zero'].



"Remove test variables"
Smalltalk removeKey: #TestObj ifAbsent: [].
self print: #done.