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

test[S8Ref] int64

"Set test variables"
JsMaxInt := 9007199254740992.
JsMinInt := -9007199254740992.



"should allow simple ints to be written and read"
| buffer value result |
buffer := NodeBuffer size: (S8Ref sizeOf: #int64).
value := 123456789.
S8Ref current writeInt64: buffer offset: 0 value: value.
result := S8Ref current readInt64: buffer offset: 0.
value = result ifFalse: [ self error: 'Wrong value' ].


"should allow INT64_MAX to be written and read"
| buffer value result |
buffer := NodeBuffer size: (S8Ref sizeOf: #int64).
value := '9223372036854775807'.
S8Ref current writeInt64: buffer offset: 0 value: value.
result := S8Ref current readInt64: buffer offset: 0.
value = result ifFalse: [ self error: 'Wrong value' ].


"should allow a hex String to be input (signed)"
| buffer value result |
buffer := NodeBuffer size: (S8Ref sizeOf: #int64).
value := '-0x1234567890'.
S8Ref current writeInt64: buffer offset: 0 value: value.
result := S8Ref current readInt64: buffer offset: 0.
(# #parseInt: value base: 16) = result ifFalse: [ self error: 'Wrong value' ].


"should allow a octal String to be input (signed)"
| buffer value result |
buffer := NodeBuffer size: (S8Ref sizeOf: #int64).
value := '-0777'.
S8Ref current writeInt64: buffer offset: 0 value: value.
result := S8Ref current readInt64: buffer offset: 0.
(# #parseInt: value base: 8) = result ifFalse: [ self error: 'Wrong value' ].


"should allow a hex String to be input (unsigned)"
| buffer value result |
buffer := NodeBuffer size: (S8Ref sizeOf: #int64).
value := '0x1234567890'.
S8Ref current writeInt64: buffer offset: 0 value: value.
result := S8Ref current readInt64: buffer offset: 0.
(# #parseInt: value base: 16) = result ifFalse: [ self error: 'Wrong value' ].


"should allow a octal String to be input (unsigned)"
| buffer value result |
buffer := NodeBuffer size: (S8Ref sizeOf: #int64).
value := '0777'.
S8Ref current writeInt64: buffer offset: 0 value: value.
result := S8Ref current readInt64: buffer offset: 0.
(# #parseInt: value base: 8) = result ifFalse: [ self error: 'Wrong value' ].


"should return a Number when reading JS_MIN_INT"
| buffer value result |
buffer := NodeBuffer size: (S8Ref sizeOf: #int64).
value := JsMinInt.
S8Ref current writeInt64: buffer offset: 0 value: value.
result := S8Ref current readInt64: buffer offset: 0.
result isNumber ifFalse: [ self error: 'Must be number' ].
value = result ifFalse: [ self error: 'Wrong value' ].


"should return a Number when reading JS_MAX_INT"
| buffer value result |
buffer := NodeBuffer size: (S8Ref sizeOf: #int64).
value := JsMaxInt.
S8Ref current writeInt64: buffer offset: 0 value: value.
result := S8Ref current readInt64: buffer offset: 0.
result isNumber ifFalse: [ self error: 'Must be number' ].
value = result ifFalse: [ self error: 'Wrong value' ].


"should return a String when reading JS_MAX_INT+1"
| buffer value result |
buffer := NodeBuffer size: (S8Ref sizeOf: #int64).
value := '9007199254740993'.
S8Ref current writeInt64: buffer offset: 0 value: value.
result := S8Ref current readInt64: buffer offset: 0.
result isString ifFalse: [ self error: 'Must be String' ].
value = result ifFalse: [ self error: 'Wrong value' ].


"should return a String when reading JS_MIN_INT-1"
| buffer value result |
buffer := NodeBuffer size: (S8Ref sizeOf: #int64).
value := '-9007199254740993'.
S8Ref current writeInt64: buffer offset: 0 value: value.
result := S8Ref current readInt64: buffer offset: 0.
result isString ifFalse: [ self error: 'Must be String' ].
value = result ifFalse: [ self error: 'Wrong value' ].


"should return a Number when reading 0, even when written as a String"
| buffer value result |
buffer := NodeBuffer size: (S8Ref sizeOf: #int64).
value := #0.
S8Ref current writeInt64: buffer offset: 0 value: value.
result := S8Ref current readInt64: buffer offset: 0.
result isNumber ifFalse: [ self error: 'Must be number' ].
0 = result ifFalse: [ self error: 'Wrong value' ].


"should throw a no digits Error when writing an invalid String (signed)"
| buffer value result |
buffer := NodeBuffer size: (S8Ref sizeOf: #int64).
value := #foo.
[ S8Ref current writeInt64: buffer offset: 0 value: value.
] on: Error do: [:ex| ^self print: 'ok - ' ,ex toString stream nextLine ].
self error: 'Must throw an error'


"should throw a no digits Error when writing an invalid String (signed)"
| buffer value result |
buffer := NodeBuffer size: (S8Ref sizeOf: #uint64).
value := #foo.
[ S8Ref current writeUInt64: buffer offset: 0 value: value.
] on: Error do: [:ex| ^self print: 'ok - ' ,ex toString stream nextLine ].
self error: 'Must throw an error'


"should throw an out of range Error when writing an invalid String (signed)"
| buffer value result |
buffer := NodeBuffer size: (S8Ref sizeOf: #int64).
value := #10000000000000000000000000.
[ S8Ref current writeInt64: buffer offset: 0 value: value.
] on: Error do: [:ex| ^self print: 'ok - ' ,ex toString stream nextLine ].
self error: 'Must throw an error'


"should throw an out of range Error when writing an invalid String (unsigned)"
| buffer value result |
buffer := NodeBuffer size: (S8Ref sizeOf: #uint64).
value := #10000000000000000000000000.
[ S8Ref current writeInt64: buffer offset: 0 value: value.
] on: Error do: [:ex| ^self print: 'ok - ' ,ex toString stream nextLine ].
self error: 'Must throw an error'


"should throw an Error when reading an int64_t from the NULL pointer"
| buffer value result |
[ result := S8Ref current readInt64: S8Ref null offset: 0
] on: Error do: [:ex| ^self print: 'ok - ' ,ex toString stream nextLine ].
self error: 'Must throw an error'


"should throw an Error when reading an uint64_t from the NULL pointer"
| buffer value result |
[ result := S8Ref current readUInt64: S8Ref null offset: 0
] on: Error do: [:ex| ^self print: 'ok - ' ,ex toString stream nextLine ].
self error: 'Must throw an error'


Endianness


"should read and write a signed LE 64-bit integer"
| buffer value result sizeof |
buffer := NodeBuffer size: (S8Ref sizeOf: #int64).
value := -123456789.
S8Ref current writeInt64LE: buffer offset: 0 value: value.
result := S8Ref current readInt64LE: buffer offset: 0.
value = result ifFalse: [ self error: 'Wrong value (',result,')' ].


"should read and write a unsigned LE 64-bit integer"
| buffer value result |
buffer := NodeBuffer size: (S8Ref sizeOf: #uint64).
value := 123456789.
S8Ref current writeUInt64LE: buffer offset: 0 value: value.
result := S8Ref current readUInt64LE: buffer offset: 0.
value = result ifFalse: [ self error: 'Wrong value (',result,')'  ].


"should read and write a signed BE 64-bit integer"
| buffer value result |
buffer := NodeBuffer size: (S8Ref sizeOf: #int64).
value := -123456789.
S8Ref current writeInt64BE: buffer offset: 0 value: value.
result := S8Ref current readInt64BE: buffer offset: 0.
value = result ifFalse: [ self error: 'Wrong value (',result,')'  ].


"should read and write a unsigned BE 64-bit integer"
| buffer value result |
buffer := NodeBuffer size: (S8Ref sizeOf: #uint64).
value := 123456789.
S8Ref current writeUInt64BE: buffer offset: 0 value: value.
result := S8Ref current readUInt64BE: buffer offset: 0.
value = result ifFalse: [ self error: 'Wrong value (',result,')'  ].