ref: 3717f0fc47461529c56475309dbe6a757aa3a993
parent: d0f5ddad3688558a7bdfa185b8628e34d764c45b
author: Ori Bernstein <[email protected]>
date: Wed Dec 18 06:03:35 EST 2013
Add test for endian writing (and fix it)
--- a/bio.myr
+++ b/bio.myr
@@ -277,7 +277,7 @@
var i
for i = sizeof(@a); i != 0; i--
- putb(f, ((v >> (i - 1)*8) & 0xff) castto(byte))
+ putb(f, ((v >> ((i-1)*8)) & 0xff) castto(byte))
;;
-> sizeof(@a)
}
--- /dev/null
+++ b/test/bio-endianwr.myr
@@ -1,0 +1,42 @@
+use std
+use bio
+
+const main = {
+ var b : byte
+ var w : uint16
+ var l : uint32
+ var q : uint64
+ var f
+
+ match bio.open("tmpout/test-endianwr", bio.Wr)
+ | `std.Some bio: f = bio
+ | `std.None: std.fatal(1, "Unable to open data file")
+ ;;
+
+ /* byte */
+ /*
+ /* FIXME: compiler bug. multiplication on byte
+ values is currently broken. */
+ b = 0xaa
+ bio.putle(f, b)
+ bio.putbe(f, b)
+ */
+
+ /* word */
+ w = 0xaabb
+ bio.putle(f, w)
+ bio.putbe(f, w)
+
+ /* long */
+ l = 0xaabbccdd
+ bio.putle(f, l)
+ bio.putbe(f, l)
+
+ /* quad */
+ q = 0x11223344aabbccdd castto(uint64)
+ bio.putle(f, q)
+ bio.putbe(f, q)
+
+ /* and test for flush on close */
+ bio.close(f);
+}
--- /dev/null
+++ b/test/data/bio-endianwr-expected
@@ -1,0 +1,1 @@
+�����̻������̻�D3""3D���
\ No newline at end of file
--- a/test/tests
+++ b/test/tests
@@ -23,7 +23,7 @@
B bio-read C
B bio-write F tmpout/test-write
B bio-delim C
-#B bio-endianwr F tmpout/test-endianwr
+B bio-endianwr F tmpout/test-endianwr
#B bio-endianrd C
#B bio-unit C
#B bio-peek C