1 UnitTests addPrototype: #ByteArray derivedFrom: {TestCase}.
2 UnitTests ByteArray `>> [
3 addSlot: #width16 valued: ({16r01. 16r02} as: ByteArray).
4 addSlot: #width32 valued: ({16r01. 16r02. 16r04. 16r08} as: ByteArray).
5 addSlot: #width64 valued: ({16r01. 16r02. 16r04. 16r08. 16r10. 16r20. 16r40. 16r80} as: ByteArray)].
7 "a@(ByteArray traits) int64At: offset
8 a@(ByteArray traits) int64At: offset put: value
9 a@(ByteArray traits) bigEndianInt64At: offset
10 a@(ByteArray traits) bigEndianInt64At: offset put: word
11 a@(ByteArray traits) littleEndianInt64At: offset
12 a@(ByteArray traits) littleEndianInt64At: offset put: word"
15 tc@(UnitTests ByteArray traits) int16At
17 "TODO: Change this to use the Platform object"
18 UnitTests ByteArray width16 isLittleEndian
19 ifTrue: [tc assert: ((UnitTests ByteArray width16 int16At: 0) = 16r0201) description: '#int16At: read wrong value from #as: ByteArray']
20 ifFalse: [tc assert: ((UnitTests ByteArray width16 int16At: 0) = 16r0102) description: '#int16At: read wrong value from #as: ByteArray'].
21 tc assert: ((UnitTests ByteArray width16 bigEndianInt16At: 0) = 16r0102) description: '#bigEndianInt16At: read wrong value from #as: ByteArray'.
22 tc assert: ((UnitTests ByteArray width16 littleEndianInt16At: 0) = 16r0201) description: '#littleEndianInt16At: read wrong value from #as: ByteArray'.
25 tc@(UnitTests ByteArray traits) int16AtPut
27 b: (ByteArray newSize: 2).
28 b int16At: 0 put: 16r0102.
29 b isLittleEndian "TODO: Change this to use the Platform object"
30 ifTrue: [tc assert: (((b byteAt: 0) = 16r02) and: [(b byteAt: 1) = 16r01]) description: '#int16At:put: inserted the wrong value into the new ByteArray']
31 ifFalse: [tc assert: (((b byteAt: 0) = 16r01) and: [(b byteAt: 1) = 16r02]) description: '#int16At:put: inserted the wrong value into the new ByteArray'].
33 b bigEndianInt16At: 0 put: 16r0102.
34 tc assert: (((b byteAt: 0) = 16r01) and: [(b byteAt: 1) = 16r02]) description: '#bigEndianInt16At:put: inserted wrong value in new ByteArray'.
35 b littleEndianInt16At: 0 put: 16r0102.
36 tc assert: (((b byteAt: 0) = 16r02) and: [(b byteAt: 1) = 16r01]) description: '#littleEndianInt16At: inserted wrong value in new ByteArray'.
40 tc@(UnitTests ByteArray traits) int32At
42 "TODO: Change this to use the Platform object"
43 UnitTests ByteArray width32 isLittleEndian
44 ifTrue: [tc assert: ((UnitTests ByteArray width32 int32At: 0) = 16r08040201) description: '#int32At: read wrong value from #as: ByteArray']
45 ifFalse: [tc assert: ((UnitTests ByteArray width32 int32At: 0) = 16r01020408) description: '#int32At: read wrong value from #as: ByteArray'].
46 tc assert: ((UnitTests ByteArray width32 bigEndianInt32At: 0) = 16r01020408) description: '#bigEndianInt32At: read wrong value from #as: ByteArray'.
47 tc assert: ((UnitTests ByteArray width32 littleEndianInt32At: 0) = 16r08040201) description: '#littleEndianInt32At: read wrong value from #as: ByteArray'.
51 tc@(UnitTests ByteArray traits) int32AtPut
53 b: (ByteArray newSize: 4).
54 b int32At: 0 put: 16r01020408.
55 b isLittleEndian "TODO: Change this to use the Platform object"
56 ifTrue: [tc assert: (b = UnitTests ByteArray width32 reversed) description: '#int32At:put: inserted the wrong value into the new ByteArray']
57 ifFalse: [tc assert: (b = UnitTests ByteArray width32) description: '#int32At:put: inserted the wrong value into the new ByteArray'].
59 b bigEndianInt32At: 0 put: 16r01020408.
60 tc assert: (b = UnitTests ByteArray width32) description: '#bigEndianInt32At:put: inserted wrong value in new ByteArray'.
61 b littleEndianInt32At: 0 put: 16r01020408.
62 tc assert: (b = UnitTests ByteArray width32 reversed) description: '#littleEndianInt32AtPut: inserted wrong value in new ByteArray'.
66 tc@(UnitTests ByteArray traits) int64At
68 "TODO: Change this to use the Platform object"
69 UnitTests ByteArray width64 isLittleEndian
70 ifTrue: [tc assert: ((UnitTests ByteArray width64 int64At: 0) = 16r8040201008040201) description: '#int64At: read wrong value from #as: ByteArray']
71 ifFalse: [tc assert: ((UnitTests ByteArray width64 int64At: 0) = 16r0102040810204080) description: '#int64At: read wrong value from #as: ByteArray'].
72 tc assert: ((UnitTests ByteArray width64 bigEndianInt64At: 0) = 16r0102040810204080) description: '#bigEndianInt64At: read wrong value from #as: ByteArray'.
73 tc assert: ((UnitTests ByteArray width64 littleEndianInt64At: 0) = 16r8040201008040201) description: '#littleEndianInt64At: read wrong value from #as: ByteArray'.
76 tc@(UnitTests ByteArray traits) int64AtPut
78 b: (ByteArray newSize: 8).
79 b int64At: 0 put: 16r0102040810204080.
80 b isLittleEndian "TODO: Change this to use the Platform object"
81 ifTrue: [tc assert: (b = UnitTests ByteArray width64 reversed) description: '#int64At:put: inserted the wrong value into the new ByteArray']
82 ifFalse: [tc assert: (b = UnitTests ByteArray width64) description: '#int64At:put: inserted the wrong value into the new ByteArray'].
84 b bigEndianInt64At: 0 put: 16r0102040810204080.
85 tc assert: (b = UnitTests ByteArray width64) description: '#bigEndianInt64At:put: inserted wrong value in new ByteArray'.
86 b littleEndianInt64At: 0 put: 16r0102040810204080.
87 tc assert: (b = UnitTests ByteArray width64 reversed) description: '#littleEndianInt64AtPut: inserted wrong value in new ByteArray'.
91 tc@(UnitTests ByteArray traits) suite
92 [tc suiteForSelectors: {