1 ! Copyright (C) 2011 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien.endian classes.struct io
4 io.encodings.binary io.streams.byte-array kernel tools.test
22 CONSTANT: endian-bytes-0f B{
28 HEX: 0 HEX: 0 HEX: 0 HEX: ff
29 HEX: 0 HEX: 0 HEX: 0 HEX: ff
30 HEX: 0 HEX: 0 HEX: 0 HEX: ff
31 HEX: 0 HEX: 0 HEX: 0 HEX: ff
33 HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: ff
34 HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: ff
35 HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: ff
36 HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: ff
39 CONSTANT: endian-bytes-f0 B{
45 HEX: ff HEX: 0 HEX: 0 HEX: 0
46 HEX: ff HEX: 0 HEX: 0 HEX: 0
47 HEX: ff HEX: 0 HEX: 0 HEX: 0
48 HEX: ff HEX: 0 HEX: 0 HEX: 0
50 HEX: ff HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: 0
51 HEX: ff HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: 0
52 HEX: ff HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: 0
53 HEX: ff HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: 0 HEX: 0
56 : endian-test-struct-0f ( -- obj )
57 endian-bytes-0f endian-struct memory>struct ;
59 : endian-test-struct-f0 ( -- obj )
60 endian-bytes-f0 endian-struct memory>struct ;
62 [ HEX: ff00 ] [ endian-test-struct-0f a>> ] unit-test
63 [ -256 ] [ endian-test-struct-0f b>> ] unit-test
64 [ HEX: 00ff ] [ endian-test-struct-0f c>> ] unit-test
65 [ HEX: 00ff ] [ endian-test-struct-0f d>> ] unit-test
67 [ HEX: ff000000 ] [ endian-test-struct-0f e>> ] unit-test
68 [ -16777216 ] [ endian-test-struct-0f f>> ] unit-test
69 [ HEX: 000000ff ] [ endian-test-struct-0f g>> ] unit-test
70 [ HEX: 000000ff ] [ endian-test-struct-0f h>> ] unit-test
72 [ HEX: ff00000000000000 ] [ endian-test-struct-0f i>> ] unit-test
73 [ -72057594037927936 ] [ endian-test-struct-0f j>> ] unit-test
74 [ HEX: 00000000000000ff ] [ endian-test-struct-0f k>> ] unit-test
75 [ HEX: 00000000000000ff ] [ endian-test-struct-0f l>> ] unit-test
78 [ HEX: ff00 ] [ endian-test-struct-f0 c>> ] unit-test
79 [ -256 ] [ endian-test-struct-f0 d>> ] unit-test
80 [ HEX: 00ff ] [ endian-test-struct-f0 a>> ] unit-test
81 [ HEX: 00ff ] [ endian-test-struct-f0 b>> ] unit-test
83 [ HEX: ff000000 ] [ endian-test-struct-f0 g>> ] unit-test
84 [ -16777216 ] [ endian-test-struct-f0 h>> ] unit-test
85 [ HEX: 000000ff ] [ endian-test-struct-f0 e>> ] unit-test
86 [ HEX: 000000ff ] [ endian-test-struct-f0 f>> ] unit-test
88 [ HEX: ff00000000000000 ] [ endian-test-struct-f0 k>> ] unit-test
89 [ -72057594037927936 ] [ endian-test-struct-f0 l>> ] unit-test
90 [ HEX: 00000000000000ff ] [ endian-test-struct-f0 i>> ] unit-test
91 [ HEX: 00000000000000ff ] [ endian-test-struct-f0 j>> ] unit-test
94 [ endian-test-struct-0f binary [ write ] with-byte-writer endian-bytes-0f = ] unit-test
97 [ endian-test-struct-f0 binary [ write ] with-byte-writer endian-bytes-f0 = ] unit-test
99 LE-STRUCT: le-endian-struct
115 endian-bytes-0f le-endian-struct memory>struct
116 binary [ write ] with-byte-writer endian-bytes-0f =
121 endian-bytes-f0 le-endian-struct memory>struct
122 binary [ write ] with-byte-writer endian-bytes-f0 =
126 BE-STRUCT: be-endian-struct
142 endian-bytes-0f be-endian-struct memory>struct
143 binary [ write ] with-byte-writer endian-bytes-0f =
148 endian-bytes-f0 be-endian-struct memory>struct
149 binary [ write ] with-byte-writer endian-bytes-f0 =
152 LE-STRUCT: le-override-struct
168 endian-bytes-0f le-override-struct memory>struct
169 binary [ write ] with-byte-writer endian-bytes-0f =
174 endian-bytes-f0 le-override-struct memory>struct
175 binary [ write ] with-byte-writer endian-bytes-f0 =
178 BE-STRUCT: be-override-struct
194 endian-bytes-0f be-override-struct memory>struct
195 binary [ write ] with-byte-writer endian-bytes-0f =
200 endian-bytes-f0 be-override-struct memory>struct
201 binary [ write ] with-byte-writer endian-bytes-f0 =
205 LE-PACKED-STRUCT: le-packed-struct
211 B{ 0 0 0 0 0 0 0 3 0 0 0 } [
212 le-packed-struct memory>struct
213 binary [ write ] with-byte-writer
219 B{ 0 0 0 0 0 0 0 3 0 0 0 } le-packed-struct memory>struct
224 BE-PACKED-STRUCT: be-packed-struct
230 B{ 0 0 0 0 0 0 0 0 0 0 3 } [
231 be-packed-struct memory>struct
232 binary [ write ] with-byte-writer
238 B{ 0 0 0 0 0 0 0 0 0 0 3 } be-packed-struct memory>struct