1 UnitTests define: #ByteArray &parents: {TestCase} &slots: {
2 #width16 -> ({16r01. 16r02} as: ByteArray).
3 #width32 -> ({16r01. 16r02. 16r04. 16r08} as: ByteArray).
4 #width64 -> ({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"
14 tc@(UnitTests ByteArray traits) int16At
16 "TODO: Change this to use the Platform object"
17 UnitTests ByteArray width16 isLittleEndian
18 ifTrue: [tc assert: ((UnitTests ByteArray width16 int16At: 0) = 16r0201) description: '#int16At: read wrong value from #as: ByteArray']
19 ifFalse: [tc assert: ((UnitTests ByteArray width16 int16At: 0) = 16r0102) description: '#int16At: read wrong value from #as: ByteArray'].
20 tc assert: ((UnitTests ByteArray width16 bigEndianInt16At: 0) = 16r0102) description: '#bigEndianInt16At: read wrong value from #as: ByteArray'.
21 tc assert: ((UnitTests ByteArray width16 littleEndianInt16At: 0) = 16r0201) description: '#littleEndianInt16At: read wrong value from #as: ByteArray'.
24 tc@(UnitTests ByteArray traits) int16AtPut
26 b ::= ByteArray newSize: 2.
27 b int16At: 0 put: 16r0102.
28 b isLittleEndian "TODO: Change this to use the Platform object"
29 ifTrue: [tc assert: (((b byteAt: 0) = 16r02) and: [(b byteAt: 1) = 16r01]) description: '#int16At:put: inserted the wrong value into the new ByteArray']
30 ifFalse: [tc assert: (((b byteAt: 0) = 16r01) and: [(b byteAt: 1) = 16r02]) description: '#int16At:put: inserted the wrong value into the new ByteArray'].
32 b bigEndianInt16At: 0 put: 16r0102.
33 tc assert: (((b byteAt: 0) = 16r01) and: [(b byteAt: 1) = 16r02]) description: '#bigEndianInt16At:put: inserted wrong value in new ByteArray'.
34 b littleEndianInt16At: 0 put: 16r0102.
35 tc assert: (((b byteAt: 0) = 16r02) and: [(b byteAt: 1) = 16r01]) description: '#littleEndianInt16At: inserted wrong value in new ByteArray'.
38 tc@(UnitTests ByteArray traits) int32At
40 "TODO: Change this to use the Platform object"
41 UnitTests ByteArray width32 isLittleEndian
42 ifTrue: [tc assert: ((UnitTests ByteArray width32 int32At: 0) = 16r08040201) description: '#int32At: read wrong value from #as: ByteArray']
43 ifFalse: [tc assert: ((UnitTests ByteArray width32 int32At: 0) = 16r01020408) description: '#int32At: read wrong value from #as: ByteArray'].
44 tc assert: ((UnitTests ByteArray width32 bigEndianInt32At: 0) = 16r01020408) description: '#bigEndianInt32At: read wrong value from #as: ByteArray'.
45 tc assert: ((UnitTests ByteArray width32 littleEndianInt32At: 0) = 16r08040201) description: '#littleEndianInt32At: read wrong value from #as: ByteArray'.
48 tc@(UnitTests ByteArray traits) int32AtPut
50 b ::= ByteArray newSize: 4.
51 b int32At: 0 put: 16r01020408.
52 b isLittleEndian "TODO: Change this to use the Platform object"
53 ifTrue: [tc assert: (b = UnitTests ByteArray width32 reversed) description: '#int32At:put: inserted the wrong value into the new ByteArray']
54 ifFalse: [tc assert: (b = UnitTests ByteArray width32) description: '#int32At:put: inserted the wrong value into the new ByteArray'].
56 b bigEndianInt32At: 0 put: 16r01020408.
57 tc assert: (b = UnitTests ByteArray width32) description: '#bigEndianInt32At:put: inserted wrong value in new ByteArray'.
58 b littleEndianInt32At: 0 put: 16r01020408.
59 tc assert: (b = UnitTests ByteArray width32 reversed) description: '#littleEndianInt32AtPut: inserted wrong value in new ByteArray'.
62 tc@(UnitTests ByteArray traits) int64At
64 "TODO: Change this to use the Platform object"
65 UnitTests ByteArray width64 isLittleEndian
66 ifTrue: [tc assert: ((UnitTests ByteArray width64 int64At: 0) = 16r8040201008040201) description: '#int64At: read wrong value from #as: ByteArray']
67 ifFalse: [tc assert: ((UnitTests ByteArray width64 int64At: 0) = 16r0102040810204080) description: '#int64At: read wrong value from #as: ByteArray'].
68 tc assert: ((UnitTests ByteArray width64 bigEndianInt64At: 0) = 16r0102040810204080) description: '#bigEndianInt64At: read wrong value from #as: ByteArray'.
69 tc assert: ((UnitTests ByteArray width64 littleEndianInt64At: 0) = 16r8040201008040201) description: '#littleEndianInt64At: read wrong value from #as: ByteArray'.
72 tc@(UnitTests ByteArray traits) int64AtPut
74 b ::= ByteArray newSize: 8.
75 b int64At: 0 put: 16r0102040810204080.
76 b isLittleEndian "TODO: Change this to use the Platform object"
77 ifTrue: [tc assert: (b = UnitTests ByteArray width64 reversed) description: '#int64At:put: inserted the wrong value into the new ByteArray']
78 ifFalse: [tc assert: (b = UnitTests ByteArray width64) description: '#int64At:put: inserted the wrong value into the new ByteArray'].
80 b bigEndianInt64At: 0 put: 16r0102040810204080.
81 tc assert: (b = UnitTests ByteArray width64) description: '#bigEndianInt64At:put: inserted wrong value in new ByteArray'.
82 b littleEndianInt64At: 0 put: 16r0102040810204080.
83 tc assert: (b = UnitTests ByteArray width64 reversed) description: '#littleEndianInt64AtPut: inserted wrong value in new ByteArray'.
86 tc@(UnitTests ByteArray traits) suite
87 [tc suiteForSelectors: {