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

test[S8Ref] ref-deref

"should work 1 layer deep"
| test one _test | Smalltalk gc.
test := NodeBuffer string: 'one layer deep'.
one := S8Ref current ref: test.
_test := S8Ref current deref: one.
_test length = test length ifFalse: [ self error: 'Invalid length' ].
_test toString = test toString ifFalse: [ self error: 'Invalid contents' ].


"should work 2 layers deep"
| test one _test two _one | Smalltalk gc.
test := NodeBuffer string: 'two layers deep'.
one := S8Ref current ref: test.
two := S8Ref current ref: one.
_one := S8Ref current deref: two.
_test := S8Ref current deref: _one.
(S8Ref current address: _one) = (S8Ref current address: one) ifFalse: [ self error: 'Invalid (one) adress' ].
(S8Ref current address: _test) = (S8Ref current address: test) ifFalse: [ self error: 'Invalid (test) adress' ].
_one length = one length ifFalse: [ self error: 'Invalid (one) length' ].
_test length = test length ifFalse: [ self error: 'Invalid (test) length' ].
_test toString = test toString ifFalse: [ self error: 'Invalid contents' ].


"should throw when derefing a Buffer with no type"
| test | Smalltalk gc.
test := NodeBuffer string: '???'.
[ S8Ref current deref: test
] on: Error do: [:ex| self print: 'ok - thrown ' ,ex toString stream nextLine ].
^self error: 'Should thrown unknown type'


"should throw when derefing a Buffer with no type 2"
| test r dtest | Smalltalk gc.
test := NodeBuffer string: '???'.
r := S8Ref current ref: test.
dtest := S8Ref current deref: r.
(S8Ref current address: test) = (S8Ref current address: dtest) ifFalse: [ ^self error: 'Invalid address' ].
[ S8Ref current deref: dtest
] on: Error do: [:ex| self print: 'ok - thrown ' ,ex toString stream nextLine ].
self error: 'Should thrown unknown type'


"should deref() a char type properly"
| test sizeof | Smalltalk gc.
test := NodeBuffer size: (S8Ref sizeOf: #char).
test type = (S8Ref type: #char) ifFalse: [ ^self error: 'Invalid type=',test type name ].
test at: 1 put: 50.
50 = (S8Ref current deref: test) ifFalse: [ ^self error: 'Invalid contents (50)' ].
test at: 1 put: 127.
127 = (S8Ref current deref: test) ifFalse: [ ^self error: 'Invalid contents (127)' ].


"should not throw when calling ref()/deref() on a void type"
| test | Smalltalk gc.
test := S8Ref alloc: (S8Ref type: #void).
test deref isNil ifFalse: [ ^self error: 'Invalid deref of void type' ].